diff options
| -rw-r--r-- | keyboards/helix/rev2/keymaps/led_test/keymap.c | 8 | ||||
| -rw-r--r-- | keyboards/helix/rev2/keymaps/led_test/rgblight.c | 185 | ||||
| -rw-r--r-- | keyboards/helix/rev2/keymaps/led_test/rgblight.h | 22 |
3 files changed, 168 insertions, 47 deletions
diff --git a/keyboards/helix/rev2/keymaps/led_test/keymap.c b/keyboards/helix/rev2/keymaps/led_test/keymap.c index b8a9baee3..d597020d8 100644 --- a/keyboards/helix/rev2/keymaps/led_test/keymap.c +++ b/keyboards/helix/rev2/keymaps/led_test/keymap.c | |||
| @@ -32,7 +32,7 @@ extern uint8_t is_master; | |||
| 32 | #define _DVORAK 2 | 32 | #define _DVORAK 2 |
| 33 | #define _LOWER 3 | 33 | #define _LOWER 3 |
| 34 | #define _RAISE 4 | 34 | #define _RAISE 4 |
| 35 | #define _ADJUST 16 | 35 | #define _ADJUST 6 |
| 36 | 36 | ||
| 37 | enum custom_keycodes { | 37 | enum custom_keycodes { |
| 38 | QWERTY = SAFE_RANGE, | 38 | QWERTY = SAFE_RANGE, |
| @@ -513,6 +513,12 @@ void music_scale_user(void) | |||
| 513 | #ifdef SSD1306OLED | 513 | #ifdef SSD1306OLED |
| 514 | 514 | ||
| 515 | void matrix_scan_user(void) { | 515 | void matrix_scan_user(void) { |
| 516 | static int scan_count = 0; | ||
| 517 | if( scan_count == 2 ) { | ||
| 518 | rgblight_enable(); | ||
| 519 | rgblight_mode(35); | ||
| 520 | } | ||
| 521 | if( scan_count < 3 ) scan_count ++; | ||
| 516 | iota_gfx_task(); // this is what updates the display continuously | 522 | iota_gfx_task(); // this is what updates the display continuously |
| 517 | } | 523 | } |
| 518 | 524 | ||
diff --git a/keyboards/helix/rev2/keymaps/led_test/rgblight.c b/keyboards/helix/rev2/keymaps/led_test/rgblight.c index fee614db0..e0ca585e0 100644 --- a/keyboards/helix/rev2/keymaps/led_test/rgblight.c +++ b/keyboards/helix/rev2/keymaps/led_test/rgblight.c | |||
| @@ -23,8 +23,15 @@ | |||
| 23 | #include "debug.h" | 23 | #include "debug.h" |
| 24 | #include "led_tables.h" | 24 | #include "led_tables.h" |
| 25 | 25 | ||
| 26 | #ifndef RGBLIGHT_LIMIT_VAL | ||
| 27 | #define RGBLIGHT_LIMIT_VAL 255 | ||
| 28 | #endif | ||
| 29 | |||
| 30 | #define MIN(a,b) (((a)<(b))?(a):(b)) | ||
| 31 | #define MAX(a,b) (((a)>(b))?(a):(b)) | ||
| 32 | |||
| 26 | __attribute__ ((weak)) | 33 | __attribute__ ((weak)) |
| 27 | const uint16_t RGBLED_BREATHING_INTERVALS[] PROGMEM = {1024, 20, 10, 5}; //modify for led_test | 34 | const uint8_t RGBLED_BREATHING_INTERVALS[] PROGMEM = {30, 20, 10, 5}; |
| 28 | __attribute__ ((weak)) | 35 | __attribute__ ((weak)) |
| 29 | const uint8_t RGBLED_RAINBOW_MOOD_INTERVALS[] PROGMEM = {120, 60, 30}; | 36 | const uint8_t RGBLED_RAINBOW_MOOD_INTERVALS[] PROGMEM = {120, 60, 30}; |
| 30 | __attribute__ ((weak)) | 37 | __attribute__ ((weak)) |
| @@ -35,9 +42,10 @@ __attribute__ ((weak)) | |||
| 35 | const uint8_t RGBLED_KNIGHT_INTERVALS[] PROGMEM = {127, 63, 31}; | 42 | const uint8_t RGBLED_KNIGHT_INTERVALS[] PROGMEM = {127, 63, 31}; |
| 36 | __attribute__ ((weak)) | 43 | __attribute__ ((weak)) |
| 37 | const uint16_t RGBLED_GRADIENT_RANGES[] PROGMEM = {360, 240, 180, 120, 90}; | 44 | const uint16_t RGBLED_GRADIENT_RANGES[] PROGMEM = {360, 240, 180, 120, 90}; |
| 45 | __attribute__ ((weak)) | ||
| 46 | const uint16_t RGBLED_RGBCYCLIC_INTERVALS[] PROGMEM = {1024}; | ||
| 38 | 47 | ||
| 39 | rgblight_config_t rgblight_config; | 48 | rgblight_config_t rgblight_config; |
| 40 | rgblight_config_t inmem_config; | ||
| 41 | 49 | ||
| 42 | LED_TYPE led[RGBLED_NUM]; | 50 | LED_TYPE led[RGBLED_NUM]; |
| 43 | uint8_t rgblight_inited = 0; | 51 | uint8_t rgblight_inited = 0; |
| @@ -46,11 +54,9 @@ bool rgblight_timer_enabled = false; | |||
| 46 | void sethsv(uint16_t hue, uint8_t sat, uint8_t val, LED_TYPE *led1) { | 54 | void sethsv(uint16_t hue, uint8_t sat, uint8_t val, LED_TYPE *led1) { |
| 47 | uint8_t r = 0, g = 0, b = 0, base, color; | 55 | uint8_t r = 0, g = 0, b = 0, base, color; |
| 48 | 56 | ||
| 49 | #ifdef RGBLIGHT_LIMIT_VAL | 57 | if (val > RGBLIGHT_LIMIT_VAL) { |
| 50 | if (val > RGBLIGHT_LIMIT_VAL) { | ||
| 51 | val=RGBLIGHT_LIMIT_VAL; // limit the val | 58 | val=RGBLIGHT_LIMIT_VAL; // limit the val |
| 52 | } | 59 | } |
| 53 | #endif | ||
| 54 | 60 | ||
| 55 | if (sat == 0) { // Acromatic color (gray). Hue doesn't mind. | 61 | if (sat == 0) { // Acromatic color (gray). Hue doesn't mind. |
| 56 | r = val; | 62 | r = val; |
| @@ -119,7 +125,8 @@ void eeconfig_update_rgblight_default(void) { | |||
| 119 | rgblight_config.mode = 1; | 125 | rgblight_config.mode = 1; |
| 120 | rgblight_config.hue = 0; | 126 | rgblight_config.hue = 0; |
| 121 | rgblight_config.sat = 255; | 127 | rgblight_config.sat = 255; |
| 122 | rgblight_config.val = 255; | 128 | rgblight_config.val = RGBLIGHT_LIMIT_VAL; |
| 129 | rgblight_config.speed = 0; | ||
| 123 | eeconfig_update_rgblight(rgblight_config.raw); | 130 | eeconfig_update_rgblight(rgblight_config.raw); |
| 124 | } | 131 | } |
| 125 | void eeconfig_debug_rgblight(void) { | 132 | void eeconfig_debug_rgblight(void) { |
| @@ -129,6 +136,7 @@ void eeconfig_debug_rgblight(void) { | |||
| 129 | dprintf("rgblight_config.hue = %d\n", rgblight_config.hue); | 136 | dprintf("rgblight_config.hue = %d\n", rgblight_config.hue); |
| 130 | dprintf("rgblight_config.sat = %d\n", rgblight_config.sat); | 137 | dprintf("rgblight_config.sat = %d\n", rgblight_config.sat); |
| 131 | dprintf("rgblight_config.val = %d\n", rgblight_config.val); | 138 | dprintf("rgblight_config.val = %d\n", rgblight_config.val); |
| 139 | dprintf("rgblight_config.speed = %d\n", rgblight_config.speed); | ||
| 132 | } | 140 | } |
| 133 | 141 | ||
| 134 | void rgblight_init(void) { | 142 | void rgblight_init(void) { |
| @@ -154,7 +162,7 @@ void rgblight_init(void) { | |||
| 154 | #endif | 162 | #endif |
| 155 | 163 | ||
| 156 | if (rgblight_config.enable) { | 164 | if (rgblight_config.enable) { |
| 157 | rgblight_mode(rgblight_config.mode); | 165 | rgblight_mode_noeeprom(rgblight_config.mode); |
| 158 | } | 166 | } |
| 159 | } | 167 | } |
| 160 | 168 | ||
| @@ -211,7 +219,7 @@ uint32_t rgblight_get_mode(void) { | |||
| 211 | return rgblight_config.mode; | 219 | return rgblight_config.mode; |
| 212 | } | 220 | } |
| 213 | 221 | ||
| 214 | void rgblight_mode(uint8_t mode) { | 222 | void rgblight_mode_eeprom_helper(uint8_t mode, bool write_to_eeprom) { |
| 215 | if (!rgblight_config.enable) { | 223 | if (!rgblight_config.enable) { |
| 216 | return; | 224 | return; |
| 217 | } | 225 | } |
| @@ -222,13 +230,18 @@ void rgblight_mode(uint8_t mode) { | |||
| 222 | } else { | 230 | } else { |
| 223 | rgblight_config.mode = mode; | 231 | rgblight_config.mode = mode; |
| 224 | } | 232 | } |
| 225 | eeconfig_update_rgblight(rgblight_config.raw); | 233 | if (write_to_eeprom) { |
| 226 | xprintf("rgblight mode: %u\n", rgblight_config.mode); | 234 | eeconfig_update_rgblight(rgblight_config.raw); |
| 235 | xprintf("rgblight mode [EEPROM]: %u\n", rgblight_config.mode); | ||
| 236 | } else { | ||
| 237 | xprintf("rgblight mode [NOEEPROM]: %u\n", rgblight_config.mode); | ||
| 238 | } | ||
| 227 | if (rgblight_config.mode == 1) { | 239 | if (rgblight_config.mode == 1) { |
| 228 | #ifdef RGBLIGHT_ANIMATIONS | 240 | #ifdef RGBLIGHT_ANIMATIONS |
| 229 | rgblight_timer_disable(); | 241 | rgblight_timer_disable(); |
| 230 | #endif | 242 | #endif |
| 231 | } else if (rgblight_config.mode >= 2 && rgblight_config.mode <= 24) { | 243 | } else if ((rgblight_config.mode >= 2 && rgblight_config.mode <= 24) || |
| 244 | rgblight_config.mode == 35 ) { | ||
| 232 | // MODE 2-5, breathing | 245 | // MODE 2-5, breathing |
| 233 | // MODE 6-8, rainbow mood | 246 | // MODE 6-8, rainbow mood |
| 234 | // MODE 9-14, rainbow swirl | 247 | // MODE 9-14, rainbow swirl |
| @@ -236,6 +249,7 @@ void rgblight_mode(uint8_t mode) { | |||
| 236 | // MODE 21-23, knight | 249 | // MODE 21-23, knight |
| 237 | // MODE 24, xmas | 250 | // MODE 24, xmas |
| 238 | // MODE 25-34, static rainbow | 251 | // MODE 25-34, static rainbow |
| 252 | // MODE 35 RGB cyclic | ||
| 239 | 253 | ||
| 240 | #ifdef RGBLIGHT_ANIMATIONS | 254 | #ifdef RGBLIGHT_ANIMATIONS |
| 241 | rgblight_timer_enable(); | 255 | rgblight_timer_enable(); |
| @@ -247,11 +261,20 @@ void rgblight_mode(uint8_t mode) { | |||
| 247 | rgblight_timer_disable(); | 261 | rgblight_timer_disable(); |
| 248 | #endif | 262 | #endif |
| 249 | } | 263 | } |
| 250 | rgblight_sethsv(rgblight_config.hue, rgblight_config.sat, rgblight_config.val); | 264 | rgblight_sethsv_noeeprom(rgblight_config.hue, rgblight_config.sat, rgblight_config.val); |
| 265 | } | ||
| 266 | |||
| 267 | void rgblight_mode(uint8_t mode) { | ||
| 268 | rgblight_mode_eeprom_helper(mode, true); | ||
| 269 | } | ||
| 270 | |||
| 271 | void rgblight_mode_noeeprom(uint8_t mode) { | ||
| 272 | rgblight_mode_eeprom_helper(mode, false); | ||
| 251 | } | 273 | } |
| 252 | 274 | ||
| 275 | |||
| 253 | void rgblight_toggle(void) { | 276 | void rgblight_toggle(void) { |
| 254 | xprintf("rgblight toggle: rgblight_config.enable = %u\n", !rgblight_config.enable); | 277 | xprintf("rgblight toggle [EEPROM]: rgblight_config.enable = %u\n", !rgblight_config.enable); |
| 255 | if (rgblight_config.enable) { | 278 | if (rgblight_config.enable) { |
| 256 | rgblight_disable(); | 279 | rgblight_disable(); |
| 257 | } | 280 | } |
| @@ -260,17 +283,34 @@ void rgblight_toggle(void) { | |||
| 260 | } | 283 | } |
| 261 | } | 284 | } |
| 262 | 285 | ||
| 286 | void rgblight_toggle_noeeprom(void) { | ||
| 287 | xprintf("rgblight toggle [NOEEPROM]: rgblight_config.enable = %u\n", !rgblight_config.enable); | ||
| 288 | if (rgblight_config.enable) { | ||
| 289 | rgblight_disable_noeeprom(); | ||
| 290 | } | ||
| 291 | else { | ||
| 292 | rgblight_enable_noeeprom(); | ||
| 293 | } | ||
| 294 | } | ||
| 295 | |||
| 263 | void rgblight_enable(void) { | 296 | void rgblight_enable(void) { |
| 264 | rgblight_config.enable = 1; | 297 | rgblight_config.enable = 1; |
| 265 | eeconfig_update_rgblight(rgblight_config.raw); | 298 | // No need to update EEPROM here. rgblight_mode() will do that, actually |
| 266 | xprintf("rgblight enable: rgblight_config.enable = %u\n", rgblight_config.enable); | 299 | //eeconfig_update_rgblight(rgblight_config.raw); |
| 300 | xprintf("rgblight enable [EEPROM]: rgblight_config.enable = %u\n", rgblight_config.enable); | ||
| 267 | rgblight_mode(rgblight_config.mode); | 301 | rgblight_mode(rgblight_config.mode); |
| 268 | } | 302 | } |
| 269 | 303 | ||
| 304 | void rgblight_enable_noeeprom(void) { | ||
| 305 | rgblight_config.enable = 1; | ||
| 306 | xprintf("rgblight enable [NOEEPROM]: rgblight_config.enable = %u\n", rgblight_config.enable); | ||
| 307 | rgblight_mode_noeeprom(rgblight_config.mode); | ||
| 308 | } | ||
| 309 | |||
| 270 | void rgblight_disable(void) { | 310 | void rgblight_disable(void) { |
| 271 | rgblight_config.enable = 0; | 311 | rgblight_config.enable = 0; |
| 272 | eeconfig_update_rgblight(rgblight_config.raw); | 312 | eeconfig_update_rgblight(rgblight_config.raw); |
| 273 | xprintf("rgblight disable: rgblight_config.enable = %u\n", rgblight_config.enable); | 313 | xprintf("rgblight disable [EEPROM]: rgblight_config.enable = %u\n", rgblight_config.enable); |
| 274 | #ifdef RGBLIGHT_ANIMATIONS | 314 | #ifdef RGBLIGHT_ANIMATIONS |
| 275 | rgblight_timer_disable(); | 315 | rgblight_timer_disable(); |
| 276 | #endif | 316 | #endif |
| @@ -278,6 +318,29 @@ void rgblight_disable(void) { | |||
| 278 | rgblight_set(); | 318 | rgblight_set(); |
| 279 | } | 319 | } |
| 280 | 320 | ||
| 321 | void rgblight_disable_noeeprom(void) { | ||
| 322 | rgblight_config.enable = 0; | ||
| 323 | xprintf("rgblight disable [noEEPROM]: rgblight_config.enable = %u\n", rgblight_config.enable); | ||
| 324 | #ifdef RGBLIGHT_ANIMATIONS | ||
| 325 | rgblight_timer_disable(); | ||
| 326 | #endif | ||
| 327 | _delay_ms(50); | ||
| 328 | rgblight_set(); | ||
| 329 | } | ||
| 330 | |||
| 331 | |||
| 332 | // Deals with the messy details of incrementing an integer | ||
| 333 | uint8_t increment( uint8_t value, uint8_t step, uint8_t min, uint8_t max ) { | ||
| 334 | int16_t new_value = value; | ||
| 335 | new_value += step; | ||
| 336 | return MIN( MAX( new_value, min ), max ); | ||
| 337 | } | ||
| 338 | |||
| 339 | uint8_t decrement( uint8_t value, uint8_t step, uint8_t min, uint8_t max ) { | ||
| 340 | int16_t new_value = value; | ||
| 341 | new_value -= step; | ||
| 342 | return MIN( MAX( new_value, min ), max ); | ||
| 343 | } | ||
| 281 | 344 | ||
| 282 | void rgblight_increase_hue(void) { | 345 | void rgblight_increase_hue(void) { |
| 283 | uint16_t hue; | 346 | uint16_t hue; |
| @@ -313,8 +376,8 @@ void rgblight_decrease_sat(void) { | |||
| 313 | } | 376 | } |
| 314 | void rgblight_increase_val(void) { | 377 | void rgblight_increase_val(void) { |
| 315 | uint8_t val; | 378 | uint8_t val; |
| 316 | if (rgblight_config.val + RGBLIGHT_VAL_STEP > 255) { | 379 | if (rgblight_config.val + RGBLIGHT_VAL_STEP > RGBLIGHT_LIMIT_VAL) { |
| 317 | val = 255; | 380 | val = RGBLIGHT_LIMIT_VAL; |
| 318 | } else { | 381 | } else { |
| 319 | val = rgblight_config.val + RGBLIGHT_VAL_STEP; | 382 | val = rgblight_config.val + RGBLIGHT_VAL_STEP; |
| 320 | } | 383 | } |
| @@ -329,24 +392,32 @@ void rgblight_decrease_val(void) { | |||
| 329 | } | 392 | } |
| 330 | rgblight_sethsv(rgblight_config.hue, rgblight_config.sat, val); | 393 | rgblight_sethsv(rgblight_config.hue, rgblight_config.sat, val); |
| 331 | } | 394 | } |
| 395 | void rgblight_increase_speed(void) { | ||
| 396 | rgblight_config.speed = increment( rgblight_config.speed, 1, 0, 3 ); | ||
| 397 | eeconfig_update_rgblight(rgblight_config.raw);//EECONFIG needs to be increased to support this | ||
| 398 | } | ||
| 332 | 399 | ||
| 333 | void rgblight_sethsv_noeeprom(uint16_t hue, uint8_t sat, uint8_t val) { | 400 | void rgblight_decrease_speed(void) { |
| 334 | inmem_config.raw = rgblight_config.raw; | 401 | rgblight_config.speed = decrement( rgblight_config.speed, 1, 0, 3 ); |
| 402 | eeconfig_update_rgblight(rgblight_config.raw);//EECONFIG needs to be increased to support this | ||
| 403 | } | ||
| 404 | |||
| 405 | void rgblight_sethsv_noeeprom_old(uint16_t hue, uint8_t sat, uint8_t val) { | ||
| 335 | if (rgblight_config.enable) { | 406 | if (rgblight_config.enable) { |
| 336 | LED_TYPE tmp_led; | 407 | LED_TYPE tmp_led; |
| 337 | sethsv(hue, sat, val, &tmp_led); | 408 | sethsv(hue, sat, val, &tmp_led); |
| 338 | inmem_config.hue = hue; | ||
| 339 | inmem_config.sat = sat; | ||
| 340 | inmem_config.val = val; | ||
| 341 | // dprintf("rgblight set hue [MEMORY]: %u,%u,%u\n", inmem_config.hue, inmem_config.sat, inmem_config.val); | 409 | // dprintf("rgblight set hue [MEMORY]: %u,%u,%u\n", inmem_config.hue, inmem_config.sat, inmem_config.val); |
| 342 | rgblight_setrgb(tmp_led.r, tmp_led.g, tmp_led.b); | 410 | rgblight_setrgb(tmp_led.r, tmp_led.g, tmp_led.b); |
| 343 | } | 411 | } |
| 344 | } | 412 | } |
| 345 | void rgblight_sethsv(uint16_t hue, uint8_t sat, uint8_t val) { | 413 | |
| 414 | void rgblight_sethsv_eeprom_helper(uint16_t hue, uint8_t sat, uint8_t val, bool write_to_eeprom) { | ||
| 346 | if (rgblight_config.enable) { | 415 | if (rgblight_config.enable) { |
| 347 | if (rgblight_config.mode == 1) { | 416 | if (rgblight_config.mode == 1) { |
| 348 | // same static color | 417 | // same static color |
| 349 | rgblight_sethsv_noeeprom(hue, sat, val); | 418 | LED_TYPE tmp_led; |
| 419 | sethsv(hue, sat, val, &tmp_led); | ||
| 420 | rgblight_setrgb(tmp_led.r, tmp_led.g, tmp_led.b); | ||
| 350 | } else { | 421 | } else { |
| 351 | // all LEDs in same color | 422 | // all LEDs in same color |
| 352 | if (rgblight_config.mode >= 2 && rgblight_config.mode <= 5) { | 423 | if (rgblight_config.mode >= 2 && rgblight_config.mode <= 5) { |
| @@ -371,11 +442,23 @@ void rgblight_sethsv(uint16_t hue, uint8_t sat, uint8_t val) { | |||
| 371 | rgblight_config.hue = hue; | 442 | rgblight_config.hue = hue; |
| 372 | rgblight_config.sat = sat; | 443 | rgblight_config.sat = sat; |
| 373 | rgblight_config.val = val; | 444 | rgblight_config.val = val; |
| 374 | eeconfig_update_rgblight(rgblight_config.raw); | 445 | if (write_to_eeprom) { |
| 375 | xprintf("rgblight set hsv [EEPROM]: %u,%u,%u\n", rgblight_config.hue, rgblight_config.sat, rgblight_config.val); | 446 | eeconfig_update_rgblight(rgblight_config.raw); |
| 447 | xprintf("rgblight set hsv [EEPROM]: %u,%u,%u\n", rgblight_config.hue, rgblight_config.sat, rgblight_config.val); | ||
| 448 | } else { | ||
| 449 | xprintf("rgblight set hsv [NOEEPROM]: %u,%u,%u\n", rgblight_config.hue, rgblight_config.sat, rgblight_config.val); | ||
| 450 | } | ||
| 376 | } | 451 | } |
| 377 | } | 452 | } |
| 378 | 453 | ||
| 454 | void rgblight_sethsv(uint16_t hue, uint8_t sat, uint8_t val) { | ||
| 455 | rgblight_sethsv_eeprom_helper(hue, sat, val, true); | ||
| 456 | } | ||
| 457 | |||
| 458 | void rgblight_sethsv_noeeprom(uint16_t hue, uint8_t sat, uint8_t val) { | ||
| 459 | rgblight_sethsv_eeprom_helper(hue, sat, val, false); | ||
| 460 | } | ||
| 461 | |||
| 379 | uint16_t rgblight_get_hue(void) { | 462 | uint16_t rgblight_get_hue(void) { |
| 380 | return rgblight_config.hue; | 463 | return rgblight_config.hue; |
| 381 | } | 464 | } |
| @@ -480,18 +563,11 @@ void rgblight_show_solid_color(uint8_t r, uint8_t g, uint8_t b) { | |||
| 480 | } | 563 | } |
| 481 | 564 | ||
| 482 | void rgblight_task(void) { | 565 | void rgblight_task(void) { |
| 483 | if (rgblight_inited == 1) { //modify for led_test | ||
| 484 | /* first call */ | ||
| 485 | rgblight_inited = 2; | ||
| 486 | rgblight_enable(); | ||
| 487 | rgblight_mode(2); | ||
| 488 | } | ||
| 489 | if (rgblight_timer_enabled) { | 566 | if (rgblight_timer_enabled) { |
| 490 | // mode = 1, static light, do nothing here | 567 | // mode = 1, static light, do nothing here |
| 491 | if (rgblight_config.mode >= 2 && rgblight_config.mode <= 5) { | 568 | if (rgblight_config.mode >= 2 && rgblight_config.mode <= 5) { |
| 492 | // mode = 2 to 5, breathing mode | 569 | // mode = 2 to 5, breathing mode |
| 493 | rgblight_effect_breathing(rgblight_config.mode - 2); | 570 | rgblight_effect_breathing(rgblight_config.mode - 2); |
| 494 | #if 0 | ||
| 495 | } else if (rgblight_config.mode >= 6 && rgblight_config.mode <= 8) { | 571 | } else if (rgblight_config.mode >= 6 && rgblight_config.mode <= 8) { |
| 496 | // mode = 6 to 8, rainbow mood mod | 572 | // mode = 6 to 8, rainbow mood mod |
| 497 | rgblight_effect_rainbow_mood(rgblight_config.mode - 6); | 573 | rgblight_effect_rainbow_mood(rgblight_config.mode - 6); |
| @@ -507,7 +583,9 @@ void rgblight_task(void) { | |||
| 507 | } else if (rgblight_config.mode == 24) { | 583 | } else if (rgblight_config.mode == 24) { |
| 508 | // mode = 24, christmas mode | 584 | // mode = 24, christmas mode |
| 509 | rgblight_effect_christmas(); | 585 | rgblight_effect_christmas(); |
| 510 | #endif | 586 | } else if (rgblight_config.mode == 35) { |
| 587 | // mode = 35, RGB cyclic | ||
| 588 | rgblight_effect_rgbcyclic(); | ||
| 511 | } | 589 | } |
| 512 | } | 590 | } |
| 513 | } | 591 | } |
| @@ -516,19 +594,19 @@ void rgblight_task(void) { | |||
| 516 | void rgblight_effect_breathing(uint8_t interval) { | 594 | void rgblight_effect_breathing(uint8_t interval) { |
| 517 | static uint8_t pos = 0; | 595 | static uint8_t pos = 0; |
| 518 | static uint16_t last_timer = 0; | 596 | static uint16_t last_timer = 0; |
| 597 | float val; | ||
| 519 | 598 | ||
| 520 | if (timer_elapsed(last_timer) < pgm_read_word(&RGBLED_BREATHING_INTERVALS[interval])) {//modify for led_test | 599 | if (timer_elapsed(last_timer) < pgm_read_byte(&RGBLED_BREATHING_INTERVALS[interval])) { |
| 521 | return; | 600 | return; |
| 522 | } | 601 | } |
| 523 | last_timer = timer_read(); | 602 | last_timer = timer_read(); |
| 524 | 603 | ||
| 525 | 604 | ||
| 526 | //modify for led_test | 605 | // http://sean.voisen.org/blog/2011/10/breathing-led-with-arduino/ |
| 527 | rgblight_config.hue = (pos*120)%360; | 606 | val = (exp(sin((pos/255.0)*M_PI)) - RGBLIGHT_EFFECT_BREATHE_CENTER/M_E)*(RGBLIGHT_EFFECT_BREATHE_MAX/(M_E-1/M_E)); |
| 528 | rgblight_sethsv_noeeprom(rgblight_config.hue, rgblight_config.sat, rgblight_config.val); | 607 | rgblight_sethsv_noeeprom_old(rgblight_config.hue, rgblight_config.sat, val); |
| 529 | pos = (pos + 1) % 3; | 608 | pos = (pos + 1) % 256; |
| 530 | } | 609 | } |
| 531 | #if 0 | ||
| 532 | void rgblight_effect_rainbow_mood(uint8_t interval) { | 610 | void rgblight_effect_rainbow_mood(uint8_t interval) { |
| 533 | static uint16_t current_hue = 0; | 611 | static uint16_t current_hue = 0; |
| 534 | static uint16_t last_timer = 0; | 612 | static uint16_t last_timer = 0; |
| @@ -537,7 +615,7 @@ void rgblight_effect_rainbow_mood(uint8_t interval) { | |||
| 537 | return; | 615 | return; |
| 538 | } | 616 | } |
| 539 | last_timer = timer_read(); | 617 | last_timer = timer_read(); |
| 540 | rgblight_sethsv_noeeprom(current_hue, rgblight_config.sat, rgblight_config.val); | 618 | rgblight_sethsv_noeeprom_old(current_hue, rgblight_config.sat, rgblight_config.val); |
| 541 | current_hue = (current_hue + 1) % 360; | 619 | current_hue = (current_hue + 1) % 360; |
| 542 | } | 620 | } |
| 543 | void rgblight_effect_rainbow_swirl(uint8_t interval) { | 621 | void rgblight_effect_rainbow_swirl(uint8_t interval) { |
| @@ -662,5 +740,24 @@ void rgblight_effect_christmas(void) { | |||
| 662 | } | 740 | } |
| 663 | rgblight_set(); | 741 | rgblight_set(); |
| 664 | } | 742 | } |
| 665 | #endif /* 0 */ | 743 | |
| 744 | void rgblight_effect_rgbcyclic(void) { | ||
| 745 | static uint8_t pos = 0; | ||
| 746 | static uint16_t last_timer = 0; | ||
| 747 | uint8_t g; uint8_t r; uint8_t b; | ||
| 748 | |||
| 749 | if (timer_elapsed(last_timer) < pgm_read_word(&RGBLED_RGBCYCLIC_INTERVALS[0])) { | ||
| 750 | return; | ||
| 751 | } | ||
| 752 | last_timer = timer_read(); | ||
| 753 | g = r = b = 0; | ||
| 754 | switch( pos ) { | ||
| 755 | case 0: r = RGBLIGHT_LIMIT_VAL; break; | ||
| 756 | case 1: g = RGBLIGHT_LIMIT_VAL; break; | ||
| 757 | case 2: b = RGBLIGHT_LIMIT_VAL; break; | ||
| 758 | } | ||
| 759 | rgblight_setrgb(r, g, b); | ||
| 760 | pos = (pos + 1) % 3; | ||
| 761 | } | ||
| 762 | |||
| 666 | #endif /* RGBLIGHT_ANIMATIONS */ | 763 | #endif /* RGBLIGHT_ANIMATIONS */ |
diff --git a/keyboards/helix/rev2/keymaps/led_test/rgblight.h b/keyboards/helix/rev2/keymaps/led_test/rgblight.h index 9c1c0add2..965a1bbf6 100644 --- a/keyboards/helix/rev2/keymaps/led_test/rgblight.h +++ b/keyboards/helix/rev2/keymaps/led_test/rgblight.h | |||
| @@ -17,7 +17,7 @@ | |||
| 17 | #define RGBLIGHT_H | 17 | #define RGBLIGHT_H |
| 18 | 18 | ||
| 19 | #ifdef RGBLIGHT_ANIMATIONS | 19 | #ifdef RGBLIGHT_ANIMATIONS |
| 20 | #define RGBLIGHT_MODES 5 | 20 | #define RGBLIGHT_MODES 35 |
| 21 | #else | 21 | #else |
| 22 | #define RGBLIGHT_MODES 1 | 22 | #define RGBLIGHT_MODES 1 |
| 23 | #endif | 23 | #endif |
| @@ -74,14 +74,16 @@ | |||
| 74 | #include "ws2812.h" | 74 | #include "ws2812.h" |
| 75 | #endif | 75 | #endif |
| 76 | #include "rgblight_types.h" | 76 | #include "rgblight_types.h" |
| 77 | #include "rgblight_list.h" | ||
| 77 | 78 | ||
| 78 | extern LED_TYPE led[RGBLED_NUM]; | 79 | extern LED_TYPE led[RGBLED_NUM]; |
| 79 | 80 | ||
| 80 | extern const uint16_t RGBLED_BREATHING_INTERVALS[4] PROGMEM; //modify for led_test | 81 | extern const uint8_t RGBLED_BREATHING_INTERVALS[4] PROGMEM; |
| 81 | extern const uint8_t RGBLED_RAINBOW_MOOD_INTERVALS[3] PROGMEM; | 82 | extern const uint8_t RGBLED_RAINBOW_MOOD_INTERVALS[3] PROGMEM; |
| 82 | extern const uint8_t RGBLED_RAINBOW_SWIRL_INTERVALS[3] PROGMEM; | 83 | extern const uint8_t RGBLED_RAINBOW_SWIRL_INTERVALS[3] PROGMEM; |
| 83 | extern const uint8_t RGBLED_SNAKE_INTERVALS[3] PROGMEM; | 84 | extern const uint8_t RGBLED_SNAKE_INTERVALS[3] PROGMEM; |
| 84 | extern const uint8_t RGBLED_KNIGHT_INTERVALS[3] PROGMEM; | 85 | extern const uint8_t RGBLED_KNIGHT_INTERVALS[3] PROGMEM; |
| 86 | extern const uint16_t RGBLED_RGBCYCLIC_INTERVALS[1] PROGMEM; | ||
| 85 | 87 | ||
| 86 | typedef union { | 88 | typedef union { |
| 87 | uint32_t raw; | 89 | uint32_t raw; |
| @@ -91,6 +93,7 @@ typedef union { | |||
| 91 | uint16_t hue :9; | 93 | uint16_t hue :9; |
| 92 | uint8_t sat :8; | 94 | uint8_t sat :8; |
| 93 | uint8_t val :8; | 95 | uint8_t val :8; |
| 96 | uint8_t speed :8;//EECONFIG needs to be increased to support this | ||
| 94 | }; | 97 | }; |
| 95 | } rgblight_config_t; | 98 | } rgblight_config_t; |
| 96 | 99 | ||
| @@ -112,6 +115,8 @@ void rgblight_increase_sat(void); | |||
| 112 | void rgblight_decrease_sat(void); | 115 | void rgblight_decrease_sat(void); |
| 113 | void rgblight_increase_val(void); | 116 | void rgblight_increase_val(void); |
| 114 | void rgblight_decrease_val(void); | 117 | void rgblight_decrease_val(void); |
| 118 | void rgblight_increase_speed(void); | ||
| 119 | void rgblight_decrease_speed(void); | ||
| 115 | void rgblight_sethsv(uint16_t hue, uint8_t sat, uint8_t val); | 120 | void rgblight_sethsv(uint16_t hue, uint8_t sat, uint8_t val); |
| 116 | uint16_t rgblight_get_hue(void); | 121 | uint16_t rgblight_get_hue(void); |
| 117 | uint8_t rgblight_get_sat(void); | 122 | uint8_t rgblight_get_sat(void); |
| @@ -125,9 +130,21 @@ void eeconfig_update_rgblight(uint32_t val); | |||
| 125 | void eeconfig_update_rgblight_default(void); | 130 | void eeconfig_update_rgblight_default(void); |
| 126 | void eeconfig_debug_rgblight(void); | 131 | void eeconfig_debug_rgblight(void); |
| 127 | 132 | ||
| 133 | void rgb_matrix_increase(void); | ||
| 134 | void rgb_matrix_decrease(void); | ||
| 135 | |||
| 128 | void sethsv(uint16_t hue, uint8_t sat, uint8_t val, LED_TYPE *led1); | 136 | void sethsv(uint16_t hue, uint8_t sat, uint8_t val, LED_TYPE *led1); |
| 129 | void setrgb(uint8_t r, uint8_t g, uint8_t b, LED_TYPE *led1); | 137 | void setrgb(uint8_t r, uint8_t g, uint8_t b, LED_TYPE *led1); |
| 138 | |||
| 130 | void rgblight_sethsv_noeeprom(uint16_t hue, uint8_t sat, uint8_t val); | 139 | void rgblight_sethsv_noeeprom(uint16_t hue, uint8_t sat, uint8_t val); |
| 140 | void rgblight_mode_noeeprom(uint8_t mode); | ||
| 141 | void rgblight_toggle_noeeprom(void); | ||
| 142 | void rgblight_enable_noeeprom(void); | ||
| 143 | void rgblight_disable_noeeprom(void); | ||
| 144 | |||
| 145 | void rgblight_sethsv_eeprom_helper(uint16_t hue, uint8_t sat, uint8_t val, bool write_to_eeprom); | ||
| 146 | void rgblight_mode_eeprom_helper(uint8_t mode, bool write_to_eeprom); | ||
| 147 | |||
| 131 | 148 | ||
| 132 | #define EZ_RGB(val) rgblight_show_solid_color((val >> 16) & 0xFF, (val >> 8) & 0xFF, val & 0xFF) | 149 | #define EZ_RGB(val) rgblight_show_solid_color((val >> 16) & 0xFF, (val >> 8) & 0xFF, val & 0xFF) |
| 133 | void rgblight_show_solid_color(uint8_t r, uint8_t g, uint8_t b); | 150 | void rgblight_show_solid_color(uint8_t r, uint8_t g, uint8_t b); |
| @@ -144,5 +161,6 @@ void rgblight_effect_rainbow_swirl(uint8_t interval); | |||
| 144 | void rgblight_effect_snake(uint8_t interval); | 161 | void rgblight_effect_snake(uint8_t interval); |
| 145 | void rgblight_effect_knight(uint8_t interval); | 162 | void rgblight_effect_knight(uint8_t interval); |
| 146 | void rgblight_effect_christmas(void); | 163 | void rgblight_effect_christmas(void); |
| 164 | void rgblight_effect_rgbcyclic(void); | ||
| 147 | 165 | ||
| 148 | #endif | 166 | #endif |
