Skip to content

Commit

Permalink
feat(underglow): maximum brightness in Kconfig
Browse files Browse the repository at this point in the history
  • Loading branch information
Jasper Smit authored and Jasper Smit committed Feb 17, 2021
1 parent af9d6e9 commit 4019d1a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
8 changes: 7 additions & 1 deletion app/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,13 @@ config ZMK_RGB_UNDERGLOW_SAT_START
default 100

config ZMK_RGB_UNDERGLOW_BRT_START
int "RGB underglow start brightness value from 0-100"
int "RGB underglow start brightness value from 0-ZMK_RGB_UNDERGLOW_BRT_MAX"
range 0 ZMK_RGB_UNDERGLOW_BRT_MAX
default ZMK_RGB_UNDERGLOW_BRT_MAX

config ZMK_RGB_UNDERGLOW_BRT_MAX
int "RGB underglow maximum brightness value from 1-100"
range 1 100
default 100

config ZMK_RGB_UNDERGLOW_SPD_START
Expand Down
9 changes: 4 additions & 5 deletions app/src/rgb_underglow.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL);

#define HUE_MAX 360
#define SAT_MAX 100
#define BRT_MAX 100

enum rgb_underglow_effect {
UNDERGLOW_EFFECT_SOLID,
Expand Down Expand Up @@ -58,7 +57,7 @@ static struct led_rgb hsb_to_rgb(struct zmk_led_hsb hsb) {
double r, g, b;

uint8_t i = hsb.h / 60;
double v = hsb.b / ((float)BRT_MAX);
double v = hsb.b / ((float)CONFIG_ZMK_RGB_UNDERGLOW_BRT_MAX);
double s = hsb.s / ((float)SAT_MAX);
double f = hsb.h / ((float)HUE_MAX) * 6 - i;
double p = v * (1 - s);
Expand Down Expand Up @@ -335,7 +334,7 @@ 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_MAX) {
return -ENOTSUP;
}

Expand Down Expand Up @@ -373,8 +372,8 @@ struct zmk_led_hsb zmk_rgb_underglow_calc_brt(int direction) {
int b = color.b + (direction * CONFIG_ZMK_RGB_UNDERGLOW_BRT_STEP);
if (b < 0) {
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;

Expand Down

0 comments on commit 4019d1a

Please sign in to comment.