From 4cb518c090ff7c64142da41eb2cb187f70845d10 Mon Sep 17 00:00:00 2001 From: Yann Locatelli Date: Mon, 5 Feb 2024 13:38:38 +0100 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20(RobotController):=20Move?= =?UTF-8?q?=20registered=20callback=20in=20methods?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- libs/RobotKit/include/RobotController.h | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/libs/RobotKit/include/RobotController.h b/libs/RobotKit/include/RobotController.h index affc92aea..0e194a3a5 100644 --- a/libs/RobotKit/include/RobotController.h +++ b/libs/RobotKit/include/RobotController.h @@ -477,7 +477,7 @@ class RobotController : public interface::RobotController } }); - auto on_low_battery = [this] { + _batterykit.onLowBattery([this] { if (!_batterykit.isCharging()) { _behaviorkit.lowBattery(); } @@ -485,8 +485,7 @@ class RobotController : public interface::RobotController if (_batterykit.level() == 0) { system_reset(); } - }; - _batterykit.onLowBattery(on_low_battery); + }); _batterykit.startEventHandler(); @@ -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(); }); @@ -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 _buffer) { + _service_commands.onCommandsReceived([this](std::span _buffer) { raise(event::command_received {}); if (!isCharging()) { @@ -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) { @@ -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 {}); }