add sensor service notify callback

This commit is contained in:
hathach committed 2020-03-06 21:00:16 +07:00
1 parent e87d1de07e
commit 8097e50f1d
5 files changed
+22 -7

No files matched your search

@@ -31,8 +31,9 @@
BLEAdafruitSensor::BLEAdafruitSensor(BLEUuid service_uuid, BLEUuid data_uuid)
: BLEService(service_uuid), _measurement(data_uuid), _period(UUID128_CHR_ADAFRUIT_MEASUREMENT_PERIOD)
{
_measure_cb = NULL;
_sensor = NULL;
_measure_cb = NULL;
_notify_cb = NULL;
}
err_t BLEAdafruitSensor::_begin(int32_t ms)
@@ -76,10 +77,15 @@ void BLEAdafruitSensor::setPeriod(int32_t period_ms)
_update_timer(period_ms);
}
void BLEAdafruitSensor::setNotifyCallback(notify_callback_t fp)
{
_notify_cb = fp;
}
//--------------------------------------------------------------------+
// Internal API
//--------------------------------------------------------------------+
void BLEAdafruitSensor::_notify_cb(uint16_t conn_hdl, uint16_t value)
void BLEAdafruitSensor::_notify_handler(uint16_t conn_hdl, uint16_t value)
{
// notify enabled
if (value & BLE_GATT_HVX_NOTIFICATION)
@@ -90,6 +96,9 @@ void BLEAdafruitSensor::_notify_cb(uint16_t conn_hdl, uint16_t value)
_timer.stop();
}
// invoke callback if any
if (_notify_cb) _notify_cb(conn_hdl, value);
// send initial notification if period = 0
// if ( 0 == svc._period.read32() )
// {
@@ -178,6 +187,6 @@ void BLEAdafruitSensor::sensor_data_cccd_cb(uint16_t conn_hdl, BLECharacteristic
{
BLEAdafruitSensor* svc = (BLEAdafruitSensor*) &chr->parentService();
svc->_notify_cb(conn_hdl, value);
svc->_notify_handler(conn_hdl, value);
}