From 1c20a31c45e8118777a5069a41cc10e4d7ae8288 Mon Sep 17 00:00:00 2001 From: Yann Locatelli Date: Mon, 22 Jan 2024 13:22:10 +0100 Subject: [PATCH] :recycle: (BLEKit): Add onHumidityRequested agglomerate with onTemperatureRequested --- libs/BLEKit/include/BLEServiceMonitoring.h | 14 ++++++++------ libs/BLEKit/tests/BLEServiceMonitoring_test.cpp | 12 ++++++------ 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/libs/BLEKit/include/BLEServiceMonitoring.h b/libs/BLEKit/include/BLEServiceMonitoring.h index 3ec71eb935..f18779af68 100644 --- a/libs/BLEKit/include/BLEServiceMonitoring.h +++ b/libs/BLEKit/include/BLEServiceMonitoring.h @@ -47,9 +47,9 @@ class BLEServiceMonitoring : public interface::BLEService auto isScreensaverEnable() const -> bool { return screensaver_enable; } - void onTemperatureRequested(const std::function &callback) + void onTemperatureHumidityRequested(const std::function &callback) { - _on_temperature_requested_callback = callback; + _on_temperature_humidity_requested_callback = callback; } void onDataReceived(const data_received_handle_t ¶ms) final @@ -75,9 +75,10 @@ class BLEServiceMonitoring : public interface::BLEService void onDataRequested(const data_requested_handle_t ¶ms) final { - if (params.handle == _temperature_characteristic.getValueHandle() && - _on_temperature_requested_callback != nullptr) { - _on_temperature_requested_callback(); + if ((params.handle == _temperature_characteristic.getValueHandle() || + params.handle == _humidity_characteristic.getValueHandle()) && + _on_temperature_humidity_requested_callback != nullptr) { + _on_temperature_humidity_requested_callback(); } } @@ -91,13 +92,14 @@ class BLEServiceMonitoring : public interface::BLEService ReadOnlyArrayGattCharacteristic _temperature_characteristic { service::monitoring::characteristic::temperature, temperature.begin(), GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY}; - std::function _on_temperature_requested_callback {}; std::array humidity {}; ReadOnlyArrayGattCharacteristic _humidity_characteristic { service::monitoring::characteristic::humidity, humidity.begin(), GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY}; + std::function _on_temperature_humidity_requested_callback {}; + bool screensaver_enable {true}; WriteOnlyGattCharacteristic screensaver_enable_characteristic { service::monitoring::characteristic::screensaver_enable, &screensaver_enable}; diff --git a/libs/BLEKit/tests/BLEServiceMonitoring_test.cpp b/libs/BLEKit/tests/BLEServiceMonitoring_test.cpp index 75409fab92..f0b64ff286 100644 --- a/libs/BLEKit/tests/BLEServiceMonitoring_test.cpp +++ b/libs/BLEKit/tests/BLEServiceMonitoring_test.cpp @@ -90,20 +90,20 @@ TEST_F(BLEServiceMonitoringTest, setHumidity) EXPECT_EQ(actual_humidity, expected_humidity); } -TEST_F(BLEServiceMonitoringTest, onTemperatureRequested) +TEST_F(BLEServiceMonitoringTest, onTemperatureHumidityRequested) { testing::MockFunction mock_callback {}; - service_monitoring.onTemperatureRequested(mock_callback.AsStdFunction()); + service_monitoring.onTemperatureHumidityRequested(mock_callback.AsStdFunction()); EXPECT_CALL(mock_callback, Call).Times(1); service_monitoring.onDataRequested(data_requested_handle); } -TEST_F(BLEServiceMonitoringTest, onTemperatureRequestedNotSameHandle) +TEST_F(BLEServiceMonitoringTest, onTemperatureHumidityRequestedNotSameHandle) { testing::MockFunction mock_callback {}; - service_monitoring.onTemperatureRequested(mock_callback.AsStdFunction()); + service_monitoring.onTemperatureHumidityRequested(mock_callback.AsStdFunction()); data_requested_handle.handle = 0xFFFF; @@ -112,9 +112,9 @@ TEST_F(BLEServiceMonitoringTest, onTemperatureRequestedNotSameHandle) service_monitoring.onDataRequested(data_requested_handle); } -TEST_F(BLEServiceMonitoringTest, onTemperatureRequestedtUnset) +TEST_F(BLEServiceMonitoringTest, onTemperatureHumidityRequestedtUnset) { - service_monitoring.onTemperatureRequested(nullptr); + service_monitoring.onTemperatureHumidityRequested(nullptr); service_monitoring.onDataRequested(data_requested_handle); }