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 Feb 17, 2021
1 parent af9d6e9 commit 3d92f44
Show file tree
Hide file tree
Showing 2 changed files with 30 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 1 5
default 0

config ZMK_RGB_UNDERGLOW_ON_START
Expand Down
13 changes: 6 additions & 7 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 @@ -371,10 +370,10 @@ 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) {
b = 0;
} else if (b > BRT_MAX) {
b = BRT_MAX;
if (b < CONFIG_ZMK_RGB_UNDERGLOW_BRT_MIN) {
b = CONFIG_ZMK_RGB_UNDERGLOW_BRT_MIN;
} 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 3d92f44

Please sign in to comment.