Course project for LE484 at Thammasat University, class of 2016

main.cpp

Committer:
3ecauz
Date:
2017-05-08
Revision:
10:25704cab4585
Parent:
7:d702abfe51e3
Child:
12:845639da2f03

File content as of revision 10:25704cab4585:

/**
* @brief        Main loop: XBee protocol handler
* @author       Supachai Vorapojpisut,Vissarut Prakobpon , Natanich Bunsila
* @date         May 8, 2017
*/

#include "mbed.h"
#include "platform.h"


Thread sensorThread;


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);
    sensorThread.start(sensorIn);    
    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);
        }
    }
}