Skip to content

Commit

Permalink
♻️ (RobotController): Move registered callback in methods
Browse files Browse the repository at this point in the history
  • Loading branch information
YannLocatelli committed Jul 10, 2024
1 parent cf512f5 commit 4cb518c
Showing 1 changed file with 7 additions and 12 deletions.
19 changes: 7 additions & 12 deletions libs/RobotKit/include/RobotController.h
Original file line number Diff line number Diff line change
Expand Up @@ -477,16 +477,15 @@ class RobotController : public interface::RobotController
}
});

auto on_low_battery = [this] {
_batterykit.onLowBattery([this] {
if (!_batterykit.isCharging()) {
_behaviorkit.lowBattery();
}

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

_batterykit.startEventHandler();

Expand All @@ -498,11 +497,9 @@ class RobotController : public interface::RobotController

// Setup callbacks for each State Machine events

auto on_charge_did_start = [this]() { raise(event::charge_did_start {}); };
_batterykit.onChargeDidStart(on_charge_did_start);
_batterykit.onChargeDidStart([this] { raise(event::charge_did_start {}); });

auto on_charge_did_stop = [this]() { raise(event::charge_did_stop {}); };
_batterykit.onChargeDidStop(on_charge_did_stop);
_batterykit.onChargeDidStop([this] { raise(event::charge_did_stop {}); });

_service_monitoring.onSoftReboot([] { system_reset(); });

Expand All @@ -512,7 +509,7 @@ class RobotController : public interface::RobotController
std::ignore = _configkit.write(config_robot_name, robot_name);
});

auto on_commands_received = [this](std::span<uint8_t> _buffer) {
_service_commands.onCommandsReceived([this](std::span<uint8_t> _buffer) {
raise(event::command_received {});

if (!isCharging()) {
Expand All @@ -521,8 +518,7 @@ class RobotController : public interface::RobotController

_cmdkit.push(std::span {_buffer.data(), std::size(_buffer)});
}
};
_service_commands.onCommandsReceived(on_commands_received);
});

_service_file_exchange.onSetFileExchangeState([this](bool file_exchange_requested) {
if (file_exchange_requested) {
Expand All @@ -532,8 +528,7 @@ class RobotController : public interface::RobotController
}
});

auto on_update_requested = [this]() { raise(event::update_requested {}); };
_service_update.onUpdateRequested(on_update_requested);
_service_update.onUpdateRequested([this] { raise(event::update_requested {}); });

raise(event::setup_complete {});
}
Expand Down

0 comments on commit 4cb518c

Please sign in to comment.