aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--control/application.c31
-rw-r--r--control/ledctl.c127
-rw-r--r--control/ledctl.h14
3 files changed, 156 insertions, 16 deletions
diff --git a/control/application.c b/control/application.c
index ce14bf2..c304a84 100644
--- a/control/application.c
+++ b/control/application.c
@@ -2,6 +2,7 @@
#include <bc_eeprom.h>
#include <bc_spi.h>
#include <bc_dice.h>
+#include "ledctl.h"
#define SERVICE_INTERVAL_INTERVAL (60 * 60 * 1000)
#define BATTERY_UPDATE_INTERVAL (60 * 60 * 1000)
@@ -51,26 +52,24 @@ void tmp112_event_handler(bc_tmp112_t *self, bc_tmp112_event_t event, void *even
bc_scheduler_plan_now(APPLICATION_TASK_ID);
}
-int brightness = 0;
-
-void set_brightness() {
- bc_radio_pub_int("led/brightness/set", &brightness);
-}
-
void lcd_button_left_event_handler(bc_button_t *self, bc_button_event_t event, void *event_param) {
- if (event != BC_BUTTON_EVENT_CLICK)
- return;
- bc_led_pulse(&led_lcd_blue, 30);
- brightness = 100;
- set_brightness();
+ if (event == BC_BUTTON_EVENT_CLICK) {
+ click_left();
+ bc_led_pulse(&led_lcd_blue, 30);
+ } else if (event == BC_BUTTON_EVENT_HOLD) {
+ hold_left();
+ bc_led_pulse(&led_lcd_blue, 500);
+ }
}
void lcd_button_right_event_handler(bc_button_t *self, bc_button_event_t event, void *event_param) {
- if (event != BC_BUTTON_EVENT_CLICK)
- return;
- bc_led_pulse(&led_lcd_red, 30);
- brightness = 0;
- set_brightness();
+ if (event == BC_BUTTON_EVENT_CLICK) {
+ click_right();
+ bc_led_pulse(&led_lcd_red, 30);
+ } else if (event == BC_BUTTON_EVENT_HOLD) {
+ hold_right();
+ bc_led_pulse(&led_lcd_red, 500);
+ }
}
void battery_event_handler(bc_module_battery_event_t event, void *event_param) {
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;
+ }
+}
diff --git a/control/ledctl.h b/control/ledctl.h
new file mode 100644
index 0000000..d7706c4
--- /dev/null
+++ b/control/ledctl.h
@@ -0,0 +1,14 @@
+#include <bcl.h>
+#include <bc_eeprom.h>
+#include <bc_spi.h>
+#include <bc_dice.h>
+
+#ifndef _LEDCTL_H_
+#define _LEDCTL_H_
+
+void click_left();
+void click_right();
+void hold_left();
+void hold_right();
+
+#endif