Bluetooth module HC-05 Lib. suppotrs printf(); support IrqAttach, with using RTOS. include feature as background rxIrq attach. the lib store rx buf of serial, therefore can have over 16 bytes string. if you want to get string, you call read() or getLine(). read() is ALL string, getLine() is under CR('\r').
Fork of HC05 by
Diff: HC05.h
- Revision:
- 5:a05c7662c51f
- Parent:
- 4:488e26ebc411
diff -r 488e26ebc411 -r a05c7662c51f HC05.h --- a/HC05.h Mon Nov 02 07:19:11 2015 +0000 +++ b/HC05.h Mon Nov 02 07:22:50 2015 +0000 @@ -1,12 +1,40 @@ -#pragma once - +/** Bluetooth module HC05 control class with using RTOS. + * + */ /** * @code +#include "mbed.h" +#include "HC05.h" +DigitalOut led[]= {LED1, LED2, LED3, LED4}; +HC05 hc05(p9, p10); +void rcvIrq(char id) +{ + led[0]= !led[0]; + if('2'<=id && id<='4') { // LED2 ~ 4 + id -= '1'; + led[id]= !led[id]; + } + return; +} + +int main() +{ + hc05.init(); + hc05.setAttachRx(rcvIrq); + while(true) { + hc05.sendLine(hc05.read()); +// hc05.sendLine(hc05.getLine()); + wait(10); + } +} +// EOF * @endcode */ +#pragma once + #include "mbed.h" #include <string> #include "RingBuffer.h" @@ -37,21 +65,18 @@ string getLine(); void sendLine(string str, bool addCR=true); -// void sendFloat(float num, string foreword=""); // to use printf() -// void sendInt(int num, string foreword=""); private: RawSerial hc05; string CR; -// string rxStr; RingBuffer ringBuf; // RxIrq function pointer as out of class. void (*fptrRxIrq)(char); // copy buf of rx to private string. - void _read(); // copy buf of rx to private string. - void _readIrq(); // copy buf of rx to private string. + void _read(); // copy buf of rx to private string. + void _readIrq(); // copy buf of rx to private string. // virtual func for printf() in Stream-class. virtual int _putc(int val);