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

Dependents:   semaforinoprova

Revision:
6:2eefa9ea0bf1
Parent:
5:a05c7662c51f
--- a/HC05.cpp	Mon Nov 02 07:22:50 2015 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,114 +0,0 @@
-#include "HC05.h"
-
-HC05::HC05(PinName TX, PinName RX)
-    : hc05(TX, RX)
-{
-}
-void HC05::init(int baudrate, int bit, int parity, int stop, bool CRLN)
-{
-    hc05.baud(baudrate);
-
-    // 力技
-    if      (parity == SerialBase::Odd)
-        hc05.format(bit, SerialBase::Odd,  stop);
-    else if (parity == SerialBase::Even)
-        hc05.format(bit, SerialBase::Even, stop);     // 8bit, NonParity, 1stopbit
-    else// if (parity == SerialBase::None)
-        hc05.format(bit, SerialBase::None, stop);     // 8bit, NonParity, 1stopbit
-
-    // attach rxIrq. because, rx buf of serial equals to 16 Bytes.
-    this->hc05.attach(this, &HC05::_readIrq, Serial::RxIrq);
-
-    CR= '\r';
-    if(CRLN)
-        CR= "\r\n";
-    return;
-}
-
-void HC05::setAttachRx(void (*fptr)(char))
-{
-    // Serial.attachから呼ばれる_readIrq()内から、fptrをCall.
-    fptrRxIrq= fptr;
-    return;
-}
-
-bool HC05::readable()
-{
-    return hc05.readable() || !ringBuf.empty();
-}
-
-string HC05::read() // public:
-{
-    _read();
-    if(ringBuf.empty())
-        return "";
-    return ringBuf.get();
-}
-
-string HC05::getLine()
-{
-    string tmp= this->read();
-    if(tmp.empty())
-        return "";
-
-    // tmp is not empty.
-    int idx= tmp.rfind('\r');
-    if(idx == string::npos) {
-        ringBuf.set(tmp);   // 戻す
-        return "";
-    }
-
-    // find \r
-    if(tmp[++idx] == '\n')
-        idx++;
-
-    // idxは改行後の文字先頭Indexを示す。
-    string rtn= tmp.substr(0, idx);
-    tmp= tmp.substr(idx);
-    ringBuf.set(tmp);
-    return rtn;
-}
-
-void HC05::sendLine(string str, bool addCR)
-{
-    if(addCR)
-        str += "\r\n";
-    hc05.printf(str.c_str());
-    return;
-}
-
-int HC05::_putc(int val)     // for printf()
-{
-    hc05.putc(val);
-    return val;
-}
-
-int HC05::_getc()       // for "Stream"
-{
-    return -1;//hc05.getc();
-}
-
-// Internal READ()
-void HC05::_readIrq(void)
-{
-    if(!hc05.readable())
-        return;
-
-    char chr= hc05.getc();
-    ringBuf.set(chr);
-
-    if(this->fptrRxIrq == NULL)
-        return;
-    fptrRxIrq(chr);
-
-    return;
-}
-void HC05::_read()
-{
-    // Bufferを吸い尽くす
-    while(hc05.readable())
-        ringBuf.set((char)hc05.getc());
-    return;         // Bufferになくなった
-}
-
-// EOF
\ No newline at end of file