summaryrefslogtreecommitdiff
path: root/quantum
diff options
context:
space:
mode:
authorDrashna Jaelre <drashna@live.com>2018-05-29 08:05:22 -0700
committerJack Humbert <jack.humb@gmail.com>2018-05-29 11:05:22 -0400
commit751719e6cb547db753b2f33f06ee6fa61607d544 (patch)
tree456437ab1d6c051e73ccd2e92d4fb1445d496ca8 /quantum
parent034a25aedf5e0ddba2b05f4b3534c1522330d5cd (diff)
Add and fix _noeeprom functions to many of the RGB Underglow functions (#3070)
* And and fix _noeeprom functions to many of the RGB Underglow functions * Many functions are unnecessarily calling the eeprom write code. The toggle/enable is command is especially guilty of this, as it writes to EEPROM 3 times. But rgb mode writes twice, every time it's called. And init resets the rgb eeprom range and then writes back to it twice! * Fixed the rgblight_sethsv_noeeprom to work as expected, by moving a lot of the code to a helper function. * Added a noeeprom function for mode, enable, disable, and toggle functions. (didn't bother for increase/decrease stuff, and didn't add new keycodes) * Add to predefined colors list * Add new functions to manual/docs * Update RGB Sleep feature to use _noeeprom Because that's exactly what it should be doing, actually!
Diffstat (limited to 'quantum')
-rw-r--r--quantum/rgblight.c93
-rw-r--r--quantum/rgblight.h9
-rw-r--r--quantum/rgblight_list.h24
3 files changed, 105 insertions, 21 deletions
diff --git a/quantum/rgblight.c b/quantum/rgblight.c
index 75512e97a7..db66e735bb 100644
--- a/quantum/rgblight.c
+++ b/quantum/rgblight.c
@@ -44,7 +44,6 @@ __attribute__ ((weak))
const uint16_t RGBLED_GRADIENT_RANGES[] PROGMEM = {360, 240, 180, 120, 90};
rgblight_config_t rgblight_config;
-rgblight_config_t inmem_config;
LED_TYPE led[RGBLED_NUM];
uint8_t rgblight_inited = 0;
@@ -161,7 +160,7 @@ void rgblight_init(void) {
#endif
if (rgblight_config.enable) {
- rgblight_mode(rgblight_config.mode);
+ rgblight_mode_noeeprom(rgblight_config.mode);
}
}
@@ -218,7 +217,7 @@ uint32_t rgblight_get_mode(void) {
return rgblight_config.mode;
}
-void rgblight_mode(uint8_t mode) {
+void rgblight_mode_eeprom_helper(uint8_t mode, bool write_to_eeprom) {
if (!rgblight_config.enable) {
return;
}
@@ -229,8 +228,12 @@ void rgblight_mode(uint8_t mode) {
} else {
rgblight_config.mode = mode;
}
- eeconfig_update_rgblight(rgblight_config.raw);
- xprintf("rgblight mode: %u\n", rgblight_config.mode);
+ if (write_to_eeprom) {
+ eeconfig_update_rgblight(rgblight_config.raw);
+ xprintf("rgblight mode [EEPROM]: %u\n", rgblight_config.mode);
+ } else {
+ xprintf("rgblight mode [NOEEPROM]: %u\n", rgblight_config.mode);
+ }
if (rgblight_config.mode == 1) {
#ifdef RGBLIGHT_ANIMATIONS
rgblight_timer_disable();
@@ -254,11 +257,20 @@ void rgblight_mode(uint8_t mode) {
rgblight_timer_disable();
#endif
}
- rgblight_sethsv(rgblight_config.hue, rgblight_config.sat, rgblight_config.val);
+ rgblight_sethsv_noeeprom(rgblight_config.hue, rgblight_config.sat, rgblight_config.val);
+}
+
+void rgblight_mode(uint8_t mode) {
+ rgblight_mode_eeprom_helper(mode, true);
+}
+
+void rgblight_mode_noeeprom(uint8_t mode) {
+ rgblight_mode_eeprom_helper(mode, false);
}
+
void rgblight_toggle(void) {
- xprintf("rgblight toggle: rgblight_config.enable = %u\n", !rgblight_config.enable);
+ xprintf("rgblight toggle [EEPROM]: rgblight_config.enable = %u\n", !rgblight_config.enable);
if (rgblight_config.enable) {
rgblight_disable();
}
@@ -267,17 +279,34 @@ void rgblight_toggle(void) {
}
}
+void rgblight_toggle_noeeprom(void) {
+ xprintf("rgblight toggle [NOEEPROM]: rgblight_config.enable = %u\n", !rgblight_config.enable);
+ if (rgblight_config.enable) {
+ rgblight_disable_noeeprom();
+ }
+ else {
+ rgblight_enable_noeeprom();
+ }
+}
+
void rgblight_enable(void) {
rgblight_config.enable = 1;
- eeconfig_update_rgblight(rgblight_config.raw);
- xprintf("rgblight enable: rgblight_config.enable = %u\n", rgblight_config.enable);
+ // No need to update EEPROM here. rgblight_mode() will do that, actually
+ //eeconfig_update_rgblight(rgblight_config.raw);
+ xprintf("rgblight enable [EEPROM]: rgblight_config.enable = %u\n", rgblight_config.enable);
rgblight_mode(rgblight_config.mode);
}
+void rgblight_enable_noeeprom(void) {
+ rgblight_config.enable = 1;
+ xprintf("rgblight enable [NOEEPROM]: rgblight_config.enable = %u\n", rgblight_config.enable);
+ rgblight_mode_noeeprom(rgblight_config.mode);
+}
+
void rgblight_disable(void) {
rgblight_config.enable = 0;
eeconfig_update_rgblight(rgblight_config.raw);
- xprintf("rgblight disable: rgblight_config.enable = %u\n", rgblight_config.enable);
+ xprintf("rgblight disable [EEPROM]: rgblight_config.enable = %u\n", rgblight_config.enable);
#ifdef RGBLIGHT_ANIMATIONS
rgblight_timer_disable();
#endif
@@ -285,6 +314,17 @@ void rgblight_disable(void) {
rgblight_set();
}
+void rgblight_disable_noeeprom(void) {
+ rgblight_config.enable = 0;
+ xprintf("rgblight disable [noEEPROM]: rgblight_config.enable = %u\n", rgblight_config.enable);
+ #ifdef RGBLIGHT_ANIMATIONS
+ rgblight_timer_disable();
+ #endif
+ _delay_ms(50);
+ rgblight_set();
+}
+
+
// Deals with the messy details of incrementing an integer
uint8_t increment( uint8_t value, uint8_t step, uint8_t min, uint8_t max ) {
int16_t new_value = value;
@@ -358,23 +398,22 @@ void rgblight_decrease_speed(void) {
eeconfig_update_rgblight(rgblight_config.raw);//EECONFIG needs to be increased to support this
}
-void rgblight_sethsv_noeeprom(uint16_t hue, uint8_t sat, uint8_t val) {
- inmem_config.raw = rgblight_config.raw;
+void rgblight_sethsv_noeeprom_old(uint16_t hue, uint8_t sat, uint8_t val) {
if (rgblight_config.enable) {
LED_TYPE tmp_led;
sethsv(hue, sat, val, &tmp_led);
- inmem_config.hue = hue;
- inmem_config.sat = sat;
- inmem_config.val = val;
// dprintf("rgblight set hue [MEMORY]: %u,%u,%u\n", inmem_config.hue, inmem_config.sat, inmem_config.val);
rgblight_setrgb(tmp_led.r, tmp_led.g, tmp_led.b);
}
}
-void rgblight_sethsv(uint16_t hue, uint8_t sat, uint8_t val) {
+
+void rgblight_sethsv_eeprom_helper(uint16_t hue, uint8_t sat, uint8_t val, bool write_to_eeprom) {
if (rgblight_config.enable) {
if (rgblight_config.mode == 1) {
// same static color
- rgblight_sethsv_noeeprom(hue, sat, val);
+ LED_TYPE tmp_led;
+ sethsv(hue, sat, val, &tmp_led);
+ rgblight_setrgb(tmp_led.r, tmp_led.g, tmp_led.b);
} else {
// all LEDs in same color
if (rgblight_config.mode >= 2 && rgblight_config.mode <= 5) {
@@ -399,11 +438,23 @@ void rgblight_sethsv(uint16_t hue, uint8_t sat, uint8_t val) {
rgblight_config.hue = hue;
rgblight_config.sat = sat;
rgblight_config.val = val;
- eeconfig_update_rgblight(rgblight_config.raw);
- xprintf("rgblight set hsv [EEPROM]: %u,%u,%u\n", rgblight_config.hue, rgblight_config.sat, rgblight_config.val);
+ if (write_to_eeprom) {
+ eeconfig_update_rgblight(rgblight_config.raw);
+ xprintf("rgblight set hsv [EEPROM]: %u,%u,%u\n", rgblight_config.hue, rgblight_config.sat, rgblight_config.val);
+ } else {
+ xprintf("rgblight set hsv [NOEEPROM]: %u,%u,%u\n", rgblight_config.hue, rgblight_config.sat, rgblight_config.val);
+ }
}
}
+void rgblight_sethsv(uint16_t hue, uint8_t sat, uint8_t val) {
+ rgblight_sethsv_eeprom_helper(hue, sat, val, true);
+}
+
+void rgblight_sethsv_noeeprom(uint16_t hue, uint8_t sat, uint8_t val) {
+ rgblight_sethsv_eeprom_helper(hue, sat, val, false);
+}
+
uint16_t rgblight_get_hue(void) {
return rgblight_config.hue;
}
@@ -546,7 +597,7 @@ void rgblight_effect_breathing(uint8_t interval) {
// http://sean.voisen.org/blog/2011/10/breathing-led-with-arduino/
val = (exp(sin((pos/255.0)*M_PI)) - RGBLIGHT_EFFECT_BREATHE_CENTER/M_E)*(RGBLIGHT_EFFECT_BREATHE_MAX/(M_E-1/M_E));
- rgblight_sethsv_noeeprom(rgblight_config.hue, rgblight_config.sat, val);
+ rgblight_sethsv_noeeprom_old(rgblight_config.hue, rgblight_config.sat, val);
pos = (pos + 1) % 256;
}
void rgblight_effect_rainbow_mood(uint8_t interval) {
@@ -557,7 +608,7 @@ void rgblight_effect_rainbow_mood(uint8_t interval) {
return;
}
last_timer = timer_read();
- rgblight_sethsv_noeeprom(current_hue, rgblight_config.sat, rgblight_config.val);
+ rgblight_sethsv_noeeprom_old(current_hue, rgblight_config.sat, rgblight_config.val);
current_hue = (current_hue + 1) % 360;
}
void rgblight_effect_rainbow_swirl(uint8_t interval) {
diff --git a/quantum/rgblight.h b/quantum/rgblight.h
index a6593af98b..569424506b 100644
--- a/quantum/rgblight.h
+++ b/quantum/rgblight.h
@@ -134,7 +134,16 @@ void rgb_matrix_decrease(void);
void sethsv(uint16_t hue, uint8_t sat, uint8_t val, LED_TYPE *led1);
void setrgb(uint8_t r, uint8_t g, uint8_t b, LED_TYPE *led1);
+
void rgblight_sethsv_noeeprom(uint16_t hue, uint8_t sat, uint8_t val);
+void rgblight_mode_noeeprom(uint8_t mode);
+void rgblight_toggle_noeeprom(void);
+void rgblight_enable_noeeprom(void);
+void rgblight_disable_noeeprom(void);
+
+void rgblight_sethsv_eeprom_helper(uint16_t hue, uint8_t sat, uint8_t val, bool write_to_eeprom);
+void rgblight_mode_eeprom_helper(uint8_t mode, bool write_to_eeprom);
+
#define EZ_RGB(val) rgblight_show_solid_color((val >> 16) & 0xFF, (val >> 8) & 0xFF, val & 0xFF)
void rgblight_show_solid_color(uint8_t r, uint8_t g, uint8_t b);
diff --git a/quantum/rgblight_list.h b/quantum/rgblight_list.h
index 29b2802263..407fd8e9d3 100644
--- a/quantum/rgblight_list.h
+++ b/quantum/rgblight_list.h
@@ -77,6 +77,30 @@
#define rgblight_sethsv_pink() rgblight_sethsv (330, 128, 255)
/* SET HSV List */
+/* If you're doing layer indication, this is best, as it won't */
+/* write to the eeprom, since it's limited (very high value). */
+/* If you want to use modes with this (since you can), then you */
+/* want to use rgblight_mode_noeeprom(x) instead. */
+#define rgblight_sethsv_noeeprom_white() rgblight_sethsv_noeeprom ( 0, 0, 255)
+#define rgblight_sethsv_noeeprom_red() rgblight_sethsv_noeeprom ( 0, 255, 255)
+#define rgblight_sethsv_noeeprom_coral() rgblight_sethsv_noeeprom ( 16, 176, 255)
+#define rgblight_sethsv_noeeprom_orange() rgblight_sethsv_noeeprom ( 39, 255, 255)
+#define rgblight_sethsv_noeeprom_goldenrod() rgblight_sethsv_noeeprom ( 43, 218, 218)
+#define rgblight_sethsv_noeeprom_gold() rgblight_sethsv_noeeprom ( 51, 255, 255)
+#define rgblight_sethsv_noeeprom_yellow() rgblight_sethsv_noeeprom ( 60, 255, 255)
+#define rgblight_sethsv_noeeprom_chartreuse() rgblight_sethsv_noeeprom ( 90, 255, 255)
+#define rgblight_sethsv_noeeprom_green() rgblight_sethsv_noeeprom (120, 255, 255)
+#define rgblight_sethsv_noeeprom_springgreen() rgblight_sethsv_noeeprom (150, 255, 255)
+#define rgblight_sethsv_noeeprom_turquoise() rgblight_sethsv_noeeprom (174, 90, 112)
+#define rgblight_sethsv_noeeprom_teal() rgblight_sethsv_noeeprom (180, 255, 128)
+#define rgblight_sethsv_noeeprom_cyan() rgblight_sethsv_noeeprom (180, 255, 255)
+#define rgblight_sethsv_noeeprom_azure() rgblight_sethsv_noeeprom (186, 102, 255)
+#define rgblight_sethsv_noeeprom_blue() rgblight_sethsv_noeeprom (240, 255, 255)
+#define rgblight_sethsv_noeeprom_purple() rgblight_sethsv_noeeprom (270, 255, 255)
+#define rgblight_sethsv_noeeprom_magenta() rgblight_sethsv_noeeprom (300, 255, 255)
+#define rgblight_sethsv_noeeprom_pink() rgblight_sethsv_noeeprom (330, 128, 255)
+
+/* SET HSV List */
#define rgblight_sethsv_white_at(at) rgblight_sethsv_at ( 0, 0, 255, at)
#define rgblight_sethsv_red_at(at) rgblight_sethsv_at ( 0, 255, 255, at)
#define rgblight_sethsv_coral_at(at) rgblight_sethsv_at ( 16, 176, 255, at)