diff --git a/app/os/CMakeLists.txt b/app/os/CMakeLists.txt index 0e6ba0039..b9274483b 100644 --- a/app/os/CMakeLists.txt +++ b/app/os/CMakeLists.txt @@ -40,6 +40,7 @@ target_link_libraries(LekaOS IMUKit MotionKit EventLoopKit + CoreHTS ) target_link_custom_leka_targets(LekaOS) diff --git a/app/os/main.cpp b/app/os/main.cpp index aad505a21..01e2765f2 100644 --- a/app/os/main.cpp +++ b/app/os/main.cpp @@ -20,6 +20,7 @@ #include "CoreFlashManagerIS25LP016D.h" #include "CoreFont.hpp" #include "CoreGraphics.hpp" +#include "CoreHTS.h" #include "CoreI2C.h" #include "CoreIMU.hpp" #include "CoreInterruptIn.h" @@ -151,6 +152,17 @@ namespace factory_reset { } // namespace factory_reset +namespace temperature_humidity { + + namespace internal { + + auto i2c = CoreI2C {PinName::SENSOR_IMU_TH_I2C_SDA, PinName::SENSOR_IMU_TH_I2C_SCL}; + } + + auto sensor = CoreHTS {internal::i2c}; + +} // namespace temperature_humidity + namespace leds { namespace internal { @@ -421,6 +433,8 @@ namespace robot { internal::timeout_state_transition, internal::timeout_autonomous_activities, battery::kit, + temperature_humidity::sensor, + temperature_humidity::sensor, internal::serialnumberkit, firmware::kit, motors::left::motor, @@ -578,6 +592,7 @@ auto main() -> int commandkit.registerCommand(command::list); activitykit.registerActivities(activities::activities); + temperature_humidity::sensor.init(); imu::coreimu.init(); imukit.init(); diff --git a/drivers/CoreHTS/include/CoreHTS.h b/drivers/CoreHTS/include/CoreHTS.h index 6b3a7dac2..38e0d7a76 100644 --- a/drivers/CoreHTS/include/CoreHTS.h +++ b/drivers/CoreHTS/include/CoreHTS.h @@ -7,32 +7,13 @@ #include #include -#include "CoreI2C.h" #include "Utils.h" #include "hts221_reg.h" +#include "interface/drivers/I2C.h" +#include "interface/drivers/TemperatureSensor.h" namespace leka { -namespace interface { - - class TemperatureSensor - { - public: - virtual ~TemperatureSensor() = default; - - virtual auto getTemperatureCelsius() -> float = 0; - }; - - class HumiditySensor - { - public: - virtual ~HumiditySensor() = default; - - virtual auto getRelativeHumidity() -> float = 0; - }; - -} // namespace interface - class CoreHTS : public interface::TemperatureSensor, public interface::HumiditySensor { using Point = leka::utils::math::Point; diff --git a/include/interface/drivers/TemperatureSensor.h b/include/interface/drivers/TemperatureSensor.h new file mode 100644 index 000000000..12a222e5f --- /dev/null +++ b/include/interface/drivers/TemperatureSensor.h @@ -0,0 +1,25 @@ +// Leka - LekaOS +// Copyright 2024 APF France handicap +// SPDX-License-Identifier: Apache-2.0 + +#pragma once + +namespace leka::interface { + +class TemperatureSensor +{ + public: + virtual ~TemperatureSensor() = default; + + virtual auto getTemperatureCelsius() -> float = 0; +}; + +class HumiditySensor +{ + public: + virtual ~HumiditySensor() = default; + + virtual auto getRelativeHumidity() -> float = 0; +}; + +} // namespace leka::interface diff --git a/libs/RobotKit/CMakeLists.txt b/libs/RobotKit/CMakeLists.txt index 2d03e705f..657d0ee4a 100644 --- a/libs/RobotKit/CMakeLists.txt +++ b/libs/RobotKit/CMakeLists.txt @@ -21,11 +21,9 @@ target_link_libraries(RobotKit BatteryKit SerialNumberKit BLEKit - CoreMotor LedKit FileManagerKit CoreMutex - VideoKit BehaviorKit CommandKit RFIDKit diff --git a/libs/RobotKit/include/RobotController.h b/libs/RobotKit/include/RobotController.h index 129bf28b0..00e006bde 100644 --- a/libs/RobotKit/include/RobotController.h +++ b/libs/RobotKit/include/RobotController.h @@ -34,6 +34,7 @@ #include "interface/drivers/FirmwareUpdate.h" #include "interface/drivers/LCD.hpp" #include "interface/drivers/Motor.h" +#include "interface/drivers/TemperatureSensor.h" #include "interface/drivers/Timeout.h" #include "interface/libs/BatteryKit.h" #include "interface/libs/LedKit.h" @@ -52,15 +53,18 @@ class RobotController : public interface::RobotController explicit RobotController(interface::Timeout &timeout_state_internal, interface::Timeout &timeout_state_transition, interface::Timeout &timeout_autonomous_activities, interface::BatteryKit &batterykit, - SerialNumberKit &serialnumberkit, interface::FirmwareUpdate &firmware_update, - interface::Motor &motor_left, interface::Motor &motor_right, interface::LED &ears, - interface::LED &belt, interface::LedKit &ledkit, interface::LCD &lcd, - interface::VideoKit &videokit, BehaviorKit &behaviorkit, CommandKit &cmdkit, - RFIDKit &rfidkit, ActivityKit &activitykit) + interface::TemperatureSensor &temperature_sensor, + interface::HumiditySensor &humidity_sensor, SerialNumberKit &serialnumberkit, + interface::FirmwareUpdate &firmware_update, interface::Motor &motor_left, + interface::Motor &motor_right, interface::LED &ears, interface::LED &belt, + interface::LedKit &ledkit, interface::LCD &lcd, interface::VideoKit &videokit, + BehaviorKit &behaviorkit, CommandKit &cmdkit, RFIDKit &rfidkit, ActivityKit &activitykit) : _timeout_state_internal(timeout_state_internal), _timeout_state_transition(timeout_state_transition), _timeout_autonomous_activities(timeout_autonomous_activities), _batterykit(batterykit), + _temperature_sensor(temperature_sensor), + _humidity_sensor(humidity_sensor), _serialnumberkit(serialnumberkit), _firmware_update(firmware_update), _motor_left(motor_left), @@ -495,6 +499,11 @@ class RobotController : public interface::RobotController _batterykit.startEventHandler(); + _service_monitoring.onTemperatureHumidityRequested([this]() { + _service_monitoring.setTemperature(_temperature_sensor.getTemperatureCelsius()); + _service_monitoring.setHumidity(_humidity_sensor.getRelativeHumidity()); + }); + _ble.onConnectionCallback([this] { raise(event::ble_connection {}); }); _ble.onDisconnectionCallback([this] { raise(event::ble_disconnection {}); }); @@ -582,6 +591,8 @@ class RobotController : public interface::RobotController interface::BatteryKit &_batterykit; uint8_t _minimal_battery_level_to_update {25}; + interface::TemperatureSensor &_temperature_sensor; + interface::HumiditySensor &_humidity_sensor; SerialNumberKit &_serialnumberkit; diff --git a/libs/RobotKit/tests/RobotController_test.h b/libs/RobotKit/tests/RobotController_test.h index 2fe10f924..cc922d237 100644 --- a/libs/RobotKit/tests/RobotController_test.h +++ b/libs/RobotKit/tests/RobotController_test.h @@ -31,6 +31,7 @@ #include "mocks/leka/LedKit.h" #include "mocks/leka/MCU.h" #include "mocks/leka/PwmOut.h" +#include "mocks/leka/TemperatureSensor.h" #include "mocks/leka/Timeout.h" #include "mocks/leka/VideoKit.h" #include "mocks/mbed/DigitalOut.h" @@ -84,6 +85,9 @@ class RobotControllerTest : public testing::Test mock::MCU mock_mcu {}; SerialNumberKit serialnumberkit {mock_mcu, SerialNumberKit::DEFAULT_CONFIG}; + mock::TemperatureSensor temperature_sensor {}; + mock::HumiditySensor humidity_sensor {}; + mock::FirmwareUpdate firmware_update {}; mock::CoreLED mock_ears; @@ -115,6 +119,8 @@ class RobotControllerTest : public testing::Test timeout_state_transition, timeout_autonomous_activities, battery, + temperature_sensor, + humidity_sensor, serialnumberkit, firmware_update, mock_motor_left, diff --git a/tests/unit/mocks/mocks/leka/TemperatureSensor.h b/tests/unit/mocks/mocks/leka/TemperatureSensor.h new file mode 100644 index 000000000..bbf504a01 --- /dev/null +++ b/tests/unit/mocks/mocks/leka/TemperatureSensor.h @@ -0,0 +1,24 @@ +// Leka - LekaOS +// Copyright 2024 APF France handicap +// SPDX-License-Identifier: Apache-2.0 + +#pragma once + +#include "gmock/gmock.h" +#include "interface/drivers/TemperatureSensor.h" + +namespace leka::mock { + +class TemperatureSensor : public interface::TemperatureSensor +{ + public: + MOCK_METHOD(float, getTemperatureCelsius, (), (override)); +}; + +class HumiditySensor : public interface::HumiditySensor +{ + public: + MOCK_METHOD(float, getRelativeHumidity, (), (override)); +}; + +} // namespace leka::mock