diff --git a/libs/BLEKit/include/BLEServiceMonitoring.h b/libs/BLEKit/include/BLEServiceMonitoring.h index 1b29dd8880..3ec71eb935 100644 --- a/libs/BLEKit/include/BLEServiceMonitoring.h +++ b/libs/BLEKit/include/BLEServiceMonitoring.h @@ -37,6 +37,14 @@ class BLEServiceMonitoring : public interface::BLEService sendData(data); } + void setHumidity(float value) + { + std::memcpy(humidity.data(), &value, 4); + + auto data = std::make_tuple(_humidity_characteristic.getValueHandle(), humidity); + sendData(data); + } + auto isScreensaverEnable() const -> bool { return screensaver_enable; } void onTemperatureRequested(const std::function &callback) @@ -85,6 +93,11 @@ class BLEServiceMonitoring : public interface::BLEService 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}; + bool screensaver_enable {true}; WriteOnlyGattCharacteristic screensaver_enable_characteristic { service::monitoring::characteristic::screensaver_enable, &screensaver_enable}; @@ -98,9 +111,9 @@ class BLEServiceMonitoring : public interface::BLEService WriteOnlyGattCharacteristic hard_reboot_characteristic {service::monitoring::characteristic::hard_reboot, &hard_reboot}; - std::array _characteristic_table { - &_charging_status_characteristic, &_temperature_characteristic, &screensaver_enable_characteristic, - &soft_reboot_characteristic, &hard_reboot_characteristic}; + std::array _characteristic_table { + &_charging_status_characteristic, &_temperature_characteristic, &_humidity_characteristic, + &screensaver_enable_characteristic, &soft_reboot_characteristic, &hard_reboot_characteristic}; }; } // namespace leka diff --git a/libs/BLEKit/include/internal/ServicesCharacteristics.h b/libs/BLEKit/include/internal/ServicesCharacteristics.h index 1fe741aa04..4d17e776d0 100644 --- a/libs/BLEKit/include/internal/ServicesCharacteristics.h +++ b/libs/BLEKit/include/internal/ServicesCharacteristics.h @@ -39,6 +39,7 @@ namespace monitoring { namespace characteristic { inline constexpr uint16_t charging_status = 0x6783; inline constexpr UUID::LongUUIDBytes_t temperature = {"Temperature"}; + inline constexpr UUID::LongUUIDBytes_t humidity = {"Humidity"}; inline constexpr uint16_t screensaver_enable = 0x8369; inline constexpr uint16_t soft_reboot = 0x8382; inline constexpr uint16_t hard_reboot = 0x7282; diff --git a/libs/BLEKit/tests/BLEServiceMonitoring_test.cpp b/libs/BLEKit/tests/BLEServiceMonitoring_test.cpp index 16ad001662..75409fab92 100644 --- a/libs/BLEKit/tests/BLEServiceMonitoring_test.cpp +++ b/libs/BLEKit/tests/BLEServiceMonitoring_test.cpp @@ -72,6 +72,24 @@ TEST_F(BLEServiceMonitoringTest, setTemperature) EXPECT_EQ(actual_temperature, expected_temperature); } +TEST_F(BLEServiceMonitoringTest, setHumidity) +{ + std::array actual_humidity {}; + std::array expected_humidity {}; + + auto spy_callback = [&actual_humidity](const BLEServiceMonitoring::data_to_send_handle_t &handle) { + for (auto i = 0; i < std::size(actual_humidity); i++) { + actual_humidity.at(i) = std::get<1>(handle)[i]; + } + }; + + service_monitoring.onDataReadyToSend(spy_callback); + + service_monitoring.setHumidity(51.24); + expected_humidity = {0xC3, 0xF5, 0x4C, 0x42}; // 51.24 little-endian as in Swift + EXPECT_EQ(actual_humidity, expected_humidity); +} + TEST_F(BLEServiceMonitoringTest, onTemperatureRequested) { testing::MockFunction mock_callback {};