aboutsummaryrefslogtreecommitdiff
path: root/control/ledctl.c
diff options
context:
space:
mode:
authorKarel Kočí <cynerd@email.cz>2018-12-09 21:29:18 +0100
committerKarel Kočí <cynerd@email.cz>2018-12-09 21:29:18 +0100
commitc54f47138d909bbc5e18fb909ee4d7a62c818f9c (patch)
tree53f12b91e74e5065bd0453653f53deb47e017f2c /control/ledctl.c
parentbbcb8d635f4c83a0a7f27bd6d3e554781780d27e (diff)
downloadbigclown-leds-c54f47138d909bbc5e18fb909ee4d7a62c818f9c.tar.gz
bigclown-leds-c54f47138d909bbc5e18fb909ee4d7a62c818f9c.tar.bz2
bigclown-leds-c54f47138d909bbc5e18fb909ee4d7a62c818f9c.zip
control: add leds control code
Diffstat (limited to 'control/ledctl.c')
-rw-r--r--control/ledctl.c127
1 files changed, 127 insertions, 0 deletions
diff --git a/control/ledctl.c b/control/ledctl.c
new file mode 100644
index 0000000..d6fdd1e
--- /dev/null
+++ b/control/ledctl.c
@@ -0,0 +1,127 @@
+#include "ledctl.h"
+
+enum {
+ MODE_SOLID_RED,
+ MODE_SOLID_GREEN,
+ MODE_SOLID_BLUE,
+ MODE_SOLID_YELLOW,
+ MODE_RAINBOW,
+} mode;
+int brightness = 7;
+int enabled = 0;
+int current_brightness = 0;
+
+const char *mode_string[] = {
+ [MODE_SOLID_RED] = "#FF0000",
+ [MODE_SOLID_GREEN] = "#00FF00",
+ [MODE_SOLID_BLUE] = "#0000FF",
+ [MODE_SOLID_YELLOW] = "#FFFF00",
+ [MODE_RAINBOW] = "{\"type\":\"rainbow\", \"wait\":50}",
+};
+
+
+enum {
+ STATE_DEFAULT,
+ STATE_COLOR_SELECT,
+ STATE_BRIGHTNESS_SELECT,
+} state = STATE_DEFAULT;
+
+
+void update_brightness() {
+ if (!enabled)
+ current_brightness = 0;
+ else
+ current_brightness = brightness > 7 ? 100 : (1 << (brightness - 1));
+ bc_radio_pub_int("led/brightness/set", &current_brightness);
+}
+
+void update_mode() {
+ if (mode == MODE_RAINBOW)
+ bc_radio_pub_string("led/effect/set", mode_string[mode]);
+ else
+ bc_radio_pub_string("led/color/set", mode_string[mode]);
+}
+
+void click_left() {
+ switch (state) {
+ case STATE_DEFAULT:
+ enabled = 1;
+ update_brightness();
+ break;
+ case STATE_BRIGHTNESS_SELECT:
+ if (brightness <= 8)
+ brightness++;
+ update_brightness();
+ break;
+ case STATE_COLOR_SELECT:
+ if (mode >= MODE_RAINBOW)
+ mode = MODE_SOLID_RED;
+ else
+ mode++;
+ update_mode();
+ break;
+ default:
+ break;
+ }
+}
+
+void click_right() {
+ switch (state) {
+ case STATE_DEFAULT:
+ enabled = 0;
+ update_brightness();
+ break;
+ case STATE_BRIGHTNESS_SELECT:
+ if (brightness >= 1)
+ brightness--;
+ update_brightness();
+ break;
+ case STATE_COLOR_SELECT:
+ if (mode <= MODE_SOLID_RED)
+ mode = MODE_RAINBOW;
+ else
+ mode--;
+ update_mode();
+ break;
+ default:
+ break;
+ }
+}
+
+void hold_left() {
+ switch (state) {
+ case STATE_DEFAULT:
+ state = STATE_BRIGHTNESS_SELECT;
+ // TODO update image
+ break;
+ case STATE_COLOR_SELECT:
+ state = STATE_COLOR_SELECT;
+ // TODO
+ break;
+ case STATE_BRIGHTNESS_SELECT:
+ state = STATE_DEFAULT;
+ // TODO
+ break;
+ default:
+ break;
+ }
+}
+
+void hold_right() {
+ switch (state) {
+ case STATE_DEFAULT:
+ state = STATE_COLOR_SELECT;
+ // TODO update image
+ break;
+ case STATE_COLOR_SELECT:
+ state = STATE_DEFAULT;
+ // TODO
+ break;
+ case STATE_BRIGHTNESS_SELECT:
+ state = STATE_BRIGHTNESS_SELECT;
+ // TODO
+ break;
+ default:
+ break;
+ }
+}