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

HC05.h

Committer:
AkinoriHashimoto
Date:
2015-11-02
Revision:
4:488e26ebc411
Parent:
3:df094ed45a88
Child:
5:a05c7662c51f

File content as of revision 4:488e26ebc411:

#pragma once

/**
 * @code


 * @endcode
*/

#include "mbed.h"
#include <string>
#include "RingBuffer.h"

/**     Bluetooth module HC05 control class.
 *
 */
class HC05 : public Stream
{
public:
    /** Create Serial port to HC05.
     *  @param TX, RX;              Serial port.
     */
    HC05(PinName tx, PinName rx);

    /** 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= 115200, int bit=8, int parity=SerialBase::None, int stop=1, bool CRLN=true);


    void setAttachRx(void (*fptr)(char));
    bool readable();
    string read();
    string getLine();

    void sendLine(string str, bool addCR=true);
//    void sendFloat(float num, string foreword="");    // to use printf()
//    void sendInt(int num, string foreword="");

private:
    RawSerial hc05;
    string CR;
//    string rxStr;
    RingBuffer ringBuf;

    // RxIrq function pointer as out of class.
    void (*fptrRxIrq)(char);

    // copy buf of rx to private string.
    void _read();   // copy buf of rx to private string.
    void _readIrq();   // copy buf of rx to private string.

    // virtual func for printf() in Stream-class.
    virtual int _putc(int val);
    virtual int _getc();

};

// EOF