Skip to content

Commit

Permalink
✨ (rc): Update advertising data in BLE with battery and charging status
Browse files Browse the repository at this point in the history
  • Loading branch information
YannLocatelli committed May 21, 2022
1 parent 1e4e662 commit 63d19b6
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 0 deletions.
5 changes: 5 additions & 0 deletions libs/RobotKit/include/RobotController.h
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,11 @@ class RobotController : public interface::RobotController
_battery_kit.onDataUpdated([this](uint8_t level) {
auto is_charging = _battery.isCharging();

auto advertising_data = _ble.getAdvertisingData();
advertising_data.battery = level;
advertising_data.is_charging = static_cast<uint8_t>(is_charging);
_ble.setAdvertisingData(advertising_data);

_service_battery.setBatteryLevel(level);
if (is_charging) {
onChargingBehavior(level);
Expand Down
1 change: 1 addition & 0 deletions libs/RobotKit/tests/RobotController_test.h
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ class RobotControllerTest : public testing::Test
Sequence on_data_updated_sequence;
EXPECT_CALL(battery, level).InSequence(on_data_updated_sequence);
EXPECT_CALL(battery, isCharging).InSequence(on_data_updated_sequence);
EXPECT_CALL(mbed_mock_gap, setAdvertisingPayload).InSequence(on_data_updated_sequence);
EXPECT_CALL(mbed_mock_gatt, write(_, _, _, _)).InSequence(on_data_updated_sequence);

EXPECT_CALL(timeout, onTimeout).WillOnce(GetCallback<interface::Timeout::callback_t>(&on_sleep_timeout));
Expand Down
2 changes: 2 additions & 0 deletions libs/RobotKit/tests/RobotController_test_registerEvents.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ TEST_F(RobotControllerTest, registerEventsBatteryIsNotCharging)
Sequence on_data_updated_sequence;
EXPECT_CALL(battery, level).InSequence(on_data_updated_sequence).WillOnce(Return(false));
EXPECT_CALL(battery, isCharging).InSequence(on_data_updated_sequence);
EXPECT_CALL(mbed_mock_gap, setAdvertisingPayload).InSequence(on_data_updated_sequence);
// TODO: Specify which BLE service and what is expected if necessary
EXPECT_CALL(mbed_mock_gatt, write(_, _, _, _)).InSequence(on_data_updated_sequence);

Expand Down Expand Up @@ -69,6 +70,7 @@ TEST_F(RobotControllerTest, registerEventsBatteryIsCharging)
Sequence on_data_updated_sequence;
EXPECT_CALL(battery, level).InSequence(on_data_updated_sequence);
EXPECT_CALL(battery, isCharging).InSequence(on_data_updated_sequence).WillOnce(Return(true));
EXPECT_CALL(mbed_mock_gap, setAdvertisingPayload).InSequence(on_data_updated_sequence);
EXPECT_CALL(mbed_mock_gatt, write(_, _, _, _)).InSequence(on_data_updated_sequence);
EXPECT_CALL(mock_videokit, displayImage).InSequence(on_data_updated_sequence);

Expand Down

0 comments on commit 63d19b6

Please sign in to comment.