Skip to content

Commit

Permalink
🚸 (rc): Add behavior when battery is low
Browse files Browse the repository at this point in the history
Increase battery level triggering the callback
  • Loading branch information
YannLocatelli authored and ladislas committed Mar 19, 2022
1 parent e2d6a18 commit 506dad8
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 2 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
9 changes: 8 additions & 1 deletion libs/RobotKit/include/RobotController.h
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,14 @@ class RobotController : public interface::RobotController

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

auto on_low_battery = [this] { system_reset(); };
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();
Expand Down

0 comments on commit 506dad8

Please sign in to comment.