From 831649bb680c41c6d663ae6fa86d13f4f8bebdd8 Mon Sep 17 00:00:00 2001 From: Joshua Diamond Date: Fri, 10 Apr 2020 23:55:20 -0400 Subject: [PATCH] Refactor spidey3 userspace to use rgb layer blink --- users/spidey3/config.h | 1 + users/spidey3/layer_rgb.c | 123 +++++++++++++++++++++----------------- users/spidey3/spidey3.c | 13 +++- users/spidey3/spidey3.h | 18 ++++-- 4 files changed, 90 insertions(+), 65 deletions(-) diff --git a/users/spidey3/config.h b/users/spidey3/config.h index 9da7f5530259..8713ef183d08 100644 --- a/users/spidey3/config.h +++ b/users/spidey3/config.h @@ -3,3 +3,4 @@ #define LED_DISABLE_WHEN_USB_SUSPENDED true #define RGB_DISABLE_WHEN_USB_SUSPENDED true #define RGBLIGHT_LAYERS +#define RGBLIGHT_LAYER_BLINK diff --git a/users/spidey3/layer_rgb.c b/users/spidey3/layer_rgb.c index 75e66384e272..7fe9012042b3 100644 --- a/users/spidey3/layer_rgb.c +++ b/users/spidey3/layer_rgb.c @@ -25,107 +25,118 @@ void eeconfig_init_user_rgb(void) spidey_swirl(); } -const rgblight_segment_t PROGMEM _capslock_layer[] = RGBLIGHT_LAYER_SEGMENTS( {0, 2, HSV_AZURE}, {14, 2, HSV_AZURE} ); -const rgblight_segment_t PROGMEM _layer1_layer[] = RGBLIGHT_LAYER_SEGMENTS( {7, 1, HSV_PURPLE} ); -const rgblight_segment_t PROGMEM _layer2_layer[] = RGBLIGHT_LAYER_SEGMENTS( {10, 3, HSV_MAGENTA} ); -const rgblight_segment_t PROGMEM _layer3_layer[] = RGBLIGHT_LAYER_SEGMENTS( {10, 1, HSV_GREEN} ); -const rgblight_segment_t PROGMEM _yes_layer[] = RGBLIGHT_LAYER_SEGMENTS( {9, 6, HSV_GREEN} ); -const rgblight_segment_t PROGMEM _no_layer[] = RGBLIGHT_LAYER_SEGMENTS( {9, 6, HSV_RED} ); +const rgblight_segment_t PROGMEM _capslock_layer[] = RGBLIGHT_LAYER_SEGMENTS( {0, 2, HSV_AZURE}, {RGBLED_NUM-2, 2, HSV_AZURE} ); // 0 +const rgblight_segment_t PROGMEM _scrolllock_layer[] = RGBLIGHT_LAYER_SEGMENTS( {2, 2, HSV_PURPLE}, {RGBLED_NUM-4, 2, HSV_PURPLE} ); // 1 + +#define LAYER_OFFSET 2 +const rgblight_segment_t PROGMEM _layer1_layer[] = RGBLIGHT_LAYER_SEGMENTS( {RGBLED_NUM/2-1, 1, HSV_PURPLE} ); // 2 +const rgblight_segment_t PROGMEM _layer2_layer[] = RGBLIGHT_LAYER_SEGMENTS( {10, 3, HSV_MAGENTA} ); // 3 +const rgblight_segment_t PROGMEM _layer3_layer[] = RGBLIGHT_LAYER_SEGMENTS( {10, 1, HSV_GREEN} ); // 4 + +#define ACK_OFFSET 5 +const rgblight_segment_t PROGMEM _no_layer[] = RGBLIGHT_LAYER_SEGMENTS( {9, 6, HSV_RED} ); // 5 +const rgblight_segment_t PROGMEM _yes_layer[] = RGBLIGHT_LAYER_SEGMENTS( {9, 6, HSV_GREEN} ); // 6 +const rgblight_segment_t PROGMEM _startup_layer[] = RGBLIGHT_LAYER_SEGMENTS( {0, RGBLED_NUM, HSV_BLUE} ); // 7 // Now define the array of layers. Later layers take precedence const rgblight_segment_t* const PROGMEM _rgb_layers[] = - RGBLIGHT_LAYERS_LIST( _capslock_layer, _layer1_layer, _layer2_layer, _layer3_layer, _yes_layer, _no_layer ); + RGBLIGHT_LAYERS_LIST( _capslock_layer, _scrolllock_layer, _layer1_layer, _layer2_layer, _layer3_layer, _no_layer, _yes_layer, _startup_layer ); const uint8_t PROGMEM _n_rgb_layers = sizeof(_rgb_layers) / sizeof(_rgb_layers[0]) - 1; void clear_rgb_layers() { + dprint("clear_rgb_layers()\n"); for (uint8_t i=0; i<_n_rgb_layers; i++) { rgblight_set_layer_state(i, false); } } void do_rgb_layers(layer_state_t state, uint8_t start, uint8_t end) { - dprint("do_rgb_layers()\n"); for (uint8_t i=start; i %u\n", yn, layer); + rgblight_blink_layer(layer, RGB_LAYER_ACK_DURATION); } extern keymap_config_t keymap_config; +extern rgblight_config_t rgblight_config; bool process_record_user_rgb(uint16_t keycode, keyrecord_t *record) { - bool pressed = record->event.pressed; - - switch (keycode) { - case SPI_GLO: - if (pressed) { - spidey_swirl(); - } - return false; - - // Acks follow... - case DEBUG: - rgb_layer_ack(debug_enable, pressed); - return false; - - case SPI_LNX: - case SPI_OSX: - case SPI_WIN: - rgb_layer_ack(true, pressed); - return false; - - // Tricky! - // For these, on press the toggle hasn't happened yet, - // so we need a little logic to invert, assuming that - // on key press the flag WILL be toggled, and on key - // release the flag has already been toggled. + if (record->event.pressed) { + switch (keycode) { + case SPI_GLO: + spidey_swirl(); + return false; + } + } + + return true; +} + +void post_process_record_user_rgb(uint16_t keycode, keyrecord_t *record) { + + switch (keycode) { + // Acks follow... + case DEBUG: + rgb_layer_ack(debug_enable); + break; + + case SPI_LNX: + case SPI_OSX: + case SPI_WIN: + rgb_layer_ack(true); + break; + + case RGB_TOG: + rgb_layer_ack(rgblight_config.enable); + break; #ifdef VELOCIKEY_ENABLE - case VLK_TOG: - rgb_layer_ack(pressed != velocikey_enabled(), pressed); - return true; + case VLK_TOG: + rgb_layer_ack(velocikey_enabled()); + break; #endif #ifdef NKRO_ENABLE - case NK_TOGG: - case NK_ON: - case NK_OFF: - rgb_layer_ack(pressed != keymap_config.nkro, pressed); - return true; + case NK_TOGG: + case NK_ON: + case NK_OFF: + rgb_layer_ack(keymap_config.nkro); + break; #endif - } + } - return true; } diff --git a/users/spidey3/spidey3.c b/users/spidey3/spidey3.c index 8be99dea046a..7c69b8365bc8 100644 --- a/users/spidey3/spidey3.c +++ b/users/spidey3/spidey3.c @@ -20,7 +20,7 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) { } eeconfig_update_debug(debug_config.raw); #endif - break; + return false; case SPI_LNX: dprint("SPI_LNX\n"); set_single_persistent_default_layer(_BASE); @@ -49,10 +49,17 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) { #ifdef RGBLIGHT_ENABLE bool res = process_record_user_rgb(keycode, record); - if (res) return true; + if (!res) return false; #endif - return false; + return true; +} + +void post_process_record_user(uint16_t keycode, keyrecord_t *record) { +#ifdef RGBLIGHT_ENABLE + post_process_record_user_rgb(keycode, record); +#endif + return; } layer_state_t default_layer_state_set_user(layer_state_t state) { diff --git a/users/spidey3/spidey3.h b/users/spidey3/spidey3.h index 224858391dce..affcf9d7a859 100644 --- a/users/spidey3/spidey3.h +++ b/users/spidey3/spidey3.h @@ -13,12 +13,6 @@ enum userspace_layers { _FN, }; -enum rgb_base_layer { - RGB_LAYER_BASE_DEFAULT = _BASE, - RGB_LAYER_BASE_REGULAR = _NUMPAD, - RGB_LAYER_BASE_ACKS = _FN+1, -}; - enum custom_keycodes { SPI_GLO = SAFE_RANGE, SPI_LNX, @@ -27,13 +21,25 @@ enum custom_keycodes { }; #ifdef RGBLIGHT_ENABLE + +enum layer_base { + LAYER_BASE_DEFAULT = _BASE, + LAYER_BASE_REGULAR = _NUMPAD, + LAYER_BASE_END = _FN+1, +}; + +#define RGB_LAYER_ACK_DURATION 500 +#define RGB_LAYER_WELCOME_DURATION 750 + void eeconfig_init_user_rgb(void); void matrix_init_user_rgb(void); void keyboard_post_init_user_rgb(void); bool process_record_user_rgb(uint16_t keycode, keyrecord_t *record); +void post_process_record_user_rgb(uint16_t keycode, keyrecord_t *record); layer_state_t layer_state_set_user_rgb(layer_state_t state); layer_state_t default_layer_state_set_user_rgb(layer_state_t state); bool led_update_user_rgb(led_t led_state); +void rgb_layer_ack(bool yn); void clear_rgb_layers(void); #endif