From eb87b912b6db2314f5a64845c17ce36d5f0661a1 Mon Sep 17 00:00:00 2001 From: Yann Locatelli Date: Mon, 22 Jan 2024 16:42:28 +0100 Subject: [PATCH] :sparkles: (RobotKit): Add CoreHTS and link to BLE service --- app/os/CMakeLists.txt | 1 + app/os/main.cpp | 15 +++++++++++++++ libs/RobotKit/include/RobotController.h | 21 ++++++++++++++++----- libs/RobotKit/tests/RobotController_test.h | 6 ++++++ 4 files changed, 38 insertions(+), 5 deletions(-) diff --git a/app/os/CMakeLists.txt b/app/os/CMakeLists.txt index 0e6ba00395..b9274483bc 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 6cf597ac1b..158814736f 100644 --- a/app/os/main.cpp +++ b/app/os/main.cpp @@ -19,6 +19,7 @@ #include "CoreFlashManagerIS25LP016D.h" #include "CoreFont.hpp" #include "CoreGraphics.hpp" +#include "CoreHTS.h" #include "CoreI2C.h" #include "CoreInterruptIn.h" #include "CoreJPEG.hpp" @@ -150,6 +151,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 { @@ -417,6 +429,8 @@ namespace robot { internal::timeout_state_transition, internal::timeout_autonomous_activities, battery::cells, + temperature_humidity::sensor, + temperature_humidity::sensor, internal::serialnumberkit, firmware::kit, motors::left::motor, @@ -561,6 +575,7 @@ auto main() -> int commandkit.registerCommand(command::list); activitykit.registerActivities(activities::activities); + temperature_humidity::sensor.init(); imu::lsm6dsox.init(); imukit.init(); diff --git a/libs/RobotKit/include/RobotController.h b/libs/RobotKit/include/RobotController.h index d6e4a98e0b..6f69bc6d95 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/LedKit.h" #include "interface/libs/VideoKit.h" @@ -49,15 +50,18 @@ class RobotController : public interface::RobotController explicit RobotController(interface::Timeout &timeout_state_internal, interface::Timeout &timeout_state_transition, interface::Timeout &timeout_autonomous_activities, interface::Battery &battery, - 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), _battery(battery), + _temperature_sensor(temperature_sensor), + _humidity_sensor(humidity_sensor), _serialnumberkit(serialnumberkit), _firmware_update(firmware_update), _motor_left(motor_left), @@ -492,6 +496,11 @@ class RobotController : public interface::RobotController _battery_kit.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 {}); }); @@ -571,6 +580,8 @@ class RobotController : public interface::RobotController interface::Battery &_battery; BatteryKit _battery_kit {_battery}; 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 f57b95a72b..6fca6e05e4 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,