Skip to content

Commit

Permalink
10 minute rgb timeout, rgb index modulo
Browse files Browse the repository at this point in the history
  • Loading branch information
speedypotato committed Sep 6, 2022
1 parent efbee31 commit ae0d059
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 36 deletions.
Binary file modified build_uf2/Pico_Game_Controller.uf2
Binary file not shown.
5 changes: 4 additions & 1 deletion src/pico_game_controller.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down
79 changes: 44 additions & 35 deletions src/rgb/color_cycle_v5.c
Original file line number Diff line number Diff line change
Expand Up @@ -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[] = {
Expand All @@ -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,
Expand Down
1 change: 1 addition & 0 deletions src/rgb/rgb_include.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit ae0d059

Please sign in to comment.