EZR

Dependencies:   CRC16 FreescaleIAP FreescaleWatchdog GGSProtocol LM75B PIMA Parameters PersistentCircularQueue SerialNumberV2COM mbed-dev-watchdog_2016_03_04

Fork of smartRamalKW by Equipe Firmware V2COM

Revision:
9:e501499af4ef
Parent:
5:1bc98277c257
Child:
10:7a1d1abb5172
--- a/main.cpp	Thu Jul 02 22:57:47 2015 +0000
+++ b/main.cpp	Wed Jul 22 15:09:01 2015 +0000
@@ -14,10 +14,12 @@
     printSerialNumber();
 
     param.loadParameters();
+    printParameters();
     ggsStream.baud(19200);
     exec.carregaEndereco(sn.get());
     exec.iniciaExecutorComandos();
-    
+    detectaCargaSemCorte();
+
     while(1){
         exec.trataPacoteGGS();
     }
@@ -45,3 +47,28 @@
     }
     printf("\r\n");
 }
+
+void printParameters(){
+    printf("Parameters:");
+    for(int i=0; i < sizeof(APP_PARAMETERS); i++){
+        printf(" %02x", ((unsigned char *)&APP_PARAMETERS)[i]);
+    }
+    printf("\r\n");
+}
+
+void detectaCargaSemCorte(){
+    bool ch0Status = getEstadoSensor(0);
+    bool ch1Status = getEstadoSensor(1);
+    
+    if(!ch0Status && ch1Status){    // Canal 0 nao esta alimentado e Canal 1 esta: entao a carga certamente e o canal 0
+        if(APP_PARAMETERS.LOAD_CHANNEL != 0){
+            APP_PARAMETERS.LOAD_CHANNEL = 0;
+            param.saveParameters();
+        }
+    } else if(ch0Status && !ch1Status){    // Canal 1 nao esta alimentado e Canal 0 esta: entao a carga certamente e o canal 1
+        if(APP_PARAMETERS.LOAD_CHANNEL != 1){
+            APP_PARAMETERS.LOAD_CHANNEL = 1;
+            param.saveParameters();
+        }
+    }
+}