-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAutoCloseSM.h
50 lines (43 loc) · 1.66 KB
/
AutoCloseSM.h
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
41
42
43
44
45
46
47
48
49
50
#ifndef autocloseSM_h
#define autocloseSM_h
#include "application.h"//needed for all Particle libraries
#include "DoorSM.h" // this includes <memory>
/****************************************************************
States
****************************************************************/
typedef enum {WAITING_FOR_DOG,
WAITING_FOR_DOOR_CLOSED,
WAITING_FOR_DOOR_OPEN,
WAITING_FOR_ALL_CLEAR,
HOLDING_DOOR_OPEN,
SIZE_OF_AUTOCLOSESTATE_ENUM} AutoCloseState_t ;
const std::string AutoCloseStateNames[] = { "WAITING_FOR_DOG",
"WAITING_FOR_DOOR_CLOSED",
"WAITING_FOR_DOOR_OPEN",
"WAITING_FOR_ALL_CLEAR",
"HOLDING_DOOR_OPEN"};
// statically check that the size of AutoCloseStateNames fits the number of DoorStates
static_assert(sizeof(AutoCloseStateNames)/sizeof(char*) == SIZE_OF_AUTOCLOSESTATE_ENUM, "sizes dont match");
/***************************************************************
* Definitions
* **************************************************************/
const uint16_t HOLDING_TIME = 3000;
/****************************************************************
Function Prototypes
****************************************************************/
class AutoCloseSM {
public:
AutoCloseSM();
void init(DoorState_t, std::bitset<SIZE_OF_FLAGS_ENUM> *flags);
void runSM(std::bitset<SIZE_OF_FLAGS_ENUM> *flags);
AutoCloseState_t getState();
private:
AutoCloseState_t currentState;
bool isEntry;
bool isExit;
bool timeoutOccurred;
void transitionTo(AutoCloseState_t);
std::unique_ptr<Timer> autoCloseTimer; // use a smart pointer. This initializes to null, but we reset in DoorSM constructor
void onTimeout();
};
#endif