diff options
Diffstat (limited to 'quantum/rgblight.c')
| -rw-r--r-- | quantum/rgblight.c | 1444 |
1 files changed, 688 insertions, 756 deletions
diff --git a/quantum/rgblight.c b/quantum/rgblight.c index f569d6b9e..a094863fe 100644 --- a/quantum/rgblight.c +++ b/quantum/rgblight.c | |||
| @@ -16,13 +16,13 @@ | |||
| 16 | #include <math.h> | 16 | #include <math.h> |
| 17 | #include <string.h> | 17 | #include <string.h> |
| 18 | #ifdef __AVR__ | 18 | #ifdef __AVR__ |
| 19 | #include <avr/eeprom.h> | 19 | # include <avr/eeprom.h> |
| 20 | #include <avr/interrupt.h> | 20 | # include <avr/interrupt.h> |
| 21 | #endif | 21 | #endif |
| 22 | #ifdef STM32_EEPROM_ENABLE | 22 | #ifdef STM32_EEPROM_ENABLE |
| 23 | #include "hal.h" | 23 | # include "hal.h" |
| 24 | #include "eeprom.h" | 24 | # include "eeprom.h" |
| 25 | #include "eeprom_stm32.h" | 25 | # include "eeprom_stm32.h" |
| 26 | #endif | 26 | #endif |
| 27 | #include "wait.h" | 27 | #include "wait.h" |
| 28 | #include "progmem.h" | 28 | #include "progmem.h" |
| @@ -33,61 +33,58 @@ | |||
| 33 | #include "led_tables.h" | 33 | #include "led_tables.h" |
| 34 | #include "lib/lib8tion/lib8tion.h" | 34 | #include "lib/lib8tion/lib8tion.h" |
| 35 | #ifdef VELOCIKEY_ENABLE | 35 | #ifdef VELOCIKEY_ENABLE |
| 36 | #include "velocikey.h" | 36 | # include "velocikey.h" |
| 37 | #endif | 37 | #endif |
| 38 | 38 | ||
| 39 | #ifdef RGBLIGHT_SPLIT | 39 | #ifdef RGBLIGHT_SPLIT |
| 40 | /* for split keyboard */ | 40 | /* for split keyboard */ |
| 41 | #define RGBLIGHT_SPLIT_SET_CHANGE_MODE rgblight_status.change_flags |= RGBLIGHT_STATUS_CHANGE_MODE | 41 | # define RGBLIGHT_SPLIT_SET_CHANGE_MODE rgblight_status.change_flags |= RGBLIGHT_STATUS_CHANGE_MODE |
| 42 | #define RGBLIGHT_SPLIT_SET_CHANGE_HSVS rgblight_status.change_flags |= RGBLIGHT_STATUS_CHANGE_HSVS | 42 | # define RGBLIGHT_SPLIT_SET_CHANGE_HSVS rgblight_status.change_flags |= RGBLIGHT_STATUS_CHANGE_HSVS |
| 43 | #define RGBLIGHT_SPLIT_SET_CHANGE_MODEHSVS rgblight_status.change_flags |= (RGBLIGHT_STATUS_CHANGE_MODE|RGBLIGHT_STATUS_CHANGE_HSVS) | 43 | # define RGBLIGHT_SPLIT_SET_CHANGE_MODEHSVS rgblight_status.change_flags |= (RGBLIGHT_STATUS_CHANGE_MODE | RGBLIGHT_STATUS_CHANGE_HSVS) |
| 44 | #define RGBLIGHT_SPLIT_SET_CHANGE_TIMER_ENABLE rgblight_status.change_flags |= RGBLIGHT_STATUS_CHANGE_TIMER | 44 | # define RGBLIGHT_SPLIT_SET_CHANGE_TIMER_ENABLE rgblight_status.change_flags |= RGBLIGHT_STATUS_CHANGE_TIMER |
| 45 | #define RGBLIGHT_SPLIT_ANIMATION_TICK rgblight_status.change_flags |= RGBLIGHT_STATUS_ANIMATION_TICK | 45 | # define RGBLIGHT_SPLIT_ANIMATION_TICK rgblight_status.change_flags |= RGBLIGHT_STATUS_ANIMATION_TICK |
| 46 | #else | 46 | #else |
| 47 | #define RGBLIGHT_SPLIT_SET_CHANGE_MODE | 47 | # define RGBLIGHT_SPLIT_SET_CHANGE_MODE |
| 48 | #define RGBLIGHT_SPLIT_SET_CHANGE_HSVS | 48 | # define RGBLIGHT_SPLIT_SET_CHANGE_HSVS |
| 49 | #define RGBLIGHT_SPLIT_SET_CHANGE_MODEHSVS | 49 | # define RGBLIGHT_SPLIT_SET_CHANGE_MODEHSVS |
| 50 | #define RGBLIGHT_SPLIT_SET_CHANGE_TIMER_ENABLE | 50 | # define RGBLIGHT_SPLIT_SET_CHANGE_TIMER_ENABLE |
| 51 | #define RGBLIGHT_SPLIT_ANIMATION_TICK | 51 | # define RGBLIGHT_SPLIT_ANIMATION_TICK |
| 52 | #endif | 52 | #endif |
| 53 | 53 | ||
| 54 | #define _RGBM_SINGLE_STATIC(sym) RGBLIGHT_MODE_ ## sym, | 54 | #define _RGBM_SINGLE_STATIC(sym) RGBLIGHT_MODE_##sym, |
| 55 | #define _RGBM_SINGLE_DYNAMIC(sym) | 55 | #define _RGBM_SINGLE_DYNAMIC(sym) |
| 56 | #define _RGBM_MULTI_STATIC(sym) RGBLIGHT_MODE_ ## sym, | 56 | #define _RGBM_MULTI_STATIC(sym) RGBLIGHT_MODE_##sym, |
| 57 | #define _RGBM_MULTI_DYNAMIC(sym) | 57 | #define _RGBM_MULTI_DYNAMIC(sym) |
| 58 | #define _RGBM_TMP_STATIC(sym, msym) RGBLIGHT_MODE_ ## sym, | 58 | #define _RGBM_TMP_STATIC(sym, msym) RGBLIGHT_MODE_##sym, |
| 59 | #define _RGBM_TMP_DYNAMIC(sym, msym) | 59 | #define _RGBM_TMP_DYNAMIC(sym, msym) |
| 60 | static uint8_t static_effect_table [] = { | 60 | static uint8_t static_effect_table[] = { |
| 61 | #include "rgblight_modes.h" | 61 | #include "rgblight_modes.h" |
| 62 | }; | 62 | }; |
| 63 | 63 | ||
| 64 | #define _RGBM_SINGLE_STATIC(sym) RGBLIGHT_MODE_ ## sym, | 64 | #define _RGBM_SINGLE_STATIC(sym) RGBLIGHT_MODE_##sym, |
| 65 | #define _RGBM_SINGLE_DYNAMIC(sym) RGBLIGHT_MODE_ ## sym, | 65 | #define _RGBM_SINGLE_DYNAMIC(sym) RGBLIGHT_MODE_##sym, |
| 66 | #define _RGBM_MULTI_STATIC(sym) RGBLIGHT_MODE_ ## sym, | 66 | #define _RGBM_MULTI_STATIC(sym) RGBLIGHT_MODE_##sym, |
| 67 | #define _RGBM_MULTI_DYNAMIC(sym) RGBLIGHT_MODE_ ## sym, | 67 | #define _RGBM_MULTI_DYNAMIC(sym) RGBLIGHT_MODE_##sym, |
| 68 | #define _RGBM_TMP_STATIC(sym, msym) RGBLIGHT_MODE_ ## msym, | 68 | #define _RGBM_TMP_STATIC(sym, msym) RGBLIGHT_MODE_##msym, |
| 69 | #define _RGBM_TMP_DYNAMIC(sym, msym) RGBLIGHT_MODE_ ## msym, | 69 | #define _RGBM_TMP_DYNAMIC(sym, msym) RGBLIGHT_MODE_##msym, |
| 70 | static uint8_t mode_base_table [] = { | 70 | static uint8_t mode_base_table[] = { |
| 71 | 0, // RGBLIGHT_MODE_zero | 71 | 0, // RGBLIGHT_MODE_zero |
| 72 | #include "rgblight_modes.h" | 72 | #include "rgblight_modes.h" |
| 73 | }; | 73 | }; |
| 74 | 74 | ||
| 75 | static inline int is_static_effect(uint8_t mode) { | 75 | static inline int is_static_effect(uint8_t mode) { return memchr(static_effect_table, mode, sizeof(static_effect_table)) != NULL; } |
| 76 | return memchr(static_effect_table, mode, sizeof(static_effect_table)) != NULL; | ||
| 77 | } | ||
| 78 | 76 | ||
| 79 | #ifdef RGBLIGHT_LED_MAP | 77 | #ifdef RGBLIGHT_LED_MAP |
| 80 | const uint8_t led_map[] PROGMEM = RGBLIGHT_LED_MAP; | 78 | const uint8_t led_map[] PROGMEM = RGBLIGHT_LED_MAP; |
| 81 | #endif | 79 | #endif |
| 82 | 80 | ||
| 83 | #ifdef RGBLIGHT_EFFECT_STATIC_GRADIENT | 81 | #ifdef RGBLIGHT_EFFECT_STATIC_GRADIENT |
| 84 | __attribute__ ((weak)) | 82 | __attribute__((weak)) const uint8_t RGBLED_GRADIENT_RANGES[] PROGMEM = {255, 170, 127, 85, 64}; |
| 85 | const uint8_t RGBLED_GRADIENT_RANGES[] PROGMEM = {255, 170, 127, 85, 64}; | ||
| 86 | #endif | 83 | #endif |
| 87 | 84 | ||
| 88 | rgblight_config_t rgblight_config; | 85 | rgblight_config_t rgblight_config; |
| 89 | rgblight_status_t rgblight_status = { .timer_enabled = false }; | 86 | rgblight_status_t rgblight_status = {.timer_enabled = false}; |
| 90 | bool is_rgblight_initialized = false; | 87 | bool is_rgblight_initialized = false; |
| 91 | 88 | ||
| 92 | #ifdef RGBLIGHT_USE_TIMER | 89 | #ifdef RGBLIGHT_USE_TIMER |
| 93 | animation_status_t animation_status = {}; | 90 | animation_status_t animation_status = {}; |
| @@ -95,596 +92,533 @@ animation_status_t animation_status = {}; | |||
| 95 | 92 | ||
| 96 | #ifndef LED_ARRAY | 93 | #ifndef LED_ARRAY |
| 97 | LED_TYPE led[RGBLED_NUM]; | 94 | LED_TYPE led[RGBLED_NUM]; |
| 98 | #define LED_ARRAY led | 95 | # define LED_ARRAY led |
| 99 | #endif | 96 | #endif |
| 100 | 97 | ||
| 101 | |||
| 102 | static uint8_t clipping_start_pos = 0; | 98 | static uint8_t clipping_start_pos = 0; |
| 103 | static uint8_t clipping_num_leds = RGBLED_NUM; | 99 | static uint8_t clipping_num_leds = RGBLED_NUM; |
| 104 | static uint8_t effect_start_pos = 0; | 100 | static uint8_t effect_start_pos = 0; |
| 105 | static uint8_t effect_end_pos = RGBLED_NUM; | 101 | static uint8_t effect_end_pos = RGBLED_NUM; |
| 106 | static uint8_t effect_num_leds = RGBLED_NUM; | 102 | static uint8_t effect_num_leds = RGBLED_NUM; |
| 107 | 103 | ||
| 108 | void rgblight_set_clipping_range(uint8_t start_pos, uint8_t num_leds) { | 104 | void rgblight_set_clipping_range(uint8_t start_pos, uint8_t num_leds) { |
| 109 | clipping_start_pos = start_pos; | 105 | clipping_start_pos = start_pos; |
| 110 | clipping_num_leds = num_leds; | 106 | clipping_num_leds = num_leds; |
| 111 | } | 107 | } |
| 112 | 108 | ||
| 113 | void rgblight_set_effect_range(uint8_t start_pos, uint8_t num_leds) { | 109 | void rgblight_set_effect_range(uint8_t start_pos, uint8_t num_leds) { |
| 114 | if (start_pos >= RGBLED_NUM) return; | 110 | if (start_pos >= RGBLED_NUM) return; |
| 115 | if (start_pos + num_leds > RGBLED_NUM) return; | 111 | if (start_pos + num_leds > RGBLED_NUM) return; |
| 116 | effect_start_pos = start_pos; | 112 | effect_start_pos = start_pos; |
| 117 | effect_end_pos = start_pos + num_leds; | 113 | effect_end_pos = start_pos + num_leds; |
| 118 | effect_num_leds = num_leds; | 114 | effect_num_leds = num_leds; |
| 119 | } | 115 | } |
| 120 | 116 | ||
| 121 | void sethsv_raw(uint8_t hue, uint8_t sat, uint8_t val, LED_TYPE *led1) { | 117 | void sethsv_raw(uint8_t hue, uint8_t sat, uint8_t val, LED_TYPE *led1) { |
| 122 | HSV hsv = { hue, sat, val }; | 118 | HSV hsv = {hue, sat, val}; |
| 123 | RGB rgb = hsv_to_rgb(hsv); | 119 | RGB rgb = hsv_to_rgb(hsv); |
| 124 | setrgb(rgb.r, rgb.g, rgb.b, led1); | 120 | setrgb(rgb.r, rgb.g, rgb.b, led1); |
| 125 | } | 121 | } |
| 126 | 122 | ||
| 127 | void sethsv(uint8_t hue, uint8_t sat, uint8_t val, LED_TYPE *led1) { | 123 | void sethsv(uint8_t hue, uint8_t sat, uint8_t val, LED_TYPE *led1) { sethsv_raw(hue, sat, val > RGBLIGHT_LIMIT_VAL ? RGBLIGHT_LIMIT_VAL : val, led1); } |
| 128 | sethsv_raw( hue, sat, | ||
| 129 | val > RGBLIGHT_LIMIT_VAL ? RGBLIGHT_LIMIT_VAL : val, | ||
| 130 | led1); | ||
| 131 | } | ||
| 132 | 124 | ||
| 133 | void setrgb(uint8_t r, uint8_t g, uint8_t b, LED_TYPE *led1) { | 125 | void setrgb(uint8_t r, uint8_t g, uint8_t b, LED_TYPE *led1) { |
| 134 | (*led1).r = r; | 126 | (*led1).r = r; |
| 135 | (*led1).g = g; | 127 | (*led1).g = g; |
| 136 | (*led1).b = b; | 128 | (*led1).b = b; |
| 137 | } | 129 | } |
| 138 | 130 | ||
| 139 | void rgblight_check_config(void) { | 131 | void rgblight_check_config(void) { |
| 140 | /* Add some out of bound checks for RGB light config */ | 132 | /* Add some out of bound checks for RGB light config */ |
| 141 | 133 | ||
| 142 | if (rgblight_config.mode < RGBLIGHT_MODE_STATIC_LIGHT) { | 134 | if (rgblight_config.mode < RGBLIGHT_MODE_STATIC_LIGHT) { |
| 143 | rgblight_config.mode = RGBLIGHT_MODE_STATIC_LIGHT; | 135 | rgblight_config.mode = RGBLIGHT_MODE_STATIC_LIGHT; |
| 144 | } | 136 | } else if (rgblight_config.mode > RGBLIGHT_MODES) { |
| 145 | else if (rgblight_config.mode > RGBLIGHT_MODES) { | 137 | rgblight_config.mode = RGBLIGHT_MODES; |
| 146 | rgblight_config.mode = RGBLIGHT_MODES; | 138 | } |
| 147 | } | 139 | |
| 148 | 140 | if (rgblight_config.val > RGBLIGHT_LIMIT_VAL) { | |
| 149 | if (rgblight_config.val > RGBLIGHT_LIMIT_VAL) { | 141 | rgblight_config.val = RGBLIGHT_LIMIT_VAL; |
| 150 | rgblight_config.val = RGBLIGHT_LIMIT_VAL; | 142 | } |
| 151 | } | ||
| 152 | } | 143 | } |
| 153 | 144 | ||
| 154 | uint32_t eeconfig_read_rgblight(void) { | 145 | uint32_t eeconfig_read_rgblight(void) { |
| 155 | #if defined(__AVR__) || defined(STM32_EEPROM_ENABLE) || defined(PROTOCOL_ARM_ATSAM) || defined(EEPROM_SIZE) | 146 | #if defined(__AVR__) || defined(STM32_EEPROM_ENABLE) || defined(PROTOCOL_ARM_ATSAM) || defined(EEPROM_SIZE) |
| 156 | return eeprom_read_dword(EECONFIG_RGBLIGHT); | 147 | return eeprom_read_dword(EECONFIG_RGBLIGHT); |
| 157 | #else | 148 | #else |
| 158 | return 0; | 149 | return 0; |
| 159 | #endif | 150 | #endif |
| 160 | } | 151 | } |
| 161 | 152 | ||
| 162 | void eeconfig_update_rgblight(uint32_t val) { | 153 | void eeconfig_update_rgblight(uint32_t val) { |
| 163 | #if defined(__AVR__) || defined(STM32_EEPROM_ENABLE) || defined(PROTOCOL_ARM_ATSAM) || defined(EEPROM_SIZE) | 154 | #if defined(__AVR__) || defined(STM32_EEPROM_ENABLE) || defined(PROTOCOL_ARM_ATSAM) || defined(EEPROM_SIZE) |
| 164 | rgblight_check_config(); | 155 | rgblight_check_config(); |
| 165 | eeprom_update_dword(EECONFIG_RGBLIGHT, val); | 156 | eeprom_update_dword(EECONFIG_RGBLIGHT, val); |
| 166 | #endif | 157 | #endif |
| 167 | } | 158 | } |
| 168 | 159 | ||
| 169 | void eeconfig_update_rgblight_default(void) { | 160 | void eeconfig_update_rgblight_default(void) { |
| 170 | rgblight_config.enable = 1; | 161 | rgblight_config.enable = 1; |
| 171 | rgblight_config.mode = RGBLIGHT_MODE_STATIC_LIGHT; | 162 | rgblight_config.mode = RGBLIGHT_MODE_STATIC_LIGHT; |
| 172 | rgblight_config.hue = 0; | 163 | rgblight_config.hue = 0; |
| 173 | rgblight_config.sat = UINT8_MAX; | 164 | rgblight_config.sat = UINT8_MAX; |
| 174 | rgblight_config.val = RGBLIGHT_LIMIT_VAL; | 165 | rgblight_config.val = RGBLIGHT_LIMIT_VAL; |
| 175 | rgblight_config.speed = 0; | 166 | rgblight_config.speed = 0; |
| 176 | RGBLIGHT_SPLIT_SET_CHANGE_MODEHSVS; | 167 | RGBLIGHT_SPLIT_SET_CHANGE_MODEHSVS; |
| 177 | eeconfig_update_rgblight(rgblight_config.raw); | 168 | eeconfig_update_rgblight(rgblight_config.raw); |
| 178 | } | 169 | } |
| 179 | 170 | ||
| 180 | void eeconfig_debug_rgblight(void) { | 171 | void eeconfig_debug_rgblight(void) { |
| 181 | dprintf("rgblight_config EEPROM:\n"); | 172 | dprintf("rgblight_config EEPROM:\n"); |
| 182 | dprintf("rgblight_config.enable = %d\n", rgblight_config.enable); | 173 | dprintf("rgblight_config.enable = %d\n", rgblight_config.enable); |
| 183 | dprintf("rghlight_config.mode = %d\n", rgblight_config.mode); | 174 | dprintf("rghlight_config.mode = %d\n", rgblight_config.mode); |
| 184 | dprintf("rgblight_config.hue = %d\n", rgblight_config.hue); | 175 | dprintf("rgblight_config.hue = %d\n", rgblight_config.hue); |
| 185 | dprintf("rgblight_config.sat = %d\n", rgblight_config.sat); | 176 | dprintf("rgblight_config.sat = %d\n", rgblight_config.sat); |
| 186 | dprintf("rgblight_config.val = %d\n", rgblight_config.val); | 177 | dprintf("rgblight_config.val = %d\n", rgblight_config.val); |
| 187 | dprintf("rgblight_config.speed = %d\n", rgblight_config.speed); | 178 | dprintf("rgblight_config.speed = %d\n", rgblight_config.speed); |
| 188 | } | 179 | } |
| 189 | 180 | ||
| 190 | void rgblight_init(void) { | 181 | void rgblight_init(void) { |
| 191 | /* if already initialized, don't do it again. | 182 | /* if already initialized, don't do it again. |
| 192 | If you must do it again, extern this and set to false, first. | 183 | If you must do it again, extern this and set to false, first. |
| 193 | This is a dirty, dirty hack until proper hooks can be added for keyboard startup. */ | 184 | This is a dirty, dirty hack until proper hooks can be added for keyboard startup. */ |
| 194 | if (is_rgblight_initialized) { return; } | 185 | if (is_rgblight_initialized) { |
| 195 | 186 | return; | |
| 196 | debug_enable = 1; // Debug ON! | 187 | } |
| 197 | dprintf("rgblight_init called.\n"); | 188 | |
| 198 | dprintf("rgblight_init start!\n"); | 189 | debug_enable = 1; // Debug ON! |
| 199 | if (!eeconfig_is_enabled()) { | 190 | dprintf("rgblight_init called.\n"); |
| 200 | dprintf("rgblight_init eeconfig is not enabled.\n"); | 191 | dprintf("rgblight_init start!\n"); |
| 201 | eeconfig_init(); | 192 | if (!eeconfig_is_enabled()) { |
| 202 | eeconfig_update_rgblight_default(); | 193 | dprintf("rgblight_init eeconfig is not enabled.\n"); |
| 203 | } | 194 | eeconfig_init(); |
| 204 | rgblight_config.raw = eeconfig_read_rgblight(); | 195 | eeconfig_update_rgblight_default(); |
| 205 | RGBLIGHT_SPLIT_SET_CHANGE_MODEHSVS; | 196 | } |
| 206 | if (!rgblight_config.mode) { | ||
| 207 | dprintf("rgblight_init rgblight_config.mode = 0. Write default values to EEPROM.\n"); | ||
| 208 | eeconfig_update_rgblight_default(); | ||
| 209 | rgblight_config.raw = eeconfig_read_rgblight(); | 197 | rgblight_config.raw = eeconfig_read_rgblight(); |
| 210 | } | 198 | RGBLIGHT_SPLIT_SET_CHANGE_MODEHSVS; |
| 211 | rgblight_check_config(); | 199 | if (!rgblight_config.mode) { |
| 200 | dprintf("rgblight_init rgblight_config.mode = 0. Write default values to EEPROM.\n"); | ||
| 201 | eeconfig_update_rgblight_default(); | ||
| 202 | rgblight_config.raw = eeconfig_read_rgblight(); | ||
| 203 | } | ||
| 204 | rgblight_check_config(); | ||
| 212 | 205 | ||
| 213 | eeconfig_debug_rgblight(); // display current eeprom values | 206 | eeconfig_debug_rgblight(); // display current eeprom values |
| 214 | 207 | ||
| 215 | #ifdef RGBLIGHT_USE_TIMER | 208 | #ifdef RGBLIGHT_USE_TIMER |
| 216 | rgblight_timer_init(); // setup the timer | 209 | rgblight_timer_init(); // setup the timer |
| 217 | #endif | 210 | #endif |
| 218 | 211 | ||
| 219 | if (rgblight_config.enable) { | 212 | if (rgblight_config.enable) { |
| 220 | rgblight_mode_noeeprom(rgblight_config.mode); | 213 | rgblight_mode_noeeprom(rgblight_config.mode); |
| 221 | } | 214 | } |
| 222 | |||
| 223 | is_rgblight_initialized = true; | ||
| 224 | 215 | ||
| 216 | is_rgblight_initialized = true; | ||
| 225 | } | 217 | } |
| 226 | 218 | ||
| 227 | uint32_t rgblight_read_dword(void) { | 219 | uint32_t rgblight_read_dword(void) { return rgblight_config.raw; } |
| 228 | return rgblight_config.raw; | ||
| 229 | } | ||
| 230 | 220 | ||
| 231 | void rgblight_update_dword(uint32_t dword) { | 221 | void rgblight_update_dword(uint32_t dword) { |
| 232 | RGBLIGHT_SPLIT_SET_CHANGE_MODEHSVS; | 222 | RGBLIGHT_SPLIT_SET_CHANGE_MODEHSVS; |
| 233 | rgblight_config.raw = dword; | 223 | rgblight_config.raw = dword; |
| 234 | if (rgblight_config.enable) | 224 | if (rgblight_config.enable) |
| 235 | rgblight_mode_noeeprom(rgblight_config.mode); | 225 | rgblight_mode_noeeprom(rgblight_config.mode); |
| 236 | else { | 226 | else { |
| 237 | #ifdef RGBLIGHT_USE_TIMER | 227 | #ifdef RGBLIGHT_USE_TIMER |
| 238 | rgblight_timer_disable(); | 228 | rgblight_timer_disable(); |
| 239 | #endif | 229 | #endif |
| 240 | rgblight_set(); | 230 | rgblight_set(); |
| 241 | } | 231 | } |
| 242 | } | 232 | } |
| 243 | 233 | ||
| 244 | void rgblight_increase(void) { | 234 | void rgblight_increase(void) { |
| 245 | uint8_t mode = 0; | 235 | uint8_t mode = 0; |
| 246 | if (rgblight_config.mode < RGBLIGHT_MODES) { | 236 | if (rgblight_config.mode < RGBLIGHT_MODES) { |
| 247 | mode = rgblight_config.mode + 1; | 237 | mode = rgblight_config.mode + 1; |
| 248 | } | 238 | } |
| 249 | rgblight_mode(mode); | 239 | rgblight_mode(mode); |
| 250 | } | 240 | } |
| 251 | void rgblight_decrease(void) { | 241 | void rgblight_decrease(void) { |
| 252 | uint8_t mode = 0; | 242 | uint8_t mode = 0; |
| 253 | // Mode will never be < 1. If it ever is, eeprom needs to be initialized. | 243 | // Mode will never be < 1. If it ever is, eeprom needs to be initialized. |
| 254 | if (rgblight_config.mode > RGBLIGHT_MODE_STATIC_LIGHT) { | 244 | if (rgblight_config.mode > RGBLIGHT_MODE_STATIC_LIGHT) { |
| 255 | mode = rgblight_config.mode - 1; | 245 | mode = rgblight_config.mode - 1; |
| 256 | } | 246 | } |
| 257 | rgblight_mode(mode); | 247 | rgblight_mode(mode); |
| 258 | } | 248 | } |
| 259 | void rgblight_step_helper(bool write_to_eeprom) { | 249 | void rgblight_step_helper(bool write_to_eeprom) { |
| 260 | uint8_t mode = 0; | 250 | uint8_t mode = 0; |
| 261 | mode = rgblight_config.mode + 1; | 251 | mode = rgblight_config.mode + 1; |
| 262 | if (mode > RGBLIGHT_MODES) { | 252 | if (mode > RGBLIGHT_MODES) { |
| 263 | mode = 1; | 253 | mode = 1; |
| 264 | } | 254 | } |
| 265 | rgblight_mode_eeprom_helper(mode, write_to_eeprom); | 255 | rgblight_mode_eeprom_helper(mode, write_to_eeprom); |
| 266 | } | ||
| 267 | void rgblight_step_noeeprom(void) { | ||
| 268 | rgblight_step_helper(false); | ||
| 269 | } | ||
| 270 | void rgblight_step(void) { | ||
| 271 | rgblight_step_helper(true); | ||
| 272 | } | 256 | } |
| 257 | void rgblight_step_noeeprom(void) { rgblight_step_helper(false); } | ||
| 258 | void rgblight_step(void) { rgblight_step_helper(true); } | ||
| 273 | void rgblight_step_reverse_helper(bool write_to_eeprom) { | 259 | void rgblight_step_reverse_helper(bool write_to_eeprom) { |
| 274 | uint8_t mode = 0; | 260 | uint8_t mode = 0; |
| 275 | mode = rgblight_config.mode - 1; | 261 | mode = rgblight_config.mode - 1; |
| 276 | if (mode < 1) { | 262 | if (mode < 1) { |
| 277 | mode = RGBLIGHT_MODES; | 263 | mode = RGBLIGHT_MODES; |
| 278 | } | 264 | } |
| 279 | rgblight_mode_eeprom_helper(mode, write_to_eeprom); | 265 | rgblight_mode_eeprom_helper(mode, write_to_eeprom); |
| 280 | } | ||
| 281 | void rgblight_step_reverse_noeeprom(void) { | ||
| 282 | rgblight_step_reverse_helper(false); | ||
| 283 | } | ||
| 284 | void rgblight_step_reverse(void) { | ||
| 285 | rgblight_step_reverse_helper(true); | ||
| 286 | } | 266 | } |
| 267 | void rgblight_step_reverse_noeeprom(void) { rgblight_step_reverse_helper(false); } | ||
| 268 | void rgblight_step_reverse(void) { rgblight_step_reverse_helper(true); } | ||
| 287 | 269 | ||
| 288 | uint8_t rgblight_get_mode(void) { | 270 | uint8_t rgblight_get_mode(void) { |
| 289 | if (!rgblight_config.enable) { | 271 | if (!rgblight_config.enable) { |
| 290 | return false; | 272 | return false; |
| 291 | } | 273 | } |
| 292 | 274 | ||
| 293 | return rgblight_config.mode; | 275 | return rgblight_config.mode; |
| 294 | } | 276 | } |
| 295 | 277 | ||
| 296 | void rgblight_mode_eeprom_helper(uint8_t mode, bool write_to_eeprom) { | 278 | void rgblight_mode_eeprom_helper(uint8_t mode, bool write_to_eeprom) { |
| 297 | if (!rgblight_config.enable) { | 279 | if (!rgblight_config.enable) { |
| 298 | return; | 280 | return; |
| 299 | } | 281 | } |
| 300 | if (mode < RGBLIGHT_MODE_STATIC_LIGHT) { | 282 | if (mode < RGBLIGHT_MODE_STATIC_LIGHT) { |
| 301 | rgblight_config.mode = RGBLIGHT_MODE_STATIC_LIGHT; | 283 | rgblight_config.mode = RGBLIGHT_MODE_STATIC_LIGHT; |
| 302 | } else if (mode > RGBLIGHT_MODES) { | 284 | } else if (mode > RGBLIGHT_MODES) { |
| 303 | rgblight_config.mode = RGBLIGHT_MODES; | 285 | rgblight_config.mode = RGBLIGHT_MODES; |
| 304 | } else { | 286 | } else { |
| 305 | rgblight_config.mode = mode; | 287 | rgblight_config.mode = mode; |
| 306 | } | 288 | } |
| 307 | RGBLIGHT_SPLIT_SET_CHANGE_MODE; | 289 | RGBLIGHT_SPLIT_SET_CHANGE_MODE; |
| 308 | if (write_to_eeprom) { | 290 | if (write_to_eeprom) { |
| 309 | eeconfig_update_rgblight(rgblight_config.raw); | 291 | eeconfig_update_rgblight(rgblight_config.raw); |
| 310 | dprintf("rgblight mode [EEPROM]: %u\n", rgblight_config.mode); | 292 | dprintf("rgblight mode [EEPROM]: %u\n", rgblight_config.mode); |
| 311 | } else { | 293 | } else { |
| 312 | dprintf("rgblight mode [NOEEPROM]: %u\n", rgblight_config.mode); | 294 | dprintf("rgblight mode [NOEEPROM]: %u\n", rgblight_config.mode); |
| 313 | } | 295 | } |
| 314 | if( is_static_effect(rgblight_config.mode) ) { | 296 | if (is_static_effect(rgblight_config.mode)) { |
| 315 | #ifdef RGBLIGHT_USE_TIMER | 297 | #ifdef RGBLIGHT_USE_TIMER |
| 316 | rgblight_timer_disable(); | 298 | rgblight_timer_disable(); |
| 317 | #endif | 299 | #endif |
| 318 | } else { | 300 | } else { |
| 319 | #ifdef RGBLIGHT_USE_TIMER | 301 | #ifdef RGBLIGHT_USE_TIMER |
| 320 | rgblight_timer_enable(); | 302 | rgblight_timer_enable(); |
| 321 | #endif | 303 | #endif |
| 322 | } | 304 | } |
| 323 | #ifdef RGBLIGHT_USE_TIMER | 305 | #ifdef RGBLIGHT_USE_TIMER |
| 324 | animation_status.restart = true; | 306 | animation_status.restart = true; |
| 325 | #endif | 307 | #endif |
| 326 | rgblight_sethsv_noeeprom(rgblight_config.hue, rgblight_config.sat, rgblight_config.val); | 308 | rgblight_sethsv_noeeprom(rgblight_config.hue, rgblight_config.sat, rgblight_config.val); |
| 327 | } | 309 | } |
| 328 | 310 | ||
| 329 | void rgblight_mode(uint8_t mode) { | 311 | void rgblight_mode(uint8_t mode) { rgblight_mode_eeprom_helper(mode, true); } |
| 330 | rgblight_mode_eeprom_helper(mode, true); | ||
| 331 | } | ||
| 332 | |||
| 333 | void rgblight_mode_noeeprom(uint8_t mode) { | ||
| 334 | rgblight_mode_eeprom_helper(mode, false); | ||
| 335 | } | ||
| 336 | 312 | ||
| 313 | void rgblight_mode_noeeprom(uint8_t mode) { rgblight_mode_eeprom_helper(mode, false); } | ||
| 337 | 314 | ||
| 338 | void rgblight_toggle(void) { | 315 | void rgblight_toggle(void) { |
| 339 | dprintf("rgblight toggle [EEPROM]: rgblight_config.enable = %u\n", !rgblight_config.enable); | 316 | dprintf("rgblight toggle [EEPROM]: rgblight_config.enable = %u\n", !rgblight_config.enable); |
| 340 | if (rgblight_config.enable) { | 317 | if (rgblight_config.enable) { |
| 341 | rgblight_disable(); | 318 | rgblight_disable(); |
| 342 | } | 319 | } else { |
| 343 | else { | 320 | rgblight_enable(); |
| 344 | rgblight_enable(); | 321 | } |
| 345 | } | ||
| 346 | } | 322 | } |
| 347 | 323 | ||
| 348 | void rgblight_toggle_noeeprom(void) { | 324 | void rgblight_toggle_noeeprom(void) { |
| 349 | dprintf("rgblight toggle [NOEEPROM]: rgblight_config.enable = %u\n", !rgblight_config.enable); | 325 | dprintf("rgblight toggle [NOEEPROM]: rgblight_config.enable = %u\n", !rgblight_config.enable); |
| 350 | if (rgblight_config.enable) { | 326 | if (rgblight_config.enable) { |
| 351 | rgblight_disable_noeeprom(); | 327 | rgblight_disable_noeeprom(); |
| 352 | } | 328 | } else { |
| 353 | else { | 329 | rgblight_enable_noeeprom(); |
| 354 | rgblight_enable_noeeprom(); | 330 | } |
| 355 | } | ||
| 356 | } | 331 | } |
| 357 | 332 | ||
| 358 | void rgblight_enable(void) { | 333 | void rgblight_enable(void) { |
| 359 | rgblight_config.enable = 1; | 334 | rgblight_config.enable = 1; |
| 360 | // No need to update EEPROM here. rgblight_mode() will do that, actually | 335 | // No need to update EEPROM here. rgblight_mode() will do that, actually |
| 361 | //eeconfig_update_rgblight(rgblight_config.raw); | 336 | // eeconfig_update_rgblight(rgblight_config.raw); |
| 362 | dprintf("rgblight enable [EEPROM]: rgblight_config.enable = %u\n", rgblight_config.enable); | 337 | dprintf("rgblight enable [EEPROM]: rgblight_config.enable = %u\n", rgblight_config.enable); |
| 363 | rgblight_mode(rgblight_config.mode); | 338 | rgblight_mode(rgblight_config.mode); |
| 364 | } | 339 | } |
| 365 | 340 | ||
| 366 | void rgblight_enable_noeeprom(void) { | 341 | void rgblight_enable_noeeprom(void) { |
| 367 | rgblight_config.enable = 1; | 342 | rgblight_config.enable = 1; |
| 368 | dprintf("rgblight enable [NOEEPROM]: rgblight_config.enable = %u\n", rgblight_config.enable); | 343 | dprintf("rgblight enable [NOEEPROM]: rgblight_config.enable = %u\n", rgblight_config.enable); |
| 369 | rgblight_mode_noeeprom(rgblight_config.mode); | 344 | rgblight_mode_noeeprom(rgblight_config.mode); |
| 370 | } | 345 | } |
| 371 | 346 | ||
| 372 | void rgblight_disable(void) { | 347 | void rgblight_disable(void) { |
| 373 | rgblight_config.enable = 0; | 348 | rgblight_config.enable = 0; |
| 374 | eeconfig_update_rgblight(rgblight_config.raw); | 349 | eeconfig_update_rgblight(rgblight_config.raw); |
| 375 | dprintf("rgblight disable [EEPROM]: rgblight_config.enable = %u\n", rgblight_config.enable); | 350 | dprintf("rgblight disable [EEPROM]: rgblight_config.enable = %u\n", rgblight_config.enable); |
| 376 | #ifdef RGBLIGHT_USE_TIMER | 351 | #ifdef RGBLIGHT_USE_TIMER |
| 377 | rgblight_timer_disable(); | 352 | rgblight_timer_disable(); |
| 378 | #endif | 353 | #endif |
| 379 | RGBLIGHT_SPLIT_SET_CHANGE_MODE; | 354 | RGBLIGHT_SPLIT_SET_CHANGE_MODE; |
| 380 | wait_ms(50); | 355 | wait_ms(50); |
| 381 | rgblight_set(); | 356 | rgblight_set(); |
| 382 | } | 357 | } |
| 383 | 358 | ||
| 384 | void rgblight_disable_noeeprom(void) { | 359 | void rgblight_disable_noeeprom(void) { |
| 385 | rgblight_config.enable = 0; | 360 | rgblight_config.enable = 0; |
| 386 | dprintf("rgblight disable [NOEEPROM]: rgblight_config.enable = %u\n", rgblight_config.enable); | 361 | dprintf("rgblight disable [NOEEPROM]: rgblight_config.enable = %u\n", rgblight_config.enable); |
| 387 | #ifdef RGBLIGHT_USE_TIMER | 362 | #ifdef RGBLIGHT_USE_TIMER |
| 388 | rgblight_timer_disable(); | 363 | rgblight_timer_disable(); |
| 389 | #endif | 364 | #endif |
| 390 | RGBLIGHT_SPLIT_SET_CHANGE_MODE; | 365 | RGBLIGHT_SPLIT_SET_CHANGE_MODE; |
| 391 | wait_ms(50); | 366 | wait_ms(50); |
| 392 | rgblight_set(); | 367 | rgblight_set(); |
| 393 | } | 368 | } |
| 394 | 369 | ||
| 395 | void rgblight_increase_hue_helper(bool write_to_eeprom) { | 370 | void rgblight_increase_hue_helper(bool write_to_eeprom) { |
| 396 | uint8_t hue = rgblight_config.hue + RGBLIGHT_HUE_STEP; | 371 | uint8_t hue = rgblight_config.hue + RGBLIGHT_HUE_STEP; |
| 397 | rgblight_sethsv_eeprom_helper(hue, rgblight_config.sat, rgblight_config.val, write_to_eeprom); | 372 | rgblight_sethsv_eeprom_helper(hue, rgblight_config.sat, rgblight_config.val, write_to_eeprom); |
| 398 | } | ||
| 399 | void rgblight_increase_hue_noeeprom(void) { | ||
| 400 | rgblight_increase_hue_helper(false); | ||
| 401 | } | ||
| 402 | void rgblight_increase_hue(void) { | ||
| 403 | rgblight_increase_hue_helper(true); | ||
| 404 | } | 373 | } |
| 374 | void rgblight_increase_hue_noeeprom(void) { rgblight_increase_hue_helper(false); } | ||
| 375 | void rgblight_increase_hue(void) { rgblight_increase_hue_helper(true); } | ||
| 405 | void rgblight_decrease_hue_helper(bool write_to_eeprom) { | 376 | void rgblight_decrease_hue_helper(bool write_to_eeprom) { |
| 406 | uint8_t hue = rgblight_config.hue - RGBLIGHT_HUE_STEP; | 377 | uint8_t hue = rgblight_config.hue - RGBLIGHT_HUE_STEP; |
| 407 | rgblight_sethsv_eeprom_helper(hue, rgblight_config.sat, rgblight_config.val, write_to_eeprom); | 378 | rgblight_sethsv_eeprom_helper(hue, rgblight_config.sat, rgblight_config.val, write_to_eeprom); |
| 408 | } | ||
| 409 | void rgblight_decrease_hue_noeeprom(void) { | ||
| 410 | rgblight_decrease_hue_helper(false); | ||
| 411 | } | ||
| 412 | void rgblight_decrease_hue(void) { | ||
| 413 | rgblight_decrease_hue_helper(true); | ||
| 414 | } | 379 | } |
| 380 | void rgblight_decrease_hue_noeeprom(void) { rgblight_decrease_hue_helper(false); } | ||
| 381 | void rgblight_decrease_hue(void) { rgblight_decrease_hue_helper(true); } | ||
| 415 | void rgblight_increase_sat_helper(bool write_to_eeprom) { | 382 | void rgblight_increase_sat_helper(bool write_to_eeprom) { |
| 416 | uint8_t sat = qadd8(rgblight_config.sat, RGBLIGHT_SAT_STEP); | 383 | uint8_t sat = qadd8(rgblight_config.sat, RGBLIGHT_SAT_STEP); |
| 417 | rgblight_sethsv_eeprom_helper(rgblight_config.hue, sat, rgblight_config.val, write_to_eeprom); | 384 | rgblight_sethsv_eeprom_helper(rgblight_config.hue, sat, rgblight_config.val, write_to_eeprom); |
| 418 | } | ||
| 419 | void rgblight_increase_sat_noeeprom(void) { | ||
| 420 | rgblight_increase_sat_helper(false); | ||
| 421 | } | ||
| 422 | void rgblight_increase_sat(void) { | ||
| 423 | rgblight_increase_sat_helper(true); | ||
| 424 | } | 385 | } |
| 386 | void rgblight_increase_sat_noeeprom(void) { rgblight_increase_sat_helper(false); } | ||
| 387 | void rgblight_increase_sat(void) { rgblight_increase_sat_helper(true); } | ||
| 425 | void rgblight_decrease_sat_helper(bool write_to_eeprom) { | 388 | void rgblight_decrease_sat_helper(bool write_to_eeprom) { |
| 426 | uint8_t sat = qsub8(rgblight_config.sat, RGBLIGHT_SAT_STEP); | 389 | uint8_t sat = qsub8(rgblight_config.sat, RGBLIGHT_SAT_STEP); |
| 427 | rgblight_sethsv_eeprom_helper(rgblight_config.hue, sat, rgblight_config.val, write_to_eeprom); | 390 | rgblight_sethsv_eeprom_helper(rgblight_config.hue, sat, rgblight_config.val, write_to_eeprom); |
| 428 | } | ||
| 429 | void rgblight_decrease_sat_noeeprom(void) { | ||
| 430 | rgblight_decrease_sat_helper(false); | ||
| 431 | } | ||
| 432 | void rgblight_decrease_sat(void) { | ||
| 433 | rgblight_decrease_sat_helper(true); | ||
| 434 | } | 391 | } |
| 392 | void rgblight_decrease_sat_noeeprom(void) { rgblight_decrease_sat_helper(false); } | ||
| 393 | void rgblight_decrease_sat(void) { rgblight_decrease_sat_helper(true); } | ||
| 435 | void rgblight_increase_val_helper(bool write_to_eeprom) { | 394 | void rgblight_increase_val_helper(bool write_to_eeprom) { |
| 436 | uint8_t val = qadd8(rgblight_config.val, RGBLIGHT_VAL_STEP); | 395 | uint8_t val = qadd8(rgblight_config.val, RGBLIGHT_VAL_STEP); |
| 437 | rgblight_sethsv_eeprom_helper(rgblight_config.hue, rgblight_config.sat, val, write_to_eeprom); | 396 | rgblight_sethsv_eeprom_helper(rgblight_config.hue, rgblight_config.sat, val, write_to_eeprom); |
| 438 | } | ||
| 439 | void rgblight_increase_val_noeeprom(void) { | ||
| 440 | rgblight_increase_val_helper(false); | ||
| 441 | } | ||
| 442 | void rgblight_increase_val(void) { | ||
| 443 | rgblight_increase_val_helper(true); | ||
| 444 | } | 397 | } |
| 398 | void rgblight_increase_val_noeeprom(void) { rgblight_increase_val_helper(false); } | ||
| 399 | void rgblight_increase_val(void) { rgblight_increase_val_helper(true); } | ||
| 445 | void rgblight_decrease_val_helper(bool write_to_eeprom) { | 400 | void rgblight_decrease_val_helper(bool write_to_eeprom) { |
| 446 | uint8_t val = qsub8(rgblight_config.val, RGBLIGHT_VAL_STEP); | 401 | uint8_t val = qsub8(rgblight_config.val, RGBLIGHT_VAL_STEP); |
| 447 | rgblight_sethsv_eeprom_helper(rgblight_config.hue, rgblight_config.sat, val, write_to_eeprom); | 402 | rgblight_sethsv_eeprom_helper(rgblight_config.hue, rgblight_config.sat, val, write_to_eeprom); |
| 448 | } | ||
| 449 | void rgblight_decrease_val_noeeprom(void) { | ||
| 450 | rgblight_decrease_val_helper(false); | ||
| 451 | } | ||
| 452 | void rgblight_decrease_val(void) { | ||
| 453 | rgblight_decrease_val_helper(true); | ||
| 454 | } | 403 | } |
| 404 | void rgblight_decrease_val_noeeprom(void) { rgblight_decrease_val_helper(false); } | ||
| 405 | void rgblight_decrease_val(void) { rgblight_decrease_val_helper(true); } | ||
| 455 | void rgblight_increase_speed(void) { | 406 | void rgblight_increase_speed(void) { |
| 456 | if (rgblight_config.speed < 3) | 407 | if (rgblight_config.speed < 3) rgblight_config.speed++; |
| 457 | rgblight_config.speed++; | 408 | // RGBLIGHT_SPLIT_SET_CHANGE_HSVS; // NEED? |
| 458 | //RGBLIGHT_SPLIT_SET_CHANGE_HSVS; // NEED? | 409 | eeconfig_update_rgblight(rgblight_config.raw); // EECONFIG needs to be increased to support this |
| 459 | eeconfig_update_rgblight(rgblight_config.raw);//EECONFIG needs to be increased to support this | ||
| 460 | } | 410 | } |
| 461 | 411 | ||
| 462 | void rgblight_decrease_speed(void) { | 412 | void rgblight_decrease_speed(void) { |
| 463 | if (rgblight_config.speed > 0) | 413 | if (rgblight_config.speed > 0) rgblight_config.speed--; |
| 464 | rgblight_config.speed--; | 414 | // RGBLIGHT_SPLIT_SET_CHANGE_HSVS; // NEED?? |
| 465 | //RGBLIGHT_SPLIT_SET_CHANGE_HSVS; // NEED?? | 415 | eeconfig_update_rgblight(rgblight_config.raw); // EECONFIG needs to be increased to support this |
| 466 | eeconfig_update_rgblight(rgblight_config.raw);//EECONFIG needs to be increased to support this | ||
| 467 | } | 416 | } |
| 468 | 417 | ||
| 469 | void rgblight_sethsv_noeeprom_old(uint8_t hue, uint8_t sat, uint8_t val) { | 418 | void rgblight_sethsv_noeeprom_old(uint8_t hue, uint8_t sat, uint8_t val) { |
| 470 | if (rgblight_config.enable) { | 419 | if (rgblight_config.enable) { |
| 471 | LED_TYPE tmp_led; | 420 | LED_TYPE tmp_led; |
| 472 | sethsv(hue, sat, val, &tmp_led); | 421 | sethsv(hue, sat, val, &tmp_led); |
| 473 | rgblight_setrgb(tmp_led.r, tmp_led.g, tmp_led.b); | 422 | rgblight_setrgb(tmp_led.r, tmp_led.g, tmp_led.b); |
| 474 | } | 423 | } |
| 475 | } | 424 | } |
| 476 | 425 | ||
| 477 | void rgblight_sethsv_eeprom_helper(uint8_t hue, uint8_t sat, uint8_t val, bool write_to_eeprom) { | 426 | void rgblight_sethsv_eeprom_helper(uint8_t hue, uint8_t sat, uint8_t val, bool write_to_eeprom) { |
| 478 | if (rgblight_config.enable) { | 427 | if (rgblight_config.enable) { |
| 479 | rgblight_status.base_mode = mode_base_table[rgblight_config.mode]; | 428 | rgblight_status.base_mode = mode_base_table[rgblight_config.mode]; |
| 480 | if (rgblight_config.mode == RGBLIGHT_MODE_STATIC_LIGHT) { | 429 | if (rgblight_config.mode == RGBLIGHT_MODE_STATIC_LIGHT) { |
| 481 | // same static color | 430 | // same static color |
| 482 | LED_TYPE tmp_led; | 431 | LED_TYPE tmp_led; |
| 483 | sethsv(hue, sat, val, &tmp_led); | 432 | sethsv(hue, sat, val, &tmp_led); |
| 484 | rgblight_setrgb(tmp_led.r, tmp_led.g, tmp_led.b); | 433 | rgblight_setrgb(tmp_led.r, tmp_led.g, tmp_led.b); |
| 485 | } else { | 434 | } else { |
| 486 | // all LEDs in same color | 435 | // all LEDs in same color |
| 487 | if ( 1 == 0 ) { //dummy | 436 | if (1 == 0) { // dummy |
| 488 | } | 437 | } |
| 489 | #ifdef RGBLIGHT_EFFECT_BREATHING | 438 | #ifdef RGBLIGHT_EFFECT_BREATHING |
| 490 | else if (rgblight_status.base_mode == RGBLIGHT_MODE_BREATHING ) { | 439 | else if (rgblight_status.base_mode == RGBLIGHT_MODE_BREATHING) { |
| 491 | // breathing mode, ignore the change of val, use in memory value instead | 440 | // breathing mode, ignore the change of val, use in memory value instead |
| 492 | val = rgblight_config.val; | 441 | val = rgblight_config.val; |
| 493 | } | 442 | } |
| 494 | #endif | 443 | #endif |
| 495 | #ifdef RGBLIGHT_EFFECT_RAINBOW_MOOD | 444 | #ifdef RGBLIGHT_EFFECT_RAINBOW_MOOD |
| 496 | else if (rgblight_status.base_mode == RGBLIGHT_MODE_RAINBOW_MOOD) { | 445 | else if (rgblight_status.base_mode == RGBLIGHT_MODE_RAINBOW_MOOD) { |
| 497 | // rainbow mood, ignore the change of hue | 446 | // rainbow mood, ignore the change of hue |
| 498 | hue = rgblight_config.hue; | 447 | hue = rgblight_config.hue; |
| 499 | } | 448 | } |
| 500 | #endif | 449 | #endif |
| 501 | #ifdef RGBLIGHT_EFFECT_RAINBOW_SWIRL | 450 | #ifdef RGBLIGHT_EFFECT_RAINBOW_SWIRL |
| 502 | else if (rgblight_status.base_mode == RGBLIGHT_MODE_RAINBOW_SWIRL) { | 451 | else if (rgblight_status.base_mode == RGBLIGHT_MODE_RAINBOW_SWIRL) { |
| 503 | // rainbow swirl, ignore the change of hue | 452 | // rainbow swirl, ignore the change of hue |
| 504 | hue = rgblight_config.hue; | 453 | hue = rgblight_config.hue; |
| 505 | } | 454 | } |
| 506 | #endif | 455 | #endif |
| 507 | #ifdef RGBLIGHT_EFFECT_STATIC_GRADIENT | 456 | #ifdef RGBLIGHT_EFFECT_STATIC_GRADIENT |
| 508 | else if (rgblight_status.base_mode == RGBLIGHT_MODE_STATIC_GRADIENT) { | 457 | else if (rgblight_status.base_mode == RGBLIGHT_MODE_STATIC_GRADIENT) { |
| 509 | // static gradient | 458 | // static gradient |
| 510 | uint8_t delta = rgblight_config.mode - rgblight_status.base_mode; | 459 | uint8_t delta = rgblight_config.mode - rgblight_status.base_mode; |
| 511 | bool direction = (delta % 2) == 0; | 460 | bool direction = (delta % 2) == 0; |
| 512 | #ifdef __AVR__ | 461 | # ifdef __AVR__ |
| 513 | // probably due to how pgm_read_word is defined for ARM, but the ARM compiler really hates this line | 462 | // probably due to how pgm_read_word is defined for ARM, but the ARM compiler really hates this line |
| 514 | uint8_t range = pgm_read_word(&RGBLED_GRADIENT_RANGES[delta / 2]); | 463 | uint8_t range = pgm_read_word(&RGBLED_GRADIENT_RANGES[delta / 2]); |
| 515 | #else | 464 | # else |
| 516 | uint8_t range = RGBLED_GRADIENT_RANGES[delta / 2]; | 465 | uint8_t range = RGBLED_GRADIENT_RANGES[delta / 2]; |
| 466 | # endif | ||
| 467 | for (uint8_t i = 0; i < effect_num_leds; i++) { | ||
| 468 | uint8_t _hue = ((uint16_t)i * (uint16_t)range) / effect_num_leds; | ||
| 469 | if (direction) { | ||
| 470 | _hue = hue + _hue; | ||
| 471 | } else { | ||
| 472 | _hue = hue - _hue; | ||
| 473 | } | ||
| 474 | dprintf("rgblight rainbow set hsv: %d,%d,%d,%u\n", i, _hue, direction, range); | ||
| 475 | sethsv(_hue, sat, val, (LED_TYPE *)&led[i + effect_start_pos]); | ||
| 476 | } | ||
| 477 | rgblight_set(); | ||
| 478 | } | ||
| 517 | #endif | 479 | #endif |
| 518 | for (uint8_t i = 0; i < effect_num_leds; i++) { | ||
| 519 | uint8_t _hue = ((uint16_t)i * (uint16_t)range) / effect_num_leds; | ||
| 520 | if (direction) { | ||
| 521 | _hue = hue + _hue; | ||
| 522 | } else { | ||
| 523 | _hue = hue - _hue; | ||
| 524 | } | ||
| 525 | dprintf("rgblight rainbow set hsv: %d,%d,%d,%u\n", i, _hue, direction, range); | ||
| 526 | sethsv(_hue, sat, val, (LED_TYPE *)&led[i + effect_start_pos]); | ||
| 527 | } | 480 | } |
| 528 | rgblight_set(); | ||
| 529 | } | ||
| 530 | #endif | ||
| 531 | } | ||
| 532 | #ifdef RGBLIGHT_SPLIT | 481 | #ifdef RGBLIGHT_SPLIT |
| 533 | if( rgblight_config.hue != hue || | 482 | if (rgblight_config.hue != hue || rgblight_config.sat != sat || rgblight_config.val != val) { |
| 534 | rgblight_config.sat != sat || | 483 | RGBLIGHT_SPLIT_SET_CHANGE_HSVS; |
| 535 | rgblight_config.val != val ) { | 484 | } |
| 536 | RGBLIGHT_SPLIT_SET_CHANGE_HSVS; | ||
| 537 | } | ||
| 538 | #endif | 485 | #endif |
| 539 | rgblight_config.hue = hue; | 486 | rgblight_config.hue = hue; |
| 540 | rgblight_config.sat = sat; | 487 | rgblight_config.sat = sat; |
| 541 | rgblight_config.val = val; | 488 | rgblight_config.val = val; |
| 542 | if (write_to_eeprom) { | 489 | if (write_to_eeprom) { |
| 543 | eeconfig_update_rgblight(rgblight_config.raw); | 490 | eeconfig_update_rgblight(rgblight_config.raw); |
| 544 | dprintf("rgblight set hsv [EEPROM]: %u,%u,%u\n", rgblight_config.hue, rgblight_config.sat, rgblight_config.val); | 491 | dprintf("rgblight set hsv [EEPROM]: %u,%u,%u\n", rgblight_config.hue, rgblight_config.sat, rgblight_config.val); |
| 545 | } else { | 492 | } else { |
| 546 | dprintf("rgblight set hsv [NOEEPROM]: %u,%u,%u\n", rgblight_config.hue, rgblight_config.sat, rgblight_config.val); | 493 | dprintf("rgblight set hsv [NOEEPROM]: %u,%u,%u\n", rgblight_config.hue, rgblight_config.sat, rgblight_config.val); |
| 494 | } | ||
| 547 | } | 495 | } |
| 548 | } | ||
| 549 | } | 496 | } |
| 550 | 497 | ||
| 551 | void rgblight_sethsv(uint8_t hue, uint8_t sat, uint8_t val) { | 498 | void rgblight_sethsv(uint8_t hue, uint8_t sat, uint8_t val) { rgblight_sethsv_eeprom_helper(hue, sat, val, true); } |
| 552 | rgblight_sethsv_eeprom_helper(hue, sat, val, true); | ||
| 553 | } | ||
| 554 | 499 | ||
| 555 | void rgblight_sethsv_noeeprom(uint8_t hue, uint8_t sat, uint8_t val) { | 500 | void rgblight_sethsv_noeeprom(uint8_t hue, uint8_t sat, uint8_t val) { rgblight_sethsv_eeprom_helper(hue, sat, val, false); } |
| 556 | rgblight_sethsv_eeprom_helper(hue, sat, val, false); | ||
| 557 | } | ||
| 558 | 501 | ||
| 559 | uint8_t rgblight_get_hue(void) { | 502 | uint8_t rgblight_get_hue(void) { return rgblight_config.hue; } |
| 560 | return rgblight_config.hue; | ||
| 561 | } | ||
| 562 | 503 | ||
| 563 | uint8_t rgblight_get_sat(void) { | 504 | uint8_t rgblight_get_sat(void) { return rgblight_config.sat; } |
| 564 | return rgblight_config.sat; | ||
| 565 | } | ||
| 566 | 505 | ||
| 567 | uint8_t rgblight_get_val(void) { | 506 | uint8_t rgblight_get_val(void) { return rgblight_config.val; } |
| 568 | return rgblight_config.val; | ||
| 569 | } | ||
| 570 | 507 | ||
| 571 | void rgblight_setrgb(uint8_t r, uint8_t g, uint8_t b) { | 508 | void rgblight_setrgb(uint8_t r, uint8_t g, uint8_t b) { |
| 572 | if (!rgblight_config.enable) { return; } | 509 | if (!rgblight_config.enable) { |
| 573 | 510 | return; | |
| 574 | for (uint8_t i = effect_start_pos; i < effect_end_pos; i++) { | 511 | } |
| 575 | led[i].r = r; | 512 | |
| 576 | led[i].g = g; | 513 | for (uint8_t i = effect_start_pos; i < effect_end_pos; i++) { |
| 577 | led[i].b = b; | 514 | led[i].r = r; |
| 578 | } | 515 | led[i].g = g; |
| 579 | rgblight_set(); | 516 | led[i].b = b; |
| 517 | } | ||
| 518 | rgblight_set(); | ||
| 580 | } | 519 | } |
| 581 | 520 | ||
| 582 | void rgblight_setrgb_at(uint8_t r, uint8_t g, uint8_t b, uint8_t index) { | 521 | void rgblight_setrgb_at(uint8_t r, uint8_t g, uint8_t b, uint8_t index) { |
| 583 | if (!rgblight_config.enable || index >= RGBLED_NUM) { return; } | 522 | if (!rgblight_config.enable || index >= RGBLED_NUM) { |
| 523 | return; | ||
| 524 | } | ||
| 584 | 525 | ||
| 585 | led[index].r = r; | 526 | led[index].r = r; |
| 586 | led[index].g = g; | 527 | led[index].g = g; |
| 587 | led[index].b = b; | 528 | led[index].b = b; |
| 588 | rgblight_set(); | 529 | rgblight_set(); |
| 589 | } | 530 | } |
| 590 | 531 | ||
| 591 | void rgblight_sethsv_at(uint8_t hue, uint8_t sat, uint8_t val, uint8_t index) { | 532 | void rgblight_sethsv_at(uint8_t hue, uint8_t sat, uint8_t val, uint8_t index) { |
| 592 | if (!rgblight_config.enable) { return; } | 533 | if (!rgblight_config.enable) { |
| 534 | return; | ||
| 535 | } | ||
| 593 | 536 | ||
| 594 | LED_TYPE tmp_led; | 537 | LED_TYPE tmp_led; |
| 595 | sethsv(hue, sat, val, &tmp_led); | 538 | sethsv(hue, sat, val, &tmp_led); |
| 596 | rgblight_setrgb_at(tmp_led.r, tmp_led.g, tmp_led.b, index); | 539 | rgblight_setrgb_at(tmp_led.r, tmp_led.g, tmp_led.b, index); |
| 597 | } | 540 | } |
| 598 | 541 | ||
| 599 | #if defined(RGBLIGHT_EFFECT_BREATHING) || defined(RGBLIGHT_EFFECT_RAINBOW_MOOD) || defined(RGBLIGHT_EFFECT_RAINBOW_SWIRL) \ | 542 | #if defined(RGBLIGHT_EFFECT_BREATHING) || defined(RGBLIGHT_EFFECT_RAINBOW_MOOD) || defined(RGBLIGHT_EFFECT_RAINBOW_SWIRL) || defined(RGBLIGHT_EFFECT_SNAKE) || defined(RGBLIGHT_EFFECT_KNIGHT) |
| 600 | || defined(RGBLIGHT_EFFECT_SNAKE) || defined(RGBLIGHT_EFFECT_KNIGHT) | ||
| 601 | 543 | ||
| 602 | static uint8_t get_interval_time(const uint8_t* default_interval_address, uint8_t velocikey_min, uint8_t velocikey_max) { | 544 | static uint8_t get_interval_time(const uint8_t *default_interval_address, uint8_t velocikey_min, uint8_t velocikey_max) { |
| 603 | return | 545 | return |
| 604 | #ifdef VELOCIKEY_ENABLE | 546 | # ifdef VELOCIKEY_ENABLE |
| 605 | velocikey_enabled() ? velocikey_match_speed(velocikey_min, velocikey_max) : | 547 | velocikey_enabled() ? velocikey_match_speed(velocikey_min, velocikey_max) : |
| 606 | #endif | 548 | # endif |
| 607 | pgm_read_byte(default_interval_address); | 549 | pgm_read_byte(default_interval_address); |
| 608 | } | 550 | } |
| 609 | 551 | ||
| 610 | #endif | 552 | #endif |
| 611 | 553 | ||
| 612 | void rgblight_setrgb_range(uint8_t r, uint8_t g, uint8_t b, uint8_t start, uint8_t end) { | 554 | void rgblight_setrgb_range(uint8_t r, uint8_t g, uint8_t b, uint8_t start, uint8_t end) { |
| 613 | if (!rgblight_config.enable || start < 0 || start >= end || end > RGBLED_NUM) { return; } | 555 | if (!rgblight_config.enable || start < 0 || start >= end || end > RGBLED_NUM) { |
| 614 | 556 | return; | |
| 615 | for (uint8_t i = start; i < end; i++) { | 557 | } |
| 616 | led[i].r = r; | 558 | |
| 617 | led[i].g = g; | 559 | for (uint8_t i = start; i < end; i++) { |
| 618 | led[i].b = b; | 560 | led[i].r = r; |
| 619 | } | 561 | led[i].g = g; |
| 620 | rgblight_set(); | 562 | led[i].b = b; |
| 621 | wait_ms(1); | 563 | } |
| 564 | rgblight_set(); | ||
| 565 | wait_ms(1); | ||
| 622 | } | 566 | } |
| 623 | 567 | ||
| 624 | void rgblight_sethsv_range(uint8_t hue, uint8_t sat, uint8_t val, uint8_t start, uint8_t end) { | 568 | void rgblight_sethsv_range(uint8_t hue, uint8_t sat, uint8_t val, uint8_t start, uint8_t end) { |
| 625 | if (!rgblight_config.enable) { return; } | 569 | if (!rgblight_config.enable) { |
| 570 | return; | ||
| 571 | } | ||
| 626 | 572 | ||
| 627 | LED_TYPE tmp_led; | 573 | LED_TYPE tmp_led; |
| 628 | sethsv(hue, sat, val, &tmp_led); | 574 | sethsv(hue, sat, val, &tmp_led); |
| 629 | rgblight_setrgb_range(tmp_led.r, tmp_led.g, tmp_led.b, start, end); | 575 | rgblight_setrgb_range(tmp_led.r, tmp_led.g, tmp_led.b, start, end); |
| 630 | } | 576 | } |
| 631 | 577 | ||
| 632 | #ifndef RGBLIGHT_SPLIT | 578 | #ifndef RGBLIGHT_SPLIT |
| 633 | void rgblight_setrgb_master(uint8_t r, uint8_t g, uint8_t b) { | 579 | void rgblight_setrgb_master(uint8_t r, uint8_t g, uint8_t b) { rgblight_setrgb_range(r, g, b, 0, (uint8_t)RGBLED_NUM / 2); } |
| 634 | rgblight_setrgb_range(r, g, b, 0 , (uint8_t) RGBLED_NUM/2); | ||
| 635 | } | ||
| 636 | 580 | ||
| 637 | void rgblight_setrgb_slave(uint8_t r, uint8_t g, uint8_t b) { | 581 | void rgblight_setrgb_slave(uint8_t r, uint8_t g, uint8_t b) { rgblight_setrgb_range(r, g, b, (uint8_t)RGBLED_NUM / 2, (uint8_t)RGBLED_NUM); } |
| 638 | rgblight_setrgb_range(r, g, b, (uint8_t) RGBLED_NUM/2, (uint8_t) RGBLED_NUM); | ||
| 639 | } | ||
| 640 | 582 | ||
| 641 | void rgblight_sethsv_master(uint8_t hue, uint8_t sat, uint8_t val) { | 583 | void rgblight_sethsv_master(uint8_t hue, uint8_t sat, uint8_t val) { rgblight_sethsv_range(hue, sat, val, 0, (uint8_t)RGBLED_NUM / 2); } |
| 642 | rgblight_sethsv_range(hue, sat, val, 0, (uint8_t) RGBLED_NUM/2); | ||
| 643 | } | ||
| 644 | 584 | ||
| 645 | void rgblight_sethsv_slave(uint8_t hue, uint8_t sat, uint8_t val) { | 585 | void rgblight_sethsv_slave(uint8_t hue, uint8_t sat, uint8_t val) { rgblight_sethsv_range(hue, sat, val, (uint8_t)RGBLED_NUM / 2, (uint8_t)RGBLED_NUM); } |
| 646 | rgblight_sethsv_range(hue, sat, val, (uint8_t) RGBLED_NUM/2, (uint8_t) RGBLED_NUM); | 586 | #endif // ifndef RGBLIGHT_SPLIT |
| 647 | } | ||
| 648 | #endif // ifndef RGBLIGHT_SPLIT | ||
| 649 | 587 | ||
| 650 | #ifndef RGBLIGHT_CUSTOM_DRIVER | 588 | #ifndef RGBLIGHT_CUSTOM_DRIVER |
| 651 | void rgblight_set(void) { | 589 | void rgblight_set(void) { |
| 652 | LED_TYPE *start_led; | 590 | LED_TYPE *start_led; |
| 653 | uint16_t num_leds = clipping_num_leds; | 591 | uint16_t num_leds = clipping_num_leds; |
| 654 | 592 | ||
| 655 | if (!rgblight_config.enable) { | 593 | if (!rgblight_config.enable) { |
| 656 | for (uint8_t i = effect_start_pos; i < effect_end_pos; i++) { | 594 | for (uint8_t i = effect_start_pos; i < effect_end_pos; i++) { |
| 657 | led[i].r = 0; | 595 | led[i].r = 0; |
| 658 | led[i].g = 0; | 596 | led[i].g = 0; |
| 659 | led[i].b = 0; | 597 | led[i].b = 0; |
| 598 | } | ||
| 660 | } | 599 | } |
| 661 | } | 600 | # ifdef RGBLIGHT_LED_MAP |
| 662 | #ifdef RGBLIGHT_LED_MAP | 601 | LED_TYPE led0[RGBLED_NUM]; |
| 663 | LED_TYPE led0[RGBLED_NUM]; | 602 | for (uint8_t i = 0; i < RGBLED_NUM; i++) { |
| 664 | for(uint8_t i = 0; i < RGBLED_NUM; i++) { | 603 | led0[i] = led[pgm_read_byte(&led_map[i])]; |
| 665 | led0[i] = led[pgm_read_byte(&led_map[i])]; | 604 | } |
| 666 | } | 605 | start_led = led0 + clipping_start_pos; |
| 667 | start_led = led0 + clipping_start_pos; | 606 | # else |
| 668 | #else | 607 | start_led = led + clipping_start_pos; |
| 669 | start_led = led + clipping_start_pos; | 608 | # endif |
| 670 | #endif | 609 | # ifdef RGBW |
| 671 | #ifdef RGBW | 610 | ws2812_setleds_rgbw(start_led, num_leds); |
| 672 | ws2812_setleds_rgbw(start_led, num_leds); | 611 | # else |
| 673 | #else | 612 | ws2812_setleds(start_led, num_leds); |
| 674 | ws2812_setleds(start_led, num_leds); | 613 | # endif |
| 675 | #endif | ||
| 676 | } | 614 | } |
| 677 | #endif | 615 | #endif |
| 678 | 616 | ||
| 679 | #ifdef RGBLIGHT_SPLIT | 617 | #ifdef RGBLIGHT_SPLIT |
| 680 | /* for split keyboard master side */ | 618 | /* for split keyboard master side */ |
| 681 | uint8_t rgblight_get_change_flags(void) { | 619 | uint8_t rgblight_get_change_flags(void) { return rgblight_status.change_flags; } |
| 682 | return rgblight_status.change_flags; | ||
| 683 | } | ||
| 684 | 620 | ||
| 685 | void rgblight_clear_change_flags(void) { | 621 | void rgblight_clear_change_flags(void) { rgblight_status.change_flags = 0; } |
| 686 | rgblight_status.change_flags = 0; | ||
| 687 | } | ||
| 688 | 622 | ||
| 689 | void rgblight_get_syncinfo(rgblight_syncinfo_t *syncinfo) { | 623 | void rgblight_get_syncinfo(rgblight_syncinfo_t *syncinfo) { |
| 690 | syncinfo->config = rgblight_config; | 624 | syncinfo->config = rgblight_config; |
| @@ -695,7 +629,7 @@ void rgblight_get_syncinfo(rgblight_syncinfo_t *syncinfo) { | |||
| 695 | void rgblight_update_sync(rgblight_syncinfo_t *syncinfo, bool write_to_eeprom) { | 629 | void rgblight_update_sync(rgblight_syncinfo_t *syncinfo, bool write_to_eeprom) { |
| 696 | if (syncinfo->status.change_flags & RGBLIGHT_STATUS_CHANGE_MODE) { | 630 | if (syncinfo->status.change_flags & RGBLIGHT_STATUS_CHANGE_MODE) { |
| 697 | if (syncinfo->config.enable) { | 631 | if (syncinfo->config.enable) { |
| 698 | rgblight_config.enable = 1; // == rgblight_enable_noeeprom(); | 632 | rgblight_config.enable = 1; // == rgblight_enable_noeeprom(); |
| 699 | rgblight_mode_eeprom_helper(syncinfo->config.mode, write_to_eeprom); | 633 | rgblight_mode_eeprom_helper(syncinfo->config.mode, write_to_eeprom); |
| 700 | } else { | 634 | } else { |
| 701 | rgblight_disable_noeeprom(); | 635 | rgblight_disable_noeeprom(); |
| @@ -705,7 +639,7 @@ void rgblight_update_sync(rgblight_syncinfo_t *syncinfo, bool write_to_eeprom) { | |||
| 705 | rgblight_sethsv_eeprom_helper(syncinfo->config.hue, syncinfo->config.sat, syncinfo->config.val, write_to_eeprom); | 639 | rgblight_sethsv_eeprom_helper(syncinfo->config.hue, syncinfo->config.sat, syncinfo->config.val, write_to_eeprom); |
| 706 | // rgblight_config.speed = config->speed; // NEED??? | 640 | // rgblight_config.speed = config->speed; // NEED??? |
| 707 | } | 641 | } |
| 708 | #ifdef RGBLIGHT_USE_TIMER | 642 | # ifdef RGBLIGHT_USE_TIMER |
| 709 | if (syncinfo->status.change_flags & RGBLIGHT_STATUS_CHANGE_TIMER) { | 643 | if (syncinfo->status.change_flags & RGBLIGHT_STATUS_CHANGE_TIMER) { |
| 710 | if (syncinfo->status.timer_enabled) { | 644 | if (syncinfo->status.timer_enabled) { |
| 711 | rgblight_timer_enable(); | 645 | rgblight_timer_enable(); |
| @@ -713,12 +647,12 @@ void rgblight_update_sync(rgblight_syncinfo_t *syncinfo, bool write_to_eeprom) { | |||
| 713 | rgblight_timer_disable(); | 647 | rgblight_timer_disable(); |
| 714 | } | 648 | } |
| 715 | } | 649 | } |
| 716 | #ifndef RGBLIGHT_SPLIT_NO_ANIMATION_SYNC | 650 | # ifndef RGBLIGHT_SPLIT_NO_ANIMATION_SYNC |
| 717 | if (syncinfo->status.change_flags & RGBLIGHT_STATUS_ANIMATION_TICK) { | 651 | if (syncinfo->status.change_flags & RGBLIGHT_STATUS_ANIMATION_TICK) { |
| 718 | animation_status.restart = true; | 652 | animation_status.restart = true; |
| 719 | } | 653 | } |
| 720 | #endif /* RGBLIGHT_SPLIT_NO_ANIMATION_SYNC */ | 654 | # endif /* RGBLIGHT_SPLIT_NO_ANIMATION_SYNC */ |
| 721 | #endif /* RGBLIGHT_USE_TIMER */ | 655 | # endif /* RGBLIGHT_USE_TIMER */ |
| 722 | } | 656 | } |
| 723 | #endif /* RGBLIGHT_SPLIT */ | 657 | #endif /* RGBLIGHT_SPLIT */ |
| 724 | 658 | ||
| @@ -728,51 +662,51 @@ typedef void (*effect_func_t)(animation_status_t *anim); | |||
| 728 | 662 | ||
| 729 | // Animation timer -- use system timer (AVR Timer0) | 663 | // Animation timer -- use system timer (AVR Timer0) |
| 730 | void rgblight_timer_init(void) { | 664 | void rgblight_timer_init(void) { |
| 731 | // OLD!!!! Animation timer -- AVR Timer3 | 665 | // OLD!!!! Animation timer -- AVR Timer3 |
| 732 | // static uint8_t rgblight_timer_is_init = 0; | 666 | // static uint8_t rgblight_timer_is_init = 0; |
| 733 | // if (rgblight_timer_is_init) { | 667 | // if (rgblight_timer_is_init) { |
| 734 | // return; | 668 | // return; |
| 735 | // } | 669 | // } |
| 736 | // rgblight_timer_is_init = 1; | 670 | // rgblight_timer_is_init = 1; |
| 737 | // /* Timer 3 setup */ | 671 | // /* Timer 3 setup */ |
| 738 | // TCCR3B = _BV(WGM32) // CTC mode OCR3A as TOP | 672 | // TCCR3B = _BV(WGM32) // CTC mode OCR3A as TOP |
| 739 | // | _BV(CS30); // Clock selelct: clk/1 | 673 | // | _BV(CS30); // Clock selelct: clk/1 |
| 740 | // /* Set TOP value */ | 674 | // /* Set TOP value */ |
| 741 | // uint8_t sreg = SREG; | 675 | // uint8_t sreg = SREG; |
| 742 | // cli(); | 676 | // cli(); |
| 743 | // OCR3AH = (RGBLED_TIMER_TOP >> 8) & 0xff; | 677 | // OCR3AH = (RGBLED_TIMER_TOP >> 8) & 0xff; |
| 744 | // OCR3AL = RGBLED_TIMER_TOP & 0xff; | 678 | // OCR3AL = RGBLED_TIMER_TOP & 0xff; |
| 745 | // SREG = sreg; | 679 | // SREG = sreg; |
| 746 | 680 | ||
| 747 | rgblight_status.timer_enabled = false; | 681 | rgblight_status.timer_enabled = false; |
| 748 | RGBLIGHT_SPLIT_SET_CHANGE_TIMER_ENABLE; | 682 | RGBLIGHT_SPLIT_SET_CHANGE_TIMER_ENABLE; |
| 749 | } | 683 | } |
| 750 | void rgblight_timer_enable(void) { | 684 | void rgblight_timer_enable(void) { |
| 751 | if( !is_static_effect(rgblight_config.mode) ) { | 685 | if (!is_static_effect(rgblight_config.mode)) { |
| 752 | rgblight_status.timer_enabled = true; | 686 | rgblight_status.timer_enabled = true; |
| 753 | } | 687 | } |
| 754 | animation_status.last_timer = timer_read(); | 688 | animation_status.last_timer = timer_read(); |
| 755 | RGBLIGHT_SPLIT_SET_CHANGE_TIMER_ENABLE; | 689 | RGBLIGHT_SPLIT_SET_CHANGE_TIMER_ENABLE; |
| 756 | dprintf("rgblight timer enabled.\n"); | 690 | dprintf("rgblight timer enabled.\n"); |
| 757 | } | 691 | } |
| 758 | void rgblight_timer_disable(void) { | 692 | void rgblight_timer_disable(void) { |
| 759 | rgblight_status.timer_enabled = false; | 693 | rgblight_status.timer_enabled = false; |
| 760 | RGBLIGHT_SPLIT_SET_CHANGE_TIMER_ENABLE; | 694 | RGBLIGHT_SPLIT_SET_CHANGE_TIMER_ENABLE; |
| 761 | dprintf("rgblight timer disable.\n"); | 695 | dprintf("rgblight timer disable.\n"); |
| 762 | } | 696 | } |
| 763 | void rgblight_timer_toggle(void) { | 697 | void rgblight_timer_toggle(void) { |
| 764 | dprintf("rgblight timer toggle.\n"); | 698 | dprintf("rgblight timer toggle.\n"); |
| 765 | if(rgblight_status.timer_enabled) { | 699 | if (rgblight_status.timer_enabled) { |
| 766 | rgblight_timer_disable(); | 700 | rgblight_timer_disable(); |
| 767 | } else { | 701 | } else { |
| 768 | rgblight_timer_enable(); | 702 | rgblight_timer_enable(); |
| 769 | } | 703 | } |
| 770 | } | 704 | } |
| 771 | 705 | ||
| 772 | void rgblight_show_solid_color(uint8_t r, uint8_t g, uint8_t b) { | 706 | void rgblight_show_solid_color(uint8_t r, uint8_t g, uint8_t b) { |
| 773 | rgblight_enable(); | 707 | rgblight_enable(); |
| 774 | rgblight_mode(RGBLIGHT_MODE_STATIC_LIGHT); | 708 | rgblight_mode(RGBLIGHT_MODE_STATIC_LIGHT); |
| 775 | rgblight_setrgb(r, g, b); | 709 | rgblight_setrgb(r, g, b); |
| 776 | } | 710 | } |
| 777 | 711 | ||
| 778 | static void rgblight_effect_dummy(animation_status_t *anim) { | 712 | static void rgblight_effect_dummy(animation_status_t *anim) { |
| @@ -788,99 +722,99 @@ static void rgblight_effect_dummy(animation_status_t *anim) { | |||
| 788 | } | 722 | } |
| 789 | 723 | ||
| 790 | void rgblight_task(void) { | 724 | void rgblight_task(void) { |
| 791 | if (rgblight_status.timer_enabled) { | 725 | if (rgblight_status.timer_enabled) { |
| 792 | effect_func_t effect_func = rgblight_effect_dummy; | 726 | effect_func_t effect_func = rgblight_effect_dummy; |
| 793 | uint16_t interval_time = 2000; // dummy interval | 727 | uint16_t interval_time = 2000; // dummy interval |
| 794 | uint8_t delta = rgblight_config.mode - rgblight_status.base_mode; | 728 | uint8_t delta = rgblight_config.mode - rgblight_status.base_mode; |
| 795 | animation_status.delta = delta; | 729 | animation_status.delta = delta; |
| 796 | 730 | ||
| 797 | // static light mode, do nothing here | 731 | // static light mode, do nothing here |
| 798 | if ( 1 == 0 ) { //dummy | 732 | if (1 == 0) { // dummy |
| 799 | } | 733 | } |
| 800 | #ifdef RGBLIGHT_EFFECT_BREATHING | 734 | # ifdef RGBLIGHT_EFFECT_BREATHING |
| 801 | else if (rgblight_status.base_mode == RGBLIGHT_MODE_BREATHING) { | 735 | else if (rgblight_status.base_mode == RGBLIGHT_MODE_BREATHING) { |
| 802 | // breathing mode | 736 | // breathing mode |
| 803 | interval_time = get_interval_time(&RGBLED_BREATHING_INTERVALS[delta], 1, 100); | 737 | interval_time = get_interval_time(&RGBLED_BREATHING_INTERVALS[delta], 1, 100); |
| 804 | effect_func = rgblight_effect_breathing; | 738 | effect_func = rgblight_effect_breathing; |
| 805 | } | 739 | } |
| 806 | #endif | 740 | # endif |
| 807 | #ifdef RGBLIGHT_EFFECT_RAINBOW_MOOD | 741 | # ifdef RGBLIGHT_EFFECT_RAINBOW_MOOD |
| 808 | else if (rgblight_status.base_mode == RGBLIGHT_MODE_RAINBOW_MOOD) { | 742 | else if (rgblight_status.base_mode == RGBLIGHT_MODE_RAINBOW_MOOD) { |
| 809 | // rainbow mood mode | 743 | // rainbow mood mode |
| 810 | interval_time = get_interval_time(&RGBLED_RAINBOW_MOOD_INTERVALS[delta], 5, 100); | 744 | interval_time = get_interval_time(&RGBLED_RAINBOW_MOOD_INTERVALS[delta], 5, 100); |
| 811 | effect_func = rgblight_effect_rainbow_mood; | 745 | effect_func = rgblight_effect_rainbow_mood; |
| 812 | } | 746 | } |
| 813 | #endif | 747 | # endif |
| 814 | #ifdef RGBLIGHT_EFFECT_RAINBOW_SWIRL | 748 | # ifdef RGBLIGHT_EFFECT_RAINBOW_SWIRL |
| 815 | else if (rgblight_status.base_mode == RGBLIGHT_MODE_RAINBOW_SWIRL) { | 749 | else if (rgblight_status.base_mode == RGBLIGHT_MODE_RAINBOW_SWIRL) { |
| 816 | // rainbow swirl mode | 750 | // rainbow swirl mode |
| 817 | interval_time = get_interval_time(&RGBLED_RAINBOW_SWIRL_INTERVALS[delta / 2], 1, 100); | 751 | interval_time = get_interval_time(&RGBLED_RAINBOW_SWIRL_INTERVALS[delta / 2], 1, 100); |
| 818 | effect_func = rgblight_effect_rainbow_swirl; | 752 | effect_func = rgblight_effect_rainbow_swirl; |
| 819 | } | 753 | } |
| 820 | #endif | 754 | # endif |
| 821 | #ifdef RGBLIGHT_EFFECT_SNAKE | 755 | # ifdef RGBLIGHT_EFFECT_SNAKE |
| 822 | else if (rgblight_status.base_mode == RGBLIGHT_MODE_SNAKE) { | 756 | else if (rgblight_status.base_mode == RGBLIGHT_MODE_SNAKE) { |
| 823 | // snake mode | 757 | // snake mode |
| 824 | interval_time = get_interval_time(&RGBLED_SNAKE_INTERVALS[delta / 2], 1, 200); | 758 | interval_time = get_interval_time(&RGBLED_SNAKE_INTERVALS[delta / 2], 1, 200); |
| 825 | effect_func = rgblight_effect_snake; | 759 | effect_func = rgblight_effect_snake; |
| 826 | } | 760 | } |
| 827 | #endif | 761 | # endif |
| 828 | #ifdef RGBLIGHT_EFFECT_KNIGHT | 762 | # ifdef RGBLIGHT_EFFECT_KNIGHT |
| 829 | else if (rgblight_status.base_mode == RGBLIGHT_MODE_KNIGHT) { | 763 | else if (rgblight_status.base_mode == RGBLIGHT_MODE_KNIGHT) { |
| 830 | // knight mode | 764 | // knight mode |
| 831 | interval_time = get_interval_time(&RGBLED_KNIGHT_INTERVALS[delta], 5, 100); | 765 | interval_time = get_interval_time(&RGBLED_KNIGHT_INTERVALS[delta], 5, 100); |
| 832 | effect_func = rgblight_effect_knight; | 766 | effect_func = rgblight_effect_knight; |
| 833 | } | 767 | } |
| 834 | #endif | 768 | # endif |
| 835 | #ifdef RGBLIGHT_EFFECT_CHRISTMAS | 769 | # ifdef RGBLIGHT_EFFECT_CHRISTMAS |
| 836 | else if (rgblight_status.base_mode == RGBLIGHT_MODE_CHRISTMAS) { | 770 | else if (rgblight_status.base_mode == RGBLIGHT_MODE_CHRISTMAS) { |
| 837 | // christmas mode | 771 | // christmas mode |
| 838 | interval_time = RGBLIGHT_EFFECT_CHRISTMAS_INTERVAL; | 772 | interval_time = RGBLIGHT_EFFECT_CHRISTMAS_INTERVAL; |
| 839 | effect_func = (effect_func_t)rgblight_effect_christmas; | 773 | effect_func = (effect_func_t)rgblight_effect_christmas; |
| 840 | } | 774 | } |
| 841 | #endif | 775 | # endif |
| 842 | #ifdef RGBLIGHT_EFFECT_RGB_TEST | 776 | # ifdef RGBLIGHT_EFFECT_RGB_TEST |
| 843 | else if (rgblight_status.base_mode == RGBLIGHT_MODE_RGB_TEST) { | 777 | else if (rgblight_status.base_mode == RGBLIGHT_MODE_RGB_TEST) { |
| 844 | // RGB test mode | 778 | // RGB test mode |
| 845 | interval_time = pgm_read_word(&RGBLED_RGBTEST_INTERVALS[0]); | 779 | interval_time = pgm_read_word(&RGBLED_RGBTEST_INTERVALS[0]); |
| 846 | effect_func = (effect_func_t)rgblight_effect_rgbtest; | 780 | effect_func = (effect_func_t)rgblight_effect_rgbtest; |
| 847 | } | 781 | } |
| 848 | #endif | 782 | # endif |
| 849 | #ifdef RGBLIGHT_EFFECT_ALTERNATING | 783 | # ifdef RGBLIGHT_EFFECT_ALTERNATING |
| 850 | else if (rgblight_status.base_mode == RGBLIGHT_MODE_ALTERNATING){ | 784 | else if (rgblight_status.base_mode == RGBLIGHT_MODE_ALTERNATING) { |
| 851 | interval_time = 500; | 785 | interval_time = 500; |
| 852 | effect_func = (effect_func_t)rgblight_effect_alternating; | 786 | effect_func = (effect_func_t)rgblight_effect_alternating; |
| 853 | } | 787 | } |
| 854 | #endif | 788 | # endif |
| 855 | if (animation_status.restart) { | 789 | if (animation_status.restart) { |
| 856 | animation_status.restart = false; | 790 | animation_status.restart = false; |
| 857 | animation_status.last_timer = timer_read() - interval_time - 1; | 791 | animation_status.last_timer = timer_read() - interval_time - 1; |
| 858 | animation_status.pos16 = 0; // restart signal to local each effect | 792 | animation_status.pos16 = 0; // restart signal to local each effect |
| 859 | } | 793 | } |
| 860 | if (timer_elapsed(animation_status.last_timer) >= interval_time) { | 794 | if (timer_elapsed(animation_status.last_timer) >= interval_time) { |
| 861 | #if defined(RGBLIGHT_SPLIT) && !defined(RGBLIGHT_SPLIT_NO_ANIMATION_SYNC) | 795 | # if defined(RGBLIGHT_SPLIT) && !defined(RGBLIGHT_SPLIT_NO_ANIMATION_SYNC) |
| 862 | static uint16_t report_last_timer = 0; | 796 | static uint16_t report_last_timer = 0; |
| 863 | static bool tick_flag = false; | 797 | static bool tick_flag = false; |
| 864 | uint16_t oldpos16; | 798 | uint16_t oldpos16; |
| 865 | if (tick_flag) { | 799 | if (tick_flag) { |
| 866 | tick_flag = false; | 800 | tick_flag = false; |
| 867 | if (timer_elapsed(report_last_timer) >= 30000) { | 801 | if (timer_elapsed(report_last_timer) >= 30000) { |
| 868 | report_last_timer = timer_read(); | 802 | report_last_timer = timer_read(); |
| 869 | dprintf("rgblight animation tick report to slave\n"); | 803 | dprintf("rgblight animation tick report to slave\n"); |
| 870 | RGBLIGHT_SPLIT_ANIMATION_TICK; | 804 | RGBLIGHT_SPLIT_ANIMATION_TICK; |
| 805 | } | ||
| 806 | } | ||
| 807 | oldpos16 = animation_status.pos16; | ||
| 808 | # endif | ||
| 809 | animation_status.last_timer += interval_time; | ||
| 810 | effect_func(&animation_status); | ||
| 811 | # if defined(RGBLIGHT_SPLIT) && !defined(RGBLIGHT_SPLIT_NO_ANIMATION_SYNC) | ||
| 812 | if (animation_status.pos16 == 0 && oldpos16 != 0) { | ||
| 813 | tick_flag = true; | ||
| 814 | } | ||
| 815 | # endif | ||
| 871 | } | 816 | } |
| 872 | } | ||
| 873 | oldpos16 = animation_status.pos16; | ||
| 874 | #endif | ||
| 875 | animation_status.last_timer += interval_time; | ||
| 876 | effect_func(&animation_status); | ||
| 877 | #if defined(RGBLIGHT_SPLIT) && !defined(RGBLIGHT_SPLIT_NO_ANIMATION_SYNC) | ||
| 878 | if (animation_status.pos16 == 0 && oldpos16 != 0) { | ||
| 879 | tick_flag = true; | ||
| 880 | } | ||
| 881 | #endif | ||
| 882 | } | 817 | } |
| 883 | } | ||
| 884 | } | 818 | } |
| 885 | 819 | ||
| 886 | #endif /* RGBLIGHT_USE_TIMER */ | 820 | #endif /* RGBLIGHT_USE_TIMER */ |
| @@ -888,237 +822,235 @@ void rgblight_task(void) { | |||
| 888 | // Effects | 822 | // Effects |
| 889 | #ifdef RGBLIGHT_EFFECT_BREATHING | 823 | #ifdef RGBLIGHT_EFFECT_BREATHING |
| 890 | 824 | ||
| 891 | #ifndef RGBLIGHT_EFFECT_BREATHE_CENTER | 825 | # ifndef RGBLIGHT_EFFECT_BREATHE_CENTER |
| 892 | #ifndef RGBLIGHT_BREATHE_TABLE_SIZE | 826 | # ifndef RGBLIGHT_BREATHE_TABLE_SIZE |
| 893 | #define RGBLIGHT_BREATHE_TABLE_SIZE 256 // 256 or 128 or 64 | 827 | # define RGBLIGHT_BREATHE_TABLE_SIZE 256 // 256 or 128 or 64 |
| 894 | #endif | 828 | # endif |
| 895 | #include <rgblight_breathe_table.h> | 829 | # include <rgblight_breathe_table.h> |
| 896 | #endif | 830 | # endif |
| 897 | 831 | ||
| 898 | __attribute__ ((weak)) | 832 | __attribute__((weak)) const uint8_t RGBLED_BREATHING_INTERVALS[] PROGMEM = {30, 20, 10, 5}; |
| 899 | const uint8_t RGBLED_BREATHING_INTERVALS[] PROGMEM = {30, 20, 10, 5}; | ||
| 900 | 833 | ||
| 901 | void rgblight_effect_breathing(animation_status_t *anim) { | 834 | void rgblight_effect_breathing(animation_status_t *anim) { |
| 902 | float val; | 835 | float val; |
| 903 | 836 | ||
| 904 | // http://sean.voisen.org/blog/2011/10/breathing-led-with-arduino/ | 837 | // http://sean.voisen.org/blog/2011/10/breathing-led-with-arduino/ |
| 905 | #ifdef RGBLIGHT_EFFECT_BREATHE_TABLE | 838 | # ifdef RGBLIGHT_EFFECT_BREATHE_TABLE |
| 906 | val = pgm_read_byte(&rgblight_effect_breathe_table[anim->pos / table_scale]); | 839 | val = pgm_read_byte(&rgblight_effect_breathe_table[anim->pos / table_scale]); |
| 907 | #else | 840 | # else |
| 908 | val = (exp(sin((anim->pos/255.0)*M_PI)) - RGBLIGHT_EFFECT_BREATHE_CENTER/M_E)*(RGBLIGHT_EFFECT_BREATHE_MAX/(M_E-1/M_E)); | 841 | val = (exp(sin((anim->pos / 255.0) * M_PI)) - RGBLIGHT_EFFECT_BREATHE_CENTER / M_E) * (RGBLIGHT_EFFECT_BREATHE_MAX / (M_E - 1 / M_E)); |
| 909 | #endif | 842 | # endif |
| 910 | rgblight_sethsv_noeeprom_old(rgblight_config.hue, rgblight_config.sat, val); | 843 | rgblight_sethsv_noeeprom_old(rgblight_config.hue, rgblight_config.sat, val); |
| 911 | anim->pos = (anim->pos + 1); | 844 | anim->pos = (anim->pos + 1); |
| 912 | } | 845 | } |
| 913 | #endif | 846 | #endif |
| 914 | 847 | ||
| 915 | #ifdef RGBLIGHT_EFFECT_RAINBOW_MOOD | 848 | #ifdef RGBLIGHT_EFFECT_RAINBOW_MOOD |
| 916 | __attribute__ ((weak)) | 849 | __attribute__((weak)) const uint8_t RGBLED_RAINBOW_MOOD_INTERVALS[] PROGMEM = {120, 60, 30}; |
| 917 | const uint8_t RGBLED_RAINBOW_MOOD_INTERVALS[] PROGMEM = {120, 60, 30}; | ||
| 918 | 850 | ||
| 919 | void rgblight_effect_rainbow_mood(animation_status_t *anim) { | 851 | void rgblight_effect_rainbow_mood(animation_status_t *anim) { |
| 920 | rgblight_sethsv_noeeprom_old(anim->current_hue, rgblight_config.sat, rgblight_config.val); | 852 | rgblight_sethsv_noeeprom_old(anim->current_hue, rgblight_config.sat, rgblight_config.val); |
| 921 | anim->current_hue++; | 853 | anim->current_hue++; |
| 922 | } | 854 | } |
| 923 | #endif | 855 | #endif |
| 924 | 856 | ||
| 925 | #ifdef RGBLIGHT_EFFECT_RAINBOW_SWIRL | 857 | #ifdef RGBLIGHT_EFFECT_RAINBOW_SWIRL |
| 926 | #ifndef RGBLIGHT_RAINBOW_SWIRL_RANGE | 858 | # ifndef RGBLIGHT_RAINBOW_SWIRL_RANGE |
| 927 | #define RGBLIGHT_RAINBOW_SWIRL_RANGE 255 | 859 | # define RGBLIGHT_RAINBOW_SWIRL_RANGE 255 |
| 928 | #endif | 860 | # endif |
| 929 | 861 | ||
| 930 | __attribute__ ((weak)) | 862 | __attribute__((weak)) const uint8_t RGBLED_RAINBOW_SWIRL_INTERVALS[] PROGMEM = {100, 50, 20}; |
| 931 | const uint8_t RGBLED_RAINBOW_SWIRL_INTERVALS[] PROGMEM = {100, 50, 20}; | ||
| 932 | 863 | ||
| 933 | void rgblight_effect_rainbow_swirl(animation_status_t *anim) { | 864 | void rgblight_effect_rainbow_swirl(animation_status_t *anim) { |
| 934 | uint8_t hue; | 865 | uint8_t hue; |
| 935 | uint8_t i; | 866 | uint8_t i; |
| 936 | 867 | ||
| 937 | for (i = 0; i < effect_num_leds; i++) { | 868 | for (i = 0; i < effect_num_leds; i++) { |
| 938 | hue = (RGBLIGHT_RAINBOW_SWIRL_RANGE / effect_num_leds * i + anim->current_hue); | 869 | hue = (RGBLIGHT_RAINBOW_SWIRL_RANGE / effect_num_leds * i + anim->current_hue); |
| 939 | sethsv(hue, rgblight_config.sat, rgblight_config.val, (LED_TYPE *)&led[i + effect_start_pos]); | 870 | sethsv(hue, rgblight_config.sat, rgblight_config.val, (LED_TYPE *)&led[i + effect_start_pos]); |
| 940 | } | 871 | } |
| 941 | rgblight_set(); | 872 | rgblight_set(); |
| 942 | 873 | ||
| 943 | if (anim->delta % 2) { | 874 | if (anim->delta % 2) { |
| 944 | anim->current_hue++; | 875 | anim->current_hue++; |
| 945 | } else { | 876 | } else { |
| 946 | anim->current_hue--; | 877 | anim->current_hue--; |
| 947 | } | 878 | } |
| 948 | } | 879 | } |
| 949 | #endif | 880 | #endif |
| 950 | 881 | ||
| 951 | #ifdef RGBLIGHT_EFFECT_SNAKE | 882 | #ifdef RGBLIGHT_EFFECT_SNAKE |
| 952 | __attribute__ ((weak)) | 883 | __attribute__((weak)) const uint8_t RGBLED_SNAKE_INTERVALS[] PROGMEM = {100, 50, 20}; |
| 953 | const uint8_t RGBLED_SNAKE_INTERVALS[] PROGMEM = {100, 50, 20}; | ||
| 954 | 884 | ||
| 955 | void rgblight_effect_snake(animation_status_t *anim) { | 885 | void rgblight_effect_snake(animation_status_t *anim) { |
| 956 | static uint8_t pos = 0; | 886 | static uint8_t pos = 0; |
| 957 | uint8_t i, j; | 887 | uint8_t i, j; |
| 958 | int8_t k; | 888 | int8_t k; |
| 959 | int8_t increment = 1; | 889 | int8_t increment = 1; |
| 960 | |||
| 961 | if (anim->delta % 2) { | ||
| 962 | increment = -1; | ||
| 963 | } | ||
| 964 | 890 | ||
| 965 | #if defined(RGBLIGHT_SPLIT) && !defined(RGBLIGHT_SPLIT_NO_ANIMATION_SYNC) | 891 | if (anim->delta % 2) { |
| 966 | if (anim->pos == 0) { // restart signal | 892 | increment = -1; |
| 967 | if (increment == 1) { | ||
| 968 | pos = effect_num_leds - 1; | ||
| 969 | } else { | ||
| 970 | pos = 0; | ||
| 971 | } | 893 | } |
| 972 | anim->pos = 1; | ||
| 973 | } | ||
| 974 | #endif | ||
| 975 | 894 | ||
| 976 | for (i = 0; i < effect_num_leds; i++) { | 895 | # if defined(RGBLIGHT_SPLIT) && !defined(RGBLIGHT_SPLIT_NO_ANIMATION_SYNC) |
| 977 | LED_TYPE *ledp = led + i + effect_start_pos; | 896 | if (anim->pos == 0) { // restart signal |
| 978 | ledp->r = 0; | 897 | if (increment == 1) { |
| 979 | ledp->g = 0; | 898 | pos = effect_num_leds - 1; |
| 980 | ledp->b = 0; | 899 | } else { |
| 981 | for (j = 0; j < RGBLIGHT_EFFECT_SNAKE_LENGTH; j++) { | 900 | pos = 0; |
| 982 | k = pos + j * increment; | 901 | } |
| 983 | if (k < 0) { | 902 | anim->pos = 1; |
| 984 | k = k + effect_num_leds; | ||
| 985 | } | ||
| 986 | if (i == k) { | ||
| 987 | sethsv(rgblight_config.hue, rgblight_config.sat, | ||
| 988 | (uint8_t)(rgblight_config.val*(RGBLIGHT_EFFECT_SNAKE_LENGTH-j)/RGBLIGHT_EFFECT_SNAKE_LENGTH), | ||
| 989 | ledp); | ||
| 990 | } | ||
| 991 | } | 903 | } |
| 992 | } | 904 | # endif |
| 993 | rgblight_set(); | 905 | |
| 994 | if (increment == 1) { | 906 | for (i = 0; i < effect_num_leds; i++) { |
| 995 | if (pos - 1 < 0) { | 907 | LED_TYPE *ledp = led + i + effect_start_pos; |
| 996 | pos = effect_num_leds - 1; | 908 | ledp->r = 0; |
| 997 | #if defined(RGBLIGHT_SPLIT) && !defined(RGBLIGHT_SPLIT_NO_ANIMATION_SYNC) | 909 | ledp->g = 0; |
| 998 | anim->pos = 0; | 910 | ledp->b = 0; |
| 999 | #endif | 911 | for (j = 0; j < RGBLIGHT_EFFECT_SNAKE_LENGTH; j++) { |
| 912 | k = pos + j * increment; | ||
| 913 | if (k < 0) { | ||
| 914 | k = k + effect_num_leds; | ||
| 915 | } | ||
| 916 | if (i == k) { | ||
| 917 | sethsv(rgblight_config.hue, rgblight_config.sat, (uint8_t)(rgblight_config.val * (RGBLIGHT_EFFECT_SNAKE_LENGTH - j) / RGBLIGHT_EFFECT_SNAKE_LENGTH), ledp); | ||
| 918 | } | ||
| 919 | } | ||
| 920 | } | ||
| 921 | rgblight_set(); | ||
| 922 | if (increment == 1) { | ||
| 923 | if (pos - 1 < 0) { | ||
| 924 | pos = effect_num_leds - 1; | ||
| 925 | # if defined(RGBLIGHT_SPLIT) && !defined(RGBLIGHT_SPLIT_NO_ANIMATION_SYNC) | ||
| 926 | anim->pos = 0; | ||
| 927 | # endif | ||
| 928 | } else { | ||
| 929 | pos -= 1; | ||
| 930 | # if defined(RGBLIGHT_SPLIT) && !defined(RGBLIGHT_SPLIT_NO_ANIMATION_SYNC) | ||
| 931 | anim->pos = 1; | ||
| 932 | # endif | ||
| 933 | } | ||
| 1000 | } else { | 934 | } else { |
| 1001 | pos -= 1; | 935 | pos = (pos + 1) % effect_num_leds; |
| 1002 | #if defined(RGBLIGHT_SPLIT) && !defined(RGBLIGHT_SPLIT_NO_ANIMATION_SYNC) | 936 | # if defined(RGBLIGHT_SPLIT) && !defined(RGBLIGHT_SPLIT_NO_ANIMATION_SYNC) |
| 1003 | anim->pos = 1; | 937 | anim->pos = pos; |
| 1004 | #endif | 938 | # endif |
| 1005 | } | 939 | } |
| 1006 | } else { | ||
| 1007 | pos = (pos + 1) % effect_num_leds; | ||
| 1008 | #if defined(RGBLIGHT_SPLIT) && !defined(RGBLIGHT_SPLIT_NO_ANIMATION_SYNC) | ||
| 1009 | anim->pos = pos; | ||
| 1010 | #endif | ||
| 1011 | } | ||
| 1012 | } | 940 | } |
| 1013 | #endif | 941 | #endif |
| 1014 | 942 | ||
| 1015 | #ifdef RGBLIGHT_EFFECT_KNIGHT | 943 | #ifdef RGBLIGHT_EFFECT_KNIGHT |
| 1016 | __attribute__ ((weak)) | 944 | __attribute__((weak)) const uint8_t RGBLED_KNIGHT_INTERVALS[] PROGMEM = {127, 63, 31}; |
| 1017 | const uint8_t RGBLED_KNIGHT_INTERVALS[] PROGMEM = {127, 63, 31}; | ||
| 1018 | 945 | ||
| 1019 | void rgblight_effect_knight(animation_status_t *anim) { | 946 | void rgblight_effect_knight(animation_status_t *anim) { |
| 1020 | 947 | static int8_t low_bound = 0; | |
| 1021 | static int8_t low_bound = 0; | 948 | static int8_t high_bound = RGBLIGHT_EFFECT_KNIGHT_LENGTH - 1; |
| 1022 | static int8_t high_bound = RGBLIGHT_EFFECT_KNIGHT_LENGTH - 1; | 949 | static int8_t increment = 1; |
| 1023 | static int8_t increment = 1; | 950 | uint8_t i, cur; |
| 1024 | uint8_t i, cur; | 951 | |
| 1025 | 952 | # if defined(RGBLIGHT_SPLIT) && !defined(RGBLIGHT_SPLIT_NO_ANIMATION_SYNC) | |
| 1026 | #if defined(RGBLIGHT_SPLIT) && !defined(RGBLIGHT_SPLIT_NO_ANIMATION_SYNC) | 953 | if (anim->pos == 0) { // restart signal |
| 1027 | if (anim->pos == 0) { // restart signal | 954 | anim->pos = 1; |
| 1028 | anim->pos = 1; | 955 | low_bound = 0; |
| 1029 | low_bound = 0; | 956 | high_bound = RGBLIGHT_EFFECT_KNIGHT_LENGTH - 1; |
| 1030 | high_bound = RGBLIGHT_EFFECT_KNIGHT_LENGTH - 1; | 957 | increment = 1; |
| 1031 | increment = 1; | ||
| 1032 | } | ||
| 1033 | #endif | ||
| 1034 | // Set all the LEDs to 0 | ||
| 1035 | for (i = effect_start_pos; i < effect_end_pos; i++) { | ||
| 1036 | led[i].r = 0; | ||
| 1037 | led[i].g = 0; | ||
| 1038 | led[i].b = 0; | ||
| 1039 | } | ||
| 1040 | // Determine which LEDs should be lit up | ||
| 1041 | for (i = 0; i < RGBLIGHT_EFFECT_KNIGHT_LED_NUM; i++) { | ||
| 1042 | cur = (i + RGBLIGHT_EFFECT_KNIGHT_OFFSET) % effect_num_leds + effect_start_pos; | ||
| 1043 | |||
| 1044 | if (i >= low_bound && i <= high_bound) { | ||
| 1045 | sethsv(rgblight_config.hue, rgblight_config.sat, rgblight_config.val, (LED_TYPE *)&led[cur]); | ||
| 1046 | } else { | ||
| 1047 | led[cur].r = 0; | ||
| 1048 | led[cur].g = 0; | ||
| 1049 | led[cur].b = 0; | ||
| 1050 | } | 958 | } |
| 1051 | } | 959 | # endif |
| 1052 | rgblight_set(); | 960 | // Set all the LEDs to 0 |
| 1053 | 961 | for (i = effect_start_pos; i < effect_end_pos; i++) { | |
| 1054 | // Move from low_bound to high_bound changing the direction we increment each | 962 | led[i].r = 0; |
| 1055 | // time a boundary is hit. | 963 | led[i].g = 0; |
| 1056 | low_bound += increment; | 964 | led[i].b = 0; |
| 1057 | high_bound += increment; | 965 | } |
| 966 | // Determine which LEDs should be lit up | ||
| 967 | for (i = 0; i < RGBLIGHT_EFFECT_KNIGHT_LED_NUM; i++) { | ||
| 968 | cur = (i + RGBLIGHT_EFFECT_KNIGHT_OFFSET) % effect_num_leds + effect_start_pos; | ||
| 1058 | 969 | ||
| 1059 | if (high_bound <= 0 || low_bound >= RGBLIGHT_EFFECT_KNIGHT_LED_NUM - 1) { | 970 | if (i >= low_bound && i <= high_bound) { |
| 1060 | increment = -increment; | 971 | sethsv(rgblight_config.hue, rgblight_config.sat, rgblight_config.val, (LED_TYPE *)&led[cur]); |
| 1061 | #if defined(RGBLIGHT_SPLIT) && !defined(RGBLIGHT_SPLIT_NO_ANIMATION_SYNC) | 972 | } else { |
| 1062 | if (increment == 1) { | 973 | led[cur].r = 0; |
| 1063 | anim->pos = 0; | 974 | led[cur].g = 0; |
| 975 | led[cur].b = 0; | ||
| 976 | } | ||
| 977 | } | ||
| 978 | rgblight_set(); | ||
| 979 | |||
| 980 | // Move from low_bound to high_bound changing the direction we increment each | ||
| 981 | // time a boundary is hit. | ||
| 982 | low_bound += increment; | ||
| 983 | high_bound += increment; | ||
| 984 | |||
| 985 | if (high_bound <= 0 || low_bound >= RGBLIGHT_EFFECT_KNIGHT_LED_NUM - 1) { | ||
| 986 | increment = -increment; | ||
| 987 | # if defined(RGBLIGHT_SPLIT) && !defined(RGBLIGHT_SPLIT_NO_ANIMATION_SYNC) | ||
| 988 | if (increment == 1) { | ||
| 989 | anim->pos = 0; | ||
| 990 | } | ||
| 991 | # endif | ||
| 1064 | } | 992 | } |
| 1065 | #endif | ||
| 1066 | } | ||
| 1067 | } | 993 | } |
| 1068 | #endif | 994 | #endif |
| 1069 | 995 | ||
| 1070 | #ifdef RGBLIGHT_EFFECT_CHRISTMAS | 996 | #ifdef RGBLIGHT_EFFECT_CHRISTMAS |
| 1071 | void rgblight_effect_christmas(animation_status_t *anim) { | 997 | void rgblight_effect_christmas(animation_status_t *anim) { |
| 1072 | uint8_t hue; | 998 | uint8_t hue; |
| 1073 | uint8_t i; | 999 | uint8_t i; |
| 1074 | 1000 | ||
| 1075 | anim->current_offset = (anim->current_offset + 1) % 2; | 1001 | anim->current_offset = (anim->current_offset + 1) % 2; |
| 1076 | for (i = 0; i < effect_num_leds; i++) { | 1002 | for (i = 0; i < effect_num_leds; i++) { |
| 1077 | hue = 0 + ((i/RGBLIGHT_EFFECT_CHRISTMAS_STEP + anim->current_offset) % 2) * 85; | 1003 | hue = 0 + ((i / RGBLIGHT_EFFECT_CHRISTMAS_STEP + anim->current_offset) % 2) * 85; |
| 1078 | sethsv(hue, rgblight_config.sat, rgblight_config.val, (LED_TYPE *)&led[i + effect_start_pos]); | 1004 | sethsv(hue, rgblight_config.sat, rgblight_config.val, (LED_TYPE *)&led[i + effect_start_pos]); |
| 1079 | } | 1005 | } |
| 1080 | rgblight_set(); | 1006 | rgblight_set(); |
| 1081 | } | 1007 | } |
| 1082 | #endif | 1008 | #endif |
| 1083 | 1009 | ||
| 1084 | #ifdef RGBLIGHT_EFFECT_RGB_TEST | 1010 | #ifdef RGBLIGHT_EFFECT_RGB_TEST |
| 1085 | __attribute__ ((weak)) | 1011 | __attribute__((weak)) const uint16_t RGBLED_RGBTEST_INTERVALS[] PROGMEM = {1024}; |
| 1086 | const uint16_t RGBLED_RGBTEST_INTERVALS[] PROGMEM = {1024}; | ||
| 1087 | 1012 | ||
| 1088 | void rgblight_effect_rgbtest(animation_status_t *anim) { | 1013 | void rgblight_effect_rgbtest(animation_status_t *anim) { |
| 1089 | static uint8_t maxval = 0; | 1014 | static uint8_t maxval = 0; |
| 1090 | uint8_t g; uint8_t r; uint8_t b; | 1015 | uint8_t g; |
| 1091 | 1016 | uint8_t r; | |
| 1092 | if( maxval == 0 ) { | 1017 | uint8_t b; |
| 1093 | LED_TYPE tmp_led; | 1018 | |
| 1094 | sethsv(0, 255, RGBLIGHT_LIMIT_VAL, &tmp_led); | 1019 | if (maxval == 0) { |
| 1095 | maxval = tmp_led.r; | 1020 | LED_TYPE tmp_led; |
| 1096 | } | 1021 | sethsv(0, 255, RGBLIGHT_LIMIT_VAL, &tmp_led); |
| 1097 | g = r = b = 0; | 1022 | maxval = tmp_led.r; |
| 1098 | switch( anim->pos ) { | 1023 | } |
| 1099 | case 0: r = maxval; break; | 1024 | g = r = b = 0; |
| 1100 | case 1: g = maxval; break; | 1025 | switch (anim->pos) { |
| 1101 | case 2: b = maxval; break; | 1026 | case 0: |
| 1102 | } | 1027 | r = maxval; |
| 1103 | rgblight_setrgb(r, g, b); | 1028 | break; |
| 1104 | anim->pos = (anim->pos + 1) % 3; | 1029 | case 1: |
| 1030 | g = maxval; | ||
| 1031 | break; | ||
| 1032 | case 2: | ||
| 1033 | b = maxval; | ||
| 1034 | break; | ||
| 1035 | } | ||
| 1036 | rgblight_setrgb(r, g, b); | ||
| 1037 | anim->pos = (anim->pos + 1) % 3; | ||
| 1105 | } | 1038 | } |
| 1106 | #endif | 1039 | #endif |
| 1107 | 1040 | ||
| 1108 | #ifdef RGBLIGHT_EFFECT_ALTERNATING | 1041 | #ifdef RGBLIGHT_EFFECT_ALTERNATING |
| 1109 | void rgblight_effect_alternating(animation_status_t *anim) { | 1042 | void rgblight_effect_alternating(animation_status_t *anim) { |
| 1110 | 1043 | for (int i = 0; i < effect_num_leds; i++) { | |
| 1111 | for (int i = 0; i < effect_num_leds; i++) { | 1044 | LED_TYPE *ledp = led + i + effect_start_pos; |
| 1112 | LED_TYPE *ledp = led + i + effect_start_pos; | 1045 | if (i < effect_num_leds / 2 && anim->pos) { |
| 1113 | if (i<effect_num_leds/2 && anim->pos) { | 1046 | sethsv(rgblight_config.hue, rgblight_config.sat, rgblight_config.val, ledp); |
| 1114 | sethsv(rgblight_config.hue, rgblight_config.sat, rgblight_config.val, ledp); | 1047 | } else if (i >= effect_num_leds / 2 && !anim->pos) { |
| 1115 | } else if (i>=effect_num_leds/2 && !anim->pos) { | 1048 | sethsv(rgblight_config.hue, rgblight_config.sat, rgblight_config.val, ledp); |
| 1116 | sethsv(rgblight_config.hue, rgblight_config.sat, rgblight_config.val, ledp); | 1049 | } else { |
| 1117 | } else { | 1050 | sethsv(rgblight_config.hue, rgblight_config.sat, 0, ledp); |
| 1118 | sethsv(rgblight_config.hue, rgblight_config.sat, 0, ledp); | 1051 | } |
| 1119 | } | 1052 | } |
| 1120 | } | 1053 | rgblight_set(); |
| 1121 | rgblight_set(); | 1054 | anim->pos = (anim->pos + 1) % 2; |
| 1122 | anim->pos = (anim->pos + 1) % 2; | ||
| 1123 | } | 1055 | } |
| 1124 | #endif | 1056 | #endif |
