init
Dependencies: MPU6050 PinDetect circular_buffer
CaseFSM/include/CaseFsm.h@0:b416214256cd, 2017-11-07 (annotated)
- Committer:
- OsmanKameric
- Date:
- Tue Nov 07 16:35:14 2017 +0000
- Revision:
- 0:b416214256cd
FIRST
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
OsmanKameric | 0:b416214256cd | 1 | #ifndef CASEFSM_FSM_H_ |
OsmanKameric | 0:b416214256cd | 2 | #define CASEFSM_FSM_H_ |
OsmanKameric | 0:b416214256cd | 3 | #include <CaseState.h> |
OsmanKameric | 0:b416214256cd | 4 | #include "mbed.h" |
OsmanKameric | 0:b416214256cd | 5 | |
OsmanKameric | 0:b416214256cd | 6 | #include <CaseEvents.h> |
OsmanKameric | 0:b416214256cd | 7 | |
OsmanKameric | 0:b416214256cd | 8 | struct SwitchPosition; |
OsmanKameric | 0:b416214256cd | 9 | struct RFIDEvent; |
OsmanKameric | 0:b416214256cd | 10 | |
OsmanKameric | 0:b416214256cd | 11 | class CaseFsmStates |
OsmanKameric | 0:b416214256cd | 12 | { |
OsmanKameric | 0:b416214256cd | 13 | public: |
OsmanKameric | 0:b416214256cd | 14 | CaseFsmStates(); |
OsmanKameric | 0:b416214256cd | 15 | |
OsmanKameric | 0:b416214256cd | 16 | CaseState* deviceEmptyState(); |
OsmanKameric | 0:b416214256cd | 17 | CaseState* deviceFullState(); |
OsmanKameric | 0:b416214256cd | 18 | CaseState* phoneUndetectedState(); |
OsmanKameric | 0:b416214256cd | 19 | CaseState* phoneDetectedState(); |
OsmanKameric | 0:b416214256cd | 20 | CaseState* currentState(); |
OsmanKameric | 0:b416214256cd | 21 | |
OsmanKameric | 0:b416214256cd | 22 | void currentState(CaseState* state); |
OsmanKameric | 0:b416214256cd | 23 | ~CaseFsmStates(); |
OsmanKameric | 0:b416214256cd | 24 | |
OsmanKameric | 0:b416214256cd | 25 | private: |
OsmanKameric | 0:b416214256cd | 26 | |
OsmanKameric | 0:b416214256cd | 27 | CaseState* deviceEmptyState_; |
OsmanKameric | 0:b416214256cd | 28 | CaseState* deviceFullState_; |
OsmanKameric | 0:b416214256cd | 29 | CaseState* phoneUndetectedState_; |
OsmanKameric | 0:b416214256cd | 30 | CaseState* phoneDetectedState_; |
OsmanKameric | 0:b416214256cd | 31 | CaseState* currentState_; |
OsmanKameric | 0:b416214256cd | 32 | |
OsmanKameric | 0:b416214256cd | 33 | Timer timer; |
OsmanKameric | 0:b416214256cd | 34 | |
OsmanKameric | 0:b416214256cd | 35 | }; |
OsmanKameric | 0:b416214256cd | 36 | |
OsmanKameric | 0:b416214256cd | 37 | class CaseFsm |
OsmanKameric | 0:b416214256cd | 38 | { |
OsmanKameric | 0:b416214256cd | 39 | public: |
OsmanKameric | 0:b416214256cd | 40 | CaseFsm(); |
OsmanKameric | 0:b416214256cd | 41 | Timeout rfidTimeout; |
OsmanKameric | 0:b416214256cd | 42 | void timerCallback(); |
OsmanKameric | 0:b416214256cd | 43 | template <typename Event> |
OsmanKameric | 0:b416214256cd | 44 | void handle(Event& event) { |
OsmanKameric | 0:b416214256cd | 45 | CaseState* state = states_.currentState()->handle(event); |
OsmanKameric | 0:b416214256cd | 46 | if(state==states_.deviceFullState()) { |
OsmanKameric | 0:b416214256cd | 47 | rfidTimeout.attach(this, &CaseFsm::timerCallback, 5.0); |
OsmanKameric | 0:b416214256cd | 48 | } |
OsmanKameric | 0:b416214256cd | 49 | if(state==states_.deviceEmptyState()) { |
OsmanKameric | 0:b416214256cd | 50 | rfidTimeout.detach(); |
OsmanKameric | 0:b416214256cd | 51 | } |
OsmanKameric | 0:b416214256cd | 52 | if(state==states_.phoneDetectedState()) { |
OsmanKameric | 0:b416214256cd | 53 | rfidTimeout.detach(); |
OsmanKameric | 0:b416214256cd | 54 | } |
OsmanKameric | 0:b416214256cd | 55 | states_.currentState(state); |
OsmanKameric | 0:b416214256cd | 56 | } |
OsmanKameric | 0:b416214256cd | 57 | bool DeviceInFullState(){ |
OsmanKameric | 0:b416214256cd | 58 | return states_.currentState() == states_.deviceFullState(); |
OsmanKameric | 0:b416214256cd | 59 | }; |
OsmanKameric | 0:b416214256cd | 60 | virtual ~CaseFsm() {} |
OsmanKameric | 0:b416214256cd | 61 | |
OsmanKameric | 0:b416214256cd | 62 | private: |
OsmanKameric | 0:b416214256cd | 63 | CaseFsmStates states_; |
OsmanKameric | 0:b416214256cd | 64 | |
OsmanKameric | 0:b416214256cd | 65 | }; |
OsmanKameric | 0:b416214256cd | 66 | #endif /* ifndef CASEFSM_FSM_H_ */ |