Supachai Vorapojpisut
/
le484_2016
Course project for LE484 at Thammasat University, class of 2016
main.cpp@7:d702abfe51e3, 2017-05-08 (annotated)
- Committer:
- 3ecauz
- Date:
- Mon May 08 04:42:04 2017 +0000
- Revision:
- 7:d702abfe51e3
- Parent:
- 6:da3c4393efee
- Child:
- 10:25704cab4585
SensorTask update
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
vsupacha | 0:aefb68fd2505 | 1 | /** |
vsupacha | 0:aefb68fd2505 | 2 | * @brief Main loop: XBee protocol handler |
natanich | 2:d117505b89ce | 3 | * @author Supachai Vorapojpisut,Vissarut Prakobpon , Natanich Bunsila |
vsupacha | 0:aefb68fd2505 | 4 | * @date May 8, 2017 |
vsupacha | 0:aefb68fd2505 | 5 | */ |
vsupacha | 0:aefb68fd2505 | 6 | |
vsupacha | 0:aefb68fd2505 | 7 | #include "mbed.h" |
vsupacha | 5:d35cd42da2ac | 8 | #include "platform.h" |
vsupacha | 0:aefb68fd2505 | 9 | |
vsupacha | 0:aefb68fd2505 | 10 | |
3ecauz | 7:d702abfe51e3 | 11 | Thread sensor; |
3ecauz | 7:d702abfe51e3 | 12 | |
3ecauz | 7:d702abfe51e3 | 13 | |
vsupacha | 3:e38819a2b38c | 14 | RawSerial pc(USBTX, USBRX); // use USB-serial for testing purpose |
vsupacha | 3:e38819a2b38c | 15 | Mail<char, 2> mbx; // use Mail API to forward data |
vsupacha | 3:e38819a2b38c | 16 | |
vsupacha | 3:e38819a2b38c | 17 | /** |
vsupacha | 3:e38819a2b38c | 18 | * @brief ISR code: reception of XBee API frame |
vsupacha | 3:e38819a2b38c | 19 | */ |
vsupacha | 3:e38819a2b38c | 20 | void rxHandler() { |
vsupacha | 3:e38819a2b38c | 21 | char *mail = mbx.alloc(); |
vsupacha | 3:e38819a2b38c | 22 | *mail = pc.getc(); |
vsupacha | 3:e38819a2b38c | 23 | mbx.put(mail); |
vsupacha | 3:e38819a2b38c | 24 | } |
vsupacha | 3:e38819a2b38c | 25 | |
vsupacha | 3:e38819a2b38c | 26 | |
vsupacha | 3:e38819a2b38c | 27 | /** |
vsupacha | 3:e38819a2b38c | 28 | * @brief Main code: initial serial RX handler, then wait for detected frame |
vsupacha | 3:e38819a2b38c | 29 | */ |
vsupacha | 0:aefb68fd2505 | 30 | int main() { |
3ecauz | 7:d702abfe51e3 | 31 | pc.attach(rxHandler); |
3ecauz | 7:d702abfe51e3 | 32 | sensor.start(sensorIn); |
vsupacha | 0:aefb68fd2505 | 33 | while (true) { |
vsupacha | 3:e38819a2b38c | 34 | osEvent evt = mbx.get(); |
vsupacha | 3:e38819a2b38c | 35 | if (evt.status == osEventMail) { |
vsupacha | 4:3aaedd16c77b | 36 | char *mail = (char*)evt.value.p; |
vsupacha | 3:e38819a2b38c | 37 | pc.printf("Got %c\n", *mail); |
vsupacha | 3:e38819a2b38c | 38 | mbx.free(mail); |
vsupacha | 3:e38819a2b38c | 39 | } |
vsupacha | 0:aefb68fd2505 | 40 | } |
vsupacha | 0:aefb68fd2505 | 41 | } |
vsupacha | 0:aefb68fd2505 | 42 |