![](/media/cache/profiles/logo.jpeg.50x50_q85.jpg)
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
Revision 1:f316de154ff7, committed 2017-04-23
- Comitter:
- hexfactory
- Date:
- Sun Apr 23 17:15:53 2017 +0000
- Parent:
- 0:da00b5dd65c6
- Commit message:
- Helligkeitssensor und T?rkontaktsensor - Display Steuerung [DE]; https://www.youtube.com/watch?v=9OA7kxGMPo8
Changed in this revision
diff -r da00b5dd65c6 -r f316de154ff7 BSP_DISCO_F746NG.lib --- a/BSP_DISCO_F746NG.lib Mon Jan 30 20:58:13 2017 +0000 +++ b/BSP_DISCO_F746NG.lib Sun Apr 23 17:15:53 2017 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/teams/ST/code/BSP_DISCO_F746NG/#458ab1edf6b2 +http://mbed.org/teams/ST/code/BSP_DISCO_F746NG/#fe313c53cdb5
diff -r da00b5dd65c6 -r f316de154ff7 F746_GUI.lib --- a/F746_GUI.lib Mon Jan 30 20:58:13 2017 +0000 +++ b/F746_GUI.lib Sun Apr 23 17:15:53 2017 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/users/MikamiUitOpen/code/F746_GUI/#483926be0cf1 +http://mbed.org/users/MikamiUitOpen/code/F746_GUI/#551a5f1b52b9
diff -r da00b5dd65c6 -r f316de154ff7 flash.cpp --- a/flash.cpp Mon Jan 30 20:58:13 2017 +0000 +++ b/flash.cpp Sun Apr 23 17:15:53 2017 +0000 @@ -1,22 +1,101 @@ - -#include "flash.h" +/*============================================================================================= + section 1 - includes + ==============================================================================================*/ +/* imported libs */ +#include "mbed.h" #include "stm32746g_discovery_qspi.h" +/* project files */ +#include "flash.h" + +/*============================================================================================= + section 2 - private defines / enumerations + ==============================================================================================*/ #define FLASH_START_ADDRESS 0 #define FLASH_START_BLOCK 0 -void flash_init(void) +/*============================================================================================= + section 3 - private typedefs + ==============================================================================================*/ + +/*============================================================================================= + section 4 - private macros + ==============================================================================================*/ + +/*============================================================================================= + section 5 - public constants definition + ==============================================================================================*/ + +/*============================================================================================= + section 6 - public variables/pointers definition + ==============================================================================================*/ + +/*============================================================================================= + section 7 - private constants definition + ==============================================================================================*/ + +/*============================================================================================= + section 8 - private variables/objects/pointers definition + ==============================================================================================*/ +static uint8_t localFlashData[FLASH_DATA_SIZE]; + +/*============================================================================================= + section 9 - private functions - declaration + ==============================================================================================*/ + +/*============================================================================================= + section 10 - private functions - implementation (definition) + ==============================================================================================*/ + +/*============================================================================================= + section 11 - public functions - implementation (definition) + ==============================================================================================*/ +void flash_init(void) { BSP_QSPI_Init(); + BSP_QSPI_Read(localFlashData, FLASH_START_ADDRESS, FLASH_DATA_SIZE); } -void flash_write(uint8_t* newFlashData) -{ - BSP_QSPI_Erase_Block(FLASH_START_BLOCK); - BSP_QSPI_Write(newFlashData, FLASH_START_ADDRESS, FLASH_DATA_SIZE); +/* liest Flash Daten aus der lokale RAM Kopie */ +uint8_t flash_read(E_FLASH_INDEX index) +{ + return localFlashData[index]; +} + +/* schreibt Flash Daten in die lokale RAM Kopie */ +void flash_write(E_FLASH_INDEX index, uint8_t data) +{ + localFlashData[index] = data; } -void flash_read(uint8_t* readFlashData) -{ - BSP_QSPI_Read(readFlashData, FLASH_START_ADDRESS, FLASH_DATA_SIZE); -} \ No newline at end of file +void flash_task(void) +{ + uint8_t tmpFlashData[FLASH_DATA_SIZE]; + uint8_t isNotEqual = 0; + uint8_t i; + + /* prüfe ob die RAM Daten != den ROM Daten sind */ + BSP_QSPI_Read(tmpFlashData, FLASH_START_ADDRESS, FLASH_DATA_SIZE); + for (i = 0; i < FLASH_DATA_SIZE; i++) + { + if (tmpFlashData[i] != localFlashData[i]) + { /* Daten ungleich */ + isNotEqual = 1; + } + } + + /* schreibe RAM Daten in das Flash ROM falls RAM Daten != ROM Daten */ + if (1 == isNotEqual) + { + BSP_QSPI_Erase_Block(FLASH_START_BLOCK); + BSP_QSPI_Write(localFlashData, FLASH_START_ADDRESS, FLASH_DATA_SIZE); + } +} + +/*============================================================================================= + section 12 - interrupt service routines (ISRs) + ==============================================================================================*/ + +/*============================================================================================= + end of file + ==============================================================================================*/ \ No newline at end of file
diff -r da00b5dd65c6 -r f316de154ff7 flash.h --- a/flash.h Mon Jan 30 20:58:13 2017 +0000 +++ b/flash.h Sun Apr 23 17:15:53 2017 +0000 @@ -1,20 +1,53 @@ -#ifndef FLASH_H -#define FLASH_H +#ifndef __FLASH_H +#define __FLASH_H +/*============================================================================================= + section 1 - includes + ==============================================================================================*/ -#include "mbed.h" +/*============================================================================================= + section 2 - public defines / enumerations + ==============================================================================================*/ +#define FLASH_DATA_SIZE 4 +enum E_FLASH_INDEX{ + FLASH_TOGGLE_BYTE_LIGHT1 = 0, + FLASH_TOGGLE_BYTE_LIGHT2 = 1, + FLASH_LIGHT_AUTOMATIC1 = 2, + FLASH_LIGHT_AUTOMATIC2 = 3 +}; +/*============================================================================================= + section 3 - public typedefs + ==============================================================================================*/ + +/*============================================================================================= + section 4 - public macros + ==============================================================================================*/ -/* global defines */ -#define FLASH_DATA_SIZE 2 -/* - BYTE 0 => TOGGLE_BYTE_LIGHT0 - BYTE 1 => TOGGLE_BYTE_LIGHT1 -*/ -#define FLASH_TOGGLE_BYTE_LIGHT1 0 -#define FLASH_TOGGLE_BYTE_LIGHT2 1 +/*============================================================================================= + section 5 - public constants declaration + ==============================================================================================*/ +//extern + +/*============================================================================================= + section 6 - public variables declaration + ==============================================================================================*/ +//extern -/* global function declaration */ -void flash_init(void); -void flash_write(uint8_t* newFlashData); -void flash_read(uint8_t* readFlashData); +/*============================================================================================= + section 7 - public functions - declaration + ==============================================================================================*/ +/* init function */ +void flash_init(void); + +/* getter functions */ + +/* setter functions */ -#endif \ No newline at end of file +/* other functions */ +void flash_write(E_FLASH_INDEX index, uint8_t data); +uint8_t flash_read(E_FLASH_INDEX index); +void flash_task(void); + +#endif /* __FLASH_H */ +/*============================================================================================= + end of file + ==============================================================================================*/ \ No newline at end of file
diff -r da00b5dd65c6 -r f316de154ff7 lightAutomatic.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lightAutomatic.cpp Sun Apr 23 17:15:53 2017 +0000 @@ -0,0 +1,407 @@ +/*============================================================================================= + section 1 - includes + ==============================================================================================*/ +/* imported libs */ +#include "mbed.h" +#include "F746_GUI.hpp" + +/* project files */ +#include "lightAutomatic.h" +#include "flash.h" +#include "relay.h" + +/*============================================================================================= + section 2 - private defines / enumerations + ==============================================================================================*/ +/* debgug switch */ +#define DEBUG_MODULE 1 /* DEBUG_MODULE 1 => ON, 0 => OFF */ + +/* GPIO Eingangswerter für Türkontaktsensor */ +#define DOOR_OPEN 1 /* high */ +#define DOOR_CLOSED 0 /* low */ + +/* GPIO Eingangswerter für Helligkeitssensor */ +#define LIGHT_DARK 1 /* high */ +#define LIGHT_BRIGHT 0 /* low */ + +enum E_FSM {INACTIVE, ACTIVE_WAITING, ACTIVE_LIGHT_ON}; +enum E_STATE {OFF = 0, ON}; + +/*============================================================================================= + section 3 - private typedefs + ==============================================================================================*/ +typedef E_STATE t_lightAutomaticState; +typedef E_STATE t_lighState; + +/*============================================================================================= + section 4 - private macros + ==============================================================================================*/ + +/*============================================================================================= + section 5 - public constants definition + ==============================================================================================*/ + +/*============================================================================================= + section 6 - public variables/pointers definition + ==============================================================================================*/ + +/*============================================================================================= + section 7 - private constants definition + ==============================================================================================*/ + +/*============================================================================================= + section 8 - private variables/objects/pointers definition + ==============================================================================================*/ +/* light automatic state pro Lampe */ +static t_lightAutomaticState lightAutomatic1State = OFF; +static t_lightAutomaticState lightAutomatic2State = OFF; + +/* speichert ein button pressed event, 1 == pressed */ +static uint8_t stayActivePressed = 0; + +/* Zustandsautomat */ +static E_FSM fsmLightAutomatic; + + /* gui */ +static Label *pLabelAutomatic1Text; +static Button *pBtnLight1Automatic; +static Label *pLabelAutomatic1State; +static Label *pLabelAutomatic2Text; +static Button *pBtnLight2Automatic; +static Label *pLabelAutomatic2State; +static Button *pBtnStayActive; + +/* gui - debug */ +#if (DEBUG_MODULE == 1) +static uint8_t doorStatusOld; +static uint8_t doorStatusNew; +static uint8_t lightStatusOld; +static uint8_t lightStatusNew; + +static Label *pLabelDebugFsm; +static Label *pLabelDebugTimer; +static Label *pLabelDebugDoorSensor; +static Label *pLabelDebugLightSensor; +#endif + +/*============================================================================================= + section 9 - private functions - declaration + ==============================================================================================*/ +static void _buttonSubTask(void); +static void _fsmSubTask(void); + +/* debug */ +#if (DEBUG_MODULE == 1) +static void _debugInit(void); +static void _debugSubTask(void); +#endif + +/*============================================================================================= + section 10 - private functions - implementation (definition) + ==============================================================================================*/ +static void _buttonSubTask(void) +{ + /* Objekte nicht initialisiert => Fehler */ + if ((pLabelAutomatic1State == NULL) || + (pBtnLight1Automatic == NULL) || + (pLabelAutomatic2State == NULL) || + (pBtnLight2Automatic == NULL)) + { + return; + } + + /* prüfe ob button gedrückt */ + if (pBtnLight1Automatic->Touched()) + { + if (OFF == lightAutomatic1State) + { /* automatic an */ + lightAutomatic1State = ON; + pLabelAutomatic1State->Draw("on"); + wait(0.5); + pBtnLight1Automatic->Draw(); + } + else { /* automatic aus */ + lightAutomatic1State = OFF; + pLabelAutomatic1State->Draw("off"); + wait(0.5); + pBtnLight1Automatic->Draw(); + } + } + + /* prüfe ob button gedrückt */ + if (pBtnLight2Automatic->Touched()) + { + if (OFF == lightAutomatic2State) + { /* automatic an */ + lightAutomatic2State = ON; + pLabelAutomatic2State->Draw("on"); + wait(0.5); + pBtnLight2Automatic->Draw(); + } + else + { /* automatic aus */ + lightAutomatic2State = OFF; + pLabelAutomatic2State->Draw("off"); + wait(0.5); + pBtnLight2Automatic->Draw(); + } + } + + /* button ist nur aktiv im Zustand ACTIVE_LIGHT_ON */ + if (fsmLightAutomatic == ACTIVE_LIGHT_ON) { + /* prüfe ob button gedrückt */ + if (pBtnStayActive->Touched()) + { + stayActivePressed = 1; + } + } + + /* sichere light state im flash */ + flash_write(FLASH_LIGHT_AUTOMATIC1, lightAutomatic1State); + flash_write(FLASH_LIGHT_AUTOMATIC2, lightAutomatic2State); +} + +static void _fsmSubTask(void) +{ + static Timer timer1; + static float startTime; + static t_lighState tmpLight1 = OFF; + static t_lighState tmpLight2 = OFF; +#if (DEBUG_MODULE == 1) + char debugBuffer[30]; +#endif + + /* debug */ + /* Objekte nicht initialisiert => Fehler */ +#if (DEBUG_MODULE == 1) + if ((pLabelDebugFsm == NULL) || + (pLabelDebugTimer == NULL)) + { + return; + } +#endif + + /* fsm */ + switch(fsmLightAutomatic) + { + case INACTIVE: + /* debug */ +#if (DEBUG_MODULE == 1) + pLabelDebugFsm->Draw("FSM: INACTIVE"); +#endif + + /* next state */ + if ((ON == lightAutomatic1State) || + (ON == lightAutomatic2State)) + { + fsmLightAutomatic = ACTIVE_WAITING; + } + break; + case ACTIVE_WAITING: + /*debug */ +#if (DEBUG_MODULE == 1) + pLabelDebugFsm->Draw("FSM: ACTIVE_WAITING"); +#endif + /* next state */ + /* INACTIVE */ + if ((OFF == lightAutomatic1State) && + (OFF == lightAutomatic2State)) + { + fsmLightAutomatic = INACTIVE; + } + /* ACTIVE_LIGHT_ON */ + else if ((DOOR_OPEN == g_doorSensor) && + (LIGHT_DARK == g_lightSensor)) + { + fsmLightAutomatic = ACTIVE_LIGHT_ON; + timer1.reset(); + timer1.start(); + startTime = timer1.read(); + pBtnStayActive->Draw(); /* show button */ + if (ON == lightAutomatic1State){ + relay_switch(RELAY_LIGHT1); + tmpLight1 = ON; + } + if (ON == lightAutomatic2State){ + relay_switch(RELAY_LIGHT2); + tmpLight2 = ON; + } + } + break; + case ACTIVE_LIGHT_ON: + /* debug */ +#if (DEBUG_MODULE == 1) + pLabelDebugFsm->Draw("FSM: ACTIVE_LIGHT_ON"); + snprintf(debugBuffer, 30, "Timer: %f", timer1.read()); + pLabelDebugTimer->Draw(debugBuffer); +#endif + + /* next state */ + if (stayActivePressed == 1) { + timer1.stop(); + fsmLightAutomatic = ACTIVE_WAITING; + pBtnStayActive->Erase(); /* hide button */ + stayActivePressed = 0; + } + else if ((timer1.read() - startTime) >= 30) + { + timer1.stop(); + fsmLightAutomatic = ACTIVE_WAITING; + pBtnStayActive->Erase(); /* hide button */ + if (ON == tmpLight1){ + relay_switch(RELAY_LIGHT1); + tmpLight1 = OFF; + } + if (ON == tmpLight2){ + relay_switch(RELAY_LIGHT2); + tmpLight2 = OFF; + } + } + break; + } +} + +#if (DEBUG_MODULE == 1) +static void _debugInit(void) +{ + /* gui labels*/ + pLabelDebugDoorSensor = new Label(10, 200, "Tuer: KEINE DATEN", Label::LEFT, Font16); + pLabelDebugLightSensor = new Label(10, 220, "Helligkeit: KEINE DATEN", Label::LEFT, Font16); + pLabelDebugFsm = new Label(10, 240, "FSM: KEINE DATEN", Label::LEFT, Font16); + pLabelDebugTimer = new Label(10, 260, "Timer: KEINE DATEN", Label::LEFT, Font16); + + /* door sensor */ + doorStatusNew = g_doorSensor; + doorStatusOld = doorStatusNew; + if (doorStatusNew == DOOR_OPEN) + { + pLabelDebugDoorSensor->Draw("Tuer: offen"); + } + else + { + pLabelDebugDoorSensor->Draw("Tuer: geschlossen"); + } + + /* light sensor */ + lightStatusNew = g_lightSensor; + lightStatusOld = lightStatusNew; + if (lightStatusNew == LIGHT_DARK) + { + pLabelDebugLightSensor->Draw("Helligkeit: dunkel"); + } + else + { + pLabelDebugLightSensor->Draw("Helligkeit: hell"); + } +} +#endif /* #if (DEBUG_MODULE == 1) */ + +#if (DEBUG_MODULE == 1) +static void _debugSubTask(void) { + /* Objekte nicht initialisiert => Fehler */ + if ((pLabelDebugDoorSensor == NULL) || + (pLabelDebugLightSensor == NULL)) + { + return; + } + + /* zeige tür offen oder zu*/ + doorStatusNew = g_doorSensor; + if (doorStatusOld != doorStatusNew) + { + doorStatusOld = doorStatusNew; + if (doorStatusNew == DOOR_OPEN) + { + pLabelDebugDoorSensor->Draw("Tuer: offen"); + } + else + { + pLabelDebugDoorSensor->Draw("Tuer: geschlossen"); + } + } + + /* zeige ob hell oder dunkel */ + lightStatusNew = g_lightSensor; + if (lightStatusOld != lightStatusNew) + { + lightStatusOld = lightStatusNew; + if (lightStatusNew == LIGHT_DARK) { + pLabelDebugLightSensor->Draw("Helligkeit: dunkel"); + } + else + { + pLabelDebugLightSensor->Draw("Helligkeit: hell"); + } + } +} +#endif /* #if (DEBUG_MODULE == 1) */ + +/*============================================================================================= + section 11 - public functions - implementation (definition) + ==============================================================================================*/ +void lightAutomatic_init(void) +{ + fsmLightAutomatic = INACTIVE; + stayActivePressed = 0; + + /* light automatic status */ + lightAutomatic1State = (t_lightAutomaticState) flash_read(FLASH_LIGHT_AUTOMATIC1); + lightAutomatic2State = (t_lightAutomaticState) flash_read(FLASH_LIGHT_AUTOMATIC2); + + /* gui - automatic for light 1 */ + pLabelAutomatic1Text = new Label( 200, 40 + 12, "Automatik:", Label::LEFT, Font16); + pBtnLight1Automatic = new Button(310, 40, 70, 40, "schalten"); + pLabelAutomatic1State = new Label( 390, 40 + 12, "off", Label::LEFT, Font16); + if (OFF == lightAutomatic1State) + { + pLabelAutomatic1State->Draw("off"); + } + else + { + pLabelAutomatic1State->Draw("on"); + } + + /* gui - automatic for light 2 */ + pLabelAutomatic2Text = new Label( 200, 90 + 12, "Automatik:", Label::LEFT, Font16); + pBtnLight2Automatic = new Button(310, 90, 70, 40, "schalten"); + pLabelAutomatic2State = new Label( 390, 90 + 12, "off", Label::LEFT, Font16); + if (OFF == lightAutomatic2State) + { + pLabelAutomatic2State->Draw("off"); + } + else + { + pLabelAutomatic2State->Draw("on"); + } + + /* gui - button für Licht-Automatik im Zustand ACTIVE_LIGHT_ON */ + pBtnStayActive = new Button(290, 160, 150, 60, "anlassen", Font24); + pBtnStayActive->Erase(); /* hide button */ + + /* debug */ +#if (DEBUG_MODULE == 1) + _debugInit(); +#endif +} + +void lightAutomatic_task(void) +{ +#if (DEBUG_MODULE == 1) + /* debug */ + _debugSubTask(); +#endif + + /* check button touched */ + _buttonSubTask(); + + /* check fsm state */ + _fsmSubTask(); +} + +/*============================================================================================= + section 12 - interrupt service routines (ISRs) + ==============================================================================================*/ + +/*============================================================================================= + end of file + ==============================================================================================*/
diff -r da00b5dd65c6 -r f316de154ff7 lightAutomatic.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lightAutomatic.h Sun Apr 23 17:15:53 2017 +0000 @@ -0,0 +1,47 @@ +#ifndef __LIGHT_AUTOMATIC_H +#define __LIGHT_AUTOMATIC_H +/*============================================================================================= + section 1 - includes + ==============================================================================================*/ + +/*============================================================================================= + section 2 - public defines / enumerations + ==============================================================================================*/ + +/*============================================================================================= + section 3 - public typedefs + ==============================================================================================*/ + +/*============================================================================================= + section 4 - public macros + ==============================================================================================*/ + +/*============================================================================================= + section 5 - public constants declaration + ==============================================================================================*/ +//extern + +/*============================================================================================= + section 6 - public variables declaration + ==============================================================================================*/ +/* inputs */ +extern DigitalIn g_doorSensor; +extern DigitalIn g_lightSensor; + +/*============================================================================================= + section 7 - public functions - declaration + ==============================================================================================*/ +/* init function */ +void lightAutomatic_init(void); + +/* getter functions */ + +/* setter functions */ + +/* other functions */ +void lightAutomatic_task(void); + +#endif /* __LIGHT_AUTOMATIC_H */ +/*============================================================================================= + end of file + ==============================================================================================*/ \ No newline at end of file
diff -r da00b5dd65c6 -r f316de154ff7 main.cpp --- a/main.cpp Mon Jan 30 20:58:13 2017 +0000 +++ b/main.cpp Sun Apr 23 17:15:53 2017 +0000 @@ -1,75 +1,90 @@ +/*============================================================================================= + section 1 - includes + ==============================================================================================*/ +/* imported libs */ #include "mbed.h" #include "F746_GUI.hpp" + +/* project files */ +#include "relay.h" #include "flash.h" +#include "lightAutomatic.h" -/************************************ - local variables / objects - ************************************/ -static DigitalOut light1Fet1(D4, 0); -static DigitalOut light1Fet2(D5, 0); -static DigitalOut light2Fet1(D6, 0); -static DigitalOut light2Fet2(D7, 0); -static uint8_t flashData[FLASH_DATA_SIZE]; +/*============================================================================================= + section 2 - private defines / enumerations + ==============================================================================================*/ -/************************************ - local function declaration - ************************************/ - -static void _switchButton(DigitalOut out1, DigitalOut out2, uint8_t *toggleByte); +/*============================================================================================= + section 3 - private typedefs + ==============================================================================================*/ -/************************************ - local function definition - ************************************/ +/*============================================================================================= + section 4 - private macros + ==============================================================================================*/ -static void _switchButton(DigitalOut out1, DigitalOut out2, uint8_t *toggleByte) { - /* toggle byte invertieren */ - *toggleByte = !(*toggleByte); - /* schreibe Daten ins Flash. Stellt Datenkonsistenz zwischen RAM und ROM sicher. */ - flash_write(flashData); - - /* Je nach Stellung des toggle Bytes, - wird Ausgang 1 oder 2 kurzzeitig geschaltet (Spannung angelegt). */ - if(*toggleByte){ - out1 = 1; - wait(0.5); - out1 = 0; - } else{ - out2 = 1; - wait(0.5); - out2 = 0; - } -} +/*============================================================================================= + section 5 - public constants definition + ==============================================================================================*/ + +/*============================================================================================= + section 6 - public variables/pointers definition + ==============================================================================================*/ +/* inputs */ +DigitalIn g_doorSensor(D3, PullUp); +DigitalIn g_lightSensor(D2, PullDown); + +/* outputs */ +DigitalOut g_light1Fet1(D4, 0); +DigitalOut g_light1Fet2(D5, 0); +DigitalOut g_light2Fet1(D6, 0); +DigitalOut g_light2Fet2(D7, 0); + +/*============================================================================================= + section 7 - private constants definition + ==============================================================================================*/ -/************************************ - global function definition - ************************************/ - -int main() { +/*============================================================================================= + section 8 - private variables/objects/pointers definition + ==============================================================================================*/ + +/*============================================================================================= + section 9 - private functions - declaration + ==============================================================================================*/ + +/*============================================================================================= + section 10 - private functions - implementation (definition) + ==============================================================================================*/ + +/*============================================================================================= + section 11 - public functions - implementation (definition) + ==============================================================================================*/ +int main() +{ + /* GUI Ojects */ + Label labelTop(240, 2, "Display Steuerung v0.2", Label::CENTER, Font16); + /*************************** init - ***************************/ - /* GUI Ojects */ - Label label1(240, 2, "Display Steuerung v0.1", Label::CENTER, Font16); - Button btnLight1(10, 40, 70, 40, "Lampe 1"); - Button btnLight2(90, 40, 70, 40, "Lampe 2"); - - /* flash */ + ***************************/ + relay_init(); flash_init(); - flash_read(flashData); /* Lese Daten von flash (ROM) in das RAM */ + lightAutomatic_init(); /*************************** main loop ***************************/ - while(1) { - /* prüft ob button "btnLight1" gerade gedrück ist */ - if (btnLight1.Touched()){ - _switchButton(light1Fet1, light1Fet2, flashData + FLASH_TOGGLE_BYTE_LIGHT1); - btnLight1.Draw(); - } - /* prüft ob button "btnLight2" gerade gedrück ist */ - if (btnLight2.Touched()){ - _switchButton(light2Fet1, light2Fet2, flashData + FLASH_TOGGLE_BYTE_LIGHT2); - btnLight2.Draw(); - } + while(1) + { + relay_task(); + lightAutomatic_task(); + flash_task(); } -} \ No newline at end of file +} + +/*============================================================================================= + section 12 - interrupt service routines (ISRs) + ==============================================================================================*/ + +/*============================================================================================= + end of file + ==============================================================================================*/ \ No newline at end of file
diff -r da00b5dd65c6 -r f316de154ff7 mbed.bld --- a/mbed.bld Mon Jan 30 20:58:13 2017 +0000 +++ b/mbed.bld Sun Apr 23 17:15:53 2017 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/users/mbed_official/code/mbed/builds/6c34061e7c34 \ No newline at end of file +http://mbed.org/users/mbed_official/code/mbed/builds/e1686b8d5b90 \ No newline at end of file
diff -r da00b5dd65c6 -r f316de154ff7 relay.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/relay.cpp Sun Apr 23 17:15:53 2017 +0000 @@ -0,0 +1,137 @@ +/*============================================================================================= + section 1 - includes + ==============================================================================================*/ +/* imported libs */ +#include "mbed.h" +#include "F746_GUI.hpp" + +/* project files */ +#include "relay.h" +#include "flash.h" + +/*============================================================================================= + section 2 - private defines / enumerations + ==============================================================================================*/ + +/*============================================================================================= + section 3 - private typedefs + ==============================================================================================*/ + +/*============================================================================================= + section 4 - private macros + ==============================================================================================*/ + +/*============================================================================================= + section 5 - public constants definition + ==============================================================================================*/ + +/*============================================================================================= + section 6 - public variables/pointers definition + ==============================================================================================*/ +/* definition public variables */ + +/* definition public pointers */ + +/*============================================================================================= + section 7 - private constants definition + ==============================================================================================*/ + +/*============================================================================================= + section 8 - private variables/objects/pointers definition + ==============================================================================================*/ +/* definition private variables */ + +/* definition private pointers */ +static Label *pLabelLight1; +static Button *pBtnLight1; +static Label *pLabelLight2; +static Button *pBtnLight2; + +/*============================================================================================= + section 9 - private functions - declaration + ==============================================================================================*/ + +/*============================================================================================= + section 10 - private functions - implementation (definition) + ==============================================================================================*/ + +/*============================================================================================= + section 11 - public functions - implementation (definition) + ==============================================================================================*/ +void relay_init(void) +{ + pLabelLight1 = new Label( 10, 40 + 12, "Lampe 1: ", Label::LEFT, Font16); + pBtnLight1 = new Button(100, 40, 70, 40, "schalten"); + pLabelLight2 = new Label( 10, 90 + 12, "Lampe 2: ", Label::LEFT, Font16); + pBtnLight2 = new Button(100, 90, 70, 40, "schalten"); +} + +void relay_switch(E_RELAY_LIGHT lightNumber) +{ + DigitalOut *out1; + DigitalOut *out2; + uint8_t toggleByte; + + if (lightNumber == RELAY_LIGHT1) + { + out1 = &g_light1Fet1; + out2 = &g_light1Fet2; + toggleByte = flash_read(FLASH_TOGGLE_BYTE_LIGHT1); + toggleByte = !toggleByte; + flash_write(FLASH_TOGGLE_BYTE_LIGHT1, toggleByte); + } + else if (lightNumber == RELAY_LIGHT2) + { + out1 = &g_light2Fet1; + out2 = &g_light2Fet2; + toggleByte = flash_read(FLASH_TOGGLE_BYTE_LIGHT2); + toggleByte = !toggleByte; + flash_write(FLASH_TOGGLE_BYTE_LIGHT2, toggleByte); + } + + /* Je nach Stellung des toggle Bytes, + wird Ausgang 1 oder 2 kurzzeitig geschaltet (Spannung angelegt). */ + if(toggleByte) + { + out1->write(1); + wait(0.5); + out1->write(0); + } + else + { + out2->write(1); + wait(0.5); + out2->write(0); + } +} + +void relay_task(void) +{ + /* Objekte nicht initialisiert => Fehler */ + if ((pBtnLight1 == NULL) || + (pBtnLight2 == NULL)) + { + return; + } + + /* prüft ob button "pBtnLight1" gerade gedrück ist */ + if (pBtnLight1->Touched()) + { + relay_switch(RELAY_LIGHT1); + pBtnLight1->Draw(); + } + + /* prüft ob button "pBtnLight2" gerade gedrück ist */ + if (pBtnLight2->Touched()) + { + relay_switch(RELAY_LIGHT2); + pBtnLight2->Draw(); + } +} +/*============================================================================================= + section 12 - interrupt service routines (ISRs) + ==============================================================================================*/ + +/*============================================================================================= + end of file + ==============================================================================================*/ \ No newline at end of file
diff -r da00b5dd65c6 -r f316de154ff7 relay.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/relay.h Sun Apr 23 17:15:53 2017 +0000 @@ -0,0 +1,52 @@ +#ifndef __RELAY_H +#define __RELAY_H +/*============================================================================================= + section 1 - includes + ==============================================================================================*/ + +/*============================================================================================= + section 2 - public defines / enumerations + ==============================================================================================*/ +enum E_RELAY_LIGHT { + RELAY_LIGHT1, + RELAY_LIGHT2 +}; + +/*============================================================================================= + section 3 - public typedefs + ==============================================================================================*/ + +/*============================================================================================= + section 4 - public macros + ==============================================================================================*/ + +/*============================================================================================= + section 5 - public constants declaration + ==============================================================================================*/ + +/*============================================================================================= + section 6 - public variables declaration + ==============================================================================================*/ +extern DigitalOut g_light1Fet1; +extern DigitalOut g_light1Fet2; +extern DigitalOut g_light2Fet1; +extern DigitalOut g_light2Fet2; + +/*============================================================================================= + section 7 - public functions - declaration + ==============================================================================================*/ +/* init function */ +void relay_init(void); + +/* getter functions */ + +/* setter functions */ + +/* other functions */ +void relay_switch(E_RELAY_LIGHT lightNumber); +void relay_task(void); + +#endif /* __RELAY_H */ +/*============================================================================================= + end of file + ==============================================================================================*/ \ No newline at end of file
diff -r da00b5dd65c6 -r f316de154ff7 template.txt --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/template.txt Sun Apr 23 17:15:53 2017 +0000 @@ -0,0 +1,56 @@ +/*============================================================================================= + section 1 - includes + ==============================================================================================*/ +/* imported libs */ +#include "mbed.h" + +/* project files */ +#include "prototype.h" + +/*============================================================================================= + section 2 - private defines / enumerations + ==============================================================================================*/ + +/*============================================================================================= + section 3 - private typedefs + ==============================================================================================*/ + +/*============================================================================================= + section 4 - private macros + ==============================================================================================*/ + +/*============================================================================================= + section 5 - public constants definition + ==============================================================================================*/ + +/*============================================================================================= + section 6 - public variables/pointers definition + ==============================================================================================*/ + +/*============================================================================================= + section 7 - private constants definition + ==============================================================================================*/ + +/*============================================================================================= + section 8 - private variables/objects/pointers definition + ==============================================================================================*/ + +/*============================================================================================= + section 9 - private functions - declaration + ==============================================================================================*/ + +/*============================================================================================= + section 10 - private functions - implementation (definition) + ==============================================================================================*/ + +/*============================================================================================= + section 11 - public functions - implementation (definition) + ==============================================================================================*/ + +/*============================================================================================= + section 12 - interrupt service routines (ISRs) + ==============================================================================================*/ + +/*============================================================================================= + end of file + ==============================================================================================*/ \ No newline at end of file
diff -r da00b5dd65c6 -r f316de154ff7 template_h.txt --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/template_h.txt Sun Apr 23 17:15:53 2017 +0000 @@ -0,0 +1,42 @@ +#ifndef __PROTOTYPE_H_ +#define __PROTOTYPE_H_ +/*============================================================================================= + section 1 - includes + ==============================================================================================*/ + +/*============================================================================================= + section 2 - public defines / enumerations + ==============================================================================================*/ + +/*============================================================================================= + section 3 - public typedefs + ==============================================================================================*/ + +/*============================================================================================= + section 4 - public macros + ==============================================================================================*/ + +/*============================================================================================= + section 5 - public constants declaration + ==============================================================================================*/ + +/*============================================================================================= + section 6 - public variables declaration + ==============================================================================================*/ + +/*============================================================================================= + section 7 - public functions - declaration + ==============================================================================================*/ +/* init function */ + +/* getter functions */ +//void module_setVal(uint8_t val); + +/* setter functions */ + +/* other functions */ + +#endif /* #ifndef __PROTOTYPE_H_ */ +/*============================================================================================= + end of file + ==============================================================================================*/ \ No newline at end of file