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!
This commit is contained in:
parent
034a25aedf
commit
751719e6cb
5 changed files with 137 additions and 28 deletions
|
@ -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) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue