mirror of
https://github.com/whowechina/diva_pico.git
synced 2026-10-09 15:09:56 +03:00
Separate slider and button level
This commit is contained in:
+18
-5
@@ -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 <slider|button> <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();
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ diva_cfg_t *diva_cfg;
|
||||
|
||||
static diva_cfg_t default_cfg = {
|
||||
.light = {
|
||||
.level = 127,
|
||||
.level = { 100, 200 },
|
||||
},
|
||||
.sense = {
|
||||
.filter = 0x10,
|
||||
|
||||
@@ -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;
|
||||
|
||||
+6
-22
@@ -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()
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user