1010#include " BLEServiceCommands.h"
1111
1212#include " BatteryKit.h"
13+ #include " BehaviorKit.h"
1314#include " CoreBattery.h"
1415#include " CoreI2C.h"
1516#include " CoreLSM6DSOX.hpp"
2425#include " LogKit.h"
2526#include " MathUtils.h"
2627#include " SealStrategy.h"
28+ #include " behaviors/AutochargeSeal.h"
2729
2830using namespace std ::chrono;
2931using namespace leka ;
@@ -100,30 +102,11 @@ auto service_commands = BLEServiceCommands {};
100102auto services = std::to_array<interface::BLEService *>({&service_commands});
101103auto blekit = BLEKit {};
102104
103- auto seal_strategy =
104- SealStrategy {event_loop, timeout, battery::cells, motors::left::motor, motors::right::motor, imukit};
105- auto happy_toupie = HappyToupie {event_loop, timeout, battery::cells, motors::left::motor, motors::right::motor};
106- auto happy_fishy = HappyFishy {event_loop, timeout, battery::cells, motors::left::motor, motors::right::motor};
105+ auto behavior_autocharge_seal = behavior::AutochargeSeal {motors::left::motor, motors::right::motor, imukit};
106+ auto behaviors = std::to_array<interface::Behavior *>({&behavior_autocharge_seal});
107+ auto behavior_kit = BehaviorKit {event_loop};
107108
108- auto last_strategy = uint8_t {0x00 };
109-
110- void runStrategy (uint8_t id)
111- {
112- if (id == 0x01 ) {
113- seal_strategy.start ();
114- last_strategy = id;
115- } else if (id == 0x02 ) {
116- happy_toupie.start ();
117- last_strategy = id;
118- } else if (id == 0x03 ) {
119- happy_fishy.start ();
120- last_strategy = id;
121- } else {
122- seal_strategy.stop ();
123- happy_toupie.stop ();
124- happy_fishy.stop ();
125- }
126- }
109+ auto last_strategy = BehaviorID {0x00 };
127110
128111auto main () -> int
129112{
@@ -140,10 +123,16 @@ auto main() -> int
140123 imukit.init ();
141124 imukit.start ();
142125
143- battery::cells.onChargeDidStop ([] { runStrategy (last_strategy); });
126+ behavior_kit.registerBehaviors (behaviors);
127+
128+ battery::cells.onChargeDidStart ([] { behavior_kit.stop (); });
129+ battery::cells.onChargeDidStop ([] { behavior_kit.start (last_strategy); });
144130
145131 blekit.setServices (services);
146- service_commands.onCommandsReceived ([](std::span<uint8_t > _buffer) { runStrategy (_buffer[0 ]); });
132+ service_commands.onCommandsReceived ([](std::span<uint8_t > _buffer) {
133+ behavior_kit.start (_buffer[0 ]);
134+ last_strategy = _buffer[0 ];
135+ });
147136 blekit.init ();
148137
149138 while (true ) {
0 commit comments