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
int "RGB underglow minimum brightness value in percent"
range 0 100
range 0 100
default 0
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;
uint8_t i = hsb.h / 60;
double v = ((float)hsb.b *
(float)(CONFIG_ZMK_RGB_UNDERGLOW_BRT_MAX - CONFIG_ZMK_RGB_UNDERGLOW_BRT_MIN) /
(float)BRT_MAX +
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_MIN) /
(float)BRT_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);
settings_load_subtree("rgb/underglow");
#endif
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 color = state.color;
int b = color.b;
b += (direction * CONFIG_ZMK_RGB_UNDERGLOW_BRT_STEP);
if (b > BRT_MAX) {
int b = color.b + (direction * CONFIG_ZMK_RGB_UNDERGLOW_BRT_STEP);
if (b < 0) {
b = 0;
} else if (b > BRT_MAX) {
b = BRT_MAX;
}
color.b = b;
return color;
}