Programa Teste para monitoramento de ativos eletricos

Dependencies:   logger

Revision:
4:bdc930225ade
Parent:
2:b5367cf9b453
Child:
5:1b0cd3a1f3c7
--- a/main.cpp	Sat May 04 12:41:39 2019 +0000
+++ b/main.cpp	Wed May 08 21:36:20 2019 -0300
@@ -5,28 +5,80 @@
 #include "Giroscopio.h"
 #include "GPS.h"
 
-#define ONE_MINUTE  60
+#define ONE_SECOND  1000
+
+#define MBED_CONF_EVENTS_PRESENT
+#define MBED_CONF_RTOS_PRESENT 
+#define DEVICE_INTERRUPTIN 
+
+DigitalOut led1 (LED1);
 
 Logger l;
 Temperatura temp;
 Giroscopio giro;
 GPS gps;
 
+InterruptIn btn(BUTTON1);
+
+EventQueue eventQueue1;
+EventQueue eventQueue2;
+
 void interrupcaoMovimentacao() {
     gps.enviaLocalizacao(10);
 }
 
+void lancaMetodo() {
+    led1 = 1;
+    temp.verificaTemperatura();
+    wait(0.4);
+    led1 = 0;
+}
+
+void contaFinalFuncao() {
+    int count = 0;
+    while(count++ < 10) {
+        sprintf(l.buffer, "Contando ... %d", count);
+        l.log(l.buffer);
+        wait(1.0f);
+    }
+
+    // eventQueue3.break_dispatch();
+}
+
+// IRQ CONTEXT !! (n pode haver LOG NA SERIAL NESSE CONTEXTO)
+void button_pressed() {
+    eventQueue2.call(&contaFinalFuncao);
+}
+
 int main() {
+    // Sistema.inicializar(/*Confs iniciais do sistema*/);
     temp.setLog(&l);
     giro.setLog(&l);
     gps.setLog(&l);
 
+    Thread eventThread(osPriorityNormal);
+    eventThread.start(callback(&eventQueue1, &EventQueue::dispatch_forever));
+ 
+    // call blink_led2 every second, automatically defering to the eventThread
+    Ticker ledTicker;
+    ledTicker.attach(eventQueue1.event(&lancaMetodo), 5.0f);
+
     // 1 - Fazer um time out para verificar a temperatura a cada 15 Minutos 
-    temp.verificaTemperatura();
+    // Ticker tempTimeOut;
+    // tempTimeOut.attach(
+    //     eventQueue.event(&lancaMetodo), 
+    //     3.0f);
 
     // 2 - Verificar se houve alguma mudança no Giroscópio
     // OBSERVA O EVENTO DE HAVER MUDANÇA
-    giro.ouvirMovimentacao( interrupcaoMovimentacao );
+    giro.ouvirMovimentacao( &interrupcaoMovimentacao );
+
+    Thread eventThread_count(osPriorityNormal);
+    eventThread_count.start(callback(&eventQueue2, &EventQueue::dispatch_forever));
 
-    return 1;
+    btn.fall(&button_pressed);
+
+    led1 = 0;
+    l.log("FINAL do main ... !");
+    wait(osWaitForever);
 }