Display Steuerung für Lampen per Relais. https://www.youtube.com/watch?v=_CupBMcZ8Xc
Dependencies: BSP_DISCO_F746NG F746_GUI LCD_DISCO_F746NG TS_DISCO_F746NG mbed
lightAutomatic.cpp@1:f316de154ff7, 2017-04-23 (annotated)
- Committer:
- hexfactory
- Date:
- Sun Apr 23 17:15:53 2017 +0000
- Revision:
- 1:f316de154ff7
Helligkeitssensor und T?rkontaktsensor - Display Steuerung [DE]; https://www.youtube.com/watch?v=9OA7kxGMPo8
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
hexfactory | 1:f316de154ff7 | 1 | /*============================================================================================= |
hexfactory | 1:f316de154ff7 | 2 | section 1 - includes |
hexfactory | 1:f316de154ff7 | 3 | ==============================================================================================*/ |
hexfactory | 1:f316de154ff7 | 4 | /* imported libs */ |
hexfactory | 1:f316de154ff7 | 5 | #include "mbed.h" |
hexfactory | 1:f316de154ff7 | 6 | #include "F746_GUI.hpp" |
hexfactory | 1:f316de154ff7 | 7 | |
hexfactory | 1:f316de154ff7 | 8 | /* project files */ |
hexfactory | 1:f316de154ff7 | 9 | #include "lightAutomatic.h" |
hexfactory | 1:f316de154ff7 | 10 | #include "flash.h" |
hexfactory | 1:f316de154ff7 | 11 | #include "relay.h" |
hexfactory | 1:f316de154ff7 | 12 | |
hexfactory | 1:f316de154ff7 | 13 | /*============================================================================================= |
hexfactory | 1:f316de154ff7 | 14 | section 2 - private defines / enumerations |
hexfactory | 1:f316de154ff7 | 15 | ==============================================================================================*/ |
hexfactory | 1:f316de154ff7 | 16 | /* debgug switch */ |
hexfactory | 1:f316de154ff7 | 17 | #define DEBUG_MODULE 1 /* DEBUG_MODULE 1 => ON, 0 => OFF */ |
hexfactory | 1:f316de154ff7 | 18 | |
hexfactory | 1:f316de154ff7 | 19 | /* GPIO Eingangswerter für Türkontaktsensor */ |
hexfactory | 1:f316de154ff7 | 20 | #define DOOR_OPEN 1 /* high */ |
hexfactory | 1:f316de154ff7 | 21 | #define DOOR_CLOSED 0 /* low */ |
hexfactory | 1:f316de154ff7 | 22 | |
hexfactory | 1:f316de154ff7 | 23 | /* GPIO Eingangswerter für Helligkeitssensor */ |
hexfactory | 1:f316de154ff7 | 24 | #define LIGHT_DARK 1 /* high */ |
hexfactory | 1:f316de154ff7 | 25 | #define LIGHT_BRIGHT 0 /* low */ |
hexfactory | 1:f316de154ff7 | 26 | |
hexfactory | 1:f316de154ff7 | 27 | enum E_FSM {INACTIVE, ACTIVE_WAITING, ACTIVE_LIGHT_ON}; |
hexfactory | 1:f316de154ff7 | 28 | enum E_STATE {OFF = 0, ON}; |
hexfactory | 1:f316de154ff7 | 29 | |
hexfactory | 1:f316de154ff7 | 30 | /*============================================================================================= |
hexfactory | 1:f316de154ff7 | 31 | section 3 - private typedefs |
hexfactory | 1:f316de154ff7 | 32 | ==============================================================================================*/ |
hexfactory | 1:f316de154ff7 | 33 | typedef E_STATE t_lightAutomaticState; |
hexfactory | 1:f316de154ff7 | 34 | typedef E_STATE t_lighState; |
hexfactory | 1:f316de154ff7 | 35 | |
hexfactory | 1:f316de154ff7 | 36 | /*============================================================================================= |
hexfactory | 1:f316de154ff7 | 37 | section 4 - private macros |
hexfactory | 1:f316de154ff7 | 38 | ==============================================================================================*/ |
hexfactory | 1:f316de154ff7 | 39 | |
hexfactory | 1:f316de154ff7 | 40 | /*============================================================================================= |
hexfactory | 1:f316de154ff7 | 41 | section 5 - public constants definition |
hexfactory | 1:f316de154ff7 | 42 | ==============================================================================================*/ |
hexfactory | 1:f316de154ff7 | 43 | |
hexfactory | 1:f316de154ff7 | 44 | /*============================================================================================= |
hexfactory | 1:f316de154ff7 | 45 | section 6 - public variables/pointers definition |
hexfactory | 1:f316de154ff7 | 46 | ==============================================================================================*/ |
hexfactory | 1:f316de154ff7 | 47 | |
hexfactory | 1:f316de154ff7 | 48 | /*============================================================================================= |
hexfactory | 1:f316de154ff7 | 49 | section 7 - private constants definition |
hexfactory | 1:f316de154ff7 | 50 | ==============================================================================================*/ |
hexfactory | 1:f316de154ff7 | 51 | |
hexfactory | 1:f316de154ff7 | 52 | /*============================================================================================= |
hexfactory | 1:f316de154ff7 | 53 | section 8 - private variables/objects/pointers definition |
hexfactory | 1:f316de154ff7 | 54 | ==============================================================================================*/ |
hexfactory | 1:f316de154ff7 | 55 | /* light automatic state pro Lampe */ |
hexfactory | 1:f316de154ff7 | 56 | static t_lightAutomaticState lightAutomatic1State = OFF; |
hexfactory | 1:f316de154ff7 | 57 | static t_lightAutomaticState lightAutomatic2State = OFF; |
hexfactory | 1:f316de154ff7 | 58 | |
hexfactory | 1:f316de154ff7 | 59 | /* speichert ein button pressed event, 1 == pressed */ |
hexfactory | 1:f316de154ff7 | 60 | static uint8_t stayActivePressed = 0; |
hexfactory | 1:f316de154ff7 | 61 | |
hexfactory | 1:f316de154ff7 | 62 | /* Zustandsautomat */ |
hexfactory | 1:f316de154ff7 | 63 | static E_FSM fsmLightAutomatic; |
hexfactory | 1:f316de154ff7 | 64 | |
hexfactory | 1:f316de154ff7 | 65 | /* gui */ |
hexfactory | 1:f316de154ff7 | 66 | static Label *pLabelAutomatic1Text; |
hexfactory | 1:f316de154ff7 | 67 | static Button *pBtnLight1Automatic; |
hexfactory | 1:f316de154ff7 | 68 | static Label *pLabelAutomatic1State; |
hexfactory | 1:f316de154ff7 | 69 | static Label *pLabelAutomatic2Text; |
hexfactory | 1:f316de154ff7 | 70 | static Button *pBtnLight2Automatic; |
hexfactory | 1:f316de154ff7 | 71 | static Label *pLabelAutomatic2State; |
hexfactory | 1:f316de154ff7 | 72 | static Button *pBtnStayActive; |
hexfactory | 1:f316de154ff7 | 73 | |
hexfactory | 1:f316de154ff7 | 74 | /* gui - debug */ |
hexfactory | 1:f316de154ff7 | 75 | #if (DEBUG_MODULE == 1) |
hexfactory | 1:f316de154ff7 | 76 | static uint8_t doorStatusOld; |
hexfactory | 1:f316de154ff7 | 77 | static uint8_t doorStatusNew; |
hexfactory | 1:f316de154ff7 | 78 | static uint8_t lightStatusOld; |
hexfactory | 1:f316de154ff7 | 79 | static uint8_t lightStatusNew; |
hexfactory | 1:f316de154ff7 | 80 | |
hexfactory | 1:f316de154ff7 | 81 | static Label *pLabelDebugFsm; |
hexfactory | 1:f316de154ff7 | 82 | static Label *pLabelDebugTimer; |
hexfactory | 1:f316de154ff7 | 83 | static Label *pLabelDebugDoorSensor; |
hexfactory | 1:f316de154ff7 | 84 | static Label *pLabelDebugLightSensor; |
hexfactory | 1:f316de154ff7 | 85 | #endif |
hexfactory | 1:f316de154ff7 | 86 | |
hexfactory | 1:f316de154ff7 | 87 | /*============================================================================================= |
hexfactory | 1:f316de154ff7 | 88 | section 9 - private functions - declaration |
hexfactory | 1:f316de154ff7 | 89 | ==============================================================================================*/ |
hexfactory | 1:f316de154ff7 | 90 | static void _buttonSubTask(void); |
hexfactory | 1:f316de154ff7 | 91 | static void _fsmSubTask(void); |
hexfactory | 1:f316de154ff7 | 92 | |
hexfactory | 1:f316de154ff7 | 93 | /* debug */ |
hexfactory | 1:f316de154ff7 | 94 | #if (DEBUG_MODULE == 1) |
hexfactory | 1:f316de154ff7 | 95 | static void _debugInit(void); |
hexfactory | 1:f316de154ff7 | 96 | static void _debugSubTask(void); |
hexfactory | 1:f316de154ff7 | 97 | #endif |
hexfactory | 1:f316de154ff7 | 98 | |
hexfactory | 1:f316de154ff7 | 99 | /*============================================================================================= |
hexfactory | 1:f316de154ff7 | 100 | section 10 - private functions - implementation (definition) |
hexfactory | 1:f316de154ff7 | 101 | ==============================================================================================*/ |
hexfactory | 1:f316de154ff7 | 102 | static void _buttonSubTask(void) |
hexfactory | 1:f316de154ff7 | 103 | { |
hexfactory | 1:f316de154ff7 | 104 | /* Objekte nicht initialisiert => Fehler */ |
hexfactory | 1:f316de154ff7 | 105 | if ((pLabelAutomatic1State == NULL) || |
hexfactory | 1:f316de154ff7 | 106 | (pBtnLight1Automatic == NULL) || |
hexfactory | 1:f316de154ff7 | 107 | (pLabelAutomatic2State == NULL) || |
hexfactory | 1:f316de154ff7 | 108 | (pBtnLight2Automatic == NULL)) |
hexfactory | 1:f316de154ff7 | 109 | { |
hexfactory | 1:f316de154ff7 | 110 | return; |
hexfactory | 1:f316de154ff7 | 111 | } |
hexfactory | 1:f316de154ff7 | 112 | |
hexfactory | 1:f316de154ff7 | 113 | /* prüfe ob button gedrückt */ |
hexfactory | 1:f316de154ff7 | 114 | if (pBtnLight1Automatic->Touched()) |
hexfactory | 1:f316de154ff7 | 115 | { |
hexfactory | 1:f316de154ff7 | 116 | if (OFF == lightAutomatic1State) |
hexfactory | 1:f316de154ff7 | 117 | { /* automatic an */ |
hexfactory | 1:f316de154ff7 | 118 | lightAutomatic1State = ON; |
hexfactory | 1:f316de154ff7 | 119 | pLabelAutomatic1State->Draw("on"); |
hexfactory | 1:f316de154ff7 | 120 | wait(0.5); |
hexfactory | 1:f316de154ff7 | 121 | pBtnLight1Automatic->Draw(); |
hexfactory | 1:f316de154ff7 | 122 | } |
hexfactory | 1:f316de154ff7 | 123 | else { /* automatic aus */ |
hexfactory | 1:f316de154ff7 | 124 | lightAutomatic1State = OFF; |
hexfactory | 1:f316de154ff7 | 125 | pLabelAutomatic1State->Draw("off"); |
hexfactory | 1:f316de154ff7 | 126 | wait(0.5); |
hexfactory | 1:f316de154ff7 | 127 | pBtnLight1Automatic->Draw(); |
hexfactory | 1:f316de154ff7 | 128 | } |
hexfactory | 1:f316de154ff7 | 129 | } |
hexfactory | 1:f316de154ff7 | 130 | |
hexfactory | 1:f316de154ff7 | 131 | /* prüfe ob button gedrückt */ |
hexfactory | 1:f316de154ff7 | 132 | if (pBtnLight2Automatic->Touched()) |
hexfactory | 1:f316de154ff7 | 133 | { |
hexfactory | 1:f316de154ff7 | 134 | if (OFF == lightAutomatic2State) |
hexfactory | 1:f316de154ff7 | 135 | { /* automatic an */ |
hexfactory | 1:f316de154ff7 | 136 | lightAutomatic2State = ON; |
hexfactory | 1:f316de154ff7 | 137 | pLabelAutomatic2State->Draw("on"); |
hexfactory | 1:f316de154ff7 | 138 | wait(0.5); |
hexfactory | 1:f316de154ff7 | 139 | pBtnLight2Automatic->Draw(); |
hexfactory | 1:f316de154ff7 | 140 | } |
hexfactory | 1:f316de154ff7 | 141 | else |
hexfactory | 1:f316de154ff7 | 142 | { /* automatic aus */ |
hexfactory | 1:f316de154ff7 | 143 | lightAutomatic2State = OFF; |
hexfactory | 1:f316de154ff7 | 144 | pLabelAutomatic2State->Draw("off"); |
hexfactory | 1:f316de154ff7 | 145 | wait(0.5); |
hexfactory | 1:f316de154ff7 | 146 | pBtnLight2Automatic->Draw(); |
hexfactory | 1:f316de154ff7 | 147 | } |
hexfactory | 1:f316de154ff7 | 148 | } |
hexfactory | 1:f316de154ff7 | 149 | |
hexfactory | 1:f316de154ff7 | 150 | /* button ist nur aktiv im Zustand ACTIVE_LIGHT_ON */ |
hexfactory | 1:f316de154ff7 | 151 | if (fsmLightAutomatic == ACTIVE_LIGHT_ON) { |
hexfactory | 1:f316de154ff7 | 152 | /* prüfe ob button gedrückt */ |
hexfactory | 1:f316de154ff7 | 153 | if (pBtnStayActive->Touched()) |
hexfactory | 1:f316de154ff7 | 154 | { |
hexfactory | 1:f316de154ff7 | 155 | stayActivePressed = 1; |
hexfactory | 1:f316de154ff7 | 156 | } |
hexfactory | 1:f316de154ff7 | 157 | } |
hexfactory | 1:f316de154ff7 | 158 | |
hexfactory | 1:f316de154ff7 | 159 | /* sichere light state im flash */ |
hexfactory | 1:f316de154ff7 | 160 | flash_write(FLASH_LIGHT_AUTOMATIC1, lightAutomatic1State); |
hexfactory | 1:f316de154ff7 | 161 | flash_write(FLASH_LIGHT_AUTOMATIC2, lightAutomatic2State); |
hexfactory | 1:f316de154ff7 | 162 | } |
hexfactory | 1:f316de154ff7 | 163 | |
hexfactory | 1:f316de154ff7 | 164 | static void _fsmSubTask(void) |
hexfactory | 1:f316de154ff7 | 165 | { |
hexfactory | 1:f316de154ff7 | 166 | static Timer timer1; |
hexfactory | 1:f316de154ff7 | 167 | static float startTime; |
hexfactory | 1:f316de154ff7 | 168 | static t_lighState tmpLight1 = OFF; |
hexfactory | 1:f316de154ff7 | 169 | static t_lighState tmpLight2 = OFF; |
hexfactory | 1:f316de154ff7 | 170 | #if (DEBUG_MODULE == 1) |
hexfactory | 1:f316de154ff7 | 171 | char debugBuffer[30]; |
hexfactory | 1:f316de154ff7 | 172 | #endif |
hexfactory | 1:f316de154ff7 | 173 | |
hexfactory | 1:f316de154ff7 | 174 | /* debug */ |
hexfactory | 1:f316de154ff7 | 175 | /* Objekte nicht initialisiert => Fehler */ |
hexfactory | 1:f316de154ff7 | 176 | #if (DEBUG_MODULE == 1) |
hexfactory | 1:f316de154ff7 | 177 | if ((pLabelDebugFsm == NULL) || |
hexfactory | 1:f316de154ff7 | 178 | (pLabelDebugTimer == NULL)) |
hexfactory | 1:f316de154ff7 | 179 | { |
hexfactory | 1:f316de154ff7 | 180 | return; |
hexfactory | 1:f316de154ff7 | 181 | } |
hexfactory | 1:f316de154ff7 | 182 | #endif |
hexfactory | 1:f316de154ff7 | 183 | |
hexfactory | 1:f316de154ff7 | 184 | /* fsm */ |
hexfactory | 1:f316de154ff7 | 185 | switch(fsmLightAutomatic) |
hexfactory | 1:f316de154ff7 | 186 | { |
hexfactory | 1:f316de154ff7 | 187 | case INACTIVE: |
hexfactory | 1:f316de154ff7 | 188 | /* debug */ |
hexfactory | 1:f316de154ff7 | 189 | #if (DEBUG_MODULE == 1) |
hexfactory | 1:f316de154ff7 | 190 | pLabelDebugFsm->Draw("FSM: INACTIVE"); |
hexfactory | 1:f316de154ff7 | 191 | #endif |
hexfactory | 1:f316de154ff7 | 192 | |
hexfactory | 1:f316de154ff7 | 193 | /* next state */ |
hexfactory | 1:f316de154ff7 | 194 | if ((ON == lightAutomatic1State) || |
hexfactory | 1:f316de154ff7 | 195 | (ON == lightAutomatic2State)) |
hexfactory | 1:f316de154ff7 | 196 | { |
hexfactory | 1:f316de154ff7 | 197 | fsmLightAutomatic = ACTIVE_WAITING; |
hexfactory | 1:f316de154ff7 | 198 | } |
hexfactory | 1:f316de154ff7 | 199 | break; |
hexfactory | 1:f316de154ff7 | 200 | case ACTIVE_WAITING: |
hexfactory | 1:f316de154ff7 | 201 | /*debug */ |
hexfactory | 1:f316de154ff7 | 202 | #if (DEBUG_MODULE == 1) |
hexfactory | 1:f316de154ff7 | 203 | pLabelDebugFsm->Draw("FSM: ACTIVE_WAITING"); |
hexfactory | 1:f316de154ff7 | 204 | #endif |
hexfactory | 1:f316de154ff7 | 205 | /* next state */ |
hexfactory | 1:f316de154ff7 | 206 | /* INACTIVE */ |
hexfactory | 1:f316de154ff7 | 207 | if ((OFF == lightAutomatic1State) && |
hexfactory | 1:f316de154ff7 | 208 | (OFF == lightAutomatic2State)) |
hexfactory | 1:f316de154ff7 | 209 | { |
hexfactory | 1:f316de154ff7 | 210 | fsmLightAutomatic = INACTIVE; |
hexfactory | 1:f316de154ff7 | 211 | } |
hexfactory | 1:f316de154ff7 | 212 | /* ACTIVE_LIGHT_ON */ |
hexfactory | 1:f316de154ff7 | 213 | else if ((DOOR_OPEN == g_doorSensor) && |
hexfactory | 1:f316de154ff7 | 214 | (LIGHT_DARK == g_lightSensor)) |
hexfactory | 1:f316de154ff7 | 215 | { |
hexfactory | 1:f316de154ff7 | 216 | fsmLightAutomatic = ACTIVE_LIGHT_ON; |
hexfactory | 1:f316de154ff7 | 217 | timer1.reset(); |
hexfactory | 1:f316de154ff7 | 218 | timer1.start(); |
hexfactory | 1:f316de154ff7 | 219 | startTime = timer1.read(); |
hexfactory | 1:f316de154ff7 | 220 | pBtnStayActive->Draw(); /* show button */ |
hexfactory | 1:f316de154ff7 | 221 | if (ON == lightAutomatic1State){ |
hexfactory | 1:f316de154ff7 | 222 | relay_switch(RELAY_LIGHT1); |
hexfactory | 1:f316de154ff7 | 223 | tmpLight1 = ON; |
hexfactory | 1:f316de154ff7 | 224 | } |
hexfactory | 1:f316de154ff7 | 225 | if (ON == lightAutomatic2State){ |
hexfactory | 1:f316de154ff7 | 226 | relay_switch(RELAY_LIGHT2); |
hexfactory | 1:f316de154ff7 | 227 | tmpLight2 = ON; |
hexfactory | 1:f316de154ff7 | 228 | } |
hexfactory | 1:f316de154ff7 | 229 | } |
hexfactory | 1:f316de154ff7 | 230 | break; |
hexfactory | 1:f316de154ff7 | 231 | case ACTIVE_LIGHT_ON: |
hexfactory | 1:f316de154ff7 | 232 | /* debug */ |
hexfactory | 1:f316de154ff7 | 233 | #if (DEBUG_MODULE == 1) |
hexfactory | 1:f316de154ff7 | 234 | pLabelDebugFsm->Draw("FSM: ACTIVE_LIGHT_ON"); |
hexfactory | 1:f316de154ff7 | 235 | snprintf(debugBuffer, 30, "Timer: %f", timer1.read()); |
hexfactory | 1:f316de154ff7 | 236 | pLabelDebugTimer->Draw(debugBuffer); |
hexfactory | 1:f316de154ff7 | 237 | #endif |
hexfactory | 1:f316de154ff7 | 238 | |
hexfactory | 1:f316de154ff7 | 239 | /* next state */ |
hexfactory | 1:f316de154ff7 | 240 | if (stayActivePressed == 1) { |
hexfactory | 1:f316de154ff7 | 241 | timer1.stop(); |
hexfactory | 1:f316de154ff7 | 242 | fsmLightAutomatic = ACTIVE_WAITING; |
hexfactory | 1:f316de154ff7 | 243 | pBtnStayActive->Erase(); /* hide button */ |
hexfactory | 1:f316de154ff7 | 244 | stayActivePressed = 0; |
hexfactory | 1:f316de154ff7 | 245 | } |
hexfactory | 1:f316de154ff7 | 246 | else if ((timer1.read() - startTime) >= 30) |
hexfactory | 1:f316de154ff7 | 247 | { |
hexfactory | 1:f316de154ff7 | 248 | timer1.stop(); |
hexfactory | 1:f316de154ff7 | 249 | fsmLightAutomatic = ACTIVE_WAITING; |
hexfactory | 1:f316de154ff7 | 250 | pBtnStayActive->Erase(); /* hide button */ |
hexfactory | 1:f316de154ff7 | 251 | if (ON == tmpLight1){ |
hexfactory | 1:f316de154ff7 | 252 | relay_switch(RELAY_LIGHT1); |
hexfactory | 1:f316de154ff7 | 253 | tmpLight1 = OFF; |
hexfactory | 1:f316de154ff7 | 254 | } |
hexfactory | 1:f316de154ff7 | 255 | if (ON == tmpLight2){ |
hexfactory | 1:f316de154ff7 | 256 | relay_switch(RELAY_LIGHT2); |
hexfactory | 1:f316de154ff7 | 257 | tmpLight2 = OFF; |
hexfactory | 1:f316de154ff7 | 258 | } |
hexfactory | 1:f316de154ff7 | 259 | } |
hexfactory | 1:f316de154ff7 | 260 | break; |
hexfactory | 1:f316de154ff7 | 261 | } |
hexfactory | 1:f316de154ff7 | 262 | } |
hexfactory | 1:f316de154ff7 | 263 | |
hexfactory | 1:f316de154ff7 | 264 | #if (DEBUG_MODULE == 1) |
hexfactory | 1:f316de154ff7 | 265 | static void _debugInit(void) |
hexfactory | 1:f316de154ff7 | 266 | { |
hexfactory | 1:f316de154ff7 | 267 | /* gui labels*/ |
hexfactory | 1:f316de154ff7 | 268 | pLabelDebugDoorSensor = new Label(10, 200, "Tuer: KEINE DATEN", Label::LEFT, Font16); |
hexfactory | 1:f316de154ff7 | 269 | pLabelDebugLightSensor = new Label(10, 220, "Helligkeit: KEINE DATEN", Label::LEFT, Font16); |
hexfactory | 1:f316de154ff7 | 270 | pLabelDebugFsm = new Label(10, 240, "FSM: KEINE DATEN", Label::LEFT, Font16); |
hexfactory | 1:f316de154ff7 | 271 | pLabelDebugTimer = new Label(10, 260, "Timer: KEINE DATEN", Label::LEFT, Font16); |
hexfactory | 1:f316de154ff7 | 272 | |
hexfactory | 1:f316de154ff7 | 273 | /* door sensor */ |
hexfactory | 1:f316de154ff7 | 274 | doorStatusNew = g_doorSensor; |
hexfactory | 1:f316de154ff7 | 275 | doorStatusOld = doorStatusNew; |
hexfactory | 1:f316de154ff7 | 276 | if (doorStatusNew == DOOR_OPEN) |
hexfactory | 1:f316de154ff7 | 277 | { |
hexfactory | 1:f316de154ff7 | 278 | pLabelDebugDoorSensor->Draw("Tuer: offen"); |
hexfactory | 1:f316de154ff7 | 279 | } |
hexfactory | 1:f316de154ff7 | 280 | else |
hexfactory | 1:f316de154ff7 | 281 | { |
hexfactory | 1:f316de154ff7 | 282 | pLabelDebugDoorSensor->Draw("Tuer: geschlossen"); |
hexfactory | 1:f316de154ff7 | 283 | } |
hexfactory | 1:f316de154ff7 | 284 | |
hexfactory | 1:f316de154ff7 | 285 | /* light sensor */ |
hexfactory | 1:f316de154ff7 | 286 | lightStatusNew = g_lightSensor; |
hexfactory | 1:f316de154ff7 | 287 | lightStatusOld = lightStatusNew; |
hexfactory | 1:f316de154ff7 | 288 | if (lightStatusNew == LIGHT_DARK) |
hexfactory | 1:f316de154ff7 | 289 | { |
hexfactory | 1:f316de154ff7 | 290 | pLabelDebugLightSensor->Draw("Helligkeit: dunkel"); |
hexfactory | 1:f316de154ff7 | 291 | } |
hexfactory | 1:f316de154ff7 | 292 | else |
hexfactory | 1:f316de154ff7 | 293 | { |
hexfactory | 1:f316de154ff7 | 294 | pLabelDebugLightSensor->Draw("Helligkeit: hell"); |
hexfactory | 1:f316de154ff7 | 295 | } |
hexfactory | 1:f316de154ff7 | 296 | } |
hexfactory | 1:f316de154ff7 | 297 | #endif /* #if (DEBUG_MODULE == 1) */ |
hexfactory | 1:f316de154ff7 | 298 | |
hexfactory | 1:f316de154ff7 | 299 | #if (DEBUG_MODULE == 1) |
hexfactory | 1:f316de154ff7 | 300 | static void _debugSubTask(void) { |
hexfactory | 1:f316de154ff7 | 301 | /* Objekte nicht initialisiert => Fehler */ |
hexfactory | 1:f316de154ff7 | 302 | if ((pLabelDebugDoorSensor == NULL) || |
hexfactory | 1:f316de154ff7 | 303 | (pLabelDebugLightSensor == NULL)) |
hexfactory | 1:f316de154ff7 | 304 | { |
hexfactory | 1:f316de154ff7 | 305 | return; |
hexfactory | 1:f316de154ff7 | 306 | } |
hexfactory | 1:f316de154ff7 | 307 | |
hexfactory | 1:f316de154ff7 | 308 | /* zeige tür offen oder zu*/ |
hexfactory | 1:f316de154ff7 | 309 | doorStatusNew = g_doorSensor; |
hexfactory | 1:f316de154ff7 | 310 | if (doorStatusOld != doorStatusNew) |
hexfactory | 1:f316de154ff7 | 311 | { |
hexfactory | 1:f316de154ff7 | 312 | doorStatusOld = doorStatusNew; |
hexfactory | 1:f316de154ff7 | 313 | if (doorStatusNew == DOOR_OPEN) |
hexfactory | 1:f316de154ff7 | 314 | { |
hexfactory | 1:f316de154ff7 | 315 | pLabelDebugDoorSensor->Draw("Tuer: offen"); |
hexfactory | 1:f316de154ff7 | 316 | } |
hexfactory | 1:f316de154ff7 | 317 | else |
hexfactory | 1:f316de154ff7 | 318 | { |
hexfactory | 1:f316de154ff7 | 319 | pLabelDebugDoorSensor->Draw("Tuer: geschlossen"); |
hexfactory | 1:f316de154ff7 | 320 | } |
hexfactory | 1:f316de154ff7 | 321 | } |
hexfactory | 1:f316de154ff7 | 322 | |
hexfactory | 1:f316de154ff7 | 323 | /* zeige ob hell oder dunkel */ |
hexfactory | 1:f316de154ff7 | 324 | lightStatusNew = g_lightSensor; |
hexfactory | 1:f316de154ff7 | 325 | if (lightStatusOld != lightStatusNew) |
hexfactory | 1:f316de154ff7 | 326 | { |
hexfactory | 1:f316de154ff7 | 327 | lightStatusOld = lightStatusNew; |
hexfactory | 1:f316de154ff7 | 328 | if (lightStatusNew == LIGHT_DARK) { |
hexfactory | 1:f316de154ff7 | 329 | pLabelDebugLightSensor->Draw("Helligkeit: dunkel"); |
hexfactory | 1:f316de154ff7 | 330 | } |
hexfactory | 1:f316de154ff7 | 331 | else |
hexfactory | 1:f316de154ff7 | 332 | { |
hexfactory | 1:f316de154ff7 | 333 | pLabelDebugLightSensor->Draw("Helligkeit: hell"); |
hexfactory | 1:f316de154ff7 | 334 | } |
hexfactory | 1:f316de154ff7 | 335 | } |
hexfactory | 1:f316de154ff7 | 336 | } |
hexfactory | 1:f316de154ff7 | 337 | #endif /* #if (DEBUG_MODULE == 1) */ |
hexfactory | 1:f316de154ff7 | 338 | |
hexfactory | 1:f316de154ff7 | 339 | /*============================================================================================= |
hexfactory | 1:f316de154ff7 | 340 | section 11 - public functions - implementation (definition) |
hexfactory | 1:f316de154ff7 | 341 | ==============================================================================================*/ |
hexfactory | 1:f316de154ff7 | 342 | void lightAutomatic_init(void) |
hexfactory | 1:f316de154ff7 | 343 | { |
hexfactory | 1:f316de154ff7 | 344 | fsmLightAutomatic = INACTIVE; |
hexfactory | 1:f316de154ff7 | 345 | stayActivePressed = 0; |
hexfactory | 1:f316de154ff7 | 346 | |
hexfactory | 1:f316de154ff7 | 347 | /* light automatic status */ |
hexfactory | 1:f316de154ff7 | 348 | lightAutomatic1State = (t_lightAutomaticState) flash_read(FLASH_LIGHT_AUTOMATIC1); |
hexfactory | 1:f316de154ff7 | 349 | lightAutomatic2State = (t_lightAutomaticState) flash_read(FLASH_LIGHT_AUTOMATIC2); |
hexfactory | 1:f316de154ff7 | 350 | |
hexfactory | 1:f316de154ff7 | 351 | /* gui - automatic for light 1 */ |
hexfactory | 1:f316de154ff7 | 352 | pLabelAutomatic1Text = new Label( 200, 40 + 12, "Automatik:", Label::LEFT, Font16); |
hexfactory | 1:f316de154ff7 | 353 | pBtnLight1Automatic = new Button(310, 40, 70, 40, "schalten"); |
hexfactory | 1:f316de154ff7 | 354 | pLabelAutomatic1State = new Label( 390, 40 + 12, "off", Label::LEFT, Font16); |
hexfactory | 1:f316de154ff7 | 355 | if (OFF == lightAutomatic1State) |
hexfactory | 1:f316de154ff7 | 356 | { |
hexfactory | 1:f316de154ff7 | 357 | pLabelAutomatic1State->Draw("off"); |
hexfactory | 1:f316de154ff7 | 358 | } |
hexfactory | 1:f316de154ff7 | 359 | else |
hexfactory | 1:f316de154ff7 | 360 | { |
hexfactory | 1:f316de154ff7 | 361 | pLabelAutomatic1State->Draw("on"); |
hexfactory | 1:f316de154ff7 | 362 | } |
hexfactory | 1:f316de154ff7 | 363 | |
hexfactory | 1:f316de154ff7 | 364 | /* gui - automatic for light 2 */ |
hexfactory | 1:f316de154ff7 | 365 | pLabelAutomatic2Text = new Label( 200, 90 + 12, "Automatik:", Label::LEFT, Font16); |
hexfactory | 1:f316de154ff7 | 366 | pBtnLight2Automatic = new Button(310, 90, 70, 40, "schalten"); |
hexfactory | 1:f316de154ff7 | 367 | pLabelAutomatic2State = new Label( 390, 90 + 12, "off", Label::LEFT, Font16); |
hexfactory | 1:f316de154ff7 | 368 | if (OFF == lightAutomatic2State) |
hexfactory | 1:f316de154ff7 | 369 | { |
hexfactory | 1:f316de154ff7 | 370 | pLabelAutomatic2State->Draw("off"); |
hexfactory | 1:f316de154ff7 | 371 | } |
hexfactory | 1:f316de154ff7 | 372 | else |
hexfactory | 1:f316de154ff7 | 373 | { |
hexfactory | 1:f316de154ff7 | 374 | pLabelAutomatic2State->Draw("on"); |
hexfactory | 1:f316de154ff7 | 375 | } |
hexfactory | 1:f316de154ff7 | 376 | |
hexfactory | 1:f316de154ff7 | 377 | /* gui - button für Licht-Automatik im Zustand ACTIVE_LIGHT_ON */ |
hexfactory | 1:f316de154ff7 | 378 | pBtnStayActive = new Button(290, 160, 150, 60, "anlassen", Font24); |
hexfactory | 1:f316de154ff7 | 379 | pBtnStayActive->Erase(); /* hide button */ |
hexfactory | 1:f316de154ff7 | 380 | |
hexfactory | 1:f316de154ff7 | 381 | /* debug */ |
hexfactory | 1:f316de154ff7 | 382 | #if (DEBUG_MODULE == 1) |
hexfactory | 1:f316de154ff7 | 383 | _debugInit(); |
hexfactory | 1:f316de154ff7 | 384 | #endif |
hexfactory | 1:f316de154ff7 | 385 | } |
hexfactory | 1:f316de154ff7 | 386 | |
hexfactory | 1:f316de154ff7 | 387 | void lightAutomatic_task(void) |
hexfactory | 1:f316de154ff7 | 388 | { |
hexfactory | 1:f316de154ff7 | 389 | #if (DEBUG_MODULE == 1) |
hexfactory | 1:f316de154ff7 | 390 | /* debug */ |
hexfactory | 1:f316de154ff7 | 391 | _debugSubTask(); |
hexfactory | 1:f316de154ff7 | 392 | #endif |
hexfactory | 1:f316de154ff7 | 393 | |
hexfactory | 1:f316de154ff7 | 394 | /* check button touched */ |
hexfactory | 1:f316de154ff7 | 395 | _buttonSubTask(); |
hexfactory | 1:f316de154ff7 | 396 | |
hexfactory | 1:f316de154ff7 | 397 | /* check fsm state */ |
hexfactory | 1:f316de154ff7 | 398 | _fsmSubTask(); |
hexfactory | 1:f316de154ff7 | 399 | } |
hexfactory | 1:f316de154ff7 | 400 | |
hexfactory | 1:f316de154ff7 | 401 | /*============================================================================================= |
hexfactory | 1:f316de154ff7 | 402 | section 12 - interrupt service routines (ISRs) |
hexfactory | 1:f316de154ff7 | 403 | ==============================================================================================*/ |
hexfactory | 1:f316de154ff7 | 404 | |
hexfactory | 1:f316de154ff7 | 405 | /*============================================================================================= |
hexfactory | 1:f316de154ff7 | 406 | end of file |
hexfactory | 1:f316de154ff7 | 407 | ==============================================================================================*/ |