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:
- 0:a4ddaf82d43d
- Child:
- 1:75bb445594e2
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/HC05.h Wed Sep 02 06:23:22 2015 +0000 @@ -0,0 +1,65 @@ +#pragma once + +#include "mbed.h" +#include <string> + + +/** Bluetooth module HC05 control class. + * + */ +class HC05 +{ +public: +/* +// static const int + static const int NG, OK;//= 1; + static const int ERR_AddrUnder12, ERR_AddrOver12, ERR_Connect, FAIL_Connect; + static const int ERR_EnterCmdMode, ERR_Disconnect; + +// static const int None, Odd, Even; + static const int ERR_NameSize; +*/ + + + /** Create Serial port to HC05. + * @param TX, RX; Serial port. + * @param baud-rate; Baud rate (bps). + * @param bit, parity, stop; Default: 1Stopbit, NoneParity, 1StopBit. + * -- parity select; N(None), O(Odd), E(Even). + * @param CRLN; true -> CR&LN (\r\n), false -> CR only (\r). + */ + HC05(PinName TX, PinName RX, int baudrate, PinName _resetPin=dp17, int bit=8, int parity=SerialBase::None, int stop=1, bool CRLN=true); + + /** + * RxStrのCRまでを返す。 + */ +// string getLine(); + string read(); + +// void sendCMD( string str, bool addCR=true); + void sendLine(string str, bool addCR=true); +// void sendFloat(float num, int base=10, string foreword=""); + void sendFloat(float num, string foreword=""); + void sendInt(int num, string foreword=""); + +// int setDev_Name(string str, bool usingAddr=true); + +// int setDev_UART(int boad, int stop=1, int parity=SerialBase::None); +// void setResetPin(PinName pin); + + void reset(); + +private: + Serial hc05; + string CR; +// string rxStr;//, str4GetLine; // 内部バッファ。read()での保管用と、GetLineまでの保管用。 + + DigitalOut resetPin;//HC05(dp17); // reset for HC05 + + + /** Just copy to rxStr from Buffer. + * + */ +// void read(); + +}; \ No newline at end of file