able to subscribe for >10hrs and still running
Dependencies: ADE7758_v1 Crypto DHT11 MQTT MbedJSONValue SDFileSystem SPI_TFT_ILI9341 SWSPI SetRTC TFT_fonts Touch W5500Interface mbed-rtos mbed-src tuanpm
Fork of PB_emma_controller_mbed_src by
Revision 12:96f637ed37f9, committed 2015-07-14
- Comitter:
- arsenalist
- Date:
- Tue Jul 14 03:03:22 2015 +0000
- Parent:
- 11:2311b2d5157d
- Child:
- 13:e8adfe305dbc
- Commit message:
- Working simple emmaModeSelection.
Changed in this revision
--- a/SDFileSystem.lib Mon Jul 13 13:29:25 2015 +0000 +++ b/SDFileSystem.lib Tue Jul 14 03:03:22 2015 +0000 @@ -1,1 +1,1 @@ -http://developer.mbed.org/users/mbed_official/code/SDFileSystem/#7b35d1709458 +http://developer.mbed.org/users/mbed_official/code/SDFileSystem/#2bfd1490ba13
--- a/emmaCode.cpp Mon Jul 13 13:29:25 2015 +0000 +++ b/emmaCode.cpp Tue Jul 14 03:03:22 2015 +0000 @@ -23,6 +23,12 @@ //init ade7758 - without cs pin ADE7758 ADE(PB_6, PB_4, PB_5, PB_2); //mosi, miso, sck, irq +//init tft lcd +SPI_TFT_ILI9341 TFT(PA_7, PA_6, PA_5, PA_4, PC_5, PC_4,"TFT"); //mosi, miso, sclk, cs, reset, dc +//init touch screen - without cs pin +TouchScreenADS7843 TP(PB_10, PB_0, PB_1, PB_2, &TFT); //mosi, miso, sclk, irq, tft +//InterruptIn tpIRQ(PB_2); + //emma settings string emmaUID; string hmac; @@ -50,6 +56,16 @@ REST restObj[NODES_MAX] = {REST(&esp),REST(&esp),REST(&esp),REST(&esp),REST(&esp)}; NODES nodes[NODES_MAX] = {NODES(&restObj[0]),NODES(&restObj[1]),NODES(&restObj[2]),NODES(&restObj[3]),NODES(&restObj[4])}; +//mode box class for main menu +class modeBox { +public: + int xTL; //TopLeft + int yTL; + int xBR; //BottomRight + int yBR; + string text; +}; + //ade7758 variables uint16_t AWattHrValue, BWattHrValue, CWattHrValue; uint16_t AVAHrValue, BVAHrValue, CVAHrValue; @@ -74,10 +90,157 @@ string globalCommand; string rxBuf; -void emmaInit(void) { +/*start lcd and touch*/ +int emmaModeSelection(void) { + bool modeSelected = false; + int md=0; + int TPx; + int TPy; + + //disable sd card and enable tft lcd + //sd._cs = 1; + //TFT._cs = 0; + + TFT.background(Black); + TFT.foreground(White); + + TFT.set_font((unsigned char*) Arial12x12); + TFT.set_orientation(1); + TFT.cls(); + TFT.locate(0,0); + TFT.printf("Hello, I'm Emma!"); + wait(3); + TFT.cls(); + + Matrix matrix; + Coordinate ScreenSample[3]; + + matrix.An = 580; + matrix.Bn = 75980; + matrix.Cn = -3410580; + matrix.Dn = 57855; + matrix.En = -2465; + matrix.Fn = -3483515; + matrix.Divider = 209144; + + ScreenSample[0].x = 230; + ScreenSample[0].y = 167; + ScreenSample[1].x = 754; + ScreenSample[1].y = 163; + ScreenSample[2].x = 771; + ScreenSample[2].y = 562; + + TP.SetCalibration(&matrix, &ScreenSample[0]); + + TFT.locate(0,0); + TFT.printf(" X:"); + TFT.locate(70,0); + TFT.printf(" Y:"); + + //draw border + TFT.line(15,15,310,15,Orange); + TFT.line(310,15,310,250,Orange); + TFT.line(310,250,15,250,Orange); + TFT.line(15,250,15,15,Orange); + + //init main menu + modeBox menu[6]; + + //wifi config mode + menu[MODE_WIFI_CONFIG].xTL = 25; + menu[MODE_WIFI_CONFIG].yTL = 25; + menu[MODE_WIFI_CONFIG].xBR = 110; + menu[MODE_WIFI_CONFIG].yBR = 90; + menu[MODE_WIFI_CONFIG].text = "wifi config"; + + //setting mode + menu[MODE_SETTINGS].xTL = 120; + menu[MODE_SETTINGS].yTL = 25; + menu[MODE_SETTINGS].xBR = 205; + menu[MODE_SETTINGS].yBR = 90; + menu[MODE_SETTINGS].text = "settings"; + + //register mode + menu[MODE_REGISTER].xTL = 25; + menu[MODE_REGISTER].yTL = 100; + menu[MODE_REGISTER].xBR = 110; + menu[MODE_REGISTER].yBR = 165; + menu[MODE_REGISTER].text = "register"; + + //operational mode + menu[MODE_OPERATION].xTL = 120; + menu[MODE_OPERATION].yTL = 100; + menu[MODE_OPERATION].xBR = 205; + menu[MODE_OPERATION].yBR = 165; + menu[MODE_OPERATION].text = "operation"; + + //firmware download mode + menu[MODE_FIRMWARE_DOWNLOAD].xTL = 215; + menu[MODE_FIRMWARE_DOWNLOAD].yTL = 25; + menu[MODE_FIRMWARE_DOWNLOAD].xBR = 300; + menu[MODE_FIRMWARE_DOWNLOAD].yBR = 90; + menu[MODE_FIRMWARE_DOWNLOAD].text = "firmware download"; + + //reserved mode + menu[5].xTL = 215; + menu[5].yTL = 100; + menu[5].xBR = 300; + menu[5].yBR = 165; + menu[5].text = "reserved"; + + for(int i=0; i<6; i++) { + TFT.fillrect(menu[i].xTL,menu[i].yTL,menu[i].xBR,menu[i].yBR,Orange); + } + + while(!modeSelected) { + if(!TP._tp_irq) { + if(TP.Read_Ads7843()) { + TP.getDisplayPoint(); + TPx = TP.display.x; + TPy = TP.display.y; + TP.TP_DrawPoint(TPx,TPy, Blue); + TFT.locate(25,0); + TFT.printf("%03d",TPx); + TFT.locate(95,0); + TFT.printf("%03d",TPy); + + for(int i=0; i<6; i++) { + if((menu[i].xTL < TPx && TPx < menu[i].xBR) && (menu[i].yTL < TPy && TPy < menu[i].yBR)) { + //TFT.locate(25,170); + //TFT.printf(" "); + //TFT.locate(25,170); + //TFT.printf("mode: %s is selected",menu[i].text.c_str()); + //wait(3); + md = i; + modeSelected = true; + } + } + } + } + } + + TFT.locate(25,170); + TFT.printf(" "); + TFT.locate(25,170); + TFT.printf("out-mode: %s is selected",menu[md].text.c_str()); + wait(3); + TFT.cls(); + + //enable sd card and disable tft lcd + //TFT._cs = 1; + //sd._cs = 0; + //wait(2); + + return md; +} +/*end lcd and touch*/ + +/*start emma mode*/ +void emmaInit(int mode) { char s[64]; DBG.baud(19200); DBG.printf("\r\nemmaInit\r\n"); + DBG.printf("mode:%d\r\n",mode); //read settings //readSetting("emmaUID"); //sd card need to be read once before working correctly @@ -1228,6 +1391,7 @@ } DBG.printf("download finished\r\n"); } +/*end emma mode*/ /*start energy related*/ void energyThread(void const*) {
--- a/emmaCode.h Mon Jul 13 13:29:25 2015 +0000 +++ b/emmaCode.h Tue Jul 14 03:03:22 2015 +0000 @@ -2,16 +2,19 @@ #define MBED_EMMACODE_H #include "mbed.h" -#include "espduino.h" //wifi mqtt -#include "mqtt.h" //wifi mqtt -#include "rest.h" //wifi rest -#include "MQTTClient.h" //eth mqtt -#include "MQTTEthernet.h" //eth mqtt -#include "MbedJSONValue.h" //json -#include "SDFileSystem.h" //sd card -#include "Crypto.h" //hash calculation -#include "cmsis_os.h" //threads -#include "ade7758.h" //ade7758 +#include "espduino.h" //wifi mqtt +#include "mqtt.h" //wifi mqtt +#include "rest.h" //wifi rest +#include "MQTTClient.h" //eth mqtt +#include "MQTTEthernet.h" //eth mqtt +#include "MbedJSONValue.h" //json +#include "SDFileSystem.h" //sd card +#include "Crypto.h" //hash calculation +#include "cmsis_os.h" //threads +#include "ade7758.h" //ade7758 +#include "SPI_TFT_ILI9341.h" //lcd +#include "Touch.h" //touch +#include "Arial12x12.h" //font #include <string> //platform @@ -65,8 +68,12 @@ #define VRMSTHRESHOLD 250 #define WATTTHRESHOLD 200 +/*start lcd and touch*/ +int emmaModeSelection(void); +/*end lcd and touch*/ + /*start emma mode*/ -void emmaInit(void); +void emmaInit(int mode); void emmaModeWiFiConfig(void); void emmaModeSettings(void); void emmaModeRegister(void);
--- a/main.cpp Mon Jul 13 13:29:25 2015 +0000 +++ b/main.cpp Tue Jul 14 03:03:22 2015 +0000 @@ -1,11 +1,13 @@ #include "emmaCode.h" -int mode = MODE_OPERATION; +int mode; + int main() { //init touchscreen and read input - + //mode = MODE_OPERATION; + mode = emmaModeSelection(); - emmaInit(); + emmaInit(mode); //switch mode switch(mode) { case MODE_SETTINGS: