Skip to content

Commit

Permalink
added rgb functions for encoders as well
Browse files Browse the repository at this point in the history
  • Loading branch information
sadekbaroudi committed May 1, 2023
1 parent 6ffd03f commit b5c09a9
Show file tree
Hide file tree
Showing 7 changed files with 301 additions and 15 deletions.
28 changes: 28 additions & 0 deletions keyboards/fingerpunch/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,18 @@ enum userspace_custom_keycodes {

The fingerpunch firmware has some pre-defined encoder behaviors, which you can specify on a per encoder and per layer basis. See the table below. If you wanted the first encoder (encoder 0) to behave as DPI pointing on layer 2, you'd set `#define FP_ENC_0_LAYER_DPI_POINTING 2` in your config.h

If you don't want to use this functionality, you can override it by creating your own `encoder_update_user()` function and return false at the end. This will bypass the fingerpunch encoder logic.

For example:
```c
bool encoder_update_kb(uint8_t index, bool clockwise) {
// Your encoder logic goes here

// return false to avoid processing the encoder_update_kb() function that fingerpunch uses
return false;
}
```
**Please note that there cannot be duplicate values per encoder config.** Below is an example of a configuration that will work. Note that you aren't limited to 0-6. If you have 8 or 9 layers, you can specify any layer, as long as none have the same layer value.
```c
Expand All @@ -106,6 +118,10 @@ The fingerpunch firmware has some pre-defined encoder behaviors, which you can s
#define FP_ENC_0_LAYER_SUPER_TAB 1
#define FP_ENC_0_LAYER_SUPER_CTRL_TAB 2
#define FP_ENC_0_LAYER_SCROLL_WHEEL 5
#define FP_ENC_0_LAYER_RGB_MODE 7
#define FP_ENC_0_LAYER_RGB_HUE 8
#define FP_ENC_0_LAYER_RGB_SAT 9
#define FP_ENC_0_LAYER_RGB_VAL 10
#define FP_ENC_1_LAYER_SUPER_TAB 4
#define FP_ENC_1_LAYER_PGUP_PGDN 6
Expand All @@ -114,6 +130,10 @@ The fingerpunch firmware has some pre-defined encoder behaviors, which you can s
#define FP_ENC_1_LAYER_SUPER_CTRL_TAB 5
#define FP_ENC_1_LAYER_SCROLL_WHEEL 2
#define FP_ENC_1_LAYER_VOLUME 0
#define FP_ENC_1_LAYER_RGB_MODE 7
#define FP_ENC_1_LAYER_RGB_HUE 8
#define FP_ENC_1_LAYER_RGB_SAT 9
#define FP_ENC_1_LAYER_RGB_VAL 10
```

| Setting | Description | Default |
Expand All @@ -125,13 +145,21 @@ The fingerpunch firmware has some pre-defined encoder behaviors, which you can s
| `FP_ENC_0_LAYER_SUPER_TAB` | Clockwise cmd/alt tab, counter clockwise shift cmd/alt tab (see `FP_MAC_PREFERRED` to determine if it uses cmd or alt) | `4` |
| `FP_ENC_0_LAYER_SUPER_CTRL_TAB` | Clockwise ctrl tab, counter clockwise volume down | `5` |
| `FP_ENC_0_LAYER_SCROLL_WHEEL` | Clockwise scroll wheel down, counter clockwise scroll wheel down | `6` |
| `FP_ENC_0_LAYER_RGB_MODE` | Clockwise to step forward in RGB mode, counter clockwise to step backwards in RGB mode | `7` |
| `FP_ENC_0_LAYER_RGB_HUE` | Clockwise to increase RGB hue, counter clockwise to decrease RGB hue | `8` |
| `FP_ENC_0_LAYER_RGB_SAT` | Clockwise to increase RGB saturation, counter clockwise to decrease RGB saturation | `9` |
| `FP_ENC_0_LAYER_RGB_VAL` | Clockwise to increase RGB value (typically brightness), counter clockwise to decrease RGB value | `10` |
| `FP_ENC_1_LAYER_SUPER_TAB` | Same as `FP_ENC_0_LAYER_SUPER_TAB`, but for encoder 1 | `0` |
| `FP_ENC_1_LAYER_PGUP_PGDN` | Same as `FP_ENC_0_LAYER_PGUP_PGDN`, but for encoder 1 | `1` |
| `FP_ENC_1_LAYER_ZOOM` | Same as `FP_ENC_0_LAYER_ZOOM`, but for encoder 1 | `2` |
| `FP_ENC_1_LAYER_DPI_POINTING` | Same as `FP_ENC_0_LAYER_DPI_POINTING`, but for encoder 1 | `3` |
| `FP_ENC_1_LAYER_SUPER_CTRL_TAB` | Same as `FP_ENC_0_LAYER_SUPER_CTRL_TAB`, but for encoder 1 | `4` |
| `FP_ENC_1_LAYER_SCROLL_WHEEL` | Same as `FP_ENC_0_LAYER_SCROLL_WHEEL`, but for encoder 1 | `5` |
| `FP_ENC_1_LAYER_VOLUME` | Same as `FP_ENC_0_LAYER_VOLUME`, but for encoder 1 | `6` |
| `FP_ENC_1_LAYER_RGB_MODE` | Same as `FP_ENC_0_LAYER_RGB_MODE`, but for encoder 1 | `7` |
| `FP_ENC_1_LAYER_RGB_HUE` | Same as `FP_ENC_0_LAYER_RGB_HUE`, but for encoder 1 | `8` |
| `FP_ENC_1_LAYER_RGB_SAT` | Same as `FP_ENC_0_LAYER_RGB_SAT`, but for encoder 1 | `9` |
| `FP_ENC_1_LAYER_RGB_VAL` | Same as `FP_ENC_0_LAYER_RGB_VAL`, but for encoder 1 | `10` |

## Pointing Device

Expand Down
132 changes: 132 additions & 0 deletions keyboards/fingerpunch/src/fp_encoder.c
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,72 @@ bool encoder_update_kb(uint8_t index, bool clockwise) {
#endif
}
break;
#if defined(RGBLIGHT_ENABLE) || defined(RGB_MATRIX_ENABLE)
case FP_ENC_0_LAYER_RGB_MODE:
// rgb mode step
if (clockwise){
#ifdef ENCODERS_A_REVERSE
fp_rgblight_step_reverse();
#else
fp_rgblight_step();
#endif
} else{
#ifdef ENCODERS_A_REVERSE
fp_rgblight_step();
#else
fp_rgblight_step_reverse();
#endif
}
break;
case FP_ENC_0_LAYER_RGB_HUE:
// rgb hue change
if (clockwise){
#ifdef ENCODERS_A_REVERSE
fp_rgblight_decrease_hue();
#else
fp_rgblight_increase_hue();
#endif
} else{
#ifdef ENCODERS_A_REVERSE
fp_rgblight_increase_hue();
#else
fp_rgblight_decrease_hue();
#endif
}
break;
case FP_ENC_0_LAYER_RGB_SAT:
// rgb saturation change
if (clockwise){
#ifdef ENCODERS_A_REVERSE
fp_rgblight_decrease_sat();
#else
fp_rgblight_increase_sat();
#endif
} else{
#ifdef ENCODERS_A_REVERSE
fp_rgblight_increase_sat();
#else
fp_rgblight_decrease_sat();
#endif
}
break;
case FP_ENC_0_LAYER_RGB_VAL:
// rgb value (brightness) change
if (clockwise){
#ifdef ENCODERS_A_REVERSE
fp_rgblight_decrease_val();
#else
fp_rgblight_increase_val();
#endif
} else{
#ifdef ENCODERS_A_REVERSE
fp_rgblight_increase_val();
#else
fp_rgblight_decrease_val();
#endif
}
break;
#endif // RGBLIGHT_ENABLE || RGB_MATRIX_ENABLE
case FP_ENC_0_LAYER_VOLUME:
default:
// volume up and down
Expand Down Expand Up @@ -229,6 +295,72 @@ bool encoder_update_kb(uint8_t index, bool clockwise) {
#endif
}
break;
#if defined(RGBLIGHT_ENABLE) || defined(RGB_MATRIX_ENABLE)
case FP_ENC_1_LAYER_RGB_MODE:
// rgb mode step
if (clockwise){
#ifdef ENCODERS_B_REVERSE
fp_rgblight_step_reverse();
#else
fp_rgblight_step();
#endif
} else{
#ifdef ENCODERS_B_REVERSE
fp_rgblight_step();
#else
fp_rgblight_step_reverse();
#endif
}
break;
case FP_ENC_1_LAYER_RGB_HUE:
// rgb hue change
if (clockwise){
#ifdef ENCODERS_B_REVERSE
fp_rgblight_decrease_hue();
#else
fp_rgblight_increase_hue();
#endif
} else{
#ifdef ENCODERS_B_REVERSE
fp_rgblight_increase_hue();
#else
fp_rgblight_decrease_hue();
#endif
}
break;
case FP_ENC_1_LAYER_RGB_SAT:
// rgb saturation change
if (clockwise){
#ifdef ENCODERS_B_REVERSE
fp_rgblight_decrease_sat();
#else
fp_rgblight_increase_sat();
#endif
} else{
#ifdef ENCODERS_B_REVERSE
fp_rgblight_increase_sat();
#else
fp_rgblight_decrease_sat();
#endif
}
break;
case FP_ENC_1_LAYER_RGB_VAL:
// rgb value (brightness) change
if (clockwise){
#ifdef ENCODERS_B_REVERSE
fp_rgblight_decrease_val();
#else
fp_rgblight_increase_val();
#endif
} else{
#ifdef ENCODERS_B_REVERSE
fp_rgblight_increase_val();
#else
fp_rgblight_decrease_val();
#endif
}
break;
#endif // RGBLIGHT_ENABLE || RGB_MATRIX_ENABLE
case FP_ENC_1_LAYER_SUPER_CTRL_TAB:
default:
// super ctrl tab
Expand Down
24 changes: 24 additions & 0 deletions keyboards/fingerpunch/src/fp_encoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,18 @@ bool fp_process_record_encoder(uint16_t keycode, keyrecord_t *record);
# ifndef FP_ENC_0_LAYER_SCROLL_WHEEL
# define FP_ENC_0_LAYER_SCROLL_WHEEL 6
# endif
# ifndef FP_ENC_0_LAYER_RGB_MODE
# define FP_ENC_0_LAYER_RGB_MODE 7
# endif
# ifndef FP_ENC_0_LAYER_RGB_HUE
# define FP_ENC_0_LAYER_RGB_HUE 8
# endif
# ifndef FP_ENC_0_LAYER_RGB_SAT
# define FP_ENC_0_LAYER_RGB_SAT 9
# endif
# ifndef FP_ENC_0_LAYER_RGB_VAL
# define FP_ENC_0_LAYER_RGB_VAL 10
# endif

# ifndef FP_ENC_1_LAYER_SUPER_TAB
# define FP_ENC_1_LAYER_SUPER_TAB 0
Expand All @@ -66,5 +78,17 @@ bool fp_process_record_encoder(uint16_t keycode, keyrecord_t *record);
# ifndef FP_ENC_1_LAYER_VOLUME
# define FP_ENC_1_LAYER_VOLUME 6
# endif
# ifndef FP_ENC_1_LAYER_RGB_MODE
# define FP_ENC_1_LAYER_RGB_MODE 7
# endif
# ifndef FP_ENC_1_LAYER_RGB_HUE
# define FP_ENC_1_LAYER_RGB_HUE 8
# endif
# ifndef FP_ENC_1_LAYER_RGB_SAT
# define FP_ENC_1_LAYER_RGB_SAT 9
# endif
# ifndef FP_ENC_1_LAYER_RGB_VAL
# define FP_ENC_1_LAYER_RGB_VAL 10
# endif

#endif
58 changes: 55 additions & 3 deletions keyboards/fingerpunch/src/fp_rgb_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -142,16 +142,19 @@ layer_state_t fp_layer_state_set_rgb(layer_state_t state) {
return state;
}

// Deferred exec function
uint32_t fp_rgb_set_config_from_current_values(uint32_t triger_time, void *cb_arg) {
void fp_rgb_set_config_from_current_values(void) {
fp_config.rgb_mode = rgblight_get_mode();
fp_config.rgb_hue = rgblight_get_hue();
fp_config.rgb_sat = rgblight_get_sat();
fp_config.rgb_val = rgblight_get_val();
fp_config.rgb_speed = rgblight_get_speed();
eeconfig_update_kb_datablock(&fp_config.raw);
xprintf("RGB: mode: %u, hue: %u, sat: %u, val: %u, speed: %u\n", fp_config.rgb_mode, fp_config.rgb_hue, fp_config.rgb_sat, fp_config.rgb_val, fp_config.rgb_speed);
}

// Deferred exec function
uint32_t fp_rgb_set_config_from_current_values_deferred(uint32_t triger_time, void *cb_arg) {
fp_rgb_set_config_from_current_values();
return 0;
}

Expand All @@ -166,7 +169,7 @@ bool fp_process_record_rgb_common(uint16_t keycode, keyrecord_t *record) {
// the rgb light change happens on the key release (!record->event.pressed), that means that this code gets called
// before the process_record key release
// Sooooo, need a defered exec event to handle this
defer_exec(20, fp_rgb_set_config_from_current_values, NULL);
defer_exec(20, fp_rgb_set_config_from_current_values_deferred, NULL);
}
break;
# ifndef FP_DISABLE_CUSTOM_KEYCODES
Expand Down Expand Up @@ -197,4 +200,53 @@ uint8_t fp_rgb_get_element_from_hsv(uint8_t hue, uint8_t sat, uint8_t val, uint8

return 0;
}

void fp_rgblight_step(void) {
fp_rgb_set_hsv_and_mode(fp_config.rgb_hue, fp_config.rgb_sat, fp_config.rgb_val, fp_config.rgb_mode);
rgblight_step();
fp_rgb_set_config_from_current_values();
}

void fp_rgblight_step_reverse(void) {
fp_rgb_set_hsv_and_mode(fp_config.rgb_hue, fp_config.rgb_sat, fp_config.rgb_val, fp_config.rgb_mode);
rgblight_step_reverse();
fp_rgb_set_config_from_current_values();
}

void fp_rgblight_increase_hue(void) {
fp_rgb_set_hsv_and_mode(fp_config.rgb_hue, fp_config.rgb_sat, fp_config.rgb_val, fp_config.rgb_mode);
rgblight_increase_hue();
fp_rgb_set_config_from_current_values();
}

void fp_rgblight_decrease_hue(void) {
fp_rgb_set_hsv_and_mode(fp_config.rgb_hue, fp_config.rgb_sat, fp_config.rgb_val, fp_config.rgb_mode);
rgblight_decrease_hue();
fp_rgb_set_config_from_current_values();
}

void fp_rgblight_increase_sat(void) {
fp_rgb_set_hsv_and_mode(fp_config.rgb_hue, fp_config.rgb_sat, fp_config.rgb_val, fp_config.rgb_mode);
rgblight_increase_sat();
fp_rgb_set_config_from_current_values();
}

void fp_rgblight_decrease_sat(void) {
fp_rgb_set_hsv_and_mode(fp_config.rgb_hue, fp_config.rgb_sat, fp_config.rgb_val, fp_config.rgb_mode);
rgblight_decrease_sat();
fp_rgb_set_config_from_current_values();
}

void fp_rgblight_increase_val(void) {
fp_rgb_set_hsv_and_mode(fp_config.rgb_hue, fp_config.rgb_sat, fp_config.rgb_val, fp_config.rgb_mode);
rgblight_increase_val();
fp_rgb_set_config_from_current_values();
}

void fp_rgblight_decrease_val(void) {
fp_rgb_set_hsv_and_mode(fp_config.rgb_hue, fp_config.rgb_sat, fp_config.rgb_val, fp_config.rgb_mode);
rgblight_decrease_val();
fp_rgb_set_config_from_current_values();
}

#endif
11 changes: 10 additions & 1 deletion keyboards/fingerpunch/src/fp_rgb_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,18 @@

layer_state_t fp_layer_state_set_rgb(layer_state_t state);
void fp_rgb_set_hsv_and_mode(uint8_t hue, uint8_t sat, uint8_t val, uint8_t mode);
void fp_rgblight_step(void);
void fp_rgblight_step_reverse(void);
void fp_rgblight_increase_hue(void);
void fp_rgblight_decrease_hue(void);
void fp_rgblight_increase_sat(void);
void fp_rgblight_decrease_sat(void);
void fp_rgblight_increase_val(void);
void fp_rgblight_decrease_val(void);
void fp_post_init_rgb_common(void);
bool fp_process_record_rgb_common(uint16_t keycode, keyrecord_t *record);
uint32_t fp_rgb_set_config_from_current_values(uint32_t triger_time, void *cb_arg);
void fp_rgb_set_config_from_current_values(void);
uint32_t fp_rgb_set_config_from_current_values_deferred(uint32_t triger_time, void *cb_arg);
uint8_t fp_rgb_get_element_from_hsv(uint8_t hue, uint8_t sat, uint8_t val, uint8_t whichOne);

#if defined(RGBLIGHT_ENABLE) || defined(RGB_MATRIX_ENABLE)
Expand Down
1 change: 1 addition & 0 deletions keyboards/fingerpunch/src/fp_rgb_matrix.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#ifdef RGB_MATRIX_ENABLE

void fp_rgb_set_hsv_and_mode(uint8_t hue, uint8_t sat, uint8_t val, uint8_t mode) {
xprintf("fp_rgb_set_hsv_and_mode fp_rgb_matrix.c: hue: %d, sat: %d, val: %d, mode: %d\n", hue, sat, val, mode);
rgb_matrix_sethsv_noeeprom(hue, sat, val);
rgb_matrix_mode_noeeprom(mode);
}
Expand Down
Loading

0 comments on commit b5c09a9

Please sign in to comment.