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

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?

UserRevisionLine numberNew 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 "relay.h"
hexfactory 1:f316de154ff7 10 #include "flash.h"
hexfactory 1:f316de154ff7 11
hexfactory 1:f316de154ff7 12 /*=============================================================================================
hexfactory 1:f316de154ff7 13 section 2 - private defines / enumerations
hexfactory 1:f316de154ff7 14 ==============================================================================================*/
hexfactory 1:f316de154ff7 15
hexfactory 1:f316de154ff7 16 /*=============================================================================================
hexfactory 1:f316de154ff7 17 section 3 - private typedefs
hexfactory 1:f316de154ff7 18 ==============================================================================================*/
hexfactory 1:f316de154ff7 19
hexfactory 1:f316de154ff7 20 /*=============================================================================================
hexfactory 1:f316de154ff7 21 section 4 - private macros
hexfactory 1:f316de154ff7 22 ==============================================================================================*/
hexfactory 1:f316de154ff7 23
hexfactory 1:f316de154ff7 24 /*=============================================================================================
hexfactory 1:f316de154ff7 25 section 5 - public constants definition
hexfactory 1:f316de154ff7 26 ==============================================================================================*/
hexfactory 1:f316de154ff7 27
hexfactory 1:f316de154ff7 28 /*=============================================================================================
hexfactory 1:f316de154ff7 29 section 6 - public variables/pointers definition
hexfactory 1:f316de154ff7 30 ==============================================================================================*/
hexfactory 1:f316de154ff7 31 /* definition public variables */
hexfactory 1:f316de154ff7 32
hexfactory 1:f316de154ff7 33 /* definition public pointers */
hexfactory 1:f316de154ff7 34
hexfactory 1:f316de154ff7 35 /*=============================================================================================
hexfactory 1:f316de154ff7 36 section 7 - private constants definition
hexfactory 1:f316de154ff7 37 ==============================================================================================*/
hexfactory 1:f316de154ff7 38
hexfactory 1:f316de154ff7 39 /*=============================================================================================
hexfactory 1:f316de154ff7 40 section 8 - private variables/objects/pointers definition
hexfactory 1:f316de154ff7 41 ==============================================================================================*/
hexfactory 1:f316de154ff7 42 /* definition private variables */
hexfactory 1:f316de154ff7 43
hexfactory 1:f316de154ff7 44 /* definition private pointers */
hexfactory 1:f316de154ff7 45 static Label *pLabelLight1;
hexfactory 1:f316de154ff7 46 static Button *pBtnLight1;
hexfactory 1:f316de154ff7 47 static Label *pLabelLight2;
hexfactory 1:f316de154ff7 48 static Button *pBtnLight2;
hexfactory 1:f316de154ff7 49
hexfactory 1:f316de154ff7 50 /*=============================================================================================
hexfactory 1:f316de154ff7 51 section 9 - private functions - declaration
hexfactory 1:f316de154ff7 52 ==============================================================================================*/
hexfactory 1:f316de154ff7 53
hexfactory 1:f316de154ff7 54 /*=============================================================================================
hexfactory 1:f316de154ff7 55 section 10 - private functions - implementation (definition)
hexfactory 1:f316de154ff7 56 ==============================================================================================*/
hexfactory 1:f316de154ff7 57
hexfactory 1:f316de154ff7 58 /*=============================================================================================
hexfactory 1:f316de154ff7 59 section 11 - public functions - implementation (definition)
hexfactory 1:f316de154ff7 60 ==============================================================================================*/
hexfactory 1:f316de154ff7 61 void relay_init(void)
hexfactory 1:f316de154ff7 62 {
hexfactory 1:f316de154ff7 63 pLabelLight1 = new Label( 10, 40 + 12, "Lampe 1: ", Label::LEFT, Font16);
hexfactory 1:f316de154ff7 64 pBtnLight1 = new Button(100, 40, 70, 40, "schalten");
hexfactory 1:f316de154ff7 65 pLabelLight2 = new Label( 10, 90 + 12, "Lampe 2: ", Label::LEFT, Font16);
hexfactory 1:f316de154ff7 66 pBtnLight2 = new Button(100, 90, 70, 40, "schalten");
hexfactory 1:f316de154ff7 67 }
hexfactory 1:f316de154ff7 68
hexfactory 1:f316de154ff7 69 void relay_switch(E_RELAY_LIGHT lightNumber)
hexfactory 1:f316de154ff7 70 {
hexfactory 1:f316de154ff7 71 DigitalOut *out1;
hexfactory 1:f316de154ff7 72 DigitalOut *out2;
hexfactory 1:f316de154ff7 73 uint8_t toggleByte;
hexfactory 1:f316de154ff7 74
hexfactory 1:f316de154ff7 75 if (lightNumber == RELAY_LIGHT1)
hexfactory 1:f316de154ff7 76 {
hexfactory 1:f316de154ff7 77 out1 = &g_light1Fet1;
hexfactory 1:f316de154ff7 78 out2 = &g_light1Fet2;
hexfactory 1:f316de154ff7 79 toggleByte = flash_read(FLASH_TOGGLE_BYTE_LIGHT1);
hexfactory 1:f316de154ff7 80 toggleByte = !toggleByte;
hexfactory 1:f316de154ff7 81 flash_write(FLASH_TOGGLE_BYTE_LIGHT1, toggleByte);
hexfactory 1:f316de154ff7 82 }
hexfactory 1:f316de154ff7 83 else if (lightNumber == RELAY_LIGHT2)
hexfactory 1:f316de154ff7 84 {
hexfactory 1:f316de154ff7 85 out1 = &g_light2Fet1;
hexfactory 1:f316de154ff7 86 out2 = &g_light2Fet2;
hexfactory 1:f316de154ff7 87 toggleByte = flash_read(FLASH_TOGGLE_BYTE_LIGHT2);
hexfactory 1:f316de154ff7 88 toggleByte = !toggleByte;
hexfactory 1:f316de154ff7 89 flash_write(FLASH_TOGGLE_BYTE_LIGHT2, toggleByte);
hexfactory 1:f316de154ff7 90 }
hexfactory 1:f316de154ff7 91
hexfactory 1:f316de154ff7 92 /* Je nach Stellung des toggle Bytes,
hexfactory 1:f316de154ff7 93 wird Ausgang 1 oder 2 kurzzeitig geschaltet (Spannung angelegt). */
hexfactory 1:f316de154ff7 94 if(toggleByte)
hexfactory 1:f316de154ff7 95 {
hexfactory 1:f316de154ff7 96 out1->write(1);
hexfactory 1:f316de154ff7 97 wait(0.5);
hexfactory 1:f316de154ff7 98 out1->write(0);
hexfactory 1:f316de154ff7 99 }
hexfactory 1:f316de154ff7 100 else
hexfactory 1:f316de154ff7 101 {
hexfactory 1:f316de154ff7 102 out2->write(1);
hexfactory 1:f316de154ff7 103 wait(0.5);
hexfactory 1:f316de154ff7 104 out2->write(0);
hexfactory 1:f316de154ff7 105 }
hexfactory 1:f316de154ff7 106 }
hexfactory 1:f316de154ff7 107
hexfactory 1:f316de154ff7 108 void relay_task(void)
hexfactory 1:f316de154ff7 109 {
hexfactory 1:f316de154ff7 110 /* Objekte nicht initialisiert => Fehler */
hexfactory 1:f316de154ff7 111 if ((pBtnLight1 == NULL) ||
hexfactory 1:f316de154ff7 112 (pBtnLight2 == NULL))
hexfactory 1:f316de154ff7 113 {
hexfactory 1:f316de154ff7 114 return;
hexfactory 1:f316de154ff7 115 }
hexfactory 1:f316de154ff7 116
hexfactory 1:f316de154ff7 117 /* prüft ob button "pBtnLight1" gerade gedrück ist */
hexfactory 1:f316de154ff7 118 if (pBtnLight1->Touched())
hexfactory 1:f316de154ff7 119 {
hexfactory 1:f316de154ff7 120 relay_switch(RELAY_LIGHT1);
hexfactory 1:f316de154ff7 121 pBtnLight1->Draw();
hexfactory 1:f316de154ff7 122 }
hexfactory 1:f316de154ff7 123
hexfactory 1:f316de154ff7 124 /* prüft ob button "pBtnLight2" gerade gedrück ist */
hexfactory 1:f316de154ff7 125 if (pBtnLight2->Touched())
hexfactory 1:f316de154ff7 126 {
hexfactory 1:f316de154ff7 127 relay_switch(RELAY_LIGHT2);
hexfactory 1:f316de154ff7 128 pBtnLight2->Draw();
hexfactory 1:f316de154ff7 129 }
hexfactory 1:f316de154ff7 130 }
hexfactory 1:f316de154ff7 131 /*=============================================================================================
hexfactory 1:f316de154ff7 132 section 12 - interrupt service routines (ISRs)
hexfactory 1:f316de154ff7 133 ==============================================================================================*/
hexfactory 1:f316de154ff7 134
hexfactory 1:f316de154ff7 135 /*=============================================================================================
hexfactory 1:f316de154ff7 136 end of file
hexfactory 1:f316de154ff7 137 ==============================================================================================*/