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:
2:931bef8c7fac
Parent:
1:75bb445594e2
Child:
3:df094ed45a88
--- a/HC05.h	Thu Oct 01 04:40:15 2015 +0000
+++ b/HC05.h	Thu Oct 01 07:14:55 2015 +0000
@@ -1,26 +1,47 @@
 #pragma once
 
+/**     Sample code
+ * #include "mbed.h"
+* #include "HC05.h"
+*   // 2,3,4が入力されたら、LED2,3,4が反転するコード。
+* DigitalOut led[]= {LED1, LED2, LED3, LED4};
+* HC05 hc05(p9, p10);
+* void receive()
+* {
+*     int id= hc05.getc() - '1';
+*     if(0<id && id<4)
+*         led[id]= !led[id];
+*     return;
+* }
+* int main()
+* {
+*     hc05.init();
+*     int iter= 0;
+*     hc05.setAttachRx(receive);      // 割り込み
+*     while(1) {
+*         hc05.printf("iter: %3d\r\n", iter);
+* //        if(hc05.readable())       // 0.2s毎に確認
+* //            receive();
+*         led[0] = !led[0];
+*         iter++;
+*         wait(0.2);
+*     }
+* }
+*/
+
 #include "mbed.h"
 #include <string>
 
-
 /**     Bluetooth module HC05 control class.
  *
  */
 class HC05 : public Stream
 {
 public:
-
     /** Create Serial port to HC05.
      *  @param TX, RX;              Serial port.
-     *  @param baud-rate;           Baud rate (bps).
-     *  @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).
      */
-//    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
@@ -28,31 +49,15 @@
      *                              -- 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);
+    void init(int baudrate= 115200, int bit=8, int parity=SerialBase::None, int stop=1, bool CRLN=true);
 
-    /**
-     *      RxStrのCRまでを返す。
-     */
-    string read();
     bool readable();
-
+    void setAttachRx(void (*fptr)(void));
+    
+    string getLine();
     void sendLine(string str, bool addCR=true);
     void sendFloat(float num, string foreword="");
     void sendInt(int num, string foreword="");
-    /*
-    name.attach(fptr, type);
-
-    fptr: 割り込み処理ルーチンのアドレス
-
-    type    備考
-    Serial::RxIrq   受信割り込み
-    Serial::TxIrq   送信バッファ空き割り込み
-    Class中での利用
-
-    name.attach(&this, T::mptr, type);
-    */
-
-    void reset();
 
 private:
     Serial hc05;
@@ -62,4 +67,6 @@
     virtual int _putc(int val);
     virtual int _getc();
 
-};
\ No newline at end of file
+};
+
+// EOF
\ No newline at end of file