jason berry
/
rtos_queue_accel
serial ploter
main.cpp@7:0cb43a362538, 2017-01-13 (annotated)
- Committer:
- mab5449
- Date:
- Fri Jan 13 19:49:53 2017 +0000
- Revision:
- 7:0cb43a362538
- Parent:
- 6:2c73ccb2a032
- Child:
- 8:72d8f12e161f
Updated to mbed 5
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
emilmont | 1:d2ba5afbf91f | 1 | #include "mbed.h" |
emilmont | 1:d2ba5afbf91f | 2 | |
emilmont | 1:d2ba5afbf91f | 3 | typedef struct { |
emilmont | 1:d2ba5afbf91f | 4 | float voltage; /* AD result of measured voltage */ |
emilmont | 1:d2ba5afbf91f | 5 | float current; /* AD result of measured current */ |
emilmont | 1:d2ba5afbf91f | 6 | uint32_t counter; /* A counter value */ |
emilmont | 1:d2ba5afbf91f | 7 | } message_t; |
emilmont | 1:d2ba5afbf91f | 8 | |
emilmont | 1:d2ba5afbf91f | 9 | MemoryPool<message_t, 16> mpool; |
emilmont | 1:d2ba5afbf91f | 10 | Queue<message_t, 16> queue; |
mab5449 | 7:0cb43a362538 | 11 | Thread thread; |
emilmont | 1:d2ba5afbf91f | 12 | |
emilmont | 1:d2ba5afbf91f | 13 | /* Send Thread */ |
Bartek Szatkowski |
6:2c73ccb2a032 | 14 | void send_thread (void) { |
emilmont | 1:d2ba5afbf91f | 15 | uint32_t i = 0; |
emilmont | 1:d2ba5afbf91f | 16 | while (true) { |
emilmont | 1:d2ba5afbf91f | 17 | i++; // fake data update |
emilmont | 1:d2ba5afbf91f | 18 | message_t *message = mpool.alloc(); |
emilmont | 1:d2ba5afbf91f | 19 | message->voltage = (i * 0.1) * 33; |
emilmont | 1:d2ba5afbf91f | 20 | message->current = (i * 0.1) * 11; |
emilmont | 1:d2ba5afbf91f | 21 | message->counter = i; |
emilmont | 1:d2ba5afbf91f | 22 | queue.put(message); |
mab5449 | 7:0cb43a362538 | 23 | wait(1); |
emilmont | 1:d2ba5afbf91f | 24 | } |
emilmont | 1:d2ba5afbf91f | 25 | } |
emilmont | 1:d2ba5afbf91f | 26 | |
emilmont | 1:d2ba5afbf91f | 27 | int main (void) { |
Bartek Szatkowski |
6:2c73ccb2a032 | 28 | thread.start(callback(send_thread)); |
emilmont | 1:d2ba5afbf91f | 29 | |
emilmont | 1:d2ba5afbf91f | 30 | while (true) { |
emilmont | 1:d2ba5afbf91f | 31 | osEvent evt = queue.get(); |
emilmont | 1:d2ba5afbf91f | 32 | if (evt.status == osEventMessage) { |
emilmont | 1:d2ba5afbf91f | 33 | message_t *message = (message_t*)evt.value.p; |
emilmont | 1:d2ba5afbf91f | 34 | printf("\nVoltage: %.2f V\n\r" , message->voltage); |
emilmont | 1:d2ba5afbf91f | 35 | printf("Current: %.2f A\n\r" , message->current); |
emilmont | 1:d2ba5afbf91f | 36 | printf("Number of cycles: %u\n\r", message->counter); |
emilmont | 1:d2ba5afbf91f | 37 | |
emilmont | 1:d2ba5afbf91f | 38 | mpool.free(message); |
emilmont | 1:d2ba5afbf91f | 39 | } |
emilmont | 1:d2ba5afbf91f | 40 | } |
emilmont | 1:d2ba5afbf91f | 41 | } |