aboutsummaryrefslogtreecommitdiff
path: root/RoundTable/momentary.c
diff options
context:
space:
mode:
authorSelene ToyKeeper2017-08-18 18:12:17 -0600
committerSelene ToyKeeper2017-08-18 18:12:17 -0600
commite96562e36df96ca755d527e479e597ae4e4e09e1 (patch)
tree9d75c5eb9c8a68a6ea45ea06134c1a780bcbd416 /RoundTable/momentary.c
parentmerged crescendo updates: added thermal regulation (diff)
downloadanduril-e96562e36df96ca755d527e479e597ae4e4e09e1.tar.gz
anduril-e96562e36df96ca755d527e479e597ae4e4e09e1.tar.bz2
anduril-e96562e36df96ca755d527e479e597ae4e4e09e1.zip
Some early ideas for Round Table. Nothing close to compile-able yet.
Diffstat (limited to '')
-rw-r--r--RoundTable/momentary.c68
1 files changed, 68 insertions, 0 deletions
diff --git a/RoundTable/momentary.c b/RoundTable/momentary.c
new file mode 100644
index 0000000..120406e
--- /dev/null
+++ b/RoundTable/momentary.c
@@ -0,0 +1,68 @@
+/*
+ * Momentary: Very simple example UI for RoundTable.
+ * Is intended to be the simplest possible RT e-switch UI.
+ * The light is in while the button is held; off otherwise.
+ *
+ * Copyright (C) 2017 Selene ToyKeeper
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#define RT_EMISAR_D4_LAYOUT
+#include "round-table.c"
+
+volatile uint8_t brightness;
+
+void light_on() {
+ PWM1_LVL = brightness;
+ PWM2_LVL = 0;
+}
+
+void light_off() {
+ PWM1_LVL = 0;
+ PWM2_LVL = 0;
+}
+
+uint8_t momentary_state(EventPtr event, uint16_t arg) {
+ switch(event) {
+
+ case EV_press:
+ brightness = 255;
+ light_on();
+ // reset current event queue
+ empty_event_sequence();
+ return 0;
+
+ case EV_release:
+ light_off();
+ // reset current event queue
+ empty_event_sequence();
+ return 0;
+
+ // LVP / low-voltage protection
+ case EV_voltage_low:
+ case EV_voltage_critical:
+ if (brightness > 0) brightness >>= 1;
+ else {
+ light_off();
+ standby_mode();
+ }
+ return 0;
+ }
+ return 1; // event not handled
+}
+
+void setup() {
+ set_state(momentary_state);
+}