Course project for LE484 at Thammasat University, class of 2016

Revision:
12:845639da2f03
Parent:
11:8b9668e37646
Parent:
10:25704cab4585
--- a/main.cpp	Mon May 08 05:06:11 2017 +0000
+++ b/main.cpp	Mon May 08 05:11:22 2017 +0000
@@ -10,24 +10,36 @@
 
 RawSerial pc(USBTX, USBRX);  // use USB-serial for testing purpose
 Mail<char, 2> mbx;  // use Mail API to forward data
-Thread ledThred;
+Thread sensorThread;
+Thread ledThread;
 
 
 /**
 * @brief        ISR code: reception of XBee API frame
 */
-void rxHandler() {
-    char *mail = mbx.alloc(); 
+void rxHandler()
+{
+    char *mail = mbx.alloc();
     *mail = pc.getc();
     mbx.put(mail);
 }
 
 
 /**
-* @brief        Main code: initial serial RX handler, then wait for detected frame 
+* @brief        Main code: initial serial RX handler, then wait for detected frame
 */
-int main() {
-     ledThread.start(led1_thread);
-    while(1);
+int main()
+{
+    ledThread.start(led1_thread);
+    sensorThread.start(sensorIn);
+    pc.attach(rxHandler);
+    while (true) {
+        osEvent evt = mbx.get();
+        if (evt.status == osEventMail) {
+            char *mail = (char*)evt.value.p;
+            pc.printf("Got %c\n", *mail);
+            mbx.free(mail);
+        }
+    }
 }