Supachai Vorapojpisut
/
le484_2016
Course project for LE484 at Thammasat University, class of 2016
Diff: main.cpp
- Revision:
- 3:e38819a2b38c
- Parent:
- 2:d117505b89ce
- Child:
- 4:3aaedd16c77b
diff -r d117505b89ce -r e38819a2b38c main.cpp --- a/main.cpp Mon May 08 03:49:55 2017 +0000 +++ b/main.cpp Mon May 08 04:05:24 2017 +0000 @@ -8,11 +8,31 @@ DigitalOut led1(LED1); -// main() runs in its own thread in the OS +RawSerial pc(USBTX, USBRX); // use USB-serial for testing purpose +Mail<char, 2> mbx; // use Mail API to forward data + +/** +* @brief ISR code: reception of XBee API frame +*/ +void rxHandler() { + char *mail = mbx.alloc(); + *mail = pc.getc(); + mbx.put(mail); +} + + +/** +* @brief Main code: initial serial RX handler, then wait for detected frame +*/ int main() { + pc.attach(rxHandler); while (true) { - led1 = !led1; - wait(0.5); + osEvent evt = mbx.get(); + if (evt.status == osEventMail) { + char *mail = (mail_t*)evt.value.p; + pc.printf("Got %c\n", *mail); + mbx.free(mail); + } } }