1
0
mirror of https://github.com/whowechina/aic_pico.git synced 2025-02-21 04:46:41 +01:00

Optimize lighting logic

This commit is contained in:
whowechina 2024-05-06 20:31:24 +08:00
parent 56893dd66b
commit a12337d55e
3 changed files with 18 additions and 13 deletions

Binary file not shown.

View File

@ -86,21 +86,25 @@ uint32_t rgb32_from_hsv(uint8_t h, uint8_t s, uint8_t v)
}
}
static uint8_t curr_level = 0;
static inline uint32_t apply_level(uint32_t color)
static inline uint32_t apply_level_by(uint32_t color, uint8_t level)
{
unsigned r = (color >> 16) & 0xff;
unsigned g = (color >> 8) & 0xff;
unsigned b = color & 0xff;
r = r * curr_level / 255;
g = g * curr_level / 255;
b = b * curr_level / 255;
r = r * level / 255;
g = g * level / 255;
b = b * level / 255;
return r << 16 | g << 8 | b;
}
static uint8_t curr_level = 0;
static inline uint32_t apply_level(uint32_t color)
{
return apply_level_by(color, curr_level);
}
/* 6 segment regular hsv color wheel, better color cycle
* https://www.arnevogel.com/rgb-rainbow/
* https://www.instructables.com/How-to-Make-Proper-Rainbow-and-Random-Colors-With-/
@ -197,7 +201,7 @@ void light_set_color(unsigned index, uint32_t color)
void light_set_color_all(uint32_t color)
{
for (int i = 0; i < RGB_NUM; i++) {
rgb_buf[i] = apply_level(color);
rgb_buf[i] = apply_level_by(color, aic_cfg->light.max);
}
}
@ -243,6 +247,7 @@ void light_init()
}
curr_level = aic_cfg->light.min;
generate_color_wheel();
}
static bool rainbow = true;
@ -254,9 +259,8 @@ void light_set_rainbow(bool enable)
void light_update()
{
if (rainbow && (time_us_64() > last_hid + 1000000)) {
generate_color_wheel();
rainbow_update();
rainbow_fade();
}
rainbow_fade();
drive_led();
}

View File

@ -51,10 +51,6 @@ void report_hid_cardio()
uint64_t now = time_us_64();
if (memcmp(hid_cardio.current, "\0\0\0\0\0\0\0\0\0", 9) != 0) {
light_stimulate();
}
if ((memcmp(hid_cardio.current, hid_cardio.reported, 9) != 0) &&
(now - hid_cardio.report_time > 1000000)) {
@ -106,8 +102,12 @@ static void light_effect()
light_set_rainbow(false);
light_set_color_all(bana_led_color());
} else {
if (memcmp(hid_cardio.current, "\0\0\0\0\0\0\0\0\0", 9) != 0) {
light_stimulate();
}
light_set_rainbow(true);
}
light_update();
}
@ -160,6 +160,7 @@ static void update_cardio(nfc_card_t *card)
static void cardio_run()
{
if (aime_is_active() || bana_is_active()) {
memset(hid_cardio.current, 0, 9);
return;
}