From a6ab1504058304012791281f9eb42c262745888f Mon Sep 17 00:00:00 2001 From: jacqueline Date: Fri, 19 May 2023 21:21:27 +1000 Subject: Add tinyfsm, start converting core functions to an FSM-based event loop --- lib/tinyfsm/examples/elevator/main.cpp | 40 ++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 lib/tinyfsm/examples/elevator/main.cpp (limited to 'lib/tinyfsm/examples/elevator/main.cpp') diff --git a/lib/tinyfsm/examples/elevator/main.cpp b/lib/tinyfsm/examples/elevator/main.cpp new file mode 100644 index 00000000..46570153 --- /dev/null +++ b/lib/tinyfsm/examples/elevator/main.cpp @@ -0,0 +1,40 @@ +#include "fsmlist.hpp" + +#include + + +int main() +{ + fsm_list::start(); + + Call call; + FloorSensor sensor; + + while(1) + { + char c; + + std::cout << "c=Call, f=FloorSensor, a=Alarm, q=Quit ? "; + std::cin >> c; + switch(c) { + case 'c': + std::cout << "Floor ? "; + std::cin >> call.floor; + send_event(call); + break; + case 'f': + std::cout << "Floor ? "; + std::cin >> sensor.floor; + send_event(sensor); + break; + case 'a': + send_event(Alarm()); + break; + case 'q': + std::cout << "Thanks for playing!" << std::endl; + return 0; + default: + std::cout << "Invalid input" << std::endl; + }; + } +} -- cgit v1.2.3