From af011b08919e42736f514ae6ffe045571dbefda9 Mon Sep 17 00:00:00 2001 From: Selene ToyKeeper Date: Wed, 30 Aug 2017 23:15:39 -0600 Subject: Reorganized FSM files, one dir per UI. --- spaghetti-monster/momentary/momentary.c | 81 +++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 spaghetti-monster/momentary/momentary.c (limited to 'spaghetti-monster/momentary') diff --git a/spaghetti-monster/momentary/momentary.c b/spaghetti-monster/momentary/momentary.c new file mode 100644 index 0000000..6b049f4 --- /dev/null +++ b/spaghetti-monster/momentary/momentary.c @@ -0,0 +1,81 @@ +/* + * Momentary: Very simple example UI for SpaghettiMonster. + * Is intended to be the simplest possible FSM e-switch UI. + * The light is on 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 . + */ + +#define FSM_EMISAR_D4_DRIVER +#define USE_LVP +#define USE_DEBUG_BLINK +#define USE_DELAY_4MS +#include "spaghetti-monster.h" + +volatile uint8_t brightness; +volatile uint8_t on_now; + +void light_on() { + on_now = 1; + PWM1_LVL = brightness; + PWM2_LVL = 0; +} + +void light_off() { + on_now = 0; + PWM1_LVL = 0; + PWM2_LVL = 0; +} + +uint8_t momentary_state(EventPtr event, uint16_t arg) { + + if (event == EV_click1_press) { + brightness = 255; + light_on(); + empty_event_sequence(); // don't attempt to parse multiple clicks + return 0; + } + + else if (event == EV_release) { + light_off(); + empty_event_sequence(); // don't attempt to parse multiple clicks + standby_mode(); // sleep while light is off + return 0; + } + + return 1; // event not handled +} + +// LVP / low-voltage protection +void low_voltage() { + if (brightness > 0) { + debug_blink(3); + brightness >>= 1; + if (on_now) light_on(); + } else { + debug_blink(8); + light_off(); + standby_mode(); + } +} + +void setup() { + debug_blink(2); + push_state(momentary_state, 0); +} + +void loop() { } + -- cgit v1.2.3 From a419850e536f00549120255a627137faffded47a Mon Sep 17 00:00:00 2001 From: Selene ToyKeeper Date: Sun, 3 Sep 2017 14:58:22 -0600 Subject: Got the 4th PWM channel to work, ish. (channel 4 is inverted though) Moved go_to_suspend thing into main() instead of making each UI handle that during loop(). Made default_state() optional. Fixed bug where battcheck and other number readouts could interfere with the state which interrupted them. (they would sometimes turn the LED off after the new state had already started) Updated darkhorse's moon levels to match new ramp on D4 hardware. --- spaghetti-monster/momentary/momentary.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'spaghetti-monster/momentary') diff --git a/spaghetti-monster/momentary/momentary.c b/spaghetti-monster/momentary/momentary.c index 6b049f4..d4ac1db 100644 --- a/spaghetti-monster/momentary/momentary.c +++ b/spaghetti-monster/momentary/momentary.c @@ -52,7 +52,7 @@ uint8_t momentary_state(EventPtr event, uint16_t arg) { else if (event == EV_release) { light_off(); empty_event_sequence(); // don't attempt to parse multiple clicks - standby_mode(); // sleep while light is off + go_to_standby = 1; // sleep while light is off return 0; } @@ -68,7 +68,7 @@ void low_voltage() { } else { debug_blink(8); light_off(); - standby_mode(); + go_to_standby = 1; } } -- cgit v1.2.3