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@6:46af1199bf9b, 2017-02-15 (annotated)
- Committer:
- mbed_official
- Date:
- Wed Feb 15 14:01:04 2017 -0600
- Revision:
- 6:46af1199bf9b
- Parent:
- 5:6602f2907ac5
- Child:
- 7:e8f1aab2aee2
Revert update to mbed-os.
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| emilmont | 2:b84386915279 | 1 | #include "mbed.h" |
| mbed_official | 6:46af1199bf9b | 2 | #include "rtos.h" |
| emilmont | 2:b84386915279 | 3 | |
| emilmont | 2:b84386915279 | 4 | /* Mail */ |
| emilmont | 2:b84386915279 | 5 | typedef struct { |
| emilmont | 2:b84386915279 | 6 | float voltage; /* AD result of measured voltage */ |
| emilmont | 2:b84386915279 | 7 | float current; /* AD result of measured current */ |
| emilmont | 2:b84386915279 | 8 | uint32_t counter; /* A counter value */ |
| emilmont | 2:b84386915279 | 9 | } mail_t; |
| emilmont | 2:b84386915279 | 10 | |
| emilmont | 2:b84386915279 | 11 | Mail<mail_t, 16> mail_box; |
| 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); |
| mbed_official | 6:46af1199bf9b | 22 | Thread::wait(1000); |
| emilmont | 2:b84386915279 | 23 | } |
| emilmont | 2:b84386915279 | 24 | } |
| emilmont | 2:b84386915279 | 25 | |
| emilmont | 2:b84386915279 | 26 | int main (void) { |
| mbed_official | 6:46af1199bf9b | 27 | Thread thread; |
| Bartek Szatkowski |
4:d9d4837009f6 | 28 | thread.start(callback(send_thread)); |
| emilmont | 2:b84386915279 | 29 | |
| emilmont | 2:b84386915279 | 30 | while (true) { |
| emilmont | 2:b84386915279 | 31 | osEvent evt = mail_box.get(); |
| emilmont | 2:b84386915279 | 32 | if (evt.status == osEventMail) { |
| emilmont | 2:b84386915279 | 33 | mail_t *mail = (mail_t*)evt.value.p; |
| emilmont | 2:b84386915279 | 34 | printf("\nVoltage: %.2f V\n\r" , mail->voltage); |
| emilmont | 2:b84386915279 | 35 | printf("Current: %.2f A\n\r" , mail->current); |
| emilmont | 2:b84386915279 | 36 | printf("Number of cycles: %u\n\r", mail->counter); |
| emilmont | 2:b84386915279 | 37 | |
| emilmont | 2:b84386915279 | 38 | mail_box.free(mail); |
| emilmont | 2:b84386915279 | 39 | } |
| emilmont | 2:b84386915279 | 40 | } |
| emilmont | 2:b84386915279 | 41 | } |