emma controller code in production board v1
Dependencies: ADE7758_v1 Crypto DHT11 MQTT MbedJSONValueEmma SDFileSystem TFT_ILI9341 SWSPI SetRTC TFT_fonts Touch W5500Interface mbed-rtos mbed-src SoftSerial
Fork of emma_controller_energy by
Diff: emmaCode.cpp
- Revision:
- 31:e2abded4d85f
- Parent:
- 30:08d290158fa7
- Child:
- 32:78633fb9b2a1
--- a/emmaCode.cpp Thu Aug 06 04:38:09 2015 +0000 +++ b/emmaCode.cpp Fri Aug 07 07:40:23 2015 +0000 @@ -108,6 +108,7 @@ int md=0; int TPx; int TPy; + Timer t; TFT.background(Black); TFT.foreground(White); @@ -210,7 +211,17 @@ //add text to main menu for(int i=0; i<6; i++) { TFT.locate(menu[i].xTL,menu[i].yTL); - TFT.printf("%s",menu[i].text.c_str()); + TFT.printf("%s",menu[i].text.c_str()); + } + + //read emma settings + emmaReadSettings(); + + //platformDOMAIN is not empty -> has been registered + if(!platformDOMAIN.empty()) { + TFT.locate(25,170); + TFT.printf(" auto select enabled"); + t.start(); } while(!modeSelected) { @@ -237,7 +248,18 @@ } } } - } + } + + //auto select (to emmaModeOperation) after some times + if(!platformDOMAIN.empty()) { + if(t.read()>20) { + md = MODE_OPERATION; + modeSelected = true; + t.stop(); + t.reset(); + } + } + } TFT.locate(25,170); @@ -251,12 +273,11 @@ } /*end lcd and touch*/ -/*start emma mode*/ -void emmaInit(int mode) { +/*start emma read settings*/ +void emmaReadSettings(void) { char s[64]; DBG.baud(19200); - DBG.printf("\r\nemmaInit\r\n"); - DBG.printf("mode:%d\r\n",mode); + DBG.printf("\r\nemmaReadSettings\r\n"); //read settings //readSetting("emmaUID"); //sd card need to be read once before working correctly @@ -288,6 +309,13 @@ DBG.printf("wifiSSID:%s\r\n",wifiSSID.c_str()); wifiPASS = readSetting("wifiPASS"); DBG.printf("wifiPASS:%s\r\n",wifiPASS.c_str()); +} +/*end emma read settings*/ + +/*start emma mode*/ +void emmaInit(int mode) { + DBG.printf("\r\nemmaInit\r\n"); + DBG.printf("mode:%d\r\n",mode); //check proxy if(!proxySERVER.empty() && !proxyPORT.empty() && !proxyAUTH.empty()) { @@ -301,7 +329,8 @@ //check available interface isEthAvailable(); //check whether cable is connected - wifiAvailable = true; //we assume wifi will always available + wifiAvailable = true; //wifi module will always on the board + gprsAvailable = true; //gprs module will always on the board DBG.printf("eth:%d\r\n",ethAvailable); DBG.printf("wifi:%d\r\n",wifiAvailable); DBG.printf("gprs:%d\r\n",gprsAvailable); @@ -1260,10 +1289,10 @@ } //debugging - seconds = time(NULL); - strftime(q, 32, "%Y-%m-%d %H:%M:%S",localtime(&seconds)); - sprintf(r,"dbgPE[%d]",dbgLoop); - DBG.printf("dbgPE:%d\r\n",writeDbg(q,r)); + //seconds = time(NULL); + //strftime(q, 32, "%Y-%m-%d %H:%M:%S",localtime(&seconds)); + //sprintf(r,"dbgPE[%d]",dbgLoop); + //DBG.printf("dbgPE:%d\r\n",writeDbg(q,r)); //panelEnergy, panelVoltage, and panelPower if(tPanelEnergy.read() > 30.0f) { @@ -1366,10 +1395,10 @@ } //debugging - seconds = time(NULL); - strftime(q, 32, "%Y-%m-%d %H:%M:%S",localtime(&seconds)); - sprintf(r,"dbgPEnv[%d]",dbgLoop); - DBG.printf("dbgPEnv:%d\r\n",writeDbg(q,r)); + //seconds = time(NULL); + //strftime(q, 32, "%Y-%m-%d %H:%M:%S",localtime(&seconds)); + //sprintf(r,"dbgPEnv[%d]",dbgLoop); + //DBG.printf("dbgPEnv:%d\r\n",writeDbg(q,r)); //panel environment checkRxBuffer(); @@ -1434,10 +1463,10 @@ } //debugging - seconds = time(NULL); - strftime(q, 32, "%Y-%m-%d %H:%M:%S",localtime(&seconds)); - sprintf(r,"dbgNT[%d]",dbgLoop); - DBG.printf("dbgNT:%d\r\n",writeDbg(q,r)); + //seconds = time(NULL); + //strftime(q, 32, "%Y-%m-%d %H:%M:%S",localtime(&seconds)); + //sprintf(r,"dbgNT[%d]",dbgLoop); + //DBG.printf("dbgNT:%d\r\n",writeDbg(q,r)); //nodeTemp checkRxBuffer(); @@ -1498,10 +1527,10 @@ } //debugging - seconds = time(NULL); - strftime(q, 32, "%Y-%m-%d %H:%M:%S",localtime(&seconds)); - sprintf(r,"dbgCmd[%d]",dbgLoop); - DBG.printf("dbgCmd:%d\r\n",writeDbg(q,r)); + //seconds = time(NULL); + //strftime(q, 32, "%Y-%m-%d %H:%M:%S",localtime(&seconds)); + //sprintf(r,"dbgCmd[%d]",dbgLoop); + //DBG.printf("dbgCmd:%d\r\n",writeDbg(q,r)); //command rest.get("/emma/api/controller/command"); @@ -1655,7 +1684,7 @@ } //debugging - dbgLoop++; + //dbgLoop++; osDelay(5000); }