From a284b3f28923442569fd794ccec981a9e0d408e9 Mon Sep 17 00:00:00 2001 From: Yann Locatelli Date: Wed, 24 Jul 2024 15:47:11 +0200 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20(IMU):=20Register=20wake?= =?UTF-8?q?=20up=20callback=20on=20enable?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- drivers/CoreIMU/include/CoreIMU.hpp | 3 +-- drivers/CoreIMU/source/CoreIMU.cpp | 9 +++----- drivers/CoreIMU/tests/CoreIMU_test.cpp | 30 +++++--------------------- include/interface/drivers/IMU.hpp | 5 ++--- tests/unit/mocks/mocks/leka/IMU.h | 3 +-- 5 files changed, 12 insertions(+), 38 deletions(-) diff --git a/drivers/CoreIMU/include/CoreIMU.hpp b/drivers/CoreIMU/include/CoreIMU.hpp index 0d7c38f4a..4ff5046f0 100644 --- a/drivers/CoreIMU/include/CoreIMU.hpp +++ b/drivers/CoreIMU/include/CoreIMU.hpp @@ -26,8 +26,7 @@ class CoreIMU : public interface::IMU, public interface::DeepSleepEnabled void enableOnDataReadyInterrupt() final; void disableOnDataReadyInterrupt() final; - void registerOnWakeUpCallback(std::function const &callback) final; - void enableOnWakeUpInterrupt() final; + void enableOnWakeUpInterrupt(std::function const &callback) final; void disableOnWakeUpInterrupt() final; void setPowerMode(PowerMode mode) final; diff --git a/drivers/CoreIMU/source/CoreIMU.cpp b/drivers/CoreIMU/source/CoreIMU.cpp index 4966482e7..22ab2887a 100644 --- a/drivers/CoreIMU/source/CoreIMU.cpp +++ b/drivers/CoreIMU/source/CoreIMU.cpp @@ -137,12 +137,7 @@ void CoreIMU::disableDeepSleep() setPowerMode(interface::IMU::PowerMode::Normal); } -void CoreIMU::registerOnWakeUpCallback(std::function const &callback) -{ - _on_wake_up_callback = callback; -} - -void CoreIMU::enableOnWakeUpInterrupt() +void CoreIMU::enableOnWakeUpInterrupt(std::function const &callback) { // ? Set filter and disable user offset lsm6dsox_xl_hp_path_internal_set(&_register_io_function, LSM6DSOX_USE_SLOPE); @@ -162,6 +157,8 @@ void CoreIMU::enableOnWakeUpInterrupt() }; lsm6dsox_pin_int1_route_set(&_register_io_function, lsm6dsox_int1); + _on_wake_up_callback = callback; + auto on_wake_up_callback = [this] { _event_queue.call([this] { lsm6dsox_all_sources_t all_source; diff --git a/drivers/CoreIMU/tests/CoreIMU_test.cpp b/drivers/CoreIMU/tests/CoreIMU_test.cpp index cb2ba2dbc..65e79c494 100644 --- a/drivers/CoreIMU/tests/CoreIMU_test.cpp +++ b/drivers/CoreIMU/tests/CoreIMU_test.cpp @@ -122,34 +122,15 @@ TEST_F(CoreIMUTest, disableDeepSleep) coreimu.disableDeepSleep(); } -TEST_F(CoreIMUTest, onWakeUpCallback) -{ - MockFunction mock_callback; - - EXPECT_CALL(mocki2c, write).Times(AtLeast(1)); - EXPECT_CALL(mocki2c, read).Times(AtLeast(1)); - EXPECT_CALL(mock_callback, Call).Times(AnyNumber()); - - coreimu.registerOnWakeUpCallback(mock_callback.AsStdFunction()); - - auto on_rise_callback = spy_InterruptIn_getRiseCallback(); - on_rise_callback(); -} - -TEST_F(CoreIMUTest, emptyOnWakeUpCallback) -{ - coreimu.registerOnWakeUpCallback({}); - - auto on_rise_callback = spy_InterruptIn_getRiseCallback(); - on_rise_callback(); -} - TEST_F(CoreIMUTest, enableOnWakeUpInterrupt) { + auto mock_wake_up_callback = MockFunction {}; + EXPECT_CALL(mocki2c, write).Times(AtLeast(1)); EXPECT_CALL(mocki2c, read).Times(AtLeast(1)); + EXPECT_CALL(mock_wake_up_callback, Call).Times(AnyNumber()); - coreimu.enableOnWakeUpInterrupt(); + coreimu.enableOnWakeUpInterrupt(mock_wake_up_callback.AsStdFunction()); } TEST_F(CoreIMUTest, disableOnWakeUpInterrupt) @@ -170,7 +151,6 @@ TEST_F(CoreIMUTest, switchCallbacks) EXPECT_CALL(mocki2c, read).Times(AnyNumber()); coreimu.registerOnDataReadyCallback(mock_data_available_callback.AsStdFunction()); - coreimu.registerOnWakeUpCallback(mock_wake_up_callback.AsStdFunction()); { // Enable Data Available @@ -194,7 +174,7 @@ TEST_F(CoreIMUTest, switchCallbacks) // Enable Wake Up EXPECT_CALL(mock_data_available_callback, Call).Times(0); EXPECT_CALL(mock_wake_up_callback, Call).Times(AnyNumber()); - coreimu.enableOnWakeUpInterrupt(); + coreimu.enableOnWakeUpInterrupt(mock_wake_up_callback.AsStdFunction()); on_rise_callback = spy_InterruptIn_getRiseCallback(); on_rise_callback(); } diff --git a/include/interface/drivers/IMU.hpp b/include/interface/drivers/IMU.hpp index b255cb2ba..bcbdcbde7 100644 --- a/include/interface/drivers/IMU.hpp +++ b/include/interface/drivers/IMU.hpp @@ -54,9 +54,8 @@ class IMU virtual void enableOnDataReadyInterrupt() = 0; virtual void disableOnDataReadyInterrupt() = 0; - virtual void registerOnWakeUpCallback(std::function const &callback) = 0; - virtual void enableOnWakeUpInterrupt() = 0; - virtual void disableOnWakeUpInterrupt() = 0; + virtual void enableOnWakeUpInterrupt(std::function const &callback) = 0; + virtual void disableOnWakeUpInterrupt() = 0; virtual void setPowerMode(PowerMode) = 0; }; diff --git a/tests/unit/mocks/mocks/leka/IMU.h b/tests/unit/mocks/mocks/leka/IMU.h index e29f4442c..828200469 100644 --- a/tests/unit/mocks/mocks/leka/IMU.h +++ b/tests/unit/mocks/mocks/leka/IMU.h @@ -19,8 +19,7 @@ class IMU : public interface::IMU MOCK_METHOD(void, enableOnDataReadyInterrupt, (), (override)); MOCK_METHOD(void, disableOnDataReadyInterrupt, (), (override)); - void registerOnWakeUpCallback(std::function const &cb) override { wake_up_callback = cb; } - MOCK_METHOD(void, enableOnWakeUpInterrupt, (), (override)); + void enableOnWakeUpInterrupt(std::function const &cb) override { wake_up_callback = cb; } MOCK_METHOD(void, disableOnWakeUpInterrupt, (), (override)); void call_data_ready_callback(const SensorData &data) { data_ready_callback(data); }