Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Revision 5:1b0cd3a1f3c7, committed 2019-05-14
- Comitter:
- AndersonIctus (anderson.ictus@gmail.com)
- Date:
- Tue May 14 22:34:36 2019 -0300
- Parent:
- 4:bdc930225ade
- Commit message:
- * Incluindo eventos ao Giroscopio
(Talvez um Girocospio Observer seria legal aqui !!)
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
| src/classes/Giroscopio.h | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Wed May 08 21:36:20 2019 -0300
+++ b/main.cpp Tue May 14 22:34:36 2019 -0300
@@ -7,9 +7,9 @@
#define ONE_SECOND 1000
-#define MBED_CONF_EVENTS_PRESENT
-#define MBED_CONF_RTOS_PRESENT
-#define DEVICE_INTERRUPTIN
+// #define MBED_CONF_EVENTS_PRESENT
+// #define MBED_CONF_RTOS_PRESENT
+// #define DEVICE_INTERRUPTIN
DigitalOut led1 (LED1);
@@ -34,50 +34,27 @@
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);
+ // 1 - Fazer um time out para verificar a temperatura a cada 5 Segundos
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
+ Giroscopio::setListener(&giro);
+ Thread eventThread_giroscopio(osPriorityNormal);
+ eventThread_giroscopio.start(callback(giro.listMovimentacoes(), &EventQueue::dispatch_forever));
- // 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);
-
+ giro.setCallBackMovimentos(&interrupcaoMovimentacao);
+ btn.fall( &Giroscopio::ouvirMovimentacao ); // Usa o evento de botao para SIMULAR uma movimentação em estado de IRQ !
+
led1 = 0;
l.log("FINAL do main ... !");
wait(osWaitForever);
--- a/src/classes/Giroscopio.h Wed May 08 21:36:20 2019 -0300
+++ b/src/classes/Giroscopio.h Tue May 14 22:34:36 2019 -0300
@@ -1,24 +1,61 @@
#include "Logger.h"
class Giroscopio {
- public:
+ public:
+ Giroscopio() {
+ instance = NULL;
+ }
+
+ ~Giroscopio() {
+ instance = NULL;
+ }
+
+ static void setListener(Giroscopio* newListener) {
+ instance = newListener;
+ }
+
/// Fica ouvindo se existe movimentação, Se existir ele executa a função de CALL BACK
- void ouvirMovimentacao( void (*fnCallBack)() ) {
+ static void ouvirMovimentacao() { // IRQ não pode haver LOG !!
+ if(instance != NULL) {
+ instance->_movimentacoes.call( &_doMovimentsActions ); //Executar fora do IRQ
+ }
+ }
+
+ void setLog(Logger * l) {
+ _l = l;
+ }
+
+ void setCallBackMovimentos( void (*fnCallBack)() ){
+ _fnCallBack = fnCallBack;
+ }
+
+ EventQueue* listMovimentacoes() {
+ return &_movimentacoes;
+ }
+
+ private:
+ Logger* _l;
+ EventQueue _movimentacoes;
+ void (*_fnCallBack)();
+
+ static Giroscopio* instance ;
+ static void _doMovimentsActions() {
+ Giroscopio::instance->doMovimentsActions();
+ }
+
+ void doMovimentsActions() {
// 1 - Faz um TIME-OUT para mostrar que houve alguma movimentação !!
_l->log("Verificando a movimentacao ...");
_l->log("Esperando o call back ...");
wait(0.5);
// 2 - quando há a movimentação, então chama o call back !!
- fnCallBack();
- _l->log("Call back lancado !!");
+ if(_fnCallBack != NULL) {
+ _fnCallBack();
+ _l->log("Call back lancado !!");
+ } else {
+ _l->log("Nenhum call back configurado !!");
+ }
}
-
- void setLog(Logger * l) {
- _l = l;
- }
-
- private:
- Logger* _l;
}
;