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

Revision:
1:75bb445594e2
Parent:
0:a4ddaf82d43d
Child:
2:931bef8c7fac
--- a/HC05.h	Wed Sep 02 06:23:22 2015 +0000
+++ b/HC05.h	Thu Oct 01 04:40:15 2015 +0000
@@ -7,19 +7,9 @@
 /**     Bluetooth module HC05 control class.
  *
  */
-class HC05
+class HC05 : public Stream
 {
 public:
-/*
-//    static const int
-    static const int NG, OK;//=                  1;
-    static const int ERR_AddrUnder12, ERR_AddrOver12, ERR_Connect, FAIL_Connect;
-    static const int ERR_EnterCmdMode, ERR_Disconnect;
-    
-//    static const int None, Odd, Even;
-    static const int ERR_NameSize;
-*/
-
 
     /** Create Serial port to HC05.
      *  @param TX, RX;              Serial port.
@@ -28,38 +18,48 @@
      *                              -- 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, 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 getLine();
     string read();
+    bool readable();
 
-//    void sendCMD( string str, bool addCR=true);
     void sendLine(string str, bool addCR=true);
-//    void sendFloat(float num, int base=10, string foreword="");
     void sendFloat(float num, string foreword="");
     void sendInt(int num, string foreword="");
-    
-//    int setDev_Name(string str, bool usingAddr=true);
+    /*
+    name.attach(fptr, type);
+
+    fptr: 割り込み処理ルーチンのアドレス
 
-//    int setDev_UART(int boad, int stop=1, int parity=SerialBase::None);
-//    void setResetPin(PinName pin);
+    type    備考
+    Serial::RxIrq   受信割り込み
+    Serial::TxIrq   送信バッファ空き割り込み
+    Class中での利用
+
+    name.attach(&this, T::mptr, type);
+    */
 
     void reset();
 
 private:
     Serial hc05;
     string CR;
-//    string rxStr;//, str4GetLine;      // 内部バッファ。read()での保管用と、GetLineまでの保管用。
 
-    DigitalOut resetPin;//HC05(dp17);  // reset for HC05
-
-
-    /** Just copy to rxStr from Buffer.
-    *
-    */
-//    void read();
+    // virtual func for printf() in Stream-class.
+    virtual int _putc(int val);
+    virtual int _getc();
 
 };
\ No newline at end of file