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: mbed mbed-rtos DHT TextLCD
main.cpp@5:6602f2907ac5, 2017-01-13 (annotated)
- Committer:
- mab5449
- Date:
- Fri Jan 13 19:48:55 2017 +0000
- Revision:
- 5:6602f2907ac5
- Parent:
- 4:d9d4837009f6
- Child:
- 6:46af1199bf9b
Updated to mbed 5
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| emilmont | 2:b84386915279 | 1 | #include "mbed.h" |
| emilmont | 2:b84386915279 | 2 | |
| emilmont | 2:b84386915279 | 3 | /* Mail */ |
| emilmont | 2:b84386915279 | 4 | typedef struct { |
| emilmont | 2:b84386915279 | 5 | float voltage; /* AD result of measured voltage */ |
| emilmont | 2:b84386915279 | 6 | float current; /* AD result of measured current */ |
| emilmont | 2:b84386915279 | 7 | uint32_t counter; /* A counter value */ |
| emilmont | 2:b84386915279 | 8 | } mail_t; |
| emilmont | 2:b84386915279 | 9 | |
| emilmont | 2:b84386915279 | 10 | Mail<mail_t, 16> mail_box; |
| mab5449 | 5:6602f2907ac5 | 11 | Thread thread; |
| emilmont | 2:b84386915279 | 12 | |
| Bartek Szatkowski |
4:d9d4837009f6 | 13 | void send_thread (void) { |
| emilmont | 2:b84386915279 | 14 | uint32_t i = 0; |
| emilmont | 2:b84386915279 | 15 | while (true) { |
| emilmont | 2:b84386915279 | 16 | i++; // fake data update |
| emilmont | 2:b84386915279 | 17 | mail_t *mail = mail_box.alloc(); |
| emilmont | 2:b84386915279 | 18 | mail->voltage = (i * 0.1) * 33; |
| emilmont | 2:b84386915279 | 19 | mail->current = (i * 0.1) * 11; |
| emilmont | 2:b84386915279 | 20 | mail->counter = i; |
| emilmont | 2:b84386915279 | 21 | mail_box.put(mail); |
| mab5449 | 5:6602f2907ac5 | 22 | wait(1); |
| emilmont | 2:b84386915279 | 23 | } |
| emilmont | 2:b84386915279 | 24 | } |
| emilmont | 2:b84386915279 | 25 | |
| emilmont | 2:b84386915279 | 26 | int main (void) { |
| Bartek Szatkowski |
4:d9d4837009f6 | 27 | thread.start(callback(send_thread)); |
| emilmont | 2:b84386915279 | 28 | |
| emilmont | 2:b84386915279 | 29 | while (true) { |
| emilmont | 2:b84386915279 | 30 | osEvent evt = mail_box.get(); |
| emilmont | 2:b84386915279 | 31 | if (evt.status == osEventMail) { |
| emilmont | 2:b84386915279 | 32 | mail_t *mail = (mail_t*)evt.value.p; |
| emilmont | 2:b84386915279 | 33 | printf("\nVoltage: %.2f V\n\r" , mail->voltage); |
| emilmont | 2:b84386915279 | 34 | printf("Current: %.2f A\n\r" , mail->current); |
| emilmont | 2:b84386915279 | 35 | printf("Number of cycles: %u\n\r", mail->counter); |
| emilmont | 2:b84386915279 | 36 | |
| emilmont | 2:b84386915279 | 37 | mail_box.free(mail); |
| emilmont | 2:b84386915279 | 38 | } |
| emilmont | 2:b84386915279 | 39 | } |
| emilmont | 2:b84386915279 | 40 | } |