From 8477e3093b73ae494257150aaf35bcb11c2df4b5 Mon Sep 17 00:00:00 2001 From: Yann Locatelli Date: Mon, 5 Feb 2024 17:02:35 +0100 Subject: [PATCH] :sparkles: (RobotController): Implement suspendHardwareForDeepSleep --- libs/RobotKit/include/RobotController.h | 10 +++++++++- libs/RobotKit/tests/RobotController_test_hardware.cpp | 5 +++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/libs/RobotKit/include/RobotController.h b/libs/RobotKit/include/RobotController.h index 86f5c04d51..2326e9f0f6 100644 --- a/libs/RobotKit/include/RobotController.h +++ b/libs/RobotKit/include/RobotController.h @@ -308,7 +308,15 @@ class RobotController : public interface::RobotController stopActuators(); } - void suspendHardwareForDeepSleep() final { log_info("TO IMPLEMENT - configuring hardware for deep sleep"); } + void suspendHardwareForDeepSleep() final + { + auto hardwares_to_suspend = + std::to_array({&_motor_left, &_motor_right, &_lcd, &_rfidkit}); + + for (auto &hardware: hardwares_to_suspend) { + hardware->enableDeepSleep(); + } + } void resetEmergencyStopCounter() final { _emergency_stop_counter = 0; } diff --git a/libs/RobotKit/tests/RobotController_test_hardware.cpp b/libs/RobotKit/tests/RobotController_test_hardware.cpp index 69b1ab7819..22312a58e1 100644 --- a/libs/RobotKit/tests/RobotController_test_hardware.cpp +++ b/libs/RobotKit/tests/RobotController_test_hardware.cpp @@ -32,6 +32,11 @@ TEST_F(RobotControllerTest, stopActuatorsAndLcd) TEST_F(RobotControllerTest, suspendHardwareForDeepSleep) { + EXPECT_CALL(mock_motor_left, enableDeepSleep); + EXPECT_CALL(mock_motor_right, enableDeepSleep); + EXPECT_CALL(mock_lcd, enableDeepSleep); + // TODO: Expect_call of RFID + rc.suspendHardwareForDeepSleep(); }