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
HC05.h@0:a4ddaf82d43d, 2015-09-02 (annotated)
- Committer:
- AkinoriHashimoto
- Date:
- Wed Sep 02 06:23:22 2015 +0000
- Revision:
- 0:a4ddaf82d43d
- Child:
- 1:75bb445594e2
15/09/02
Who changed what in which revision?
User | Revision | Line number | New 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 | 0:a4ddaf82d43d | 10 | class HC05 |
AkinoriHashimoto | 0:a4ddaf82d43d | 11 | { |
AkinoriHashimoto | 0:a4ddaf82d43d | 12 | public: |
AkinoriHashimoto | 0:a4ddaf82d43d | 13 | /* |
AkinoriHashimoto | 0:a4ddaf82d43d | 14 | // static const int |
AkinoriHashimoto | 0:a4ddaf82d43d | 15 | static const int NG, OK;//= 1; |
AkinoriHashimoto | 0:a4ddaf82d43d | 16 | static const int ERR_AddrUnder12, ERR_AddrOver12, ERR_Connect, FAIL_Connect; |
AkinoriHashimoto | 0:a4ddaf82d43d | 17 | static const int ERR_EnterCmdMode, ERR_Disconnect; |
AkinoriHashimoto | 0:a4ddaf82d43d | 18 | |
AkinoriHashimoto | 0:a4ddaf82d43d | 19 | // static const int None, Odd, Even; |
AkinoriHashimoto | 0:a4ddaf82d43d | 20 | static const int ERR_NameSize; |
AkinoriHashimoto | 0:a4ddaf82d43d | 21 | */ |
AkinoriHashimoto | 0:a4ddaf82d43d | 22 | |
AkinoriHashimoto | 0:a4ddaf82d43d | 23 | |
AkinoriHashimoto | 0:a4ddaf82d43d | 24 | /** Create Serial port to HC05. |
AkinoriHashimoto | 0:a4ddaf82d43d | 25 | * @param TX, RX; Serial port. |
AkinoriHashimoto | 0:a4ddaf82d43d | 26 | * @param baud-rate; Baud rate (bps). |
AkinoriHashimoto | 0:a4ddaf82d43d | 27 | * @param bit, parity, stop; Default: 1Stopbit, NoneParity, 1StopBit. |
AkinoriHashimoto | 0:a4ddaf82d43d | 28 | * -- parity select; N(None), O(Odd), E(Even). |
AkinoriHashimoto | 0:a4ddaf82d43d | 29 | * @param CRLN; true -> CR&LN (\r\n), false -> CR only (\r). |
AkinoriHashimoto | 0:a4ddaf82d43d | 30 | */ |
AkinoriHashimoto | 0:a4ddaf82d43d | 31 | HC05(PinName TX, PinName RX, int baudrate, PinName _resetPin=dp17, 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 getLine(); |
AkinoriHashimoto | 0:a4ddaf82d43d | 37 | string read(); |
AkinoriHashimoto | 0:a4ddaf82d43d | 38 | |
AkinoriHashimoto | 0:a4ddaf82d43d | 39 | // void sendCMD( string str, bool addCR=true); |
AkinoriHashimoto | 0:a4ddaf82d43d | 40 | void sendLine(string str, bool addCR=true); |
AkinoriHashimoto | 0:a4ddaf82d43d | 41 | // void sendFloat(float num, int base=10, string foreword=""); |
AkinoriHashimoto | 0:a4ddaf82d43d | 42 | void sendFloat(float num, string foreword=""); |
AkinoriHashimoto | 0:a4ddaf82d43d | 43 | void sendInt(int num, string foreword=""); |
AkinoriHashimoto | 0:a4ddaf82d43d | 44 | |
AkinoriHashimoto | 0:a4ddaf82d43d | 45 | // int setDev_Name(string str, bool usingAddr=true); |
AkinoriHashimoto | 0:a4ddaf82d43d | 46 | |
AkinoriHashimoto | 0:a4ddaf82d43d | 47 | // int setDev_UART(int boad, int stop=1, int parity=SerialBase::None); |
AkinoriHashimoto | 0:a4ddaf82d43d | 48 | // void setResetPin(PinName pin); |
AkinoriHashimoto | 0:a4ddaf82d43d | 49 | |
AkinoriHashimoto | 0:a4ddaf82d43d | 50 | void reset(); |
AkinoriHashimoto | 0:a4ddaf82d43d | 51 | |
AkinoriHashimoto | 0:a4ddaf82d43d | 52 | private: |
AkinoriHashimoto | 0:a4ddaf82d43d | 53 | Serial hc05; |
AkinoriHashimoto | 0:a4ddaf82d43d | 54 | string CR; |
AkinoriHashimoto | 0:a4ddaf82d43d | 55 | // string rxStr;//, str4GetLine; // 内部バッファ。read()での保管用と、GetLineまでの保管用。 |
AkinoriHashimoto | 0:a4ddaf82d43d | 56 | |
AkinoriHashimoto | 0:a4ddaf82d43d | 57 | DigitalOut resetPin;//HC05(dp17); // reset for HC05 |
AkinoriHashimoto | 0:a4ddaf82d43d | 58 | |
AkinoriHashimoto | 0:a4ddaf82d43d | 59 | |
AkinoriHashimoto | 0:a4ddaf82d43d | 60 | /** Just copy to rxStr from Buffer. |
AkinoriHashimoto | 0:a4ddaf82d43d | 61 | * |
AkinoriHashimoto | 0:a4ddaf82d43d | 62 | */ |
AkinoriHashimoto | 0:a4ddaf82d43d | 63 | // void read(); |
AkinoriHashimoto | 0:a4ddaf82d43d | 64 | |
AkinoriHashimoto | 0:a4ddaf82d43d | 65 | }; |