5#ifndef INDEXABLE_BEHAVIOR_MANAGER_H
6#define INDEXABLE_BEHAVIOR_MANAGER_H
29 auto manager = get_context();
35 if (manager.state.isInFavoriteMockGroup)
38 manager.state.lastFavoriteStep += 1;
40 if (not manager.jump_to_favorite(manager.state.lastFavoriteStep,
false))
42 manager.exit_favorite_group(manager.state.beforeFavoriteActiveIndex);
47 if (manager.state.isLastScrollAGroupChange and manager.lamp.now - manager.state.lastScrollStopped < 2000)
54 manager.state.isLastScrollAGroupChange =
false;
64 int _groupId = manager.get_active_group();
65 int _modeId = manager.get_active_mode();
66 fprintf(stderr,
"group %d *mode %d\n", _groupId, _modeId);
67 if (manager.everySunsetCallback[_groupId][_modeId])
68 fprintf(stderr,
" - hasSunsetAnimation\n");
69 if (manager.everyBrightCallback[_groupId][_modeId])
70 fprintf(stderr,
" - hasBrightCallback\n");
71 if (manager.everyCustomRamp[_groupId][_modeId])
72 fprintf(stderr,
" - hasCustomRamp\n");
73 if (manager.state.rampHandler.animEffect)
74 fprintf(stderr,
" - has anim effect\n");
75 if (manager.everyRequireUserThread[_groupId][_modeId])
76 fprintf(stderr,
" - requireUserThread\n");
77 if (manager.everySystemCallbacks[_groupId][_modeId])
78 fprintf(stderr,
" - hasSystemCallbacks\n");
79 if (manager.everyButtonCustomUI[_groupId][_modeId])
80 fprintf(stderr,
" - hasButtonCustomUI\n");
89 if (manager.state.isInFavoriteMockGroup)
92 manager.exit_favorite_group(manager.state.beforeFavoriteActiveIndex);
100#ifdef LMBD_SIMULATION
102 int _groupId = manager.get_active_group();
103 int _modeId = manager.get_active_mode();
104 fprintf(stderr,
"group %d *mode %d\n", _groupId, _modeId);
105 if (manager.everySunsetCallback[_groupId][_modeId])
106 fprintf(stderr,
" - hasSunsetAnimation\n");
107 if (manager.everyBrightCallback[_groupId][_modeId])
108 fprintf(stderr,
" - hasBrightCallback\n");
109 if (manager.everyCustomRamp[_groupId][_modeId])
110 fprintf(stderr,
" - hasCustomRamp\n");
111 if (manager.state.rampHandler.animEffect)
112 fprintf(stderr,
" - has anim effect\n");
113 if (manager.everyRequireUserThread[_groupId][_modeId])
114 fprintf(stderr,
" - requireUserThread\n");
115 if (manager.everySystemCallbacks[_groupId][_modeId])
116 fprintf(stderr,
" - hasSystemCallbacks\n");
117 if (manager.everyButtonCustomUI[_groupId][_modeId])
118 fprintf(stderr,
" - hasButtonCustomUI\n");
126 if (not manager.state.isInFavoriteMockGroup)
129 manager.jump_to_favorite(manager.state.lastFavoriteStep,
true);
131#ifdef LMBD_SIMULATION
133 int _groupId = manager.get_active_group();
134 int _modeId = manager.get_active_mode();
135 fprintf(stderr,
"group %d *mode %d\n", _groupId, _modeId);
136 if (manager.everySunsetCallback[_groupId][_modeId])
137 fprintf(stderr,
" - hasSunsetAnimation\n");
138 if (manager.everyBrightCallback[_groupId][_modeId])
139 fprintf(stderr,
" - hasBrightCallback\n");
140 if (manager.everyCustomRamp[_groupId][_modeId])
141 fprintf(stderr,
" - hasCustomRamp\n");
142 if (manager.state.rampHandler.animEffect)
143 fprintf(stderr,
" - has anim effect\n");
144 if (manager.everyRequireUserThread[_groupId][_modeId])
145 fprintf(stderr,
" - requireUserThread\n");
146 if (manager.everySystemCallbacks[_groupId][_modeId])
147 fprintf(stderr,
" - hasSystemCallbacks\n");
148 if (manager.everyButtonCustomUI[_groupId][_modeId])
149 fprintf(stderr,
" - hasButtonCustomUI\n");
168 auto manager = get_context();
169 auto& rampHandler = manager.state.rampHandler;
175 if (not isEndOfHoldEvent)
179 if (not manager.state.isInFavoriteMockGroup && not manager.state.isInDeleteFavorite)
182 manager.animate_favorite_pick(holdDuration, 1500);
187 manager.animate_favorite_delete(holdDuration, 2000);
192 manager.state.isInDeleteFavorite =
false;
200 if (not manager.state.isInFavoriteMockGroup)
203 if (isEndOfHoldEvent)
206 manager.state.lastScrollStopped = manager.lamp.now;
210 manager.handle_scroll_modes(holdDuration);
236 auto manager = get_context();
237 if (manager.get_hidden_groups_count() <= 0)
239 bsp::lampda_print(
"Cannot use bluetooth control without an hidden bluetooth group");
243 const auto bluetoothGroup = manager.template get_group_id_of_mode<modes::bluetooth::ColorControlMode>();
244 if (bluetoothGroup < 0)
250 const auto availableModes = manager.get_modes_count();
251 if (availableModes <= patternIndex)
257 manager.exit_favorite_group(manager.state.beforeFavoriteActiveIndex);
258 manager.set_active_group(bluetoothGroup);
259 manager.set_active_mode(patternIndex);
262 const int trueIndex = manager.template get_mode_id<modes::bluetooth::ColorControlMode>();
263 assert(trueIndex == 0 &&
"Bluetooth group should have the programmable color output as the first group index");
266 if (patternIndex == 0)
268 auto& modeState = manager.template get_state_of_mode<modes::bluetooth::ColorControlMode>();
271 const uint16_t compressedColor = modes::colors::get_compressed_16b_color(requestedColor);
272 const uint8_t ramp = (compressedColor >> 8) & 0xFF;
273 const uint8_t index = compressedColor & 0xFF;
274 manager.set_active_custom_ramp(ramp);
275 manager.set_active_custom_index(index);
289 auto manager = get_context();
290 if (favoriteIndex >= manager.state.usedFavoriteCount)
292 bsp::lampda_print(
"Cannot jump to favorite %d, max index should be less than %d",
294 manager.state.usedFavoriteCount);
298 manager.jump_to_favorite(favoriteIndex,
true);
311 auto manager = get_context();
314 if (manager.state.isInFavoriteMockGroup)
317 const uint8_t allowedFavorites = manager.get_number_of_allowed_favorites();
320 if (favoriteIndex >= allowedFavorites)
322 bsp::lampda_print(
"Max favorites is [0; %d[, cannot add index %d", allowedFavorites, favoriteIndex);
327 manager.set_current_mode_as_favorite(favoriteIndex, 1000);
335 if (default_behaviors::handle_user_command(command))
341 switch (command.get_type())
347 __private::handle_pattern_select_command(0, color);
356 __private::handle_pattern_select_command(index);
365 __private::handle_go_to_favorite_command(index);
374 __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
Manipulate color representations.
void handle_set_favorite_command(const uint8_t favoriteIndex)
Set the current mode to favorite.
Definition: indexable_behavior.hpp:305
void handle_go_to_favorite_command(const uint8_t favoriteIndex)
Go to the given favorite index if possible.
Definition: indexable_behavior.hpp:283
void handle_pattern_select_command(const uint8_t patternIndex, const uint32_t requestedColor=0)
Handle a pattern change command.
Definition: indexable_behavior.hpp:229
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:20
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:159
void handle_user_command(const common::UserCommand &command)
Handle user command.
Definition: indexable_behavior.hpp:332