source for demo Book And Plug
Dependencies: APA102
LedCtrl.h@1:8c2e60bafc91, 2018-05-17 (annotated)
- Committer:
- vrou44
- Date:
- Thu May 17 17:12:17 2018 +0000
- Revision:
- 1:8c2e60bafc91
- Parent:
- 0:5648c217e527
Initial release
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
vrou44 | 0:5648c217e527 | 1 | /* |
vrou44 | 0:5648c217e527 | 2 | * LedCtrl.h |
vrou44 | 0:5648c217e527 | 3 | * |
vrou44 | 0:5648c217e527 | 4 | * Created on: 26 mars 2018 |
vrou44 | 0:5648c217e527 | 5 | * Author: hd01073 |
vrou44 | 0:5648c217e527 | 6 | */ |
vrou44 | 0:5648c217e527 | 7 | |
vrou44 | 0:5648c217e527 | 8 | #ifndef LEDCTRL_H_ |
vrou44 | 0:5648c217e527 | 9 | #define LEDCTRL_H_ |
vrou44 | 0:5648c217e527 | 10 | |
vrou44 | 0:5648c217e527 | 11 | #include "mbed.h" |
vrou44 | 0:5648c217e527 | 12 | #include "mbed_events.h" |
vrou44 | 0:5648c217e527 | 13 | |
vrou44 | 0:5648c217e527 | 14 | #define nbTypOfActivities 6 |
vrou44 | 0:5648c217e527 | 15 | #define NB_LED_STR1 22 |
vrou44 | 0:5648c217e527 | 16 | #define NB_LED_STR2 46 |
vrou44 | 0:5648c217e527 | 17 | |
vrou44 | 0:5648c217e527 | 18 | class LedCtrl |
vrou44 | 0:5648c217e527 | 19 | { |
vrou44 | 0:5648c217e527 | 20 | public: |
vrou44 | 0:5648c217e527 | 21 | static LedCtrl *singleInstP ; |
vrou44 | 0:5648c217e527 | 22 | static LedCtrl &getInst(void) { |
vrou44 | 0:5648c217e527 | 23 | if (!singleInstP) singleInstP = new LedCtrl() ; |
vrou44 | 0:5648c217e527 | 24 | return *singleInstP ; |
vrou44 | 0:5648c217e527 | 25 | }; |
vrou44 | 0:5648c217e527 | 26 | |
vrou44 | 0:5648c217e527 | 27 | static void delInst(void) { |
vrou44 | 0:5648c217e527 | 28 | if (singleInstP) { |
vrou44 | 0:5648c217e527 | 29 | delete singleInstP ; |
vrou44 | 0:5648c217e527 | 30 | singleInstP = 0 ; |
vrou44 | 0:5648c217e527 | 31 | } |
vrou44 | 0:5648c217e527 | 32 | } ; |
vrou44 | 0:5648c217e527 | 33 | |
vrou44 | 0:5648c217e527 | 34 | enum Evt { |
vrou44 | 0:5648c217e527 | 35 | activityChangeRequired |
vrou44 | 0:5648c217e527 | 36 | }; |
vrou44 | 0:5648c217e527 | 37 | |
vrou44 | 0:5648c217e527 | 38 | enum Activity { |
vrou44 | 0:5648c217e527 | 39 | undefinedActivity = -1, |
vrou44 | 0:5648c217e527 | 40 | noActivity = 0 , |
vrou44 | 0:5648c217e527 | 41 | signalingTermIdle = 1 , |
vrou44 | 0:5648c217e527 | 42 | signalingTermSelected = 2 , |
vrou44 | 0:5648c217e527 | 43 | signalingPlugSelected = 3 , |
vrou44 | 0:5648c217e527 | 44 | signalingCharging = 4 , |
vrou44 | 0:5648c217e527 | 45 | signalingChargeSuspended = 5 |
vrou44 | 0:5648c217e527 | 46 | }; |
vrou44 | 0:5648c217e527 | 47 | |
vrou44 | 0:5648c217e527 | 48 | void init(void) ; |
vrou44 | 0:5648c217e527 | 49 | static void signalEvent(Evt evt) ; |
vrou44 | 0:5648c217e527 | 50 | |
vrou44 | 0:5648c217e527 | 51 | public: |
vrou44 | 0:5648c217e527 | 52 | static Activity currentActivity ; |
vrou44 | 0:5648c217e527 | 53 | static Activity requiredActivity ; |
vrou44 | 0:5648c217e527 | 54 | // unsigned int *frameB1 ; |
vrou44 | 0:5648c217e527 | 55 | // unsigned int *frameB2 ; |
vrou44 | 0:5648c217e527 | 56 | |
vrou44 | 0:5648c217e527 | 57 | private : |
vrou44 | 0:5648c217e527 | 58 | LedCtrl(void) ; |
vrou44 | 0:5648c217e527 | 59 | ~LedCtrl() ; |
vrou44 | 0:5648c217e527 | 60 | |
vrou44 | 0:5648c217e527 | 61 | static void instanceFeedFsm(Evt evt) |
vrou44 | 0:5648c217e527 | 62 | { |
vrou44 | 0:5648c217e527 | 63 | singleInstP->feedFsm(evt) ; |
vrou44 | 0:5648c217e527 | 64 | } ; |
vrou44 | 0:5648c217e527 | 65 | void feedFsm(Evt evt) ; |
vrou44 | 0:5648c217e527 | 66 | static void expirationDelayHdlr(void) ; |
vrou44 | 0:5648c217e527 | 67 | static void refreshDelayHdlr(void) ; |
vrou44 | 0:5648c217e527 | 68 | |
vrou44 | 0:5648c217e527 | 69 | private: |
vrou44 | 0:5648c217e527 | 70 | int delayRequestId ; |
vrou44 | 0:5648c217e527 | 71 | struct ActivityCtxt { // generic context for activity |
vrou44 | 0:5648c217e527 | 72 | virtual void start(void) = 0 ; |
vrou44 | 0:5648c217e527 | 73 | virtual void keepAlive(void) = 0 ; |
vrou44 | 0:5648c217e527 | 74 | LedCtrl &ledCtrl ; |
vrou44 | 0:5648c217e527 | 75 | unsigned char lightIntensity ; |
vrou44 | 0:5648c217e527 | 76 | int nbRefresh ; // work around hardware isssue : first repaint may not work |
vrou44 | 0:5648c217e527 | 77 | bool increaseIntensB ; |
vrou44 | 0:5648c217e527 | 78 | ActivityCtxt(LedCtrl &_ledCtrl) : |
vrou44 | 0:5648c217e527 | 79 | ledCtrl(_ledCtrl), |
vrou44 | 0:5648c217e527 | 80 | lightIntensity(0), |
vrou44 | 0:5648c217e527 | 81 | nbRefresh(0), |
vrou44 | 0:5648c217e527 | 82 | increaseIntensB(false) |
vrou44 | 0:5648c217e527 | 83 | { |
vrou44 | 0:5648c217e527 | 84 | } ; |
vrou44 | 0:5648c217e527 | 85 | virtual ~ActivityCtxt() |
vrou44 | 0:5648c217e527 | 86 | { |
vrou44 | 0:5648c217e527 | 87 | } ; |
vrou44 | 0:5648c217e527 | 88 | }; |
vrou44 | 0:5648c217e527 | 89 | ActivityCtxt *currentActivityCtxtP ; |
vrou44 | 0:5648c217e527 | 90 | |
vrou44 | 0:5648c217e527 | 91 | struct NoActivityCtxt : |
vrou44 | 0:5648c217e527 | 92 | public ActivityCtxt { // specific context |
vrou44 | 0:5648c217e527 | 93 | NoActivityCtxt (LedCtrl &_ledCtrl) ; |
vrou44 | 0:5648c217e527 | 94 | virtual ~NoActivityCtxt() {} ; |
vrou44 | 0:5648c217e527 | 95 | virtual void start(void) ; |
vrou44 | 0:5648c217e527 | 96 | virtual void keepAlive(void) ; |
vrou44 | 0:5648c217e527 | 97 | } ; |
vrou44 | 0:5648c217e527 | 98 | |
vrou44 | 0:5648c217e527 | 99 | struct SignalingTermIdleCtxt : |
vrou44 | 0:5648c217e527 | 100 | public ActivityCtxt { // specific context |
vrou44 | 0:5648c217e527 | 101 | SignalingTermIdleCtxt (LedCtrl &_ledCtrl) ; |
vrou44 | 0:5648c217e527 | 102 | virtual ~SignalingTermIdleCtxt() {} ; |
vrou44 | 0:5648c217e527 | 103 | virtual void start(void) ; |
vrou44 | 0:5648c217e527 | 104 | virtual void keepAlive(void) ; |
vrou44 | 0:5648c217e527 | 105 | } ; |
vrou44 | 0:5648c217e527 | 106 | |
vrou44 | 0:5648c217e527 | 107 | struct SignalingTermSelectedCtxt : |
vrou44 | 0:5648c217e527 | 108 | public ActivityCtxt { |
vrou44 | 0:5648c217e527 | 109 | SignalingTermSelectedCtxt(LedCtrl &_ledCtrl) ; |
vrou44 | 0:5648c217e527 | 110 | virtual ~SignalingTermSelectedCtxt() {} ; |
vrou44 | 0:5648c217e527 | 111 | virtual void start(void) ; |
vrou44 | 0:5648c217e527 | 112 | virtual void keepAlive(void) ; |
vrou44 | 0:5648c217e527 | 113 | |
vrou44 | 0:5648c217e527 | 114 | } ; |
vrou44 | 0:5648c217e527 | 115 | |
vrou44 | 0:5648c217e527 | 116 | struct SignalingPlugSelectedCtxt : |
vrou44 | 0:5648c217e527 | 117 | public ActivityCtxt { |
vrou44 | 0:5648c217e527 | 118 | SignalingPlugSelectedCtxt(LedCtrl &_ledCtrl) ; |
vrou44 | 0:5648c217e527 | 119 | virtual ~SignalingPlugSelectedCtxt() {} ; |
vrou44 | 0:5648c217e527 | 120 | virtual void start(void) ; |
vrou44 | 0:5648c217e527 | 121 | virtual void keepAlive(void) ; |
vrou44 | 0:5648c217e527 | 122 | } ; |
vrou44 | 0:5648c217e527 | 123 | |
vrou44 | 0:5648c217e527 | 124 | struct SignalingChargingCtxt : |
vrou44 | 0:5648c217e527 | 125 | public ActivityCtxt { |
vrou44 | 0:5648c217e527 | 126 | int startIdxStr1 ; |
vrou44 | 0:5648c217e527 | 127 | int startIdxStr2 ; |
vrou44 | 0:5648c217e527 | 128 | SignalingChargingCtxt(LedCtrl &_ledCtrl) ; |
vrou44 | 0:5648c217e527 | 129 | virtual ~SignalingChargingCtxt() {} ; |
vrou44 | 0:5648c217e527 | 130 | virtual void start(void) ; |
vrou44 | 0:5648c217e527 | 131 | virtual void keepAlive(void) ; |
vrou44 | 0:5648c217e527 | 132 | } ; |
vrou44 | 0:5648c217e527 | 133 | |
vrou44 | 0:5648c217e527 | 134 | struct SignalingChargeSuspendedCtxt : |
vrou44 | 0:5648c217e527 | 135 | public ActivityCtxt { |
vrou44 | 0:5648c217e527 | 136 | SignalingChargeSuspendedCtxt(LedCtrl &_ledCtrl) ; |
vrou44 | 0:5648c217e527 | 137 | virtual ~SignalingChargeSuspendedCtxt() {} ; |
vrou44 | 0:5648c217e527 | 138 | virtual void start(void) ; |
vrou44 | 0:5648c217e527 | 139 | virtual void keepAlive(void) ; |
vrou44 | 0:5648c217e527 | 140 | } ; |
vrou44 | 0:5648c217e527 | 141 | |
vrou44 | 0:5648c217e527 | 142 | NoActivityCtxt noActivityCtxt ; |
vrou44 | 0:5648c217e527 | 143 | SignalingTermIdleCtxt signalingTermIdleCtxt ; |
vrou44 | 0:5648c217e527 | 144 | SignalingTermSelectedCtxt signalingTermSelectedCtxt ; |
vrou44 | 0:5648c217e527 | 145 | SignalingPlugSelectedCtxt signalingPlugSelectedCtxt ; |
vrou44 | 0:5648c217e527 | 146 | SignalingChargingCtxt signalingChargingCtxt ; |
vrou44 | 0:5648c217e527 | 147 | SignalingChargeSuspendedCtxt signalingChargeSuspendedCtxt ; |
vrou44 | 0:5648c217e527 | 148 | |
vrou44 | 0:5648c217e527 | 149 | ActivityCtxt *ctxtAP[nbTypOfActivities] ; |
vrou44 | 0:5648c217e527 | 150 | }; |
vrou44 | 0:5648c217e527 | 151 | |
vrou44 | 0:5648c217e527 | 152 | |
vrou44 | 0:5648c217e527 | 153 | #endif /* LEDCTRL_H_ */ |