Skip to content

Commit

Permalink
Revert "♻️ (IMU): Register wake up callback on enable"
Browse files Browse the repository at this point in the history
This reverts commit 1669492.
  • Loading branch information
YannLocatelli committed Aug 19, 2024
1 parent a284b3f commit 4276867
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 12 deletions.
3 changes: 2 additions & 1 deletion drivers/CoreIMU/include/CoreIMU.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ class CoreIMU : public interface::IMU, public interface::DeepSleepEnabled
void enableOnDataReadyInterrupt() final;
void disableOnDataReadyInterrupt() final;

void enableOnWakeUpInterrupt(std::function<void()> const &callback) final;
void registerOnWakeUpCallback(std::function<void()> const &callback) final;
void enableOnWakeUpInterrupt() final;
void disableOnWakeUpInterrupt() final;

void setPowerMode(PowerMode mode) final;
Expand Down
9 changes: 6 additions & 3 deletions drivers/CoreIMU/source/CoreIMU.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,12 @@ void CoreIMU::disableDeepSleep()
setPowerMode(interface::IMU::PowerMode::Normal);
}

void CoreIMU::enableOnWakeUpInterrupt(std::function<void()> const &callback)
void CoreIMU::registerOnWakeUpCallback(std::function<void()> const &callback)
{
_on_wake_up_callback = callback;
}

void CoreIMU::enableOnWakeUpInterrupt()
{
// ? Set filter and disable user offset
lsm6dsox_xl_hp_path_internal_set(&_register_io_function, LSM6DSOX_USE_SLOPE);
Expand All @@ -157,8 +162,6 @@ void CoreIMU::enableOnWakeUpInterrupt(std::function<void()> const &callback)
};
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;
Expand Down
30 changes: 25 additions & 5 deletions drivers/CoreIMU/tests/CoreIMU_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,15 +122,34 @@ TEST_F(CoreIMUTest, disableDeepSleep)
coreimu.disableDeepSleep();
}

TEST_F(CoreIMUTest, enableOnWakeUpInterrupt)
TEST_F(CoreIMUTest, onWakeUpCallback)
{
auto mock_wake_up_callback = MockFunction<void()> {};
MockFunction<void()> 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)
{
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(mock_wake_up_callback.AsStdFunction());
coreimu.enableOnWakeUpInterrupt();
}

TEST_F(CoreIMUTest, disableOnWakeUpInterrupt)
Expand All @@ -151,6 +170,7 @@ 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
Expand All @@ -174,7 +194,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(mock_wake_up_callback.AsStdFunction());
coreimu.enableOnWakeUpInterrupt();
on_rise_callback = spy_InterruptIn_getRiseCallback();
on_rise_callback();
}
Expand Down
5 changes: 3 additions & 2 deletions include/interface/drivers/IMU.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,9 @@ class IMU
virtual void enableOnDataReadyInterrupt() = 0;
virtual void disableOnDataReadyInterrupt() = 0;

virtual void enableOnWakeUpInterrupt(std::function<void()> const &callback) = 0;
virtual void disableOnWakeUpInterrupt() = 0;
virtual void registerOnWakeUpCallback(std::function<void()> const &callback) = 0;
virtual void enableOnWakeUpInterrupt() = 0;
virtual void disableOnWakeUpInterrupt() = 0;

virtual void setPowerMode(PowerMode) = 0;
};
Expand Down
3 changes: 2 additions & 1 deletion tests/unit/mocks/mocks/leka/IMU.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ class IMU : public interface::IMU
MOCK_METHOD(void, enableOnDataReadyInterrupt, (), (override));
MOCK_METHOD(void, disableOnDataReadyInterrupt, (), (override));

void enableOnWakeUpInterrupt(std::function<void()> const &cb) override { wake_up_callback = cb; }
void registerOnWakeUpCallback(std::function<void()> const &cb) override { wake_up_callback = cb; }
MOCK_METHOD(void, enableOnWakeUpInterrupt, (), (override));
MOCK_METHOD(void, disableOnWakeUpInterrupt, (), (override));

void call_data_ready_callback(const SensorData &data) { data_ready_callback(data); }
Expand Down

0 comments on commit 4276867

Please sign in to comment.