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:
Mon Nov 02 07:19:11 2015 +0000
Revision:
4:488e26ebc411
Parent:
3:df094ed45a88
Child:
5:a05c7662c51f
Include Ring Buffer for with using RTOS.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
AkinoriHashimoto 0:a4ddaf82d43d 1 #pragma once
AkinoriHashimoto 0:a4ddaf82d43d 2
AkinoriHashimoto 3:df094ed45a88 3 /**
AkinoriHashimoto 3:df094ed45a88 4 * @code
AkinoriHashimoto 3:df094ed45a88 5
AkinoriHashimoto 3:df094ed45a88 6
AkinoriHashimoto 3:df094ed45a88 7 * @endcode
AkinoriHashimoto 2:931bef8c7fac 8 */
AkinoriHashimoto 2:931bef8c7fac 9
AkinoriHashimoto 0:a4ddaf82d43d 10 #include "mbed.h"
AkinoriHashimoto 0:a4ddaf82d43d 11 #include <string>
AkinoriHashimoto 4:488e26ebc411 12 #include "RingBuffer.h"
AkinoriHashimoto 0:a4ddaf82d43d 13
AkinoriHashimoto 0:a4ddaf82d43d 14 /** Bluetooth module HC05 control class.
AkinoriHashimoto 0:a4ddaf82d43d 15 *
AkinoriHashimoto 0:a4ddaf82d43d 16 */
AkinoriHashimoto 1:75bb445594e2 17 class HC05 : public Stream
AkinoriHashimoto 0:a4ddaf82d43d 18 {
AkinoriHashimoto 0:a4ddaf82d43d 19 public:
AkinoriHashimoto 0:a4ddaf82d43d 20 /** Create Serial port to HC05.
AkinoriHashimoto 0:a4ddaf82d43d 21 * @param TX, RX; Serial port.
AkinoriHashimoto 0:a4ddaf82d43d 22 */
AkinoriHashimoto 1:75bb445594e2 23 HC05(PinName tx, PinName rx);
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 2:931bef8c7fac 31 void init(int baudrate= 115200, int bit=8, int parity=SerialBase::None, int stop=1, bool CRLN=true);
AkinoriHashimoto 0:a4ddaf82d43d 32
AkinoriHashimoto 3:df094ed45a88 33
AkinoriHashimoto 4:488e26ebc411 34 void setAttachRx(void (*fptr)(char));
AkinoriHashimoto 1:75bb445594e2 35 bool readable();
AkinoriHashimoto 3:df094ed45a88 36 string read();
AkinoriHashimoto 2:931bef8c7fac 37 string getLine();
AkinoriHashimoto 3:df094ed45a88 38
AkinoriHashimoto 0:a4ddaf82d43d 39 void sendLine(string str, bool addCR=true);
AkinoriHashimoto 3:df094ed45a88 40 // void sendFloat(float num, string foreword=""); // to use printf()
AkinoriHashimoto 3:df094ed45a88 41 // void sendInt(int num, string foreword="");
AkinoriHashimoto 0:a4ddaf82d43d 42
AkinoriHashimoto 0:a4ddaf82d43d 43 private:
AkinoriHashimoto 4:488e26ebc411 44 RawSerial hc05;
AkinoriHashimoto 0:a4ddaf82d43d 45 string CR;
AkinoriHashimoto 4:488e26ebc411 46 // string rxStr;
AkinoriHashimoto 4:488e26ebc411 47 RingBuffer ringBuf;
AkinoriHashimoto 3:df094ed45a88 48
AkinoriHashimoto 3:df094ed45a88 49 // RxIrq function pointer as out of class.
AkinoriHashimoto 4:488e26ebc411 50 void (*fptrRxIrq)(char);
AkinoriHashimoto 3:df094ed45a88 51
AkinoriHashimoto 3:df094ed45a88 52 // copy buf of rx to private string.
AkinoriHashimoto 3:df094ed45a88 53 void _read(); // copy buf of rx to private string.
AkinoriHashimoto 3:df094ed45a88 54 void _readIrq(); // copy buf of rx to private string.
AkinoriHashimoto 0:a4ddaf82d43d 55
AkinoriHashimoto 1:75bb445594e2 56 // virtual func for printf() in Stream-class.
AkinoriHashimoto 1:75bb445594e2 57 virtual int _putc(int val);
AkinoriHashimoto 1:75bb445594e2 58 virtual int _getc();
AkinoriHashimoto 0:a4ddaf82d43d 59
AkinoriHashimoto 2:931bef8c7fac 60 };
AkinoriHashimoto 2:931bef8c7fac 61
AkinoriHashimoto 2:931bef8c7fac 62 // EOF