Emulate 「Serial」of Arduino library for mbed. We can easily port arduino's project into mbed by this library.
Dependents: MPU6050 MPU9150 MPU6050 MPU6050 ... more
Revision 0:35db472ea9e6, committed 2016-01-31
- Comitter:
- syundo0730
- Date:
- Sun Jan 31 09:11:43 2016 +0000
- Child:
- 1:e5a32ea3587b
- Commit message:
- first commit
Changed in this revision
ArduinoSerial.h | Show annotated file Show diff for this revision Revisions of this file |
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ArduinoSerial.h Sun Jan 31 09:11:43 2016 +0000 @@ -0,0 +1,42 @@ +#ifndef _ARDUINO_SERIAL_H_ +#define _ARDUINO_SERIAL_H_ + +#include "mbed.h" + +enum Format { BIN, OCT, DEC, HEX }; + +class ArduinoSerial +{ +public: + ArduinoSerial() : serial(USBTX, USBRX) {} + ArduinoSerial(PinName tx, PinName rx) : serial(tx, rx) {} + +private: + Serial serial; + +public: + template <typename T> + void inline print(T x, Format fmt = BIN) { + if(fmt == OCT) { + serial.printf("%o", x); + } else if (fmt == DEC) { + serial.printf("%d", x); + } else if (fmt == HEX) { + serial.printf("%x", x); + } else { + serial.printf("We aren't supporting this format: %d", x); + } + } + + void inline print(const char* x) { + serial.printf("%s", x); + } + + template <typename T> + void inline println(T x, Format fmt = BIN) { + ArduinoSerial::print(x, fmt); + serial.printf("\r\n"); + } +}; + +#endif /* _ARDUINO_SERIAL_H_ */ \ No newline at end of file