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').
HC05.h
- Committer:
- AkinoriHashimoto
- Date:
- 2015-10-01
- Revision:
- 1:75bb445594e2
- Parent:
- 0:a4ddaf82d43d
- Child:
- 2:931bef8c7fac
File content as of revision 1:75bb445594e2:
#pragma once #include "mbed.h" #include <string> /** Bluetooth module HC05 control class. * */ class HC05 : public Stream { public: /** 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); HC05(PinName tx, PinName rx); // HC05(Serial &_serial); /** init * @param baud-rate; Baud rate (bps). 9600, 38,400, 115,200, 230,400 * @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). */ void init(int baudrate, int bit=8, int parity=SerialBase::None, int stop=1, bool CRLN=true); /** * RxStrのCRまでを返す。 */ string read(); bool readable(); void sendLine(string str, bool addCR=true); void sendFloat(float num, string foreword=""); void sendInt(int num, string foreword=""); /* name.attach(fptr, type); fptr: 割り込み処理ルーチンのアドレス type 備考 Serial::RxIrq 受信割り込み Serial::TxIrq 送信バッファ空き割り込み Class中での利用 name.attach(&this, T::mptr, type); */ void reset(); private: Serial hc05; string CR; // virtual func for printf() in Stream-class. virtual int _putc(int val); virtual int _getc(); };