tidy up, fix underflow again

This commit is contained in:
git@jrhrsmit.nl 2021-10-07 09:54:13 +02:00
parent 7193788189
commit 8b5862a227
2 changed files with 9 additions and 8 deletions

View file

@ -294,7 +294,7 @@ config ZMK_RGB_UNDERGLOW_BRT_START
config ZMK_RGB_UNDERGLOW_BRT_MIN config ZMK_RGB_UNDERGLOW_BRT_MIN
int "RGB underglow minimum brightness value in percent" int "RGB underglow minimum brightness value in percent"
range 0 100 range 0 100
default 0 default 0
config ZMK_RGB_UNDERGLOW_BRT_MAX config ZMK_RGB_UNDERGLOW_BRT_MAX

View file

@ -58,9 +58,8 @@ static struct led_rgb hsb_to_rgb(struct zmk_led_hsb hsb) {
double r, g, b; double r, g, b;
uint8_t i = hsb.h / 60; uint8_t i = hsb.h / 60;
double v = ((float)hsb.b * double v = ((float)hsb.b / (float)BRT_MAX *
(float)(CONFIG_ZMK_RGB_UNDERGLOW_BRT_MAX - CONFIG_ZMK_RGB_UNDERGLOW_BRT_MIN) / (float)(CONFIG_ZMK_RGB_UNDERGLOW_BRT_MAX - CONFIG_ZMK_RGB_UNDERGLOW_BRT_MIN) +
(float)BRT_MAX +
(float)CONFIG_ZMK_RGB_UNDERGLOW_BRT_MIN) / (float)CONFIG_ZMK_RGB_UNDERGLOW_BRT_MIN) /
(float)BRT_MAX; (float)BRT_MAX;
double s = hsb.s / ((float)SAT_MAX); double s = hsb.s / ((float)SAT_MAX);
@ -253,7 +252,6 @@ static int zmk_rgb_underglow_init(const struct device *_arg) {
k_delayed_work_init(&underglow_save_work, zmk_rgb_underglow_save_state_work); k_delayed_work_init(&underglow_save_work, zmk_rgb_underglow_save_state_work);
settings_load_subtree("rgb/underglow"); settings_load_subtree("rgb/underglow");
#endif #endif
k_timer_start(&underglow_tick, K_NO_WAIT, K_MSEC(50)); k_timer_start(&underglow_tick, K_NO_WAIT, K_MSEC(50));
@ -374,12 +372,15 @@ struct zmk_led_hsb zmk_rgb_underglow_calc_sat(int direction) {
struct zmk_led_hsb zmk_rgb_underglow_calc_brt(int direction) { struct zmk_led_hsb zmk_rgb_underglow_calc_brt(int direction) {
struct zmk_led_hsb color = state.color; struct zmk_led_hsb color = state.color;
int b = color.b;
b += (direction * CONFIG_ZMK_RGB_UNDERGLOW_BRT_STEP); int b = color.b + (direction * CONFIG_ZMK_RGB_UNDERGLOW_BRT_STEP);
if (b > BRT_MAX) { if (b < 0) {
b = 0;
} else if (b > BRT_MAX) {
b = BRT_MAX; b = BRT_MAX;
} }
color.b = b; color.b = b;
return color; return color;
} }