Skip to content

Commit

Permalink
reorganization
Browse files Browse the repository at this point in the history
  • Loading branch information
YannLocatelli committed Jul 19, 2024
1 parent 31357bb commit be9b76e
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 38 deletions.
2 changes: 0 additions & 2 deletions drivers/CoreIMU/include/CoreIMU.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ class CoreIMU : public interface::IMU, public interface::DeepSleepEnabled

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

void setPowerMode(PowerMode mode) final;

Expand Down Expand Up @@ -64,7 +63,6 @@ class CoreIMU : public interface::IMU, public interface::DeepSleepEnabled
std::array<uint8_t, kMaxBufferLength> _rx_buffer {};

std::function<void()> _on_wake_up_callback {};
std::function<void()> _on_wake_up_wrapper_callback {};
};

} // namespace leka
14 changes: 2 additions & 12 deletions drivers/CoreIMU/source/CoreIMU.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ void CoreIMU::enableOnWakeUpInterrupt()
};
lsm6dsox_pin_int1_route_set(&_register_io_function, lsm6dsox_int1);

_on_wake_up_wrapper_callback = [this] {
auto on_wake_up_wrapper_callback = [this] {
_event_queue.call([this] {
lsm6dsox_all_sources_t all_source;
lsm6dsox_all_sources_get(&_register_io_function, &all_source);
Expand All @@ -173,17 +173,7 @@ void CoreIMU::enableOnWakeUpInterrupt()
});
};

setDataReadyInterruptCallback(_on_wake_up_wrapper_callback);
}

void CoreIMU::disableOnWakeUpInterrupt()
{
lsm6dsox_pin_int1_route_t lsm6dsox_int1 {
.sleep_change = PROPERTY_DISABLE,
};
lsm6dsox_pin_int1_route_set(&_register_io_function, lsm6dsox_int1);

setDataReadyInterruptCallback({});
setDataReadyInterruptCallback(on_wake_up_wrapper_callback);
}

auto CoreIMU::read(uint8_t register_address, uint16_t number_bytes_to_read, uint8_t *p_buffer) -> int32_t
Expand Down
27 changes: 5 additions & 22 deletions drivers/CoreIMU/tests/CoreIMU_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,14 +152,6 @@ TEST_F(CoreIMUTest, enableOnWakeUpInterrupt)
coreimu.enableOnWakeUpInterrupt();
}

TEST_F(CoreIMUTest, disableOnWakeUpInterrupt)
{
EXPECT_CALL(mocki2c, write).Times(AtLeast(1));
EXPECT_CALL(mocki2c, read).Times(AtLeast(1));

coreimu.disableOnWakeUpInterrupt();
}

TEST_F(CoreIMUTest, switchCallbacks)
{
auto mock_data_available_callback = MockFunction<void(const leka::interface::IMU::SensorData &data)> {};
Expand All @@ -182,28 +174,19 @@ TEST_F(CoreIMUTest, switchCallbacks)
}

{
// Enable Wake Up
// Disable Data Available
EXPECT_CALL(mock_data_available_callback, Call).Times(0);
EXPECT_CALL(mock_wake_up_callback, Call).Times(AnyNumber());
coreimu.enableOnWakeUpInterrupt();
on_rise_callback = spy_InterruptIn_getRiseCallback();
on_rise_callback();
}

{
// Enable Data Available
EXPECT_CALL(mock_data_available_callback, Call).Times(1);
EXPECT_CALL(mock_wake_up_callback, Call).Times(0);
coreimu.enableOnDataReadyInterrupt();
coreimu.disableOnDataReadyInterrupt();
on_rise_callback = spy_InterruptIn_getRiseCallback();
on_rise_callback();
}

{
// Disable Data Available
// Enable Wake Up
EXPECT_CALL(mock_data_available_callback, Call).Times(0);
EXPECT_CALL(mock_wake_up_callback, Call).Times(0);
coreimu.disableOnDataReadyInterrupt();
EXPECT_CALL(mock_wake_up_callback, Call).Times(AnyNumber());
coreimu.enableOnWakeUpInterrupt();
on_rise_callback = spy_InterruptIn_getRiseCallback();
on_rise_callback();
}
Expand Down
1 change: 0 additions & 1 deletion include/interface/drivers/IMU.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ class IMU

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

virtual void setPowerMode(PowerMode) = 0;
};
Expand Down
1 change: 0 additions & 1 deletion tests/unit/mocks/mocks/leka/IMU.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ class IMU : public interface::IMU

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); }
void call_wake_up_callback() { wake_up_callback(); }
Expand Down

0 comments on commit be9b76e

Please sign in to comment.