Skip to content

Commit

Permalink
🔀 Merge branch 'yann/feature/rc/on-low-battery' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
ladislas committed Mar 19, 2022
2 parents fc846a0 + 506dad8 commit ecd5579
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 4 deletions.
2 changes: 1 addition & 1 deletion libs/BatteryKit/source/BatteryKit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ using namespace std::chrono_literals;
void BatteryKit::startEventHandler()
{
auto on_tick = [this] {
if (_on_low_battery && level() == 0) {
if (_on_low_battery && level() <= 5) {
_on_low_battery();
}

Expand Down
2 changes: 2 additions & 0 deletions libs/BehaviorKit/include/BehaviorKit.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ class BehaviorKit
void sleeping();
void waiting();

void lowBattery();

void chargingZero();
void chargingRed();
void chargingOrange();
Expand Down
5 changes: 5 additions & 0 deletions libs/BehaviorKit/source/BehaviorKit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ void BehaviorKit::waiting()
"/fs/videos/2022_02_14-animation-face-state-waiting-looking-top-right-to-left-without-eyebrows.avi");
}

void BehaviorKit::lowBattery()
{
_videokit.displayImage("/fs/images/loading.jpg");
}

void BehaviorKit::chargingZero()
{
_ledkit.start(&LedKit::animation::charging_red);
Expand Down
5 changes: 5 additions & 0 deletions libs/BehaviorKit/tests/BehaviorKit_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,11 @@ TEST_F(BehaviorKitTest, spinRight)
behaviorkit.spinBlink();
}

TEST_F(BehaviorKitTest, lowBattery)
{
behaviorkit.lowBattery();
}

TEST_F(BehaviorKitTest, stop)
{
static constexpr auto speed = 0.5;
Expand Down
10 changes: 10 additions & 0 deletions libs/RobotKit/include/RobotController.h
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,16 @@ class RobotController : public interface::RobotController

_battery_kit.onDataUpdated([](uint8_t level) { _service_battery.setBatteryLevel(level); });

auto on_low_battery = [this] {
_event_queue.call(&_behaviorkit, &BehaviorKit::lowBattery);
// TODO: Add turn on screen

if (_battery.level() == 0) {
system_reset();
}
};
_battery_kit.onLowBattery(on_low_battery);

_battery_kit.startEventHandler();

// Setup callbacks for each State Machine events
Expand Down
6 changes: 3 additions & 3 deletions libs/RobotKit/tests/RobotController_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class RobotControllerTest : public testing::Test

rc.initializeComponents();

EXPECT_CALL(battery, level).Times(1);
EXPECT_CALL(battery, level).Times(AnyNumber());
EXPECT_CALL(mbed_mock_gatt, write(_, _, _, _)).Times(AnyNumber());
EXPECT_CALL(sleep_timeout, onTimeout).WillOnce(GetCallback<interface::Timeout::callback_t>(&on_sleep_timeout));
EXPECT_CALL(battery, onChargeDidStart).WillOnce(GetCallback<mbed::Callback<void()>>(&on_charge_did_start));
Expand Down Expand Up @@ -178,7 +178,7 @@ TEST_F(RobotControllerTest, stateSetupEventSetupCompleteGuardIsChargingFalse)
rc.state_machine.set_current_states(lksm::state::setup);

auto expected_level = 0x2A;
EXPECT_CALL(battery, level).WillOnce(Return(expected_level));
EXPECT_CALL(battery, level).WillRepeatedly(Return(expected_level));
EXPECT_CALL(mbed_mock_gatt, write(_, sameValue(expected_level), _, _)).Times(1);

EXPECT_CALL(sleep_timeout, onTimeout).Times(1);
Expand All @@ -200,7 +200,7 @@ TEST_F(RobotControllerTest, stateSetupEventSetupCompleteGuardIsChargingTrue)
rc.state_machine.set_current_states(lksm::state::setup);

auto expected_level = 0x2A;
EXPECT_CALL(battery, level).WillOnce(Return(expected_level));
EXPECT_CALL(battery, level).WillRepeatedly(Return(expected_level));
EXPECT_CALL(mbed_mock_gatt, write(_, sameValue(expected_level), _, _)).Times(1);

EXPECT_CALL(sleep_timeout, onTimeout).Times(1);
Expand Down

0 comments on commit ecd5579

Please sign in to comment.