add sensor service notify callback
This commit is contained in:
1 parent
e87d1de07e
commit
8097e50f1d
5 files changed
+22
-7
No files matched your search
@@ -95,7 +95,7 @@ void BLEAdafruitQuaternion::setCalibration(Adafruit_Sensor_Calibration* calib)
|
||||
_calib = calib;
|
||||
}
|
||||
|
||||
void BLEAdafruitQuaternion::_notify_cb(uint16_t conn_hdl, uint16_t value)
|
||||
void BLEAdafruitQuaternion::_notify_handler(uint16_t conn_hdl, uint16_t value)
|
||||
{
|
||||
// Start/Stop filter timer
|
||||
if (value & BLE_GATT_HVX_NOTIFICATION)
|
||||
@@ -107,7 +107,7 @@ void BLEAdafruitQuaternion::_notify_cb(uint16_t conn_hdl, uint16_t value)
|
||||
}
|
||||
|
||||
// Call SuperClass function
|
||||
BLEAdafruitSensor::_notify_cb(conn_hdl, value);
|
||||
BLEAdafruitSensor::_notify_handler(conn_hdl, value);
|
||||
}
|
||||
|
||||
void BLEAdafruitQuaternion::_update_timer(int32_t ms)
|
||||
|
||||
@@ -43,7 +43,7 @@ class BLEAdafruitQuaternion : public BLEAdafruitSensor
|
||||
protected:
|
||||
void _update_timer(int32_t ms);
|
||||
void _measure_handler(void);
|
||||
void _notify_cb(uint16_t conn_hdl, uint16_t value);
|
||||
void _notify_handler(uint16_t conn_hdl, uint16_t value);
|
||||
|
||||
void _fitler_update(void);
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -31,6 +31,8 @@ class BLEAdafruitSensor : public BLEService
|
||||
{
|
||||
public:
|
||||
static const int32_t DEFAULT_PERIOD = 1000;
|
||||
|
||||
typedef void (*notify_callback_t)(uint16_t conn_hdl, bool enabled);
|
||||
typedef uint16_t (*measure_callback_t )(uint8_t* buf, uint16_t bufsize);
|
||||
|
||||
BLEAdafruitSensor(BLEUuid service_uuid, BLEUuid data_uuid);
|
||||
@@ -39,6 +41,7 @@ class BLEAdafruitSensor : public BLEService
|
||||
virtual err_t begin(Adafruit_Sensor* sensor, int32_t ms = DEFAULT_PERIOD);
|
||||
|
||||
void setPeriod(int32_t period_ms);
|
||||
void setNotifyCallback(notify_callback_t fp);
|
||||
|
||||
protected:
|
||||
BLECharacteristic _period;
|
||||
@@ -47,13 +50,15 @@ class BLEAdafruitSensor : public BLEService
|
||||
Adafruit_Sensor* _sensor;
|
||||
|
||||
measure_callback_t _measure_cb;
|
||||
notify_callback_t _notify_cb;
|
||||
|
||||
SoftwareTimer _timer;
|
||||
|
||||
err_t _begin(int32_t ms);
|
||||
|
||||
virtual void _update_timer(int32_t ms);
|
||||
virtual void _measure_handler(void);
|
||||
virtual void _notify_cb(uint16_t conn_hdl, uint16_t value);
|
||||
virtual void _notify_handler(uint16_t conn_hdl, uint16_t value);
|
||||
|
||||
static void sensor_timer_cb(TimerHandle_t xTimer);
|
||||
static void sensor_period_write_cb(uint16_t conn_hdl, BLECharacteristic* chr, uint8_t* data, uint16_t len);
|
||||
|
||||
@@ -43,6 +43,7 @@ extern "C"
|
||||
// LEDs
|
||||
#define PIN_LED1 (17)
|
||||
#define PIN_NEOPIXEL (18)
|
||||
#define PIN_LED2 (43) // dual white LEDs
|
||||
|
||||
#define LED_BUILTIN PIN_LED1
|
||||
|
||||
|
||||
Reference in new issue
Block a user