aboutsummaryrefslogtreecommitdiff
path: root/ui
diff options
context:
space:
mode:
authorChristian Schubert2026-04-02 21:54:14 +0200
committerChristian Schubert2026-04-02 21:54:14 +0200
commitadfc5a05a1238f5d6069c0356cfb2a4fe442010a (patch)
treea009b4396e6b7d8fd15a784e00522611c9952acf /ui
parentdetect_weak_battery() on powerup (diff)
downloadanduril-adfc5a05a1238f5d6069c0356cfb2a4fe442010a.tar.gz
anduril-adfc5a05a1238f5d6069c0356cfb2a4fe442010a.tar.bz2
anduril-adfc5a05a1238f5d6069c0356cfb2a4fe442010a.zip
3C from aux/on: color wheel
Diffstat (limited to '')
-rw-r--r--ui/simple/simple.c61
1 files changed, 60 insertions, 1 deletions
diff --git a/ui/simple/simple.c b/ui/simple/simple.c
index 12184df..38e2922 100644
--- a/ui/simple/simple.c
+++ b/ui/simple/simple.c
@@ -46,10 +46,12 @@ static const uint8_t brightness_levels[NUM_LEVELS] = {
#define HOLD_TICKS_PER_LEVEL 48 // cycle time 0.75s (48/64 Hz)
#define AUX_TIMEOUT_TICKS 320 // 5s
+#define COLOR_TICKS 320 // 5s
uint8_t off_state(Event event, uint16_t arg);
uint8_t aux_state(Event event, uint16_t arg);
uint8_t on_state(Event event, uint16_t arg);
+uint8_t color_state(Event event, uint16_t arg);
uint8_t current_level_idx = 0;
uint8_t current_level = 0;
@@ -79,6 +81,25 @@ static const uint8_t voltage_levels[] = {
255, 0x15, // R+G+B
};
+#define NUM_COLORS 12
+
+static const uint8_t color_wheel[NUM_COLORS] = {
+ 0b000010,
+ 0b000110,
+ 0b001010,
+ 0b001001,
+ 0b001000,
+ 0b011000,
+ 0b101000,
+ 0b100100,
+ 0b100000,
+ 0b100001,
+ 0b100010,
+ 0b010010,
+};
+
+uint8_t color_idx = 0;
+
static uint8_t voltage_color(void) {
uint8_t v = voltage;
if (v == 0) return 0;
@@ -139,6 +160,11 @@ uint8_t aux_state(Event event, uint16_t arg) {
return EVENT_HANDLED;
}
+ if (event == EV_3clicks) {
+ set_state(color_state, 0);
+ return EVENT_HANDLED;
+ }
+
if (event == EV_tick) {
if (arg >= AUX_TIMEOUT_TICKS) {
set_state(off_state, 0);
@@ -193,6 +219,39 @@ uint8_t on_state(Event event, uint16_t arg) {
return EVENT_HANDLED;
}
+ if (event == EV_3clicks) {
+ set_state(color_state, 0);
+ return EVENT_HANDLED;
+ }
+
+ return EVENT_NOT_HANDLED;
+}
+
+uint8_t color_state(Event event, uint16_t arg) {
+ if (color_idx >= NUM_COLORS) {
+ color_idx = 0;
+ }
+
+ if (event == EV_enter_state) {
+ set_level_therm(0, 0, 0);
+ rgb_led_set(color_wheel[color_idx]);
+ button_led_set(2);
+ return EVENT_HANDLED;
+ }
+
+ if (event == EV_1click) {
+ set_state(aux_state, 0);
+ return EVENT_HANDLED;
+ }
+
+ if (event == EV_tick) {
+ if (!(arg % COLOR_TICKS)) {
+ if (++color_idx == NUM_COLORS) color_idx = 0;
+ rgb_led_set(color_wheel[color_idx]);
+ }
+ return EVENT_HANDLED;
+ }
+
return EVENT_NOT_HANDLED;
}
@@ -229,7 +288,7 @@ void blink_once() {
void loop(void) {
StatePtr state = current_state;
- if (state == on_state || state == aux_state) {
+ if (state == on_state || state == aux_state || state == color_state) {
idle_mode();
}
}
If you find this content useful please consider a small donation via bitcoin: bitcoin:1mxKyQsHHugqRxPKgwaA7wUwJEGCNthn2?amount=0.001&message=Donation Scraping git contents via cgit is very resource intensive. The continued hosting of these git repositories is entirely financed by your bitcoin contributions. For donations of a least 1 mBTC you include your IP address in the message of your bitcoin donation. This will remove this message in the future for requests from your IP, which will significantly reduce token usage. In any case, any contributions to bitcoin address 1mxKyQsHHugqRxPKgwaA7wUwJEGCNthn2 are very welcome. Thanks in advance for you contribution to a self-sustaining ecosystem.