Stm for the project "Fahradlicht"
STM_Fahrrad_Licht.cpp@0:3d7042171419, 2018-11-23 (annotated)
- Committer:
- lordofthestorm12
- Date:
- Fri Nov 23 15:26:49 2018 +0000
- Revision:
- 0:3d7042171419
stm class;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
lordofthestorm12 | 0:3d7042171419 | 1 | #include "STM_Fahrrad_Licht.h" |
lordofthestorm12 | 0:3d7042171419 | 2 | |
lordofthestorm12 | 0:3d7042171419 | 3 | StateDefine::StateDefine() |
lordofthestorm12 | 0:3d7042171419 | 4 | { |
lordofthestorm12 | 0:3d7042171419 | 5 | _stmTimer.start(); |
lordofthestorm12 | 0:3d7042171419 | 6 | _curLEDPos = 1; |
lordofthestorm12 | 0:3d7042171419 | 7 | _timerval = 0.1; |
lordofthestorm12 | 0:3d7042171419 | 8 | } |
lordofthestorm12 | 0:3d7042171419 | 9 | |
lordofthestorm12 | 0:3d7042171419 | 10 | void StateDefine::st_off(void) |
lordofthestorm12 | 0:3d7042171419 | 11 | { |
lordofthestorm12 | 0:3d7042171419 | 12 | _STMLed.setLED(0); |
lordofthestorm12 | 0:3d7042171419 | 13 | } |
lordofthestorm12 | 0:3d7042171419 | 14 | |
lordofthestorm12 | 0:3d7042171419 | 15 | void StateDefine::st_all(void) |
lordofthestorm12 | 0:3d7042171419 | 16 | { |
lordofthestorm12 | 0:3d7042171419 | 17 | _STMLed.setLED(7); |
lordofthestorm12 | 0:3d7042171419 | 18 | } |
lordofthestorm12 | 0:3d7042171419 | 19 | |
lordofthestorm12 | 0:3d7042171419 | 20 | void StateDefine:: st_ll() |
lordofthestorm12 | 0:3d7042171419 | 21 | { |
lordofthestorm12 | 0:3d7042171419 | 22 | if(_stmTimer >= _timerval || _stmTimer <= 0) { |
lordofthestorm12 | 0:3d7042171419 | 23 | |
lordofthestorm12 | 0:3d7042171419 | 24 | _curLEDPos--; |
lordofthestorm12 | 0:3d7042171419 | 25 | |
lordofthestorm12 | 0:3d7042171419 | 26 | if(_curLEDPos >= 1 && _curLEDPos <= 4) { |
lordofthestorm12 | 0:3d7042171419 | 27 | ; |
lordofthestorm12 | 0:3d7042171419 | 28 | _stmTimer.reset(); |
lordofthestorm12 | 0:3d7042171419 | 29 | _STMLed.setLED(_curLEDPos); |
lordofthestorm12 | 0:3d7042171419 | 30 | } else { |
lordofthestorm12 | 0:3d7042171419 | 31 | _stmTimer.reset(); |
lordofthestorm12 | 0:3d7042171419 | 32 | _curLEDPos = 4; |
lordofthestorm12 | 0:3d7042171419 | 33 | _STMLed.setLED(_curLEDPos); |
lordofthestorm12 | 0:3d7042171419 | 34 | } |
lordofthestorm12 | 0:3d7042171419 | 35 | |
lordofthestorm12 | 0:3d7042171419 | 36 | } |
lordofthestorm12 | 0:3d7042171419 | 37 | } |
lordofthestorm12 | 0:3d7042171419 | 38 | |
lordofthestorm12 | 0:3d7042171419 | 39 | void StateDefine:: st_lr() |
lordofthestorm12 | 0:3d7042171419 | 40 | { |
lordofthestorm12 | 0:3d7042171419 | 41 | if(_stmTimer >= _timerval || _stmTimer <= 0) { |
lordofthestorm12 | 0:3d7042171419 | 42 | |
lordofthestorm12 | 0:3d7042171419 | 43 | _curLEDPos++; |
lordofthestorm12 | 0:3d7042171419 | 44 | |
lordofthestorm12 | 0:3d7042171419 | 45 | if(_curLEDPos >= 1 && _curLEDPos <= 4) { |
lordofthestorm12 | 0:3d7042171419 | 46 | ; |
lordofthestorm12 | 0:3d7042171419 | 47 | _stmTimer.reset(); |
lordofthestorm12 | 0:3d7042171419 | 48 | _STMLed.setLED(_curLEDPos); |
lordofthestorm12 | 0:3d7042171419 | 49 | } else { |
lordofthestorm12 | 0:3d7042171419 | 50 | _stmTimer.reset(); |
lordofthestorm12 | 0:3d7042171419 | 51 | _curLEDPos = 1; |
lordofthestorm12 | 0:3d7042171419 | 52 | _STMLed.setLED(_curLEDPos); |
lordofthestorm12 | 0:3d7042171419 | 53 | } |
lordofthestorm12 | 0:3d7042171419 | 54 | |
lordofthestorm12 | 0:3d7042171419 | 55 | } |
lordofthestorm12 | 0:3d7042171419 | 56 | } |
lordofthestorm12 | 0:3d7042171419 | 57 | |
lordofthestorm12 | 0:3d7042171419 | 58 | void StateDefine:: st_blinki() |
lordofthestorm12 | 0:3d7042171419 | 59 | { |
lordofthestorm12 | 0:3d7042171419 | 60 | |
lordofthestorm12 | 0:3d7042171419 | 61 | if(_stmTimer >= 0.5 || _stmTimer <= 0) { |
lordofthestorm12 | 0:3d7042171419 | 62 | |
lordofthestorm12 | 0:3d7042171419 | 63 | if(_curLEDPos == 1) { |
lordofthestorm12 | 0:3d7042171419 | 64 | _curLEDPos++; |
lordofthestorm12 | 0:3d7042171419 | 65 | _STMLed.setLED(7); |
lordofthestorm12 | 0:3d7042171419 | 66 | _stmTimer.reset(); |
lordofthestorm12 | 0:3d7042171419 | 67 | } else { |
lordofthestorm12 | 0:3d7042171419 | 68 | _curLEDPos = 1; |
lordofthestorm12 | 0:3d7042171419 | 69 | _STMLed.setLED(0); |
lordofthestorm12 | 0:3d7042171419 | 70 | _stmTimer.reset(); |
lordofthestorm12 | 0:3d7042171419 | 71 | } |
lordofthestorm12 | 0:3d7042171419 | 72 | } |
lordofthestorm12 | 0:3d7042171419 | 73 | } |
lordofthestorm12 | 0:3d7042171419 | 74 | |
lordofthestorm12 | 0:3d7042171419 | 75 | void StateDefine:: st_defblinki() |
lordofthestorm12 | 0:3d7042171419 | 76 | { |
lordofthestorm12 | 0:3d7042171419 | 77 | |
lordofthestorm12 | 0:3d7042171419 | 78 | if(_stmTimer >= _timerval || _stmTimer <= 0) { |
lordofthestorm12 | 0:3d7042171419 | 79 | |
lordofthestorm12 | 0:3d7042171419 | 80 | if(_curLEDPos == 1) { |
lordofthestorm12 | 0:3d7042171419 | 81 | _curLEDPos++; |
lordofthestorm12 | 0:3d7042171419 | 82 | _STMLed.setLED(7); |
lordofthestorm12 | 0:3d7042171419 | 83 | _stmTimer.reset(); |
lordofthestorm12 | 0:3d7042171419 | 84 | } else { |
lordofthestorm12 | 0:3d7042171419 | 85 | _curLEDPos = 1; |
lordofthestorm12 | 0:3d7042171419 | 86 | _STMLed.setLED(0); |
lordofthestorm12 | 0:3d7042171419 | 87 | _stmTimer.reset(); |
lordofthestorm12 | 0:3d7042171419 | 88 | } |
lordofthestorm12 | 0:3d7042171419 | 89 | } |
lordofthestorm12 | 0:3d7042171419 | 90 | } |
lordofthestorm12 | 0:3d7042171419 | 91 | |
lordofthestorm12 | 0:3d7042171419 | 92 | void StateDefine:: st_policelight() |
lordofthestorm12 | 0:3d7042171419 | 93 | { |
lordofthestorm12 | 0:3d7042171419 | 94 | |
lordofthestorm12 | 0:3d7042171419 | 95 | if(_stmTimer >= 0.25 || _stmTimer <= 0) { |
lordofthestorm12 | 0:3d7042171419 | 96 | |
lordofthestorm12 | 0:3d7042171419 | 97 | if(_curLEDPos == 1) { |
lordofthestorm12 | 0:3d7042171419 | 98 | _curLEDPos++; |
lordofthestorm12 | 0:3d7042171419 | 99 | _STMLed.setLED(5); |
lordofthestorm12 | 0:3d7042171419 | 100 | _stmTimer.reset(); |
lordofthestorm12 | 0:3d7042171419 | 101 | } else { |
lordofthestorm12 | 0:3d7042171419 | 102 | _curLEDPos = 1; |
lordofthestorm12 | 0:3d7042171419 | 103 | _STMLed.setLED(6); |
lordofthestorm12 | 0:3d7042171419 | 104 | _stmTimer.reset(); |
lordofthestorm12 | 0:3d7042171419 | 105 | } |
lordofthestorm12 | 0:3d7042171419 | 106 | } |
lordofthestorm12 | 0:3d7042171419 | 107 | |
lordofthestorm12 | 0:3d7042171419 | 108 | } |
lordofthestorm12 | 0:3d7042171419 | 109 | |
lordofthestorm12 | 0:3d7042171419 | 110 | void StateDefine:: STATEChange(CurState aCS , float aCurTimerVal){ |
lordofthestorm12 | 0:3d7042171419 | 111 | |
lordofthestorm12 | 0:3d7042171419 | 112 | _timerval = aCurTimerVal; |
lordofthestorm12 | 0:3d7042171419 | 113 | |
lordofthestorm12 | 0:3d7042171419 | 114 | switch(aCS){ |
lordofthestorm12 | 0:3d7042171419 | 115 | case OFF: st_off(); break; |
lordofthestorm12 | 0:3d7042171419 | 116 | case ALL: st_all(); break; |
lordofthestorm12 | 0:3d7042171419 | 117 | case LL: st_ll(); break; |
lordofthestorm12 | 0:3d7042171419 | 118 | case LR: st_lr(); break; |
lordofthestorm12 | 0:3d7042171419 | 119 | case BLINKI: st_blinki(); break; |
lordofthestorm12 | 0:3d7042171419 | 120 | case DEFBLINKI: st_defblinki(); break; |
lordofthestorm12 | 0:3d7042171419 | 121 | case POLICELIGHT: st_policelight();break; |
lordofthestorm12 | 0:3d7042171419 | 122 | } |
lordofthestorm12 | 0:3d7042171419 | 123 | |
lordofthestorm12 | 0:3d7042171419 | 124 | |
lordofthestorm12 | 0:3d7042171419 | 125 | } |