Skip to content

Commit

Permalink
feat(underglow): max and min brightness in Kconfig
Browse files Browse the repository at this point in the history
  • Loading branch information
Jasper Smit committed Mar 9, 2021
1 parent a7c6e08 commit 4cc10db
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 13 deletions.
30 changes: 24 additions & 6 deletions app/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
23 changes: 16 additions & 7 deletions app/src/rgb_underglow.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
}

Expand Down

0 comments on commit 4cc10db

Please sign in to comment.