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.
Dependencies: Buffer MMA8451Q mbed-rtos mbed
logger.cpp
00001 #include "logger.h" 00002 00003 Logger::Logger(PinName tx, PinName rx) : 00004 port(tx, rx), 00005 redLed(LED_RED), 00006 blueLed(LED_BLUE), 00007 greenLed(LED_GREEN), 00008 acc(PTE25, PTE24, MMA8451Q_I2C_ADDRESS), 00009 //tx_th(tx_thread, (void*)this), 00010 data_th(this->data_thread, (void*)this), 00011 led_th(this->led_thread, (void*)&blueLed), 00012 acc_x(BUF_SIZE) 00013 00014 { 00015 redLed = 1; blueLed = 1; greenLed = 1; 00016 msg = 0; 00017 newMsg = false; 00018 port.baud(BAUD_115200); 00019 port.attach(this, &Logger::rcv_isr, Serial::RxIrq); 00020 } 00021 00022 /* Rutina de interrupción para recibir datos del servidor */ 00023 /* Funciona! */ 00024 void Logger::rcv_isr() 00025 { 00026 msg = UART0->D; // Leer UART0 para desactivar bandera de interrupción. 00027 while(UART0->S1 & UART_S1_RDRF_MASK); // Esperar a UART0 listo. 00028 newMsg = true; 00029 //redLed = !redLed; 00030 } 00031 00032 /* Thread para adquisicion de datos de los sensores */ 00033 /* Funciona */ 00034 void Logger::data_thread(const void* args) 00035 { 00036 Logger* log = (Logger*)args; 00037 float temp[3]; 00038 //Buffer<float> buf_x(BUF_SIZE); Buffer<float> buf_y(BUF_SIZE); Buffer<float> buf_z(BUF_SIZE); 00039 while(true) 00040 { 00041 log->led_th.signal_set(LED_SIGNAL); 00042 log->acc.getAccAllAxis(temp); 00043 log->acc_x.put(temp[0]); 00044 //buf_x.put(temp[0]); buf_y.put(temp[1]); buf_z.put(temp[2]); 00045 //log->port.printf("a[x]: %f, a[y]: %f, a[z]: %f\n\r", temp[0], temp[1], temp[2]); 00046 log->port.printf("a[x}: %f\n\r", log->acc_x.get()); 00047 Thread::wait(SAMPLE_RATE); 00048 } 00049 00050 } 00051 00052 void Logger::led_thread(const void* args) 00053 { 00054 DigitalOut* led = (DigitalOut*)args; 00055 while(true) 00056 { 00057 Thread::signal_wait(LED_SIGNAL); 00058 *led = !(*led); 00059 } 00060 } 00061 00062 /* Thread para el envio de datos al servidor */ 00063 //void Logger::tx_thread(const void* args) {} 00064 00065 00066 00067 /* Destructor */ 00068 Logger::~Logger() 00069 { 00070 00071 }
Generated on Sun Jul 24 2022 23:33:31 by
1.7.2