complete central uart read/write
This commit is contained in:
1 parent
dade06c68a
commit
3966c7be89
4 files changed
+19
-4
No files matched your search
@@ -12,6 +12,10 @@
|
||||
any redistribution
|
||||
*********************************************************************/
|
||||
|
||||
/*
|
||||
* This sketch demonstrate the central API(). A additional bluefruit
|
||||
* that has bleuart as peripheral is required for the demo.
|
||||
*/
|
||||
#include <bluefruit.h>
|
||||
|
||||
BLECentralUart bleCentralUart;
|
||||
@@ -21,7 +25,8 @@ void setup()
|
||||
Serial.begin(115200);
|
||||
|
||||
Serial.println("Bluefruit52 Central BLEUART Example");
|
||||
|
||||
Serial.println("-----------------------------------");
|
||||
|
||||
// up to 1 peripheral conn and 1 central conn
|
||||
Bluefruit.begin(true, true);
|
||||
Bluefruit.setName("Bluefruit52");
|
||||
@@ -85,6 +90,7 @@ void loop()
|
||||
{
|
||||
if ( Bluefruit.Central.connected() )
|
||||
{
|
||||
// Not discovered yet
|
||||
if ( !bleCentralUart.discovered() )
|
||||
{
|
||||
Serial.print("Discovering BLE Uart Service ... ");
|
||||
@@ -103,7 +109,12 @@ void loop()
|
||||
}
|
||||
}else
|
||||
{
|
||||
// do nothing
|
||||
// Discovered means in working state
|
||||
// Get Serial input and send to Peripheral
|
||||
if ( Serial.available() )
|
||||
{
|
||||
bleCentralUart.write( (char) Serial.read() );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -399,6 +399,9 @@ void BLECentral::_event_handler(ble_evt_t* evt)
|
||||
vSemaphoreDelete(_txpacket_sem);
|
||||
_txpacket_sem = NULL;
|
||||
|
||||
// disconnect all registered services
|
||||
for(uint8_t i=0; i<_svc_count; i++) _svc_list[i]->disconnect();
|
||||
|
||||
if ( _disconnect_cb ) _disconnect_cb(evt->evt.gap_evt.params.disconnected.reason);
|
||||
|
||||
startScanning();
|
||||
|
||||
@@ -45,6 +45,7 @@ class BLECentralService
|
||||
bool _discovered;
|
||||
|
||||
void _init(void);
|
||||
virtual void disconnect(void);
|
||||
|
||||
public:
|
||||
static BLECentralService* lastService;
|
||||
@@ -58,7 +59,6 @@ class BLECentralService
|
||||
|
||||
virtual bool discover (void);
|
||||
bool discovered(void);
|
||||
virtual void disconnect(void);
|
||||
|
||||
friend class BLECentral;
|
||||
};
|
||||
|
||||
@@ -53,7 +53,6 @@ class BLECentralUart : public BLECentralService, public Stream
|
||||
|
||||
virtual bool begin(void);
|
||||
virtual bool discover(void);
|
||||
virtual void disconnect(void);
|
||||
|
||||
bool enableNotify(void);
|
||||
void setRxCallback( rx_callback_t fp);
|
||||
@@ -70,6 +69,8 @@ class BLECentralUart : public BLECentralService, public Stream
|
||||
// pull in write(str) and write(buf, size) from Print
|
||||
using Print::write;
|
||||
|
||||
protected:
|
||||
virtual void disconnect(void);
|
||||
|
||||
private:
|
||||
BLECentralCharacteristic _txd;
|
||||
|
||||
Reference in new issue
Block a user