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').

Dependencies:   RingBuffer

Fork of HC05 by Akinori Hashimoto

Committer:
AkinoriHashimoto
Date:
Thu Oct 01 04:40:15 2015 +0000
Revision:
1:75bb445594e2
Parent:
0:a4ddaf82d43d
Child:
2:931bef8c7fac
1st publish.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
AkinoriHashimoto 0:a4ddaf82d43d 1 #pragma once
AkinoriHashimoto 0:a4ddaf82d43d 2
AkinoriHashimoto 0:a4ddaf82d43d 3 #include "mbed.h"
AkinoriHashimoto 0:a4ddaf82d43d 4 #include <string>
AkinoriHashimoto 0:a4ddaf82d43d 5
AkinoriHashimoto 0:a4ddaf82d43d 6
AkinoriHashimoto 0:a4ddaf82d43d 7 /** Bluetooth module HC05 control class.
AkinoriHashimoto 0:a4ddaf82d43d 8 *
AkinoriHashimoto 0:a4ddaf82d43d 9 */
AkinoriHashimoto 1:75bb445594e2 10 class HC05 : public Stream
AkinoriHashimoto 0:a4ddaf82d43d 11 {
AkinoriHashimoto 0:a4ddaf82d43d 12 public:
AkinoriHashimoto 0:a4ddaf82d43d 13
AkinoriHashimoto 0:a4ddaf82d43d 14 /** Create Serial port to HC05.
AkinoriHashimoto 0:a4ddaf82d43d 15 * @param TX, RX; Serial port.
AkinoriHashimoto 0:a4ddaf82d43d 16 * @param baud-rate; Baud rate (bps).
AkinoriHashimoto 0:a4ddaf82d43d 17 * @param bit, parity, stop; Default: 1Stopbit, NoneParity, 1StopBit.
AkinoriHashimoto 0:a4ddaf82d43d 18 * -- parity select; N(None), O(Odd), E(Even).
AkinoriHashimoto 0:a4ddaf82d43d 19 * @param CRLN; true -> CR&LN (\r\n), false -> CR only (\r).
AkinoriHashimoto 0:a4ddaf82d43d 20 */
AkinoriHashimoto 1:75bb445594e2 21 // HC05(PinName TX, PinName RX, int baudrate, PinName _resetPin=dp17, int bit=8, int parity=SerialBase::None, int stop=1, bool CRLN=true);
AkinoriHashimoto 1:75bb445594e2 22 HC05(PinName tx, PinName rx);
AkinoriHashimoto 1:75bb445594e2 23 // HC05(Serial &_serial);
AkinoriHashimoto 1:75bb445594e2 24
AkinoriHashimoto 1:75bb445594e2 25 /** init
AkinoriHashimoto 1:75bb445594e2 26 * @param baud-rate; Baud rate (bps). 9600, 38,400, 115,200, 230,400
AkinoriHashimoto 1:75bb445594e2 27 * @param bit, parity, stop; Default: 1Stopbit, NoneParity, 1StopBit.
AkinoriHashimoto 1:75bb445594e2 28 * -- parity select; N(None), O(Odd), E(Even).
AkinoriHashimoto 1:75bb445594e2 29 * @param CRLN; true -> CR&LN (\r\n), false -> CR only (\r).
AkinoriHashimoto 1:75bb445594e2 30 */
AkinoriHashimoto 1:75bb445594e2 31 void init(int baudrate, int bit=8, int parity=SerialBase::None, int stop=1, bool CRLN=true);
AkinoriHashimoto 0:a4ddaf82d43d 32
AkinoriHashimoto 0:a4ddaf82d43d 33 /**
AkinoriHashimoto 0:a4ddaf82d43d 34 * RxStrのCRまでを返す。
AkinoriHashimoto 0:a4ddaf82d43d 35 */
AkinoriHashimoto 0:a4ddaf82d43d 36 string read();
AkinoriHashimoto 1:75bb445594e2 37 bool readable();
AkinoriHashimoto 0:a4ddaf82d43d 38
AkinoriHashimoto 0:a4ddaf82d43d 39 void sendLine(string str, bool addCR=true);
AkinoriHashimoto 0:a4ddaf82d43d 40 void sendFloat(float num, string foreword="");
AkinoriHashimoto 0:a4ddaf82d43d 41 void sendInt(int num, string foreword="");
AkinoriHashimoto 1:75bb445594e2 42 /*
AkinoriHashimoto 1:75bb445594e2 43 name.attach(fptr, type);
AkinoriHashimoto 1:75bb445594e2 44
AkinoriHashimoto 1:75bb445594e2 45 fptr: 割り込み処理ルーチンのアドレス
AkinoriHashimoto 0:a4ddaf82d43d 46
AkinoriHashimoto 1:75bb445594e2 47 type 備考
AkinoriHashimoto 1:75bb445594e2 48 Serial::RxIrq 受信割り込み
AkinoriHashimoto 1:75bb445594e2 49 Serial::TxIrq 送信バッファ空き割り込み
AkinoriHashimoto 1:75bb445594e2 50 Class中での利用
AkinoriHashimoto 1:75bb445594e2 51
AkinoriHashimoto 1:75bb445594e2 52 name.attach(&this, T::mptr, type);
AkinoriHashimoto 1:75bb445594e2 53 */
AkinoriHashimoto 0:a4ddaf82d43d 54
AkinoriHashimoto 0:a4ddaf82d43d 55 void reset();
AkinoriHashimoto 0:a4ddaf82d43d 56
AkinoriHashimoto 0:a4ddaf82d43d 57 private:
AkinoriHashimoto 0:a4ddaf82d43d 58 Serial hc05;
AkinoriHashimoto 0:a4ddaf82d43d 59 string CR;
AkinoriHashimoto 0:a4ddaf82d43d 60
AkinoriHashimoto 1:75bb445594e2 61 // virtual func for printf() in Stream-class.
AkinoriHashimoto 1:75bb445594e2 62 virtual int _putc(int val);
AkinoriHashimoto 1:75bb445594e2 63 virtual int _getc();
AkinoriHashimoto 0:a4ddaf82d43d 64
AkinoriHashimoto 0:a4ddaf82d43d 65 };