I wonder what's the best way to implement state machines on the Teensy.
I started with a switch statement that was initially around 100 - 150 lines or so. But due to additional requirements, creeping features, plus error checking/handling, it's over 700 lines now, and I wonder if it would be better to switch to function pointers, or some other method that would eliminate that big switch(){} because it's a royal PITA to work with that.
The high level (logical) state machine contains only 5 states: ON, OFF, INIT, POWERDOWN, and FAIL where INIT stands for the OFF -> ON transition and POWERDOWN stands for the ON -> OFF transition. The low level state machine has 20+ states with most of the growth coming from the breakup of INIT and POWERDOWN states, plus various error handling/retry states not indicated in the high level description.
Is there any disadvantage to use function pointers in Arduino?
Is there any other method aside from the two I already mentioned that could be used to efficiently implement a state machine while having easily maintainable code?
HW & SW: T3.2, Arduino 1.8.4, Teensyduino 1.41
I started with a switch statement that was initially around 100 - 150 lines or so. But due to additional requirements, creeping features, plus error checking/handling, it's over 700 lines now, and I wonder if it would be better to switch to function pointers, or some other method that would eliminate that big switch(){} because it's a royal PITA to work with that.
The high level (logical) state machine contains only 5 states: ON, OFF, INIT, POWERDOWN, and FAIL where INIT stands for the OFF -> ON transition and POWERDOWN stands for the ON -> OFF transition. The low level state machine has 20+ states with most of the growth coming from the breakup of INIT and POWERDOWN states, plus various error handling/retry states not indicated in the high level description.
Is there any disadvantage to use function pointers in Arduino?
Is there any other method aside from the two I already mentioned that could be used to efficiently implement a state machine while having easily maintainable code?
HW & SW: T3.2, Arduino 1.8.4, Teensyduino 1.41