diff --git a/build_uf2/Pico_Game_Controller.uf2 b/build_uf2/Pico_Game_Controller.uf2 index 2283fc5e..ce24a055 100644 Binary files a/build_uf2/Pico_Game_Controller.uf2 and b/build_uf2/Pico_Game_Controller.uf2 differ diff --git a/src/pico_game_controller.c b/src/pico_game_controller.c index f814ecee..abc27198 100644 --- a/src/pico_game_controller.c +++ b/src/pico_game_controller.c @@ -145,7 +145,10 @@ void core1_entry() { uint32_t rgb_idx = 0; while (1) { counter++; - if (counter % 32 == 0) ws2812b_mode(++rgb_idx); + if (counter % 32 == 0) { + rgb_idx = ++rgb_idx % 768; + ws2812b_mode(rgb_idx); + } sleep_ms(1); } } diff --git a/src/rgb/color_cycle_v5.c b/src/rgb/color_cycle_v5.c index 055e113a..9da5c685 100644 --- a/src/rgb/color_cycle_v5.c +++ b/src/rgb/color_cycle_v5.c @@ -2,6 +2,7 @@ * Color cycle effect & reactive buttons for Pocket SDVX Pico v5 * @author SpeedyPotato **/ +const uint64_t timeout_us = 600000000; // 600000000us = 10min const double WS2812B_BRIGHTNESS = 0.5; const RGB_t COLOR_BLACK = {0, 0, 0}; const RGB_t SW_LABEL_COLORS[] = { @@ -26,50 +27,58 @@ const RGB_t SW_COLORS[] = { RGB_t ws2812b_data[WS2812B_LED_SIZE] = {0}; void ws2812b_color_cycle_v5(uint32_t counter) { - RGB_t base_color = color_wheel_rgbt(counter); - /* Peripheral RGB */ - for (int i = (SW_GPIO_SIZE - 2) * 2; i < WS2812B_LED_SIZE; i++) { - if (time_us_64() - reactive_timeout_timestamp >= REACTIVE_TIMEOUT_MAX) { - ws2812b_data[i] = base_color; - } else { - ws2812b_data[i].r = lights_report.lights.rgb[0].r; - ws2812b_data[i].g = lights_report.lights.rgb[0].g; - ws2812b_data[i].b = lights_report.lights.rgb[0].b; + // rgb timeout + uint64_t latest_switch_ts = sw_timestamp[0]; + for (int i = 1; i < SW_GPIO_SIZE; i++) + if (latest_switch_ts < sw_timestamp[i]) latest_switch_ts = sw_timestamp[i]; + if (time_us_64() > latest_switch_ts + timeout_us) { // timed out + for (int i = 0; i < WS2812B_LED_SIZE; i++) ws2812b_data[i] = COLOR_BLACK; + } else { + RGB_t base_color = color_wheel_rgbt(counter); + /* Peripheral RGB */ + for (int i = (SW_GPIO_SIZE - 2) * 2; i < WS2812B_LED_SIZE; i++) { + if (time_us_64() - reactive_timeout_timestamp >= REACTIVE_TIMEOUT_MAX) { + ws2812b_data[i] = base_color; + } else { + ws2812b_data[i].r = lights_report.lights.rgb[0].r; + ws2812b_data[i].g = lights_report.lights.rgb[0].g; + ws2812b_data[i].b = lights_report.lights.rgb[0].b; + } } - } - /* Switches */ - for (int i = 0; i < SW_GPIO_SIZE - 3; i++) { + /* Switches */ + for (int i = 0; i < SW_GPIO_SIZE - 3; i++) { + if (time_us_64() - reactive_timeout_timestamp >= REACTIVE_TIMEOUT_MAX) { + if ((report.buttons >> i) % 2 == 1) { + ws2812b_data[2 * i + 2] = SW_COLORS[i + 1]; + } else { + ws2812b_data[2 * i + 2] = COLOR_BLACK; + } + } else { + if (lights_report.lights.buttons[i] == 0) { + ws2812b_data[2 * i + 2] = COLOR_BLACK; + } else { + ws2812b_data[2 * i + 2] = SW_COLORS[i + 1]; + } + } + } + /* start button sw_val index is offset by two with respect to LED_GPIO */ if (time_us_64() - reactive_timeout_timestamp >= REACTIVE_TIMEOUT_MAX) { - if ((report.buttons >> i) % 2 == 1) { - ws2812b_data[2 * i + 2] = SW_COLORS[i + 1]; + if ((report.buttons >> (SW_GPIO_SIZE - 1)) % 2 == 1) { + ws2812b_data[0] = SW_COLORS[0]; } else { - ws2812b_data[2 * i + 2] = COLOR_BLACK; + ws2812b_data[0] = COLOR_BLACK; } } else { - if (lights_report.lights.buttons[i] == 0) { - ws2812b_data[2 * i + 2] = COLOR_BLACK; + if (lights_report.lights.buttons[SW_GPIO_SIZE - 3] == 0) { + ws2812b_data[0] = COLOR_BLACK; } else { - ws2812b_data[2 * i + 2] = SW_COLORS[i + 1]; + ws2812b_data[0] = SW_COLORS[0]; } } - } - /* start button sw_val index is offset by two with respect to LED_GPIO */ - if (time_us_64() - reactive_timeout_timestamp >= REACTIVE_TIMEOUT_MAX) { - if ((report.buttons >> (SW_GPIO_SIZE - 1)) % 2 == 1) { - ws2812b_data[0] = SW_COLORS[0]; - } else { - ws2812b_data[0] = COLOR_BLACK; + /* Switch Labels */ + for (int i = 0; i < SW_GPIO_SIZE - 2; i++) { + ws2812b_data[2 * i + 1] = SW_LABEL_COLORS[i]; } - } else { - if (lights_report.lights.buttons[SW_GPIO_SIZE - 3] == 0) { - ws2812b_data[0] = COLOR_BLACK; - } else { - ws2812b_data[0] = SW_COLORS[0]; - } - } - /* Switch Labels */ - for (int i = 0; i < SW_GPIO_SIZE - 2; i++) { - ws2812b_data[2 * i + 1] = SW_LABEL_COLORS[i]; } for (int i = 0; i < WS2812B_LED_SIZE; ++i) { put_pixel(urgb_u32(ws2812b_data[i].r * WS2812B_BRIGHTNESS, diff --git a/src/rgb/rgb_include.h b/src/rgb/rgb_include.h index 77c3b789..151cc9e1 100644 --- a/src/rgb/rgb_include.h +++ b/src/rgb/rgb_include.h @@ -10,6 +10,7 @@ extern uint32_t enc_val[ENC_GPIO_SIZE]; extern report_t report; extern lights_report_t lights_report; extern uint64_t reactive_timeout_timestamp; +extern uint64_t sw_timestamp[SW_GPIO_SIZE]; #include "ws2812b_util.c" #include "color_cycle.c"