Programa Teste para monitoramento de ativos eletricos

Dependencies:   logger

main.cpp

Committer:
AndersonIctus (anderson.ictus@gmail.com)
Date:
2019-05-08
Revision:
4:bdc930225ade
Parent:
2:b5367cf9b453
Child:
5:1b0cd3a1f3c7

File content as of revision 4:bdc930225ade:

#include "mbed.h"
#include "Logger.h"

#include "Temperatura.h"
#include "Giroscopio.h"
#include "GPS.h"

#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 
    // 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 );

    Thread eventThread_count(osPriorityNormal);
    eventThread_count.start(callback(&eventQueue2, &EventQueue::dispatch_forever));

    btn.fall(&button_pressed);

    led1 = 0;
    l.log("FINAL do main ... !");
    wait(osWaitForever);
}