jason berry
/
rtos_queue_accell_1
serial ploter
Diff: main.cpp
- Revision:
- 5:b19a92f1f5ec
- Parent:
- 3:c490e2d69dd8
--- a/main.cpp Tue Jun 04 16:03:43 2013 +0100 +++ b/main.cpp Tue Oct 13 14:06:59 2020 +0000 @@ -1,10 +1,29 @@ #include "mbed.h" #include "rtos.h" +#include "LM75B.h" +#include "MMA7660.h" +MMA7660 MMA(p28, p27); //I2C Accelerometer +LM75B sensor(p28,p27); + +//serial data +//////////////////////////////////////////////////////////// +//typedef struct { +// float voltage; /* AD result of measured voltage */ +// float current; /* AD result of measured current */ +// uint32_t counter; /* A counter value */ +//} message_t; + +//plotter data temperature +////////////////////////////////////////////////////////////// +//typedef struct { +// uint32_t temperature; /* AD result of measured voltage */ +//} message_t; + +//plotter data acceleromter +////////////////////////////////////////////////////////////// typedef struct { - float voltage; /* AD result of measured voltage */ - float current; /* AD result of measured current */ - uint32_t counter; /* A counter value */ + uint32_t x_axis; /* AD result of measured voltage */ } message_t; MemoryPool<message_t, 16> mpool; @@ -16,25 +35,47 @@ while (true) { i++; // fake data update message_t *message = mpool.alloc(); - message->voltage = (i * 0.1) * 33; - message->current = (i * 0.1) * 11; - message->counter = i; + + //fake message + //message->voltage = (i * 0.1) * 33; + //message->current = (i * 0.1) * 11; + //message->counter = i; + + //temperature message + //message->temperature = (uint32_t)sensor; + + //acceleration message + message->x_axis = (uint32_t)(MMA.x()*100); + queue.put(message); - Thread::wait(1000); + Thread::wait(10); + + } } int main (void) { Thread thread(send_thread); + sensor.open(); + MMA.testConnection(); + while (true) { osEvent evt = queue.get(); if (evt.status == osEventMessage) { message_t *message = (message_t*)evt.value.p; - printf("\nVoltage: %.2f V\n\r" , message->voltage); - printf("Current: %.2f A\n\r" , message->current); - printf("Number of cycles: %u\n\r", message->counter); + //serial print out + //printf("\nVoltage: %.2f V\n\r" , message->voltage); + //printf("Current: %.2f A\n\r" , message->current); + //printf("Number of cycles: %u\n\r", message->counter); + + //serial plotter start with $ end with ; + //printf("$%d;\n\r", message->temperature); + + //serial plotter start with $ end with ; + printf("$%d;\n\r", message->x_axis); + mpool.free(message); } }