Skip to content

Commit

Permalink
✨ (StateMachine): Add magic_card_detected event to wakeUp from DeepSl…
Browse files Browse the repository at this point in the history
…eeping
  • Loading branch information
YannLocatelli committed Jul 22, 2024
1 parent b7867ed commit 5cf3059
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
1 change: 1 addition & 0 deletions libs/RobotKit/include/RobotController.h
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,7 @@ class RobotController : public interface::RobotController
// ! The order of the following functions MUST NOT
// ! be changed. It is a temporary fix for #1311
// TODO(@leka/dev-embedded): remove when fixed
raise(event::magic_card_detected {});
_service_magic_card.setMagicCard(card);
onMagicCardAvailable(card);
});
Expand Down
7 changes: 5 additions & 2 deletions libs/RobotKit/include/StateMachine.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ namespace sm::event {
struct autonomous_activities_mode_exited {
};

struct magic_card_detected {
};

} // namespace sm::event

namespace sm::state {
Expand Down Expand Up @@ -243,8 +246,8 @@ struct StateMachine {

, sm::state::deep_sleeping + event<sm::event::charge_did_start> = X
, sm::state::deep_sleeping + event<sm::event::charge_did_stop> = X

, sm::state::deep_sleeping + event<sm::event::ble_connection> = X
, sm::state::deep_sleeping + event<sm::event::ble_connection> = X
, sm::state::deep_sleeping + event<sm::event::magic_card_detected> = X

, sm::state::charging + boost::sml::on_entry<_> / (sm::action::start_deep_sleep_timeout {}, sm::action::start_charging_behavior {} )
, sm::state::charging + boost::sml::on_exit<_> / (sm::action::stop_deep_sleep_timeout {}, sm::action::stop_charging_behavior {} )
Expand Down
11 changes: 11 additions & 0 deletions libs/RobotKit/tests/StateMachine_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,17 @@ TEST_F(StateMachineTest, stateDeepSleepingEventBleConnection)
EXPECT_TRUE(sm.is(X));
}

TEST_F(StateMachineTest, stateDeepSleepingEventMagicCardDetected)
{
sm.set_current_states(lksm::state::deep_sleeping);

EXPECT_CALL(mock_rc, wakeUp);

sm.process_event(lksm::event::magic_card_detected {});

EXPECT_TRUE(sm.is(X));
}

TEST_F(StateMachineTest, stateIdleEventChargeDidStart)
{
sm.set_current_states(lksm::state::idle);
Expand Down

0 comments on commit 5cf3059

Please sign in to comment.