From 4cc10dbff1c584a36368c380c263c9f0da769975 Mon Sep 17 00:00:00 2001 From: Jasper Smit Date: Sun, 3 Jan 2021 19:11:08 +0100 Subject: [PATCH] feat(underglow): max and min brightness in Kconfig --- app/Kconfig | 30 ++++++++++++++++++++++++------ app/src/rgb_underglow.c | 23 ++++++++++++++++------- 2 files changed, 40 insertions(+), 13 deletions(-) diff --git a/app/Kconfig b/app/Kconfig index d83561b702c8..c1aebfd48b00 100644 --- a/app/Kconfig +++ b/app/Kconfig @@ -210,35 +210,53 @@ config ZMK_RGB_UNDERGLOW_EXT_POWER default y config ZMK_RGB_UNDERGLOW_HUE_STEP - int "RGB underglow hue step in degrees of 360" + int "RGB underglow hue step in degrees" + range 0 359 default 10 config ZMK_RGB_UNDERGLOW_SAT_STEP - int "RGB underglow sturation step in percent" + int "RGB underglow saturation step in percent" + range 0 100 default 10 config ZMK_RGB_UNDERGLOW_BRT_STEP int "RGB underglow brightness step in percent" + range 0 100 default 10 config ZMK_RGB_UNDERGLOW_HUE_START - int "RGB underglow start hue value from 0-359" + int "RGB underglow start hue value in degrees" + range 0 359 default 0 config ZMK_RGB_UNDERGLOW_SAT_START - int "RGB underglow start saturations value from 0-100" + int "RGB underglow start saturations value in percent" + range 0 100 default 100 config ZMK_RGB_UNDERGLOW_BRT_START - int "RGB underglow start brightness value from 0-100" + int "RGB underglow start brightness value in percent" + range ZMK_RGB_UNDERGLOW_BRT_MIN ZMK_RGB_UNDERGLOW_BRT_MAX + default ZMK_RGB_UNDERGLOW_BRT_MAX + +config ZMK_RGB_UNDERGLOW_BRT_MIN + int "RGB underglow minimum brightness value in percent" + range 0 100 + default 0 + +config ZMK_RGB_UNDERGLOW_BRT_MAX + int "RGB underglow maximum brightness value in percent" + range ZMK_RGB_UNDERGLOW_BRT_MIN 100 default 100 config ZMK_RGB_UNDERGLOW_SPD_START - int "RGB underglow start animation speed value from 1-5" + int "RGB underglow start animation speed value" + range 1 5 default 3 config ZMK_RGB_UNDERGLOW_EFF_START int "RGB underglow start effect int value related to the effect enum list" + range 0 3 default 0 config ZMK_RGB_UNDERGLOW_ON_START diff --git a/app/src/rgb_underglow.c b/app/src/rgb_underglow.c index 5f38aba76b98..4c325abfea52 100644 --- a/app/src/rgb_underglow.c +++ b/app/src/rgb_underglow.c @@ -249,6 +249,11 @@ 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"); + if (state.color.b < CONFIG_ZMK_RGB_UNDERGLOW_BRT_MIN) { + state.color.b = CONFIG_ZMK_RGB_UNDERGLOW_BRT_MIN; + } else if (state.color.b > CONFIG_ZMK_RGB_UNDERGLOW_BRT_MAX) { + state.color.b = CONFIG_ZMK_RGB_UNDERGLOW_BRT_MAX; + } #endif k_timer_start(&underglow_tick, K_NO_WAIT, K_MSEC(50)); @@ -335,7 +340,8 @@ int zmk_rgb_underglow_toggle() { } int zmk_rgb_underglow_set_hsb(struct zmk_led_hsb color) { - if (color.h > HUE_MAX || color.s > SAT_MAX || color.b > BRT_MAX) { + if (color.h > HUE_MAX || color.s > SAT_MAX || color.b < CONFIG_ZMK_RGB_UNDERGLOW_BRT_MIN || + color.b > CONFIG_ZMK_RGB_UNDERGLOW_BRT_MAX) { return -ENOTSUP; } @@ -369,15 +375,18 @@ 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 + (direction * CONFIG_ZMK_RGB_UNDERGLOW_BRT_STEP); - if (b < 0) { + int b = color.b; + if (direction > 0 && b < CONFIG_ZMK_RGB_UNDERGLOW_BRT_MIN) { + b = CONFIG_ZMK_RGB_UNDERGLOW_BRT_MIN; + } else { + b += (direction * CONFIG_ZMK_RGB_UNDERGLOW_BRT_STEP); + } + if (b < CONFIG_ZMK_RGB_UNDERGLOW_BRT_MIN) { b = 0; - } else if (b > BRT_MAX) { - b = BRT_MAX; + } else if (b > CONFIG_ZMK_RGB_UNDERGLOW_BRT_MAX) { + b = CONFIG_ZMK_RGB_UNDERGLOW_BRT_MAX; } color.b = b; - return color; }