KEIS
Dependencies: C12832_lcd mbed-rtos mbed
Fork of rtos_mail by
main.cpp@4:4273c11c7ac1, 2013-09-25 (annotated)
- Committer:
- khayakawa
- Date:
- Wed Sep 25 05:12:23 2013 +0000
- Revision:
- 4:4273c11c7ac1
- Parent:
- 2:b84386915279
KEIS
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 | #include "rtos.h" |
khayakawa | 4:4273c11c7ac1 | 3 | #include "C12832_lcd.h" |
khayakawa | 4:4273c11c7ac1 | 4 | |
khayakawa | 4:4273c11c7ac1 | 5 | C12832_LCD lcd; |
emilmont | 2:b84386915279 | 6 | |
emilmont | 2:b84386915279 | 7 | /* Mail */ |
emilmont | 2:b84386915279 | 8 | typedef struct { |
khayakawa | 4:4273c11c7ac1 | 9 | float temp; |
khayakawa | 4:4273c11c7ac1 | 10 | float humid; |
khayakawa | 4:4273c11c7ac1 | 11 | float illumi; |
khayakawa | 4:4273c11c7ac1 | 12 | // uint32_t count; |
emilmont | 2:b84386915279 | 13 | } mail_t; |
emilmont | 2:b84386915279 | 14 | |
emilmont | 2:b84386915279 | 15 | Mail<mail_t, 16> mail_box; |
emilmont | 2:b84386915279 | 16 | |
emilmont | 2:b84386915279 | 17 | void send_thread (void const *args) { |
khayakawa | 4:4273c11c7ac1 | 18 | uint32_t count= 0; |
emilmont | 2:b84386915279 | 19 | while (true) { |
khayakawa | 4:4273c11c7ac1 | 20 | count++; // fake data update |
emilmont | 2:b84386915279 | 21 | mail_t *mail = mail_box.alloc(); |
khayakawa | 4:4273c11c7ac1 | 22 | mail->temp = ( count * 0.1) * 30; |
khayakawa | 4:4273c11c7ac1 | 23 | mail->humid = (count * 0.1) * 50; |
khayakawa | 4:4273c11c7ac1 | 24 | mail->illumi = (count * 0.1) * 50; |
khayakawa | 4:4273c11c7ac1 | 25 | // mail->count = count; |
emilmont | 2:b84386915279 | 26 | mail_box.put(mail); |
emilmont | 2:b84386915279 | 27 | Thread::wait(1000); |
emilmont | 2:b84386915279 | 28 | } |
emilmont | 2:b84386915279 | 29 | } |
emilmont | 2:b84386915279 | 30 | |
emilmont | 2:b84386915279 | 31 | int main (void) { |
emilmont | 2:b84386915279 | 32 | Thread thread(send_thread); |
emilmont | 2:b84386915279 | 33 | |
emilmont | 2:b84386915279 | 34 | while (true) { |
emilmont | 2:b84386915279 | 35 | osEvent evt = mail_box.get(); |
emilmont | 2:b84386915279 | 36 | if (evt.status == osEventMail) { |
emilmont | 2:b84386915279 | 37 | mail_t *mail = (mail_t*)evt.value.p; |
khayakawa | 4:4273c11c7ac1 | 38 | lcd.printf("temp: %.2f \n\r" , mail->temp); |
khayakawa | 4:4273c11c7ac1 | 39 | lcd.printf("humid: %.2f \n\r" , mail->humid); |
khayakawa | 4:4273c11c7ac1 | 40 | lcd.printf("illumination: %.2f \n\r" , mail->illumi); |
khayakawa | 4:4273c11c7ac1 | 41 | // lcd.printf("Number of cycles: %u\n\r", mail->counter); |
emilmont | 2:b84386915279 | 42 | |
emilmont | 2:b84386915279 | 43 | mail_box.free(mail); |
emilmont | 2:b84386915279 | 44 | } |
emilmont | 2:b84386915279 | 45 | } |
emilmont | 2:b84386915279 | 46 | } |