summaryrefslogtreecommitdiff
path: root/lib/tinyfsm/examples/elevator/main.cpp
blob: 465701537959a88b24f7725cd8f3f478aadf8b08 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include "fsmlist.hpp"

#include <iostream>


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;
    };
  }
}