Light effects when idle

This commit is contained in:
whowechina 2024-04-28 11:47:02 +08:00
parent a28375dd05
commit bbd2ff3472
4 changed files with 569 additions and 558 deletions

Binary file not shown.

View File

@ -8,6 +8,8 @@
#include "touch.h" #include "touch.h"
#include "rgb.h" #include "rgb.h"
#define IO_TIMEOUT_SEC 10
static struct { static struct {
bool stat; bool stat;
uint64_t last_io_time; uint64_t last_io_time;
@ -373,7 +375,11 @@ void io_update()
send_touch(); send_touch();
} }
uint64_t io_last_io_time() bool io_is_active()
{ {
return ctx.last_io_time; if (ctx.last_io_time == 0) {
return false;
}
return time_us_64() < ctx.last_io_time + IO_TIMEOUT_SEC * 1000000;
} }

View File

@ -7,6 +7,6 @@
#define IO_H_ #define IO_H_
void io_update(); void io_update();
uint64_t io_last_io_time(); bool io_is_active();
#endif #endif

View File

@ -40,15 +40,20 @@
static void run_lights() static void run_lights()
{ {
uint64_t now = time_us_64(); uint64_t now = time_us_64();
if (io_last_io_time() != 0 && now - io_last_io_time() < 60000000) { if (io_is_active()) {
return; return;
} }
static uint16_t loop = 0;
loop++;
uint16_t buttons = button_read(); uint16_t buttons = button_read();
for (int i = 0; i < 8; i++) { for (int i = 0; i < 8; i++) {
uint32_t color = mai_cfg->color.key_off; uint8_t phase = (i * 256 + loop) / 8;
uint32_t color;
if (buttons & (1 << i)) { if (buttons & (1 << i)) {
color = mai_cfg->color.key_on; color = rgb32_from_hsv(phase, 64, 255);
} else {
color = rgb32_from_hsv(phase, 240, 20);
} }
rgb_set_button(i, color, 0); rgb_set_button(i, color, 0);
} }
@ -89,7 +94,7 @@ static void core1_loop()
static void core0_loop() static void core0_loop()
{ {
static uint64_t next_frame = 0; uint64_t next_frame = time_us_64();
while(1) { while(1) {
tud_task(); tud_task();
@ -101,7 +106,7 @@ static void core0_loop()
cli_fps_count(0); cli_fps_count(0);
sleep_until(next_frame); sleep_until(next_frame);
next_frame = time_us_64() + 1000; // 1KHz next_frame += 1000; // 1KHz
touch_update(); touch_update();
button_update(); button_update();