From 73a5a6974a98aa73ab392272b4d69d285c85dee5 Mon Sep 17 00:00:00 2001 From: Selene ToyKeeper Date: Sat, 19 Aug 2017 17:20:46 -0600 Subject: Completely reorganized SpaghettiMonster code into smaller logical pieces: fsm-*.c and fsm-*.h. --- spaghetti-monster/fsm-states.h | 44 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 spaghetti-monster/fsm-states.h (limited to 'spaghetti-monster/fsm-states.h') diff --git a/spaghetti-monster/fsm-states.h b/spaghetti-monster/fsm-states.h new file mode 100644 index 0000000..0daf915 --- /dev/null +++ b/spaghetti-monster/fsm-states.h @@ -0,0 +1,44 @@ +/* + * fsm-states.h: State-handling functions for SpaghettiMonster. + * + * 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 . + */ + +#ifndef FSM_STATES_H +#define FSM_STATES_H + +#include "fsm-adc.h" + +// typedefs +typedef uint8_t State(EventPtr event, uint16_t arg); +typedef State * StatePtr; + +// top of the stack +volatile StatePtr current_state; + +// stack for states, to allow shared utility states like "input a number" +// and such, which return to the previous state after finishing +#define STATE_STACK_SIZE 8 +StatePtr state_stack[STATE_STACK_SIZE]; +uint8_t state_stack_len = 0; + +void _set_state(StatePtr new_state, uint16_t arg); +int8_t push_state(StatePtr new_state, uint16_t arg); +StatePtr pop_state(); +uint8_t set_state(StatePtr new_state, uint16_t arg); +uint8_t default_state(EventPtr event, uint16_t arg); + +#endif -- cgit v1.2.3 From dce497bf15799133bf336ab46c3e39d7b0d92839 Mon Sep 17 00:00:00 2001 From: Selene ToyKeeper Date: Sun, 27 Aug 2017 19:40:40 -0600 Subject: Ramp config mode actually works now... Added EV_reenter_state event to indicate an obscuring state was popped off the stack and the underlying one is now on top again. --- spaghetti-monster/fsm-states.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'spaghetti-monster/fsm-states.h') diff --git a/spaghetti-monster/fsm-states.h b/spaghetti-monster/fsm-states.h index 0daf915..f92abba 100644 --- a/spaghetti-monster/fsm-states.h +++ b/spaghetti-monster/fsm-states.h @@ -35,7 +35,8 @@ volatile StatePtr current_state; StatePtr state_stack[STATE_STACK_SIZE]; uint8_t state_stack_len = 0; -void _set_state(StatePtr new_state, uint16_t arg); +void _set_state(StatePtr new_state, uint16_t arg, + EventPtr exit_event, EventPtr enter_event); int8_t push_state(StatePtr new_state, uint16_t arg); StatePtr pop_state(); uint8_t set_state(StatePtr new_state, uint16_t arg); -- 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/fsm-states.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'spaghetti-monster/fsm-states.h') diff --git a/spaghetti-monster/fsm-states.h b/spaghetti-monster/fsm-states.h index f92abba..6e4a2a0 100644 --- a/spaghetti-monster/fsm-states.h +++ b/spaghetti-monster/fsm-states.h @@ -40,6 +40,8 @@ void _set_state(StatePtr new_state, uint16_t arg, int8_t push_state(StatePtr new_state, uint16_t arg); StatePtr pop_state(); uint8_t set_state(StatePtr new_state, uint16_t arg); +#ifndef DONT_USE_DEFAULT_STATE uint8_t default_state(EventPtr event, uint16_t arg); +#endif #endif -- cgit v1.2.3