5#ifndef INDEXABLE_BEHAVIOR_MANAGER_H
6#define INDEXABLE_BEHAVIOR_MANAGER_H
27 auto manager = get_context();
33 if (manager.state.isInFavoriteMockGroup)
36 manager.state.lastFavoriteStep += 1;
38 if (not manager.jump_to_favorite(manager.state.lastFavoriteStep,
false))
40 manager.exit_favorite_group(manager.state.beforeFavoriteActiveIndex);
45 if (manager.state.isLastScrollAGroupChange and manager.lamp.now - manager.state.lastScrollStopped < 2000)
52 manager.state.isLastScrollAGroupChange =
false;
62 int _groupId = manager.get_active_group();
63 int _modeId = manager.get_active_mode();
64 fprintf(stderr,
"group %d *mode %d\n", _groupId, _modeId);
65 if (manager.everySunsetCallback[_groupId][_modeId])
66 fprintf(stderr,
" - hasSunsetAnimation\n");
67 if (manager.everyBrightCallback[_groupId][_modeId])
68 fprintf(stderr,
" - hasBrightCallback\n");
69 if (manager.everyCustomRamp[_groupId][_modeId])
70 fprintf(stderr,
" - hasCustomRamp\n");
71 if (manager.state.rampHandler.animEffect)
72 fprintf(stderr,
" - has anim effect\n");
73 if (manager.everyRequireUserThread[_groupId][_modeId])
74 fprintf(stderr,
" - requireUserThread\n");
75 if (manager.everySystemCallbacks[_groupId][_modeId])
76 fprintf(stderr,
" - hasSystemCallbacks\n");
77 if (manager.everyButtonCustomUI[_groupId][_modeId])
78 fprintf(stderr,
" - hasButtonCustomUI\n");
87 if (manager.state.isInFavoriteMockGroup)
90 manager.exit_favorite_group(manager.state.beforeFavoriteActiveIndex);
100 int _groupId = manager.get_active_group();
101 int _modeId = manager.get_active_mode();
102 fprintf(stderr,
"group %d *mode %d\n", _groupId, _modeId);
103 if (manager.everySunsetCallback[_groupId][_modeId])
104 fprintf(stderr,
" - hasSunsetAnimation\n");
105 if (manager.everyBrightCallback[_groupId][_modeId])
106 fprintf(stderr,
" - hasBrightCallback\n");
107 if (manager.everyCustomRamp[_groupId][_modeId])
108 fprintf(stderr,
" - hasCustomRamp\n");
109 if (manager.state.rampHandler.animEffect)
110 fprintf(stderr,
" - has anim effect\n");
111 if (manager.everyRequireUserThread[_groupId][_modeId])
112 fprintf(stderr,
" - requireUserThread\n");
113 if (manager.everySystemCallbacks[_groupId][_modeId])
114 fprintf(stderr,
" - hasSystemCallbacks\n");
115 if (manager.everyButtonCustomUI[_groupId][_modeId])
116 fprintf(stderr,
" - hasButtonCustomUI\n");
124 if (not manager.state.isInFavoriteMockGroup)
127 manager.jump_to_favorite(manager.state.lastFavoriteStep,
true);
129#ifdef LMBD_SIMULATION
131 int _groupId = manager.get_active_group();
132 int _modeId = manager.get_active_mode();
133 fprintf(stderr,
"group %d *mode %d\n", _groupId, _modeId);
134 if (manager.everySunsetCallback[_groupId][_modeId])
135 fprintf(stderr,
" - hasSunsetAnimation\n");
136 if (manager.everyBrightCallback[_groupId][_modeId])
137 fprintf(stderr,
" - hasBrightCallback\n");
138 if (manager.everyCustomRamp[_groupId][_modeId])
139 fprintf(stderr,
" - hasCustomRamp\n");
140 if (manager.state.rampHandler.animEffect)
141 fprintf(stderr,
" - has anim effect\n");
142 if (manager.everyRequireUserThread[_groupId][_modeId])
143 fprintf(stderr,
" - requireUserThread\n");
144 if (manager.everySystemCallbacks[_groupId][_modeId])
145 fprintf(stderr,
" - hasSystemCallbacks\n");
146 if (manager.everyButtonCustomUI[_groupId][_modeId])
147 fprintf(stderr,
" - hasButtonCustomUI\n");
166 auto manager = get_context();
167 auto& rampHandler = manager.state.rampHandler;
173 if (not isEndOfHoldEvent)
177 if (not manager.state.isInFavoriteMockGroup && not manager.state.isInDeleteFavorite)
180 manager.animate_favorite_pick(holdDuration, 1500);
185 manager.animate_favorite_delete(holdDuration, 2000);
190 manager.state.isInDeleteFavorite =
false;
198 if (not manager.state.isInFavoriteMockGroup)
201 if (isEndOfHoldEvent)
204 manager.state.lastScrollStopped = manager.lamp.now;
208 manager.handle_scroll_modes(holdDuration);
234 auto manager = get_context();
235 if (manager.get_hidden_groups_count() <= 0)
237 bsp::lampda_print(
"Cannot use bluetooth control without an hidden bluetooth group");
241 const auto bluetoothGroup = manager.template get_group_id_of_mode<modes::bluetooth::ColorControlMode>();
242 if (bluetoothGroup < 0)
248 const auto availableModes = manager.get_modes_count();
249 if (availableModes <= patternIndex)
255 manager.set_active_group(bluetoothGroup);
256 manager.set_active_mode(patternIndex);
259 const int trueIndex = manager.template get_mode_id<modes::bluetooth::ColorControlMode>();
260 assert(trueIndex == 0 &&
"Bluetooth group should have the programmable color output as the first group index");
263 if (patternIndex == 0)
265 auto& modeState = manager.template get_state_of_mode<modes::bluetooth::ColorControlMode>();
266 modeState.color = requestedColor;
280 auto manager = get_context();
283 manager.jump_to_favorite(favoriteIndex,
true);
296 auto manager = get_context();
299 if (manager.state.isInFavoriteMockGroup)
302 const uint8_t allowedFavorites = manager.get_number_of_allowed_favorites();
305 if (favoriteIndex >= allowedFavorites)
307 bsp::lampda_print(
"Max favorites is [0; %d[, cannot add index %d", allowedFavorites, favoriteIndex);
312 manager.set_current_mode_as_favorite(favoriteIndex, 1000);
320 if (default_behaviors::handle_user_command(command))
326 switch (command.get_type())
332 __private::handle_pattern_select_command(0, color);
341 __private::handle_pattern_select_command(index);
350 __private::handle_go_to_favorite_command(index);
359 __private::handle_set_favorite_command(index);
Define assertions helpers.
Define a command destined to the user layer. Command can only be created by the static make_* methods...
Definition: user_commands.h:21
bool parse_set_favorite_command(uint8_t &index) const
Parse the current command for a set favorite.
Definition: user_commands.cpp:214
bool parse_set_ble_mode_command(uint8_t &index) const
Parse the current command for a set current mode to BLE mode.
Definition: user_commands.cpp:198
bool parse_go_to_favorite_command(uint8_t &index) const
Parse the current command for a go to favorite.
Definition: user_commands.cpp:206
@ SetBleMode
switch to a target BLE mode
@ SetBleCustomColorMode
switch to BLE custom color mode
@ SetFavoriteIndex
Set the current mode to the target favorite index.
@ GoToFavoriteIndex
Go to the target favorite index.
bool parse_set_ble_custom_color_mode_command(uint32_t &color) const
Parse the current command for a set current mode to BLE custom color.
Definition: user_commands.cpp:189
void handle_set_favorite_command(const uint8_t favoriteIndex)
Set the current mode to favorite.
Definition: indexable_behavior.hpp:290
void handle_go_to_favorite_command(const uint8_t favoriteIndex)
Go to the given favorite index if possible.
Definition: indexable_behavior.hpp:274
void handle_pattern_select_command(const uint8_t patternIndex, const uint32_t requestedColor=0)
Handle a pattern change command.
Definition: indexable_behavior.hpp:227
void lampda_print(const char *format,...)
C linkage to print functions.
Definition: text_out.cpp:227
bool is_in_output_state()
return true if the system is in output mode
Definition: behavior.cpp:139
bool button_hold(const uint8_t clicks, const bool isEndOfHoldEvent, const uint32_t holdDuration)
must be called by the lampda::user::button_hold_default
Definition: default_behavior.hpp:247
bool button_clicked(const uint8_t clicks)
must be called by the lampda::user::button_clicked_default
Definition: default_behavior.hpp:219
Contains code handling custom user mode functions for indexable strips.
Definition: default_behavior.hpp:18
bool button_clicked_default(const uint8_t)
Called to handle button click events for default user mode behaviors.
Definition: indexable_behavior.hpp:18
bool button_hold_default(const uint8_t, const bool, const uint32_t)
Called to handle button click+hold events for user mode behaviors.
Definition: indexable_behavior.hpp:157
void handle_user_command(const common::UserCommand &command)
Handle user command.
Definition: indexable_behavior.hpp:317