From 145c196f67d7fec27b897b22160bb7e8bcfceb2a Mon Sep 17 00:00:00 2001 From: whowechina Date: Sat, 13 Dec 2025 11:15:09 +0800 Subject: [PATCH] Separate slider and button level --- firmware/src/commands.c | 23 ++++++++++++++++++----- firmware/src/config.c | 2 +- firmware/src/config.h | 10 +++++----- firmware/src/rgb.c | 28 ++++++---------------------- firmware/src/rgb.h | 3 --- 5 files changed, 30 insertions(+), 36 deletions(-) diff --git a/firmware/src/commands.c b/firmware/src/commands.c index 94e02c6..261b847 100644 --- a/firmware/src/commands.c +++ b/firmware/src/commands.c @@ -21,7 +21,8 @@ static void disp_light() { printf("[Light]\n"); - printf(" Level: %d\n", diva_cfg->light.level); + printf(" Slider Level: %d\n", diva_cfg->light.level.slider); + printf(" Button Level: %d\n", diva_cfg->light.level.button); } static void disp_sense() @@ -123,19 +124,31 @@ void fps_count(int core) static void handle_level(int argc, char *argv[]) { - const char *usage = "Usage: level <0..255>\n"; - if (argc != 1) { + const char *usage = "Usage: level <0..255>\n"; + if (argc != 2) { printf(usage); return; } - int level = cli_extract_non_neg_int(argv[0], 0); + const char *target[] = { "slider", "button" }; + int match = cli_match_prefix(target, 2, argv[0]); + if (match < 0) { + printf(usage); + return; + } + + int level = cli_extract_non_neg_int(argv[1], 0); if ((level < 0) || (level > 255)) { printf(usage); return; } - diva_cfg->light.level = level; + if (match == 0) { + diva_cfg->light.level.slider = level; + } else if (match == 1) { + diva_cfg->light.level.button = level; + } + config_changed(); disp_light(); } diff --git a/firmware/src/config.c b/firmware/src/config.c index b3a556f..31d00c7 100644 --- a/firmware/src/config.c +++ b/firmware/src/config.c @@ -13,7 +13,7 @@ diva_cfg_t *diva_cfg; static diva_cfg_t default_cfg = { .light = { - .level = 127, + .level = { 100, 200 }, }, .sense = { .filter = 0x10, diff --git a/firmware/src/config.h b/firmware/src/config.h index 0f5828c..a93c9ca 100644 --- a/firmware/src/config.h +++ b/firmware/src/config.h @@ -11,11 +11,11 @@ typedef struct __attribute__((packed)) { struct { - uint32_t not_used[3]; - } colors; - struct { - uint8_t not_used[3]; - uint8_t level; + struct { + uint8_t slider; + uint8_t button; + } level; + uint8_t reserved[2]; } light; struct { uint8_t filter; diff --git a/firmware/src/rgb.c b/firmware/src/rgb.c index f2a6256..e72d65f 100644 --- a/firmware/src/rgb.c +++ b/firmware/src/rgb.c @@ -108,15 +108,15 @@ void rgb_set_colors(const uint32_t *colors, unsigned index, size_t num) memcpy(&rgb_buf[index], colors, num * sizeof(*colors)); } -static inline uint32_t apply_level(uint32_t color) +static inline uint32_t apply_level(uint32_t color, uint8_t level) { unsigned r = (color >> 16) & 0xff; unsigned g = (color >> 8) & 0xff; unsigned b = color & 0xff; - r = r * diva_cfg->light.level / 255; - g = g * diva_cfg->light.level / 255; - b = b * diva_cfg->light.level / 255; + r = r * level / 255; + g = g * level / 255; + b = b * level / 255; return r << 16 | g << 8 | b; } @@ -124,7 +124,7 @@ static inline uint32_t apply_level(uint32_t color) void rgb_button_color(unsigned index, uint32_t color) { if (index < count_of(button_rgb)) { - rgb_buf[button_rgb[index]] = apply_level(color); + rgb_buf[button_rgb[index]] = apply_level(color, diva_cfg->light.level.button); } } @@ -133,23 +133,7 @@ void rgb_slider_color(unsigned index, uint32_t color) if (index > 32) { return; } - rgb_buf[5 + index] = apply_level(color); -} - -void rgb_set_brg(unsigned index, const uint8_t *brg_array, size_t num) -{ - if (index >= count_of(rgb_buf)) { - return; - } - if (index + num > count_of(rgb_buf)) { - num = count_of(rgb_buf) - index; - } - for (int i = 0; i < num; i++) { - uint8_t b = brg_array[i * 3 + 0]; - uint8_t r = brg_array[i * 3 + 1]; - uint8_t g = brg_array[i * 3 + 2]; - rgb_buf[index + i] = apply_level(rgb32(r, g, b, false)); - } + rgb_buf[5 + index] = apply_level(color, diva_cfg->light.level.slider); } void rgb_init() diff --git a/firmware/src/rgb.h b/firmware/src/rgb.h index 061329b..178fb95 100644 --- a/firmware/src/rgb.h +++ b/firmware/src/rgb.h @@ -22,7 +22,4 @@ void rgb_set_colors(const uint32_t *colors, unsigned index, size_t num); void rgb_button_color(unsigned index, uint32_t color); void rgb_slider_color(unsigned index, uint32_t color); -/* num of the rgb leds, num*3 bytes in the array */ -void rgb_set_brg(unsigned index, const uint8_t *brg_array, size_t num); - #endif