simple data logger
Dependencies: Buffer MMA8451Q mbed-rtos mbed
logger.cpp@0:93d648fde6cf, 2013-06-04 (annotated)
- Committer:
- jhestolano
- Date:
- Tue Jun 04 01:42:20 2013 +0000
- Revision:
- 0:93d648fde6cf
Simple data logger.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jhestolano | 0:93d648fde6cf | 1 | #include "logger.h" |
jhestolano | 0:93d648fde6cf | 2 | |
jhestolano | 0:93d648fde6cf | 3 | Logger::Logger(PinName tx, PinName rx) : |
jhestolano | 0:93d648fde6cf | 4 | port(tx, rx), |
jhestolano | 0:93d648fde6cf | 5 | redLed(LED_RED), |
jhestolano | 0:93d648fde6cf | 6 | blueLed(LED_BLUE), |
jhestolano | 0:93d648fde6cf | 7 | greenLed(LED_GREEN), |
jhestolano | 0:93d648fde6cf | 8 | acc(PTE25, PTE24, MMA8451Q_I2C_ADDRESS), |
jhestolano | 0:93d648fde6cf | 9 | //tx_th(tx_thread, (void*)this), |
jhestolano | 0:93d648fde6cf | 10 | data_th(this->data_thread, (void*)this), |
jhestolano | 0:93d648fde6cf | 11 | led_th(this->led_thread, (void*)&blueLed), |
jhestolano | 0:93d648fde6cf | 12 | acc_x(BUF_SIZE) |
jhestolano | 0:93d648fde6cf | 13 | |
jhestolano | 0:93d648fde6cf | 14 | { |
jhestolano | 0:93d648fde6cf | 15 | redLed = 1; blueLed = 1; greenLed = 1; |
jhestolano | 0:93d648fde6cf | 16 | msg = 0; |
jhestolano | 0:93d648fde6cf | 17 | newMsg = false; |
jhestolano | 0:93d648fde6cf | 18 | port.baud(BAUD_115200); |
jhestolano | 0:93d648fde6cf | 19 | port.attach(this, &Logger::rcv_isr, Serial::RxIrq); |
jhestolano | 0:93d648fde6cf | 20 | } |
jhestolano | 0:93d648fde6cf | 21 | |
jhestolano | 0:93d648fde6cf | 22 | /* Rutina de interrupción para recibir datos del servidor */ |
jhestolano | 0:93d648fde6cf | 23 | /* Funciona! */ |
jhestolano | 0:93d648fde6cf | 24 | void Logger::rcv_isr() |
jhestolano | 0:93d648fde6cf | 25 | { |
jhestolano | 0:93d648fde6cf | 26 | msg = UART0->D; // Leer UART0 para desactivar bandera de interrupción. |
jhestolano | 0:93d648fde6cf | 27 | while(UART0->S1 & UART_S1_RDRF_MASK); // Esperar a UART0 listo. |
jhestolano | 0:93d648fde6cf | 28 | newMsg = true; |
jhestolano | 0:93d648fde6cf | 29 | //redLed = !redLed; |
jhestolano | 0:93d648fde6cf | 30 | } |
jhestolano | 0:93d648fde6cf | 31 | |
jhestolano | 0:93d648fde6cf | 32 | /* Thread para adquisicion de datos de los sensores */ |
jhestolano | 0:93d648fde6cf | 33 | /* Funciona */ |
jhestolano | 0:93d648fde6cf | 34 | void Logger::data_thread(const void* args) |
jhestolano | 0:93d648fde6cf | 35 | { |
jhestolano | 0:93d648fde6cf | 36 | Logger* log = (Logger*)args; |
jhestolano | 0:93d648fde6cf | 37 | float temp[3]; |
jhestolano | 0:93d648fde6cf | 38 | //Buffer<float> buf_x(BUF_SIZE); Buffer<float> buf_y(BUF_SIZE); Buffer<float> buf_z(BUF_SIZE); |
jhestolano | 0:93d648fde6cf | 39 | while(true) |
jhestolano | 0:93d648fde6cf | 40 | { |
jhestolano | 0:93d648fde6cf | 41 | log->led_th.signal_set(LED_SIGNAL); |
jhestolano | 0:93d648fde6cf | 42 | log->acc.getAccAllAxis(temp); |
jhestolano | 0:93d648fde6cf | 43 | log->acc_x.put(temp[0]); |
jhestolano | 0:93d648fde6cf | 44 | //buf_x.put(temp[0]); buf_y.put(temp[1]); buf_z.put(temp[2]); |
jhestolano | 0:93d648fde6cf | 45 | //log->port.printf("a[x]: %f, a[y]: %f, a[z]: %f\n\r", temp[0], temp[1], temp[2]); |
jhestolano | 0:93d648fde6cf | 46 | log->port.printf("a[x}: %f\n\r", log->acc_x.get()); |
jhestolano | 0:93d648fde6cf | 47 | Thread::wait(SAMPLE_RATE); |
jhestolano | 0:93d648fde6cf | 48 | } |
jhestolano | 0:93d648fde6cf | 49 | |
jhestolano | 0:93d648fde6cf | 50 | } |
jhestolano | 0:93d648fde6cf | 51 | |
jhestolano | 0:93d648fde6cf | 52 | void Logger::led_thread(const void* args) |
jhestolano | 0:93d648fde6cf | 53 | { |
jhestolano | 0:93d648fde6cf | 54 | DigitalOut* led = (DigitalOut*)args; |
jhestolano | 0:93d648fde6cf | 55 | while(true) |
jhestolano | 0:93d648fde6cf | 56 | { |
jhestolano | 0:93d648fde6cf | 57 | Thread::signal_wait(LED_SIGNAL); |
jhestolano | 0:93d648fde6cf | 58 | *led = !(*led); |
jhestolano | 0:93d648fde6cf | 59 | } |
jhestolano | 0:93d648fde6cf | 60 | } |
jhestolano | 0:93d648fde6cf | 61 | |
jhestolano | 0:93d648fde6cf | 62 | /* Thread para el envio de datos al servidor */ |
jhestolano | 0:93d648fde6cf | 63 | //void Logger::tx_thread(const void* args) {} |
jhestolano | 0:93d648fde6cf | 64 | |
jhestolano | 0:93d648fde6cf | 65 | |
jhestolano | 0:93d648fde6cf | 66 | |
jhestolano | 0:93d648fde6cf | 67 | /* Destructor */ |
jhestolano | 0:93d648fde6cf | 68 | Logger::~Logger() |
jhestolano | 0:93d648fde6cf | 69 | { |
jhestolano | 0:93d648fde6cf | 70 | |
jhestolano | 0:93d648fde6cf | 71 | } |