wrap up discovery

This commit is contained in:
hathach committed 2017-03-30 00:09:20 +07:00
1 parent 6d79f0106e
commit d5a8e8a738
5 files changed
+25 -5

No files matched your search

@@ -113,7 +113,12 @@ void loop()
// Get Serial input and send to Peripheral
if ( Serial.available() )
{
bleCentralUart.write( (char) Serial.read() );
delay(2); // delay a bit for all characters to arrive
char str[20+1] = { 0 };
Serial.readBytes(str, 20);
bleCentralUart.print( str );
}
}
}
+2 -1
View File
@@ -70,7 +70,8 @@ BLECentral::BLECentral(void)
void BLECentral::begin(void)
{
// Central will very likely use Discovery
Bluefruit.Discovery.begin();
}
bool BLECentral::_registerService(BLECentralService* svc)
+11 -1
View File
@@ -50,7 +50,15 @@ BLEDiscovery::BLEDiscovery(void)
void BLEDiscovery::begin(void)
{
_evt_sem = xSemaphoreCreateBinary();
if (_evt_sem == NULL)
{
_evt_sem = xSemaphoreCreateBinary();
}
}
bool BLEDiscovery::begun(void)
{
return (_evt_sem != NULL);
}
bool BLEDiscovery::discoverService(uint16_t conn_handle, BLECentralService& svc, uint16_t start_handle)
@@ -223,6 +231,8 @@ void BLEDiscovery::_event_handler(ble_evt_t* evt)
xSemaphoreGive(_evt_sem);
}
break;
default: break;
}
}
+3 -2
View File
@@ -57,13 +57,14 @@ class BLEDiscovery
public:
BLEDiscovery(void);
void begin(void);
void begin(void);
bool begun(void);
bool discoverService(uint16_t conn_handle, BLECentralService& svc, uint16_t start_handle = 1);
uint8_t discoverCharacteristic(uint16_t conn_handle, BLECentralCharacteristic* chr[], uint8_t count);
uint16_t _discoverDescriptor(uint16_t conn_handle, ble_gattc_evt_desc_disc_rsp_t* disc_desc, uint16_t max_count);
friend class AdafruitBluefruit;
friend class BLECentral;
};
#endif /* BLEDISCOVERY_H_ */
@@ -683,6 +683,9 @@ void AdafruitBluefruit::_ble_handler(ble_evt_t* evt)
// Central Event Handler
if (_central_enabled) Central._event_handler(evt);
// Discovery Event Handler
if ( Discovery.begun() ) Discovery._event_handler(evt);
// GATTs characteristics event handler
for(int i=0; i<_chars_count; i++)
{