From 5229734647706054066c277ea348a6d25cc38095 Mon Sep 17 00:00:00 2001 From: Takeshi ISHII <2170248+mtei@users.noreply.github.com> Date: Tue, 5 Jun 2018 00:10:39 +0900 Subject: [PATCH] Add rgblight mode 35 (R,G,B test mode) (#3114) * add rgblight mode 35 (RGB cyclic mode) into quantum/rgblight.c * Update docs, add rgblight mode 35(RGB cyclic) * rename RGBCYCLIC to RGBTEST --- docs/feature_rgblight.md | 1 + docs/keycodes.md | 1 + quantum/quantum.c | 7 ++++++- quantum/quantum_keycodes.h | 2 ++ quantum/rgblight.c | 38 +++++++++++++++++++++++++++++++++++--- quantum/rgblight.h | 4 +++- 6 files changed, 48 insertions(+), 5 deletions(-) diff --git a/docs/feature_rgblight.md b/docs/feature_rgblight.md index 5369d2fb7..e0918d11b 100644 --- a/docs/feature_rgblight.md +++ b/docs/feature_rgblight.md @@ -146,6 +146,7 @@ These control the RGB Lighting functionality. |`RGB_MODE_KNIGHT` |`RGB_M_K` |"Knight Rider" animation mode | |`RGB_MODE_XMAS` |`RGB_M_X` |Christmas animation mode | |`RGB_MODE_GRADIENT`|`RGB_M_G` |Static gradient animation mode | +|`RGB_MODE_RGBTEST `|`RGB_M_T` |Red,Green,Blue test animation mode | note: for backwards compatibility, `RGB_SMOD` is an alias for `RGB_MOD`. diff --git a/docs/keycodes.md b/docs/keycodes.md index 9a5f6e2b3..ca81d02b6 100644 --- a/docs/keycodes.md +++ b/docs/keycodes.md @@ -283,6 +283,7 @@ This is a reference only. Each group of keys links to the page documenting their |`RGB_MODE_KNIGHT` |`RGB_M_K` |"Knight Rider" animation mode | |`RGB_MODE_XMAS` |`RGB_M_X` |Christmas animation mode | |`RGB_MODE_GRADIENT`|`RGB_M_G` |Static gradient animation mode | +|`RGB_MODE_RGBTEST` |`RGB_M_T` |Red,Green,Blue test animation mode | ## [RGB Matrix Lighting](feature_rgb_matrix.md) diff --git a/quantum/quantum.c b/quantum/quantum.c index f9b3e2197..cfa3df741 100644 --- a/quantum/quantum.c +++ b/quantum/quantum.c @@ -442,7 +442,12 @@ bool process_record_quantum(keyrecord_t *record) { } } return false; - #endif + case RGB_MODE_RGBTEST: + if (record->event.pressed) { + rgblight_mode(35); + } + return false; + #endif // defined(RGBLIGHT_ENABLE) || defined(RGB_MATRIX_ENABLE) #ifdef PROTOCOL_LUFA case OUT_AUTO: if (record->event.pressed) { diff --git a/quantum/quantum_keycodes.h b/quantum/quantum_keycodes.h index 405741eb1..f2cdb8a3b 100644 --- a/quantum/quantum_keycodes.h +++ b/quantum/quantum_keycodes.h @@ -423,6 +423,7 @@ enum quantum_keycodes { RGB_MODE_KNIGHT, RGB_MODE_XMAS, RGB_MODE_GRADIENT, + RGB_MODE_RGBTEST, // Left shift, open paren KC_LSPO, @@ -586,6 +587,7 @@ enum quantum_keycodes { #define RGB_M_K RGB_MODE_KNIGHT #define RGB_M_X RGB_MODE_XMAS #define RGB_M_G RGB_MODE_GRADIENT +#define RGB_M_T RGB_MODE_RGBTEST // L-ayer, T-ap - 256 keycode max, 16 layer max #define LT(layer, kc) (kc | QK_LAYER_TAP | ((layer & 0xF) << 8)) diff --git a/quantum/rgblight.c b/quantum/rgblight.c index db66e735b..8b2a3cd9f 100644 --- a/quantum/rgblight.c +++ b/quantum/rgblight.c @@ -42,6 +42,8 @@ __attribute__ ((weak)) const uint8_t RGBLED_KNIGHT_INTERVALS[] PROGMEM = {127, 63, 31}; __attribute__ ((weak)) const uint16_t RGBLED_GRADIENT_RANGES[] PROGMEM = {360, 240, 180, 120, 90}; +__attribute__ ((weak)) +const uint16_t RGBLED_RGBTEST_INTERVALS[] PROGMEM = {1024}; rgblight_config_t rgblight_config; @@ -238,14 +240,15 @@ void rgblight_mode_eeprom_helper(uint8_t mode, bool write_to_eeprom) { #ifdef RGBLIGHT_ANIMATIONS rgblight_timer_disable(); #endif - } else if (rgblight_config.mode >= 2 && rgblight_config.mode <= 24) { + } else if ((rgblight_config.mode >= 2 && rgblight_config.mode <= 24) || + rgblight_config.mode == 35 ) { // MODE 2-5, breathing // MODE 6-8, rainbow mood // MODE 9-14, rainbow swirl // MODE 15-20, snake // MODE 21-23, knight // MODE 24, xmas - // MODE 25-34, static rainbow + // MODE 35 RGB test #ifdef RGBLIGHT_ANIMATIONS rgblight_timer_enable(); @@ -579,6 +582,9 @@ void rgblight_task(void) { } else if (rgblight_config.mode == 24) { // mode = 24, christmas mode rgblight_effect_christmas(); + } else if (rgblight_config.mode == 35) { + // mode = 35, RGB test + rgblight_effect_rgbtest(); } } } @@ -734,4 +740,30 @@ void rgblight_effect_christmas(void) { rgblight_set(); } -#endif +void rgblight_effect_rgbtest(void) { + static uint8_t pos = 0; + static uint16_t last_timer = 0; + static uint8_t maxval = 0; + uint8_t g; uint8_t r; uint8_t b; + + if (timer_elapsed(last_timer) < pgm_read_word(&RGBLED_RGBTEST_INTERVALS[0])) { + return; + } + + if( maxval == 0 ) { + LED_TYPE tmp_led; + sethsv(0, 255, RGBLIGHT_LIMIT_VAL, &tmp_led); + maxval = tmp_led.r; + } + last_timer = timer_read(); + g = r = b = 0; + switch( pos ) { + case 0: r = maxval; break; + case 1: g = maxval; break; + case 2: b = maxval; break; + } + rgblight_setrgb(r, g, b); + pos = (pos + 1) % 3; +} + +#endif /* RGBLIGHT_ANIMATIONS */ diff --git a/quantum/rgblight.h b/quantum/rgblight.h index 569424506..e9c192a4e 100644 --- a/quantum/rgblight.h +++ b/quantum/rgblight.h @@ -17,7 +17,7 @@ #define RGBLIGHT_H #ifdef RGBLIGHT_ANIMATIONS - #define RGBLIGHT_MODES 34 + #define RGBLIGHT_MODES 35 #else #define RGBLIGHT_MODES 1 #endif @@ -83,6 +83,7 @@ extern const uint8_t RGBLED_RAINBOW_MOOD_INTERVALS[3] PROGMEM; extern const uint8_t RGBLED_RAINBOW_SWIRL_INTERVALS[3] PROGMEM; extern const uint8_t RGBLED_SNAKE_INTERVALS[3] PROGMEM; extern const uint8_t RGBLED_KNIGHT_INTERVALS[3] PROGMEM; +extern const uint16_t RGBLED_RGBTEST_INTERVALS[1] PROGMEM; typedef union { uint32_t raw; @@ -160,5 +161,6 @@ void rgblight_effect_rainbow_swirl(uint8_t interval); void rgblight_effect_snake(uint8_t interval); void rgblight_effect_knight(uint8_t interval); void rgblight_effect_christmas(void); +void rgblight_effect_rgbtest(void); #endif