From c68b1fd6c0dde73b649d3aa22cb63d7c16ba9afc Mon Sep 17 00:00:00 2001 From: Kai Ryu Date: Sun, 26 Apr 2015 22:20:25 +0900 Subject: [PATCH] Add two new fading backlight effects - Fade in when press and fade out when release - Fade out when press and fade in when release --- keyboard/staryu/backlight.c | 73 +++++++++++++++++++++++++---------- keyboard/staryu/config_lite.h | 2 +- 2 files changed, 54 insertions(+), 21 deletions(-) diff --git a/keyboard/staryu/backlight.c b/keyboard/staryu/backlight.c index 62c1c648..9b223dcc 100644 --- a/keyboard/staryu/backlight.c +++ b/keyboard/staryu/backlight.c @@ -53,16 +53,18 @@ void backlight_set(uint8_t level) breathing_led_set_duration(6 - level); break; case 7: - fading_led_enable_all(); - breathing_led_disable_all(); - fading_led_set_direction(FADING_LED_FADE_IN); - fading_led_set_duration(3); - break; case 8: fading_led_enable_all(); breathing_led_disable_all(); - fading_led_set_direction(FADING_LED_FADE_OUT); - fading_led_set_duration(3); + fading_led_set_direction_all(FADING_LED_FADE_IN); + fading_led_set_duration(level == 7 ? 3 : 0); + break; + case 9: + case 10: + fading_led_enable_all(); + breathing_led_disable_all(); + fading_led_set_direction_all(FADING_LED_FADE_OUT); + fading_led_set_duration(level == 9 ? 3 : 0); break; case 0: default: @@ -129,15 +131,35 @@ void softpwm_led_off(uint8_t index) void action_keyevent(keyevent_t event) { if (backlight_config.enable) { - if (backlight_config.level == 7) { - if (event.pressed) { - softpwm_led_decrease(event.key.col, 32); - } - } - if (backlight_config.level == 8) { - if (event.pressed) { - softpwm_led_increase(event.key.col, 32); - } + switch (backlight_config.level) { + case 7: + if (event.pressed) { + fading_led_set_delay(event.key.col, 64); + softpwm_led_decrease(event.key.col, 32); + } + break; + case 8: + if (event.pressed) { + fading_led_set_direction(event.key.col, FADING_LED_FADE_OUT); + } + else { + fading_led_set_direction(event.key.col, FADING_LED_FADE_IN); + } + break; + case 9: + if (event.pressed) { + fading_led_set_delay(event.key.col, 64); + softpwm_led_increase(event.key.col, 32); + } + break; + case 10: + if (event.pressed) { + fading_led_set_direction(event.key.col, FADING_LED_FADE_IN); + } + else { + fading_led_set_direction(event.key.col, FADING_LED_FADE_OUT); + } + break; } } } @@ -145,11 +167,22 @@ void action_keyevent(keyevent_t event) #ifdef CUSTOM_LED_ENABLE void fading_led_custom(uint8_t *value) { - uint8_t max = 0; - for (uint8_t i = 0; i < LED_COUNT; i++) { - if (value[i] > max) max = value[i]; + uint8_t tmp = value[0]; + switch (backlight_config.level) { + case 7: + case 8: + for (uint8_t i = 0; i < LED_COUNT; i++) { + if (value[i] < tmp) tmp = value[i]; + } + break; + case 9: + case 10: + for (uint8_t i = 0; i < LED_COUNT; i++) { + if (value[i] > tmp) tmp = value[i]; + } + break; } - rgb_set_brightness(max); + rgb_set_brightness(tmp); } void breathing_led_custom(uint8_t *value) diff --git a/keyboard/staryu/config_lite.h b/keyboard/staryu/config_lite.h index 3a6e3776..81fa44ba 100644 --- a/keyboard/staryu/config_lite.h +++ b/keyboard/staryu/config_lite.h @@ -42,7 +42,7 @@ along with this program. If not, see . #define DEBOUNCE 5 /* number of backlight levels */ -#define BACKLIGHT_LEVELS 8 +#define BACKLIGHT_LEVELS 10 /* number of LEDs */ #define LED_COUNT 5