The following diagram shows the state machine we plan to implement in firmware. SupervisorSM is the higher level state machine that keeps track of the "mode" (auto or manual) and "auto-mode" (auto open or auto close). DoorSM handles opening and closing the door, and runs orthogonally to Supervisor SM. Lastly, AutoCloseSM is nested in SupervisorSM when we enter the AUTO-CLOSED state and implements the logic of opening the door when a dog is detected outside, but otherwise keeps the door closed.
The actual code is on github here: github.com/gmkado/DoggieDoor
The code is written in c++ for the photon, where each state machine is a separate library. "doggiedoor.ino" contains the setup and main loop (similar to arduino). The main loop calls the runSM(flags) function for the appropriate statemachines, which use a bitset variable "myFlags" to pass events and commands between eachother and the main loop.
The code is written in c++ for the photon, where each state machine is a separate library. "doggiedoor.ino" contains the setup and main loop (similar to arduino). The main loop calls the runSM(flags) function for the appropriate statemachines, which use a bitset variable "myFlags" to pass events and commands between eachother and the main loop.