Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Revision 12:845639da2f03, committed 2017-05-08
- Comitter:
- vsupacha
- Date:
- Mon May 08 05:11:22 2017 +0000
- Parent:
- 11:8b9668e37646
- Parent:
- 10:25704cab4585
- Commit message:
- Fix wrong code
Changed in this revision
--- 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); + } + } }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp.orig Mon May 08 05:11:22 2017 +0000 @@ -0,0 +1,33 @@ +/** +* @brief Main loop: XBee protocol handler +* @author Supachai Vorapojpisut,Vissarut Prakobpon , Natanich Bunsila +* @date May 8, 2017 +*/ + +#include "mbed.h" +#include "platform.h" + + +RawSerial pc(USBTX, USBRX); // use USB-serial for testing purpose +Mail<char, 2> mbx; // use Mail API to forward data +Thread ledThred; + + +/** +* @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() { + ledThread.start(led1_thread); + while(1); +} +
--- a/platform.h Mon May 08 05:06:11 2017 +0000 +++ b/platform.h Mon May 08 05:11:22 2017 +0000 @@ -1,7 +1,8 @@ #ifndef PLATFORM_H #define PLATFORM_H -void led1_thread(void) +void led1_thread(void); +void sensorIn(void); extern Thread sensorThread; extern Thread ledThread;
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/platform.h.orig Mon May 08 05:11:22 2017 +0000 @@ -0,0 +1,10 @@ +#ifndef PLATFORM_H +#define PLATFORM_H + +void led1_thread(void) + +extern Thread sensorThread; +extern Thread ledThread; + + +#endif \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/sensorTask.cpp Mon May 08 05:11:22 2017 +0000 @@ -0,0 +1,16 @@ +#include "mbed.h" +#include "platform.h" + +AnalogIn analog_value(A0); + +void sensorIn() +{ + float meas; + + while(1) { + meas = analog_value.read(); + meas = meas * 3300; + printf("measure = %.0f mV\n", meas); + + } +}