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 Emma

Revision:
60:1d4232f5f9c9
Parent:
59:009596ea660d
Child:
61:4eda981730ae
--- a/emmaCode.cpp	Tue Sep 22 02:59:22 2015 +0000
+++ b/emmaCode.cpp	Fri Sep 25 08:44:03 2015 +0000
@@ -237,7 +237,7 @@
     //2. registrasi or lanjut
     //3. controller or lanjut
     //4. wifi or update firmware
-    string menuText[8] = {"Jalan","Pengaturan","Daftar","Lanjut","Atur EMMA","Lanjut","Atur WiFi","Update"};
+    string menuText[8] = {"Jalan","Pengaturan","Daftar","Lanjut","P. EMMA","Lanjut","P. WiFi","Update"};
     
     //init main menu
     modeCircle menu;
@@ -566,32 +566,43 @@
 }
 void emmaModeWiFiConfig(void) {
     bool findCh;
+    bool waitAnimation = false;
     string str;
     Timer t;
         
     DBG.printf("emmaModeWiFiConfig\r\n");
     
     //waiting
+    _ESP.attach(&rxInterrupt,Serial::RxIrq);
         
-    t.start();
     //set wifi module to configuration
     _ESP.printf("MODE=C");
-    while(1) {
-        char rcv[128] = {};
-        wifiRcvReply(rcv,3000);
-        str = rcv;
-        if(str.find("SC_STATUS_FIND_CHANNEL") != std::string::npos) {
-            findCh = true;
-            break;
+    waitAnimation = true;
+    
+    t.start();
+    while(waitAnimation) {
+        for(int i=0; i<2880; i+=4) {
+            TFT.fillarc(160, 130, 92, 4, (i >> 1)-45, (i >> 1)+45, colorDarkGray);
+            TFT.fillarc(160, 130, 92, 4, (i >> 1)-45-4, (i >> 1)-45, Blue);
+            TFT.fillarc(160, 130, 95, 4, 1440-i-45, 1440-i+45, colorDarkGray);
+            TFT.fillarc(160, 130, 95, 4, 1440-i+45, 1440-i+45+4, colorLightGray);
+            
+            if(rxBuf.find("SC_STATUS_FIND_CHANNEL") != std::string::npos) {
+                findCh = true;
+                waitAnimation = false;
+            }
+            if(t.read() > 60.0f) {
+                t.stop();
+                t.reset();
+                findCh = false;
+                waitAnimation = false;
+            }
         }
-        if(t.read() > 60.0f) {
-            t.stop();
-            t.reset();
-            findCh = false;
-            break;    
-        }    
     }
+    //disable UART2 IRQ
+    NVIC_DisableIRQ(USART2_IRQn);
     
+    TFT.cls();
     if(findCh) {
         TFT.locate(10,200);
         TFT.printf("Silakan sambungkan dg App");
@@ -662,6 +673,7 @@
 void emmaModeSettings(void) {
     bool clientIsConnected = false;
     bool serverIsListened = false;
+    bool waitAnimation = false;
     char s[32];
     string str;
     
@@ -802,14 +814,27 @@
     } else if(wifiAvailable) {
         DBG.printf("emmaModeSettings - wifi\r\n");
         
+        _ESP.attach(&rxInterrupt,Serial::RxIrq);
+        
         _ESP.printf("MODE=S");
-        while(1) {
-            char rcv[128] = {};
-            wifiRcvReply(rcv,3000);
-            str = rcv;
-            if(str.find("MODE=S_OK") != std::string::npos)
-                break;
+        waitAnimation = true;
+        
+        while(waitAnimation) {
+            for(int i=0; i<2880; i+=4) {
+                TFT.fillarc(160, 130, 92, 4, (i >> 1)-45, (i >> 1)+45, colorDarkGray);
+                TFT.fillarc(160, 130, 92, 4, (i >> 1)-45-4, (i >> 1)-45, Blue);
+                TFT.fillarc(160, 130, 95, 4, 1440-i-45, 1440-i+45, colorDarkGray);
+                TFT.fillarc(160, 130, 95, 4, 1440-i+45, 1440-i+45+4, colorLightGray);
+                
+                if(rxBuf.find("MODE=S_OK") != std::string::npos) {
+                    waitAnimation = false;
+                }
+            }
         }
+        //disable UART2 IRQ
+        NVIC_DisableIRQ(USART2_IRQn);
+        
+        TFT.cls();
         TFT.locate(10,200);
         TFT.printf(" Silakan sambungkan dg App");
         DBG.printf("enter EMMA settings mode\r\n");
@@ -2186,7 +2211,7 @@
         t.reset();
         */
         
-        //disable UART2
+        //disable UART2 IRQ
         NVIC_DisableIRQ(USART2_IRQn);
         
         //init rest to remotes
@@ -2201,7 +2226,7 @@
             }
         }
         
-        //enable UART2
+        //enable UART2 IRQ
         NVIC_EnableIRQ(USART2_IRQn);
         
         //_ESP.attach(&rxInterrupt,Serial::RxIrq);