5#ifndef DEFAULT_BEHAVIOR_MANAGER_HPP
6#define DEFAULT_BEHAVIOR_MANAGER_HPP
33 auto manager = get_context();
36 manager.lamp.startup();
39 manager.power_on_sequence();
45 auto manager = get_context();
46 manager.power_off_sequence();
50 manager.lamp.show_now();
53 ensure_build_canary();
58 auto manager = get_context();
61 if (brightness <= ::lampda::brightness::absoluteMaximumBrightness)
64 manager.lamp.align_internal_to_system_brightness();
67 manager.lamp.setBrightness(brightness,
true,
true);
70 manager.brightness_update(brightness);
75 manager.lamp.enforce_internal_brightness_limits();
81 auto manager = get_context();
84 manager.sunset_update(progress);
89 auto manager = get_context();
90 manager.write_parameters();
95 auto manager = get_context();
96 manager.read_parameters();
107 if (not isEndOfHoldEvent and holdDuration > 0)
110 auto manager = get_context();
111 if (manager.overlay_animate_ramp(
112 holdDuration, 1000, modes::colors::PaletteGradient<modes::colors::White, modes::colors::Red>))
115 manager.state.isSunsetTimingPending = 2;
129 auto manager = get_context();
130 return manager.custom_click(clicks);
135 auto manager = get_context();
136 return manager.custom_hold(clicks, isEndOfHoldEvent, holdDuration);
141 auto manager = get_context();
145 manager.lamp.signal_display();
150#ifdef LMBD_LAMP_TYPE__INDEXABLE
154 auto manager = get_context();
155 return manager.should_spawn_thread();
161 auto manager = get_context();
164 if (manager.should_spawn_thread())
165 manager.user_thread();
169namespace default_behaviors {
174 auto manager = get_context();
180 if (manager.state.isInFavoriteMockGroup)
182 manager.state.isInFavoriteMockGroup =
false;
185 manager.set_active_group(0);
186 manager.set_active_mode(0);
197bool button_hold(
const uint8_t clicks,
const bool isEndOfHoldEvent,
const uint32_t holdDuration)
199 auto manager = get_context();
200 auto& rampHandler = manager.state.rampHandler;
206 if (not manager.state.isInFavoriteMockGroup)
208 rampHandler.update_ramp(manager.get_active_custom_ramp(), holdDuration, [&](uint8_t rampValue) {
209 manager.custom_ramp_update(rampValue);
210 manager.set_active_custom_ramp(rampValue);
222 auto manager = get_context();
223 if (manager.overlay_animate_ramp(
224 holdDuration, 1000, modes::colors::PaletteGradient<modes::colors::White, modes::colors::Red>))
227 manager.state.isSunsetTimingPending = 2;
235 if (not isEndOfHoldEvent and holdDuration > 0)
237 auto manager = get_context();
238 if (manager.overlay_animate_ramp(
239 holdDuration, 5000, modes::colors::PaletteGradient<modes::colors::Red, modes::colors::Red>))
246 const bool shouldSaveUserParameters =
false;
247 logic::behavior::internal::handle_shutdown_state(shouldSaveUserParameters);
255 if (not isEndOfHoldEvent and holdDuration > 0)
257 auto manager = get_context();
258 if (manager.overlay_animate_ramp(
259 holdDuration, 5000, modes::colors::PaletteGradient<modes::colors::Red, modes::colors::Red>))
266 const bool shouldSaveUserParameters =
false;
267 const bool shouldSaveSystemParameters =
false;
268 logic::behavior::internal::handle_shutdown_state(shouldSaveUserParameters, shouldSaveSystemParameters);
278namespace __private_elk {
288 static constexpr float brightnessMultiplier = ::lampda::brightness::absoluteMaximumBrightness / 100.0f;
290 min<brightness_t>(::lampda::brightness::absoluteMaximumBrightness,
291 static_cast<brightness_t>(requiredBrigthness * brightnessMultiplier));
327 auto manager = get_context();
330 manager.custom_ramp_update(speed, 1000);
332 manager.set_active_custom_ramp(speed);
339 switch (elkControlCommand.type)
343 __private_elk::handle_brigthness_control(elkControlCommand.data[0]);
348 const bool shouldTurnOn = elkControlCommand.data[0] > 0;
349 __private_elk::handle_on_off_command(shouldTurnOn);
354 const uint8_t speed = (elkControlCommand.data[0] / 100.0) * UINT8_MAX;
355 __private_elk::handle_speed_command(speed);
void clear(const Type type)
Clear an alert.
Definition: alerts.cpp:882
void handle_on_off_command(const bool shouldBeOn)
handle the On or Off command
Definition: default_behavior.hpp:301
void handle_brigthness_control(const uint8_t requiredBrigthness)
handle the brightness command
Definition: default_behavior.hpp:281
void handle_speed_command(const uint8_t speed)
Handle the speed command.
Definition: default_behavior.hpp:321
void set_power_on()
set system state to "output on"
Definition: behavior.cpp:123
void set_power_off()
set system state to "output off". Can be ignored
Definition: behavior.cpp:124
bool is_in_output_state()
return true if the system is in output mode
Definition: behavior.cpp:137
void update_brightness(const brightness_t newBrightness, const bool shouldCallUserBrightnessCallback)
update the internal brightness values
Definition: brightness_handle.cpp:66
void update_saved_brightness()
Update the saved brightness value with the current brightness.
Definition: brightness_handle.cpp:58
void bump_timer()
signal to the timer that some time must be added. Limited to 10 minutes
Definition: sunset_timer.cpp:154
bool is_enabled()
True if timer is running.
Definition: sunset_timer.cpp:189
void clear_internal_fs()
hard clean of the whole filesystem, you will loose all stored data.
Definition: fileSystem.cpp:89
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:197
bool button_clicked(const uint8_t clicks)
must be called by the lampda::user::button_clicked_default
Definition: default_behavior.hpp:172
Contains code handling custom user mode functions for indexable strips.
Definition: default_behavior.hpp:15
void brightness_update(const brightness_t brightness)
Called when the system changes the LED strip brightness.
Definition: default_behavior.hpp:56
void user_thread()
Called at each tick of the secondary thread.
Definition: default_behavior.hpp:159
bool button_hold_usermode(const uint8_t clicks, const bool isEndOfHoldEvent, const uint32_t holdDuration)
Called to handle button click+hold events if "usermode UI" is on.
Definition: default_behavior.hpp:133
bool button_start_hold_default(const uint8_t clicks, const bool isEndOfHoldEvent, const uint32_t holdDuration)
Called to handle button hold on lamp start.
Definition: default_behavior.hpp:101
void read_parameters()
Called when system wants to read parameters from filesystem.
Definition: default_behavior.hpp:93
void power_on_sequence()
Called when the system powers on (must be non blocking function!)
Definition: default_behavior.hpp:31
void sunset_timer_update(const float progress)
Called when the sunset timer progresses [0; 1].
Definition: default_behavior.hpp:79
bool button_start_click_default(const uint8_t clicks)
Called to handle button click on lamp start.
Definition: default_behavior.hpp:99
bool should_spawn_thread()
Determine if a second user_thread() loop thread should be spawned.
Definition: default_behavior.hpp:148
void write_parameters()
Called when system wants to write parameters to filesystem.
Definition: default_behavior.hpp:87
void 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:118
void power_off_sequence()
Called when the system powers off (must be non blocking function!)
Definition: default_behavior.hpp:42
void loop()
Called at each tick of the main loop.
Definition: default_behavior.hpp:139
void button_clicked_default(const uint8_t)
Called to handle button click events for default user mode behaviors.
Definition: indexable_behavior.hpp:18
bool button_clicked_usermode(const uint8_t clicks)
Called to handle button click events if "usermode UI" is active.
Definition: default_behavior.hpp:127
@ PATTERN_SPEED
set the current pattern speed
@ BRIGHTNESS
set a brightness
@ ONOFF
turn output onand off
uint16_t brightness_t
Define the type of the brightness parameters.
Definition: constants.h:147
Definition: elk_decoder.h:33