void led_set_user(uint8_t usb_led) { // Turn LEDs On/Off for Caps Lock if (host_keyboard_leds() & (1 << USB_LED_CAPS_LOCK)) { rgblight_enable_noeeprom(); rgblight_sethsv_noeeprom(0, 0, 80); } else { rgblight_sethsv_noeeprom(0, 0, 80); rgblight_disable_noeeprom(); } }
bool process_record_user(uint16_t keycode, keyrecord_t *record) { switch (keycode) { case RGB_MOD: if (record->event.pressed) { isTapAnim = false; } break; case RGB_RST: #ifdef RGBLIGHT_ENABLE if (record->event.pressed) { eeconfig_update_rgblight_default(); rgblight_enable(); } #endif break; case TAP_ANIM: if (record->event.pressed) { isTapAnim = !isTapAnim; } break; } if (isTapAnim) { rgblight_mode_noeeprom(1); uint16_t hue = (rgblight_config.hue + 5) % 360; rgblight_sethsv_noeeprom(hue, rgblight_config.sat, rgblight_config.val); } return true; }
void rgblight_mode_eeprom_helper(uint8_t mode, bool write_to_eeprom) { if (!rgblight_config.enable) { return; } if (mode < RGBLIGHT_MODE_STATIC_LIGHT) { rgblight_config.mode = RGBLIGHT_MODE_STATIC_LIGHT; } else if (mode > RGBLIGHT_MODES) { rgblight_config.mode = RGBLIGHT_MODES; } else { rgblight_config.mode = mode; } RGBLIGHT_SPLIT_SET_CHANGE_MODE; if (write_to_eeprom) { eeconfig_update_rgblight(rgblight_config.raw); xprintf("rgblight mode [EEPROM]: %u\n", rgblight_config.mode); } else { xprintf("rgblight mode [NOEEPROM]: %u\n", rgblight_config.mode); } if( is_static_effect(rgblight_config.mode) ) { #ifdef RGBLIGHT_USE_TIMER rgblight_timer_disable(); #endif } else { #ifdef RGBLIGHT_USE_TIMER rgblight_timer_enable(); #endif } #ifdef RGBLIGHT_USE_TIMER animation_status.restart = true; #endif rgblight_sethsv_noeeprom(rgblight_config.hue, rgblight_config.sat, rgblight_config.val); }
void rgblight_sethsv(uint16_t hue, uint8_t sat, uint8_t val) { if (rgblight_config.enable) { if (rgblight_config.mode == 1) { // same static color rgblight_sethsv_noeeprom(hue, sat, val); } else { // all LEDs in same color if (rgblight_config.mode >= 2 && rgblight_config.mode <= 5) { // breathing mode, ignore the change of val, use in memory value instead val = rgblight_config.val; } else if (rgblight_config.mode >= 6 && rgblight_config.mode <= 14) { // rainbow mood and rainbow swirl, ignore the change of hue hue = rgblight_config.hue; } else if (rgblight_config.mode >= 25 && rgblight_config.mode <= 34) { // static gradient uint16_t _hue; int8_t direction = ((rgblight_config.mode - 25) % 2) ? -1 : 1; uint16_t range = pgm_read_word(&RGBLED_GRADIENT_RANGES[(rgblight_config.mode - 25) / 2]); for (uint8_t i = 0; i < RGBLED_NUM; i++) { _hue = (range / RGBLED_NUM * i * direction + hue + 360) % 360; dprintf("rgblight rainbow set hsv: %u,%u,%d,%u\n", i, _hue, direction, range); sethsv(_hue, sat, val, (LED_TYPE *)&led[i]); } rgblight_set(); } } rgblight_config.hue = hue; rgblight_config.sat = sat; rgblight_config.val = val; eeconfig_update_rgblight(rgblight_config.raw); xprintf("rgblight set hsv [EEPROM]: %u,%u,%u\n", rgblight_config.hue, rgblight_config.sat, rgblight_config.val); } }
void rgblight_effect_rainbow_mood(uint8_t interval) { static uint16_t current_hue = 0; static uint16_t last_timer = 0; if (timer_elapsed(last_timer) < pgm_read_byte(&RGBLED_RAINBOW_MOOD_INTERVALS[interval])) { return; } last_timer = timer_read(); rgblight_sethsv_noeeprom(current_hue, rgblight_config.sat, rgblight_config.val); current_hue = (current_hue + 1) % 360; }
// Effects void rgblight_effect_breathing(uint8_t interval) { static uint8_t pos = 0; static uint16_t last_timer = 0; if (timer_elapsed(last_timer) < pgm_read_byte(&RGBLED_BREATHING_INTERVALS[interval])) { return; } last_timer = timer_read(); rgblight_sethsv_noeeprom(rgblight_config.hue, rgblight_config.sat, pgm_read_byte(&RGBLED_BREATHING_TABLE[pos])); pos = (pos + 1) % 256; }
void keyboard_post_init_rgb(void) { #ifdef RGBLIGHT_ENABLE rgblight_enable_noeeprom(); layer_state_set_user(layer_state); uint16_t old_hue = rgblight_config.hue; rgblight_mode_noeeprom(RGBLIGHT_MODE_STATIC_LIGHT); for (uint16_t i = 360; i > 0; i--) { rgblight_sethsv_noeeprom( ( i + old_hue) % 360, 255, 255); wait_ms(10); } layer_state_set_user(layer_state); #endif }
void keyboard_post_init_rgb(void) { #if defined(RGBLIGHT_ENABLE) && defined(RGBLIGHT_STARTUP_ANIMATION) if (userspace_config.rgb_layer_change) { rgblight_enable_noeeprom(); } if (rgblight_config.enable) { layer_state_set_user(layer_state); uint16_t old_hue = rgblight_config.hue; rgblight_mode_noeeprom(RGBLIGHT_MODE_STATIC_LIGHT); for (uint16_t i = 255; i > 0; i--) { rgblight_sethsv_noeeprom( ( i + old_hue) % 255, 255, 255); matrix_scan(); wait_ms(10); } } #endif layer_state_set_user(layer_state); }
void rgblight_mode_eeprom_helper(uint8_t mode, bool write_to_eeprom) { if (!rgblight_config.enable) { return; } if (mode < 1) { rgblight_config.mode = 1; } else if (mode > RGBLIGHT_MODES) { rgblight_config.mode = RGBLIGHT_MODES; } else { rgblight_config.mode = mode; } if (write_to_eeprom) { eeconfig_update_rgblight(rgblight_config.raw); xprintf("rgblight mode [EEPROM]: %u\n", rgblight_config.mode); } else { xprintf("rgblight mode [NOEEPROM]: %u\n", rgblight_config.mode); } if (rgblight_config.mode == 1) { #ifdef RGBLIGHT_ANIMATIONS rgblight_timer_disable(); #endif } else if ((rgblight_config.mode >= 2 && rgblight_config.mode <= 24) || rgblight_config.mode == 35 ) { // MODE 2-5, breathing // MODE 6-8, rainbow mood // MODE 9-14, rainbow swirl // MODE 15-20, snake // MODE 21-23, knight // MODE 24, xmas // MODE 35 RGB test #ifdef RGBLIGHT_ANIMATIONS rgblight_timer_enable(); #endif } else if (rgblight_config.mode >= 25 && rgblight_config.mode <= 34) { // MODE 25-34, static gradient #ifdef RGBLIGHT_ANIMATIONS rgblight_timer_disable(); #endif } rgblight_sethsv_noeeprom(rgblight_config.hue, rgblight_config.sat, rgblight_config.val); }
bool process_record_user(uint16_t keycode, keyrecord_t *record) { switch(keycode) { case RGB_RST: #ifdef RGBLIGHT_ENABLE if (record->event.pressed) { eeconfig_update_rgblight_default(); rgblight_enable(); } #endif break; case RGB_MOD: #ifdef RGBLIGHT_ENABLE if (record->event.pressed) { enableLEDTypeAnime = false; rgblight_step(); } #endif return false; case RGB_TYPE: #ifdef RGBLIGHT_ENABLE if (record->event.pressed) { rgblight_enable_noeeprom(); rgblight_mode_noeeprom(1); enableLEDTypeAnime = !enableLEDTypeAnime; } #endif return false; default: break; } #ifdef RGBLIGHT_ENABLE if(enableLEDTypeAnime) { rgblight_mode_noeeprom(1); uint16_t hue = (rgblight_config.hue + 5) % 360; rgblight_sethsv_noeeprom(hue, rgblight_config.sat, rgblight_config.val); } #endif return true; }
void rgblight_sethsv(uint16_t hue, uint8_t sat, uint8_t val) { if (rgblight_config.enable) { if (rgblight_config.mode == 1) { // same static color rgblight_sethsv_noeeprom(hue, sat, val); } else { // all LEDs in same color if (rgblight_config.mode >= 2 && rgblight_config.mode <= 5) { // breathing mode, ignore the change of val, use in memory value instead val = rgblight_config.val; } else if (rgblight_config.mode >= 6 && rgblight_config.mode <= 14) { // rainbow mood and rainbow swirl, ignore the change of hue hue = rgblight_config.hue; } } rgblight_config.hue = hue; rgblight_config.sat = sat; rgblight_config.val = val; eeconfig_update_rgblight(rgblight_config.raw); xprintf("rgblight set hsv [EEPROM]: %u,%u,%u\n", rgblight_config.hue, rgblight_config.sat, rgblight_config.val); } }