diff --git a/Production/Firmware/aic_pico.uf2 b/Production/Firmware/aic_pico.uf2 index 952c1bb..af9f319 100644 Binary files a/Production/Firmware/aic_pico.uf2 and b/Production/Firmware/aic_pico.uf2 differ diff --git a/firmware/src/light.c b/firmware/src/light.c index b685429..7bd948e 100644 --- a/firmware/src/light.c +++ b/firmware/src/light.c @@ -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(); } diff --git a/firmware/src/main.c b/firmware/src/main.c index 45f2d23..775ee9a 100644 --- a/firmware/src/main.c +++ b/firmware/src/main.c @@ -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; }