aboutsummaryrefslogtreecommitdiff
path: root/quantum
diff options
context:
space:
mode:
authorJack Humbert <jack.humb@gmail.com>2017-02-07 13:32:31 -0500
committerGitHub <noreply@github.com>2017-02-07 13:32:31 -0500
commit13c394fba40d6a6c9eb0d2958d06a4ebae9e8e3f (patch)
treecca209200dcd72368b9544fd624b7a90ba1e08d8 /quantum
parentc0c69a1a7cb232538e99cb4b9cf00370e8c6ce5c (diff)
parenta7882b1ffceb6002dd1adf916a8fc32523227860 (diff)
downloadqmk_firmware-13c394fba40d6a6c9eb0d2958d06a4ebae9e8e3f.tar.gz
qmk_firmware-13c394fba40d6a6c9eb0d2958d06a4ebae9e8e3f.zip
Merge pull request #1071 from dungdung/rgb_tweaks
RGB tweaks
Diffstat (limited to 'quantum')
-rw-r--r--quantum/rgblight.c35
-rw-r--r--quantum/rgblight.h11
2 files changed, 41 insertions, 5 deletions
diff --git a/quantum/rgblight.c b/quantum/rgblight.c
index 52a09817a..dd1b91c63 100644
--- a/quantum/rgblight.c
+++ b/quantum/rgblight.c
@@ -66,6 +66,8 @@ __attribute__ ((weak))
66const uint8_t RGBLED_SNAKE_INTERVALS[] PROGMEM = {100, 50, 20}; 66const uint8_t RGBLED_SNAKE_INTERVALS[] PROGMEM = {100, 50, 20};
67__attribute__ ((weak)) 67__attribute__ ((weak))
68const uint8_t RGBLED_KNIGHT_INTERVALS[] PROGMEM = {100, 50, 20}; 68const uint8_t RGBLED_KNIGHT_INTERVALS[] PROGMEM = {100, 50, 20};
69__attribute__ ((weak))
70const uint16_t RGBLED_GRADIENT_RANGES[] PROGMEM = {360, 240, 180, 120, 90};
69 71
70rgblight_config_t rgblight_config; 72rgblight_config_t rgblight_config;
71rgblight_config_t inmem_config; 73rgblight_config_t inmem_config;
@@ -219,6 +221,14 @@ void rgblight_step(void) {
219 } 221 }
220 rgblight_mode(mode); 222 rgblight_mode(mode);
221} 223}
224void rgblight_step_reverse(void) {
225 uint8_t mode = 0;
226 mode = rgblight_config.mode - 1;
227 if (mode < 1) {
228 mode = RGBLIGHT_MODES;
229 }
230 rgblight_mode(mode);
231}
222 232
223void rgblight_mode(uint8_t mode) { 233void rgblight_mode(uint8_t mode) {
224 if (!rgblight_config.enable) { 234 if (!rgblight_config.enable) {
@@ -237,7 +247,7 @@ void rgblight_mode(uint8_t mode) {
237 #ifdef RGBLIGHT_ANIMATIONS 247 #ifdef RGBLIGHT_ANIMATIONS
238 rgblight_timer_disable(); 248 rgblight_timer_disable();
239 #endif 249 #endif
240 } else if (rgblight_config.mode >= 2 && rgblight_config.mode <= 23) { 250 } else if (rgblight_config.mode >= 2 && rgblight_config.mode <= 24) {
241 // MODE 2-5, breathing 251 // MODE 2-5, breathing
242 // MODE 6-8, rainbow mood 252 // MODE 6-8, rainbow mood
243 // MODE 9-14, rainbow swirl 253 // MODE 9-14, rainbow swirl
@@ -247,6 +257,12 @@ void rgblight_mode(uint8_t mode) {
247 #ifdef RGBLIGHT_ANIMATIONS 257 #ifdef RGBLIGHT_ANIMATIONS
248 rgblight_timer_enable(); 258 rgblight_timer_enable();
249 #endif 259 #endif
260 } else if (rgblight_config.mode >= 25 && rgblight_config.mode <= 34) {
261 // MODE 25-34, static gradient
262
263 #ifdef RGBLIGHT_ANIMATIONS
264 rgblight_timer_disable();
265 #endif
250 } 266 }
251 rgblight_sethsv(rgblight_config.hue, rgblight_config.sat, rgblight_config.val); 267 rgblight_sethsv(rgblight_config.hue, rgblight_config.sat, rgblight_config.val);
252} 268}
@@ -350,6 +366,17 @@ void rgblight_sethsv(uint16_t hue, uint8_t sat, uint8_t val) {
350 } else if (rgblight_config.mode >= 6 && rgblight_config.mode <= 14) { 366 } else if (rgblight_config.mode >= 6 && rgblight_config.mode <= 14) {
351 // rainbow mood and rainbow swirl, ignore the change of hue 367 // rainbow mood and rainbow swirl, ignore the change of hue
352 hue = rgblight_config.hue; 368 hue = rgblight_config.hue;
369 } else if (rgblight_config.mode >= 25 && rgblight_config.mode <= 34) {
370 // static gradient
371 uint16_t _hue;
372 int8_t direction = ((rgblight_config.mode - 25) % 2) ? -1 : 1;
373 uint16_t range = pgm_read_word(&RGBLED_GRADIENT_RANGES[(rgblight_config.mode - 25) / 2]);
374 for (uint8_t i = 0; i < RGBLED_NUM; i++) {
375 _hue = (range / RGBLED_NUM * i * direction + hue + 360) % 360;
376 dprintf("rgblight rainbow set hsv: %u,%u,%d,%u\n", i, _hue, direction, range);
377 sethsv(_hue, sat, val, (LED_TYPE *)&led[i]);
378 }
379 rgblight_set();
353 } 380 }
354 } 381 }
355 rgblight_config.hue = hue; 382 rgblight_config.hue = hue;
@@ -450,7 +477,7 @@ void rgblight_task(void) {
450 } else if (rgblight_config.mode >= 21 && rgblight_config.mode <= 23) { 477 } else if (rgblight_config.mode >= 21 && rgblight_config.mode <= 23) {
451 // mode = 21 to 23, knight mode 478 // mode = 21 to 23, knight mode
452 rgblight_effect_knight(rgblight_config.mode - 21); 479 rgblight_effect_knight(rgblight_config.mode - 21);
453 } else { 480 } else if (rgblight_config.mode == 24) {
454 // mode = 24, christmas mode 481 // mode = 24, christmas mode
455 rgblight_effect_christmas(); 482 rgblight_effect_christmas();
456 } 483 }
@@ -604,13 +631,13 @@ void rgblight_effect_christmas(void) {
604 static uint16_t last_timer = 0; 631 static uint16_t last_timer = 0;
605 uint16_t hue; 632 uint16_t hue;
606 uint8_t i; 633 uint8_t i;
607 if (timer_elapsed(last_timer) < 1000) { 634 if (timer_elapsed(last_timer) < RGBLIGHT_EFFECT_CHRISTMAS_INTERVAL) {
608 return; 635 return;
609 } 636 }
610 last_timer = timer_read(); 637 last_timer = timer_read();
611 current_offset = (current_offset + 1) % 2; 638 current_offset = (current_offset + 1) % 2;
612 for (i = 0; i < RGBLED_NUM; i++) { 639 for (i = 0; i < RGBLED_NUM; i++) {
613 hue = 0 + ((RGBLED_NUM * (i + current_offset)) % 2) * 80; 640 hue = 0 + ((i/RGBLIGHT_EFFECT_CHRISTMAS_STEP + current_offset) % 2) * 120;
614 sethsv(hue, rgblight_config.sat, rgblight_config.val, (LED_TYPE *)&led[i]); 641 sethsv(hue, rgblight_config.sat, rgblight_config.val, (LED_TYPE *)&led[i]);
615 } 642 }
616 rgblight_set(); 643 rgblight_set();
diff --git a/quantum/rgblight.h b/quantum/rgblight.h
index 726b8de72..2b3e791bf 100644
--- a/quantum/rgblight.h
+++ b/quantum/rgblight.h
@@ -2,7 +2,7 @@
2#define RGBLIGHT_H 2#define RGBLIGHT_H
3 3
4#ifdef RGBLIGHT_ANIMATIONS 4#ifdef RGBLIGHT_ANIMATIONS
5 #define RGBLIGHT_MODES 24 5 #define RGBLIGHT_MODES 34
6#else 6#else
7 #define RGBLIGHT_MODES 1 7 #define RGBLIGHT_MODES 1
8#endif 8#endif
@@ -22,6 +22,14 @@
22#define RGBLIGHT_EFFECT_DUALKNIGHT_LENGTH 4 22#define RGBLIGHT_EFFECT_DUALKNIGHT_LENGTH 4
23#endif 23#endif
24 24
25#ifndef RGBLIGHT_EFFECT_CHRISTMAS_INTERVAL
26#define RGBLIGHT_EFFECT_CHRISTMAS_INTERVAL 1000
27#endif
28
29#ifndef RGBLIGHT_EFFECT_CHRISTMAS_STEP
30#define RGBLIGHT_EFFECT_CHRISTMAS_STEP 2
31#endif
32
25#ifndef RGBLIGHT_HUE_STEP 33#ifndef RGBLIGHT_HUE_STEP
26#define RGBLIGHT_HUE_STEP 10 34#define RGBLIGHT_HUE_STEP 10
27#endif 35#endif
@@ -65,6 +73,7 @@ void rgblight_decrease(void);
65void rgblight_toggle(void); 73void rgblight_toggle(void);
66void rgblight_enable(void); 74void rgblight_enable(void);
67void rgblight_step(void); 75void rgblight_step(void);
76void rgblight_step_reverse(void);
68void rgblight_mode(uint8_t mode); 77void rgblight_mode(uint8_t mode);
69void rgblight_set(void); 78void rgblight_set(void);
70void rgblight_update_dword(uint32_t dword); 79void rgblight_update_dword(uint32_t dword);