17#include "src/modes/include/default_config.hpp"
25template<
typename NewLocalMode>
static auto context_as(
auto& ctx) {
return ctx.template context_as<NewLocalMode>(); }
28template<
typename LocalBasicMode,
typename ModeManager>
struct ContextTy
43 static constexpr bool isMode = is_mode<LocalModeTy>;
46 static constexpr bool isModeManager = std::is_same_v<LocalModeTy, ModeManagerTy>;
47 static constexpr bool isGroupManager =
false;
50 static constexpr bool hasSunsetAnimation = LocalModeTy::hasSunsetAnimation;
51 static constexpr bool hasBrightCallback = LocalModeTy::hasBrightCallback;
52 static constexpr bool hasSystemCallbacks = LocalModeTy::hasSystemCallbacks;
53 static constexpr bool requireUserThread = LocalModeTy::requireUserThread;
54 static constexpr bool hasCustomRamp = LocalModeTy::hasCustomRamp;
55 static constexpr bool hasButtonCustomUI = LocalModeTy::hasButtonCustomUI;
58 static constexpr auto everySunsetCallback = LocalModeTy::everySunsetCallback;
59 static constexpr auto everyBrightCallback = LocalModeTy::everyBrightCallback;
60 static constexpr auto everySystemCallbacks = LocalModeTy::everySystemCallbacks;
61 static constexpr auto everyRequireUserThread = LocalModeTy::everyRequireUserThread;
62 static constexpr auto everyCustomRamp = LocalModeTy::everyCustomRamp;
63 static constexpr auto everyButtonCustomUI = LocalModeTy::everyButtonCustomUI;
70 template<
typename NewLocalMode>
auto LMBD_INLINE
context_as()
79 modeManager {modeManager}
84 ContextTy(
const ContextTy&) =
delete;
85 ContextTy& operator=(
const ContextTy&) =
delete;
92 auto LMBD_INLINE next_group()
94 if constexpr (LocalModeTy::isGroupManager)
96 LocalModeTy::next_group(*
this);
100 auto manager = modeManager.get_context();
101 return manager.next_group();
106 auto LMBD_INLINE next_mode()
108 if constexpr (LocalModeTy::isModeManager)
110 LocalModeTy::next_mode(*
this);
114 auto manager = modeManager.get_context();
120 bool LMBD_INLINE jump_to_favorite(uint8_t which_one,
bool shouldSaveLastActiveIndex)
122 if constexpr (LocalModeTy::isModeManager)
124 return LocalModeTy::jump_to_favorite(*
this, which_one, shouldSaveLastActiveIndex);
128 auto manager = modeManager.get_context();
129 return manager.jump_to_favorite(which_one, shouldSaveLastActiveIndex);
134 bool LMBD_INLINE exit_favorite_group(
auto nextActiveIndex)
136 if constexpr (LocalModeTy::isModeManager)
138 return LocalModeTy::exit_favorite_group(*
this, nextActiveIndex);
142 auto manager = modeManager.get_context();
143 return manager.exit_favorite_group(nextActiveIndex);
148 auto LMBD_INLINE set_favorite_now(uint8_t which_one = 0)
150 if constexpr (LocalModeTy::isModeManager)
152 return LocalModeTy::set_favorite_now(*
this, which_one);
156 auto manager = modeManager.get_context();
157 return manager.set_favorite_now(which_one);
162 auto LMBD_INLINE delete_favorite_now()
164 if constexpr (LocalModeTy::isModeManager)
166 return LocalModeTy::delete_favorite_now(*
this);
170 auto manager = modeManager.get_context();
171 return manager.delete_favorite_now();
176 auto LMBD_INLINE handle_scroll_modes(
const uint32_t holdDuration)
178 if constexpr (LocalModeTy::isModeManager)
180 return LocalModeTy::handle_scroll_modes(*
this, holdDuration);
184 auto manager = modeManager.get_context();
185 return manager.handle_scroll_modes(holdDuration);
190 auto LMBD_INLINE enter_hidden_group(
const uint8_t hiddenGroupIndex)
192 if constexpr (LocalModeTy::isModeManager)
194 return LocalModeTy::enter_hidden_group(*
this, hiddenGroupIndex);
198 auto manager = modeManager.get_context();
199 return manager.enter_hidden_group(hiddenGroupIndex);
204 auto LMBD_INLINE overlay_animate_ramp(
float holdDuration,
207 const uint32_t timeout = 0)
209 if constexpr (LocalModeTy::isModeManager)
211 return modeManager.overlay_animate_ramp(*
this, holdDuration, stepSize, palette, timeout);
215 auto manager = modeManager.get_context();
216 return manager.overlay_animate_ramp(holdDuration, stepSize, palette, timeout);
221 auto LMBD_INLINE overlay_animate_ramp(uint8_t progress,
const colors::PaletteTy& palette,
const uint32_t timeout = 0)
223 if constexpr (LocalModeTy::isModeManager)
225 return modeManager.overlay_animate_ramp(*
this, progress, palette, timeout);
229 auto manager = modeManager.get_context();
230 return manager.overlay_animate_ramp(progress, palette, timeout);
235 auto LMBD_INLINE get_groups_count() {
return modeManager.nbGroupsTotal; }
237 auto LMBD_INLINE get_accessible_groups_count() {
return modeManager.nbAccessibleGroups; }
239 auto LMBD_INLINE get_hidden_groups_count() {
return modeManager.hiddenGroupCount; }
242 auto LMBD_INLINE get_modes_count()
244 if constexpr (LocalModeTy::isModeManager)
246 return modeManager.get_modes_count(*
this);
250 auto manager = modeManager.get_context();
251 return manager.get_modes_count();
262 uint8_t groupIndex = modeManager.activeIndex.groupIndex;
263 return (groupIndex + 1) > maxValueWrap ? 0 : groupIndex;
269 if (value + 1 > maxValueWrap)
282 uint8_t modeIndex = modeManager.activeIndex.modeIndex;
283 return (modeIndex + 1) > maxValueWrap ? 0 : modeIndex;
289 if (value + 1 > maxValueWrap)
292 auto manager = modeManager.get_context();
296 manager.cancel_blip();
299 if (modeManager.activeIndex.modeIndex == value)
309 modeManager.quit_mode(manager);
311 modeManager.activeIndex.modeIndex = value;
313 modeManager.enter_mode(manager);
329 modeManager.activeIndex.rampIndex = value;
339 modeManager.activeIndex.customIndex = value;
348 template<
typename Mode> StateTyOf<Mode>&
get_state_of_mode() {
return modeManager.template getStateOf<Mode>(); }
353 return details::GroupIdFrom<Mode, typename ModeManagerTy::AllGroupsTy>;
359 return details::ModeIdFrom<Mode, typename ModeManagerTy::AllGroupsTy, get_group_id_of_mode<Mode>()>;
363 static constexpr int groupId = get_group_id_of_mode<LocalModeTy>();
366 static constexpr int modeId = get_mode_id<LocalModeTy>();
369 static constexpr auto prefix =
370 (isModeManager ? store::PrefixValues::managerKeys :
371 (isMode ? store::PrefixValues::generalKeys : store::PrefixValues::privateKeys));
374 using StoreEnum = StoreEnumOf<LocalModeTy>;
377 using LocalStore = store::KeyStore<StoreEnum, groupId, modeId, prefix>;
380 static constexpr bool hasStore = not std::is_same_v<StoreEnum, NoStoreHere>;
421 template<StoreEnum _key,
typename T>
struct KeyProxy
423 static_assert(std::is_same_v<T, std::conditional_t<hasStore, T, NoStoreId>>,
424 "KeyProxy can not be used when no storeId has been defined!");
427 static constexpr StoreEnum
key = _key;
436 LocalStore::template setValue<key, T>(value);
440 inline bool LMBD_INLINE
getValue() {
return LocalStore::template getValue<key, T>(
local); }
443 inline void LMBD_INLINE
getValue(T defVal) { LocalStore::template getValue<key, T>(
local, defVal); }
446 inline bool LMBD_INLINE
hasValue() {
return LocalStore::template hasValue<key, T>(); }
453 inline void LMBD_INLINE forceSave() { LocalStore::template setValue<key, T>(
local); }
471 template<StoreEnum key,
typename T = u
int32_t>
485 template<StoreEnum key,
typename T = u
int32_t>
static bool LMBD_INLINE
storageLoadOnly(LMBD_USED T& local)
487 return LocalStore::template getValue<key, T>(local);
491 template<StoreEnum key,
typename T = u
int32_t>
494 LocalStore::template getValue<key, T>(local, defaultValue);
498 template<StoreEnum key,
typename T = u
int32_t>
static void LMBD_INLINE
storageSaveOnly(LMBD_USED T& local)
500 return LocalStore::template setValue<key, T>(local);
513 auto ctx = modeManager.get_context();
517 ctx.state.rampHandler.rampSaturates = value;
520 ctx.state.clearStripOnModeChange = value;
523 ctx.state.rampHandler.animEffect = value;
526 assert(
false &&
"unsupported config key for booleans!");
537 auto ctx = modeManager.get_context();
541 ctx.state.rampHandler.stepSpeed = value;
544 ctx.state.rampHandler.animChoice = value;
547 assert(
false &&
"unsupported config key for u32!");
560 void blip(
const uint32_t duration)
562 auto ctx = modeManager.get_context();
564 ctx.state.skipNextFrameEffect = ceil(duration /
static_cast<float>(ctx.lamp.frameDurationMs));
566 ctx.lamp.blip(duration);
572 auto ctx = modeManager.get_context();
574 ctx.state.skipNextFrameEffect = 0;
575 ctx.lamp.cancel_blip();
581 auto ctx = modeManager.get_context();
582 return ctx.lamp.is_bliping();
595 auto ctx = modeManager.get_context();
596 ctx.lamp.config.skipFirstLedsForAmount = amount;
597 ctx.lamp.config.skipFirstLedsForEffect = count;
607 if constexpr (LocalModeTy::isModeManager)
609 LocalModeTy::enter_group(*
this, value);
613 auto& manager = modeManager.get_context();
614 return manager.enter_group(value);
621 if constexpr (LocalModeTy::isModeManager)
623 LocalModeTy::quit_group(*
this);
627 auto& manager = modeManager.get_context();
628 return manager.quit_group();
635 if constexpr (LocalModeTy::isModeManager)
637 LocalModeTy::enter_mode(*
this);
641 auto& manager = modeManager.get_context();
642 return manager.enter_mode();
649 if constexpr (LocalModeTy::isModeManager)
651 LocalModeTy::quit_mode(*
this);
655 auto& manager = modeManager.get_context();
656 return manager.quit_mode();
665 void LMBD_INLINE
loop() { LocalModeTy::loop(*
this); }
672 LocalStore::template migrateStoreIfNeeded<LocalModeTy::storeId>();
674 LocalModeTy::on_enter_mode(*
this);
681 LocalModeTy::on_exit_mode(*
this);
687 if constexpr (LocalModeTy::hasSunsetAnimation)
689 LocalModeTy::sunset_update(*
this, progress);
696 if constexpr (LocalModeTy::hasBrightCallback)
698 LocalModeTy::brightness_update(*
this, brightness);
705 if constexpr (LocalModeTy::isGroupManager)
707 LocalModeTy::custom_ramp_update(*
this, rampValue, timeout);
709 else if constexpr (LocalModeTy::hasCustomRamp)
711 LocalModeTy::custom_ramp_update(*
this, rampValue);
718 if constexpr (LocalModeTy::hasButtonCustomUI)
720 return LocalModeTy::custom_click(*
this, nbClick);
728 LMBD_USED
bool isEndOfHoldEvent,
729 LMBD_USED uint32_t holdDuration)
731 if constexpr (LocalModeTy::hasButtonCustomUI)
733 return LocalModeTy::custom_hold(*
this, nbClickAndHold, isEndOfHoldEvent, holdDuration);
739 void display_favorite_number_ramp(
const uint8_t favoriteIndex,
740 const uint8_t maxFavoriteIndex,
741 const bool display =
false,
742 const uint32_t timeout = 0)
744 if constexpr (LocalModeTy::isModeManager)
746 modeManager.template display_favorite_number_ramp(*
this, favoriteIndex, maxFavoriteIndex, display, timeout);
750 auto& manager = modeManager.get_context();
751 manager.display_favorite_number_ramp(favoriteIndex, maxFavoriteIndex, display, timeout);
755 template<
bool displayFavoriteNumber = true>
756 auto set_current_mode_as_favorite(uint8_t favoriteIndex, uint32_t displayTimeout_s = 0)
758 if constexpr (LocalModeTy::isModeManager)
760 modeManager.template set_current_mode_as_favorite<displayFavoriteNumber>(*
this, favoriteIndex, displayTimeout_s);
764 auto&
manager = modeManager.get_context();
765 manager.set_current_mode_as_favorite<displayFavoriteNumber>(favoriteIndex, displayTimeout_s);
769 auto get_number_of_allowed_favorites()
771 if constexpr (LocalModeTy::isModeManager)
773 return modeManager.template get_number_of_allowed_favorites(*
this);
777 auto&
manager = modeManager.get_context();
778 return manager.get_number_of_allowed_favorites(*
this);
782 template<
bool displayFavoriteNumber = true>
auto LMBD_INLINE animate_favorite_pick(
float holdDuration,
float stepSize)
784 if constexpr (LocalModeTy::isModeManager)
786 return modeManager.template animate_favorite_pick<displayFavoriteNumber>(*
this, holdDuration, stepSize);
790 auto&
manager = modeManager.get_context();
791 return manager.template animate_favorite_pick<displayFavoriteNumber>(holdDuration, stepSize);
795 template<
bool displayFavoriteNumber = true>
796 auto LMBD_INLINE animate_favorite_delete(
float holdDuration,
float stepSize)
798 if constexpr (LocalModeTy::isModeManager)
800 return modeManager.template animate_favorite_delete<displayFavoriteNumber>(*
this, holdDuration, stepSize);
804 auto&
manager = modeManager.get_context();
805 return manager.template animate_favorite_delete<displayFavoriteNumber>(holdDuration, stepSize);
815 if constexpr (LocalModeTy::hasSystemCallbacks)
817 LocalModeTy::power_on_sequence(*
this);
824 if constexpr (LocalModeTy::hasSystemCallbacks)
826 LocalModeTy::power_off_sequence(*
this);
833 if constexpr (LocalModeTy::hasSystemCallbacks)
835 LocalModeTy::write_parameters(*
this);
842 if constexpr (LocalModeTy::hasSystemCallbacks)
844 LocalModeTy::read_parameters(*
this);
854 if constexpr (LocalModeTy::requireUserThread)
856 LocalModeTy::user_thread(*
this);
Filesystem interaction tools.
Define the main led strip interaction object.
AlertManager_t manager
Instanciation of the AlertManager.
Definition: alerts.cpp:29
std::array< uint32_t, 16 > PaletteTy
Palette types.
Definition: palettes.hpp:18
Contains basic interface types to implement custom user modes.
Definition: control_fixed_modes.hpp:12
@ customRampAnimEffect
(bool) Mode uses custom ramp anim. or not?
@ rampSaturates
(bool) Mode saturates on custom ramp, or else wrap?
@ clearStripOnModeChange
(bool) Mode clear strip after reset, or else do nothing?
@ customRampStepSpeedMs
(u32) Mode time step for incrementing custom ramp (ms)
@ customRampAnimChoice
(u32) Which custom ramp anim. to use (rainbow, etc)
static auto context_as(auto &ctx)
Bind provided context to another modes::BasicMode.
Definition: context_type.hpp:25
uint16_t brightness_t
Define the type of the brightness parameters.
Definition: constants.h:147
(store) Binds a local variable of type T to key in storage (with automatic read & save)
Definition: context_type.hpp:422
void LMBD_INLINE getValue(T defVal)
(optional) Read key value, if not found, set local to defVal
Definition: context_type.hpp:443
void LMBD_INLINE setValue(T value)
(optional) Set local to value then write key to store
Definition: context_type.hpp:433
static constexpr StoreEnum key
Enumeration value uniquely identifying where local will be stored.
Definition: context_type.hpp:427
bool LMBD_INLINE getValue()
(optional) Read key from store, return True if local was written
Definition: context_type.hpp:440
T & local
Local variable reference bound to KeyProxy.
Definition: context_type.hpp:430
bool LMBD_INLINE hasValue()
(optional) Return True if key is set in store, False if unknown
Definition: context_type.hpp:446
KeyProxy(T &local)
Use ContextTy::storageFor to construct a KeyProxy bound to local.
Definition: context_type.hpp:460
Local context exposing system features to active BasicMode.
Definition: context_type.hpp:29
static void LMBD_INLINE storageLoadOnly(LMBD_USED T &local, const T defaultValue)
(store) Load key into local if available (single-shot), or load the default value
Definition: context_type.hpp:492
void LMBD_INLINE set_config_bool(bool value)
(setter) Set a configurable boolean to target value
Definition: context_type.hpp:511
void LMBD_INLINE power_on_sequence()
Binds to local BasicMode::power_on_sequence()
Definition: context_type.hpp:813
void LMBD_INLINE brightness_update(LMBD_USED brightness_t brightness)
Binds to local BasicMode::brightness_update()
Definition: context_type.hpp:694
void LMBD_INLINE enter_group(const uint8_t value)
Call when entering a group.
Definition: context_type.hpp:605
void LMBD_INLINE set_config_u32(uint32_t value)
(setter) Set a configurable integer (u32) to target value
Definition: context_type.hpp:535
bool LMBD_INLINE custom_hold(LMBD_USED uint8_t nbClickAndHold, LMBD_USED bool isEndOfHoldEvent, LMBD_USED uint32_t holdDuration)
Binds to local BasicMode::custom_hold()
Definition: context_type.hpp:727
void LMBD_INLINE on_exit_mode()
Binds to local BasicMode::on_exit_mode()
Definition: context_type.hpp:678
void LMBD_INLINE quit_group()
Call when quitting a group.
Definition: context_type.hpp:619
uint8_t LMBD_INLINE get_active_custom_index() const
(getter) Get active custom index (recalled when jumping favorites)
Definition: context_type.hpp:334
static constexpr bool hasStore
(store) True if LocalBasicMode has access to a local key store
Definition: context_type.hpp:380
friend ModeManager
Friend class.
Definition: context_type.hpp:31
uint8_t LMBD_INLINE set_active_custom_ramp(uint8_t value)
(setter) Set active custom ramp value (overrides user choice)
Definition: context_type.hpp:327
void LMBD_INLINE read_parameters()
Binds to local BasicMode::read_parameters()
Definition: context_type.hpp:840
LocalBasicMode LocalModeTy
Type of a local mode.
Definition: context_type.hpp:38
static void LMBD_INLINE storageSaveOnly(LMBD_USED T &local)
(store) Save local into key storage (single-shot)
Definition: context_type.hpp:498
static constexpr int get_mode_id()
Return the.
Definition: context_type.hpp:357
uint8_t LMBD_INLINE get_active_custom_ramp() const
(getter) Get active custom ramp value (as configured by user)
Definition: context_type.hpp:321
void LMBD_INLINE loop()
Binds to local BasicMode::loop()
Definition: context_type.hpp:665
void LMBD_INLINE on_enter_mode()
Binds to local BasicMode::on_enter_mode()
Definition: context_type.hpp:668
uint8_t LMBD_INLINE set_active_mode(uint8_t value, uint8_t maxValueWrap=255)
(setter) Set active mode index (as numbered in local group)
Definition: context_type.hpp:287
void LMBD_INLINE write_parameters()
Binds to local BasicMode::write_parameters()
Definition: context_type.hpp:831
void LMBD_INLINE skipFirstLedsForFrames(uint8_t amount, uint8_t count=1)
Skip the first few LEDs update during several frames.
Definition: context_type.hpp:593
ModeManager ModeManagerTy
Type of the mode manager.
Definition: context_type.hpp:36
bool LMBD_INLINE custom_click(LMBD_USED uint8_t nbClick)
Binds to local BasicMode::custom_click()
Definition: context_type.hpp:716
void cancel_blip() const
Cancel an ongoing blip of the ouput.
Definition: context_type.hpp:570
uint8_t LMBD_INLINE set_active_custom_index(uint8_t value)
(setter) Set active custom index (recalled when jumping favorites)
Definition: context_type.hpp:337
bool is_bliping() const
Return true if the systems is currently bliping the output.
Definition: context_type.hpp:579
void LMBD_INLINE power_off_sequence()
Binds to local BasicMode::power_off_sequence()
Definition: context_type.hpp:822
void LMBD_INLINE quit_mode()
Call when quitting a mode.
Definition: context_type.hpp:647
static auto LMBD_INLINE storageFor(LMBD_USED T &local)
(store) Get storage KeyProxy for key bound to local variable
Definition: context_type.hpp:472
StateTyOf< Mode > & get_state_of_mode()
Return the state of a given mode.
Definition: context_type.hpp:348
void blip(const uint32_t duration)
Turn off the output for a duration.
Definition: context_type.hpp:560
void LMBD_INLINE user_thread()
Binds to local BasicMode::user_thread()
Definition: context_type.hpp:852
uint8_t LMBD_INLINE get_active_mode(uint8_t maxValueWrap=255) const
(getter) Get active mode index (as numbered in local group)
Definition: context_type.hpp:280
StateTyOf< LocalModeTy > StateTy
Type of the State of a local mode.
Definition: context_type.hpp:40
void LMBD_INLINE sunset_update(LMBD_USED float progress)
Binds to local BasicMode::sunset_update()
Definition: context_type.hpp:685
hardware::LampTy & lamp
Interact with the lamp hardware.
Definition: context_type.hpp:864
static bool LMBD_INLINE storageLoadOnly(LMBD_USED T &local)
(store) Load key into local if available (single-shot)
Definition: context_type.hpp:485
void LMBD_INLINE enter_mode()
Call when entering a mode.
Definition: context_type.hpp:633
uint8_t LMBD_INLINE set_active_group(uint8_t value, uint8_t maxValueWrap=255)
(setter) Set active group index
Definition: context_type.hpp:267
auto LMBD_INLINE context_as()
Get the same context, but for another mode, see modes::context_as()
Definition: context_type.hpp:70
uint8_t LMBD_INLINE get_active_group(uint8_t maxValueWrap=255) const
(getter) Get active group index
Definition: context_type.hpp:260
StateTy & state
Interact with the current active mode state.
Definition: context_type.hpp:865
bool LMBD_INLINE should_spawn_thread()
Returns BasicMode::requireUserThread.
Definition: context_type.hpp:849
static constexpr int get_group_id_of_mode()
Return the id of the group containing a target mode, or -1 if it does not exist.
Definition: context_type.hpp:351
auto LMBD_INLINE get_custom_ramp_default_value()
Return the default ramp values for all the modes under this group.
Definition: context_type.hpp:810
void LMBD_INLINE custom_ramp_update(LMBD_USED uint8_t rampValue, uint32_t timeout=0)
Binds to local BasicMode::custom_ramp_update()
Definition: context_type.hpp:703
Main interface between the user and the hardware of the lamp.
Definition: lamp_type.hpp:118
Convertion header to use the text out functions from C code.