15#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 auto LMBD_INLINE set_favorite_now(uint8_t which_one = 0)
136 if constexpr (LocalModeTy::isModeManager)
138 return LocalModeTy::set_favorite_now(*
this, which_one);
142 auto manager = modeManager.get_context();
143 return manager.set_favorite_now(which_one);
148 auto LMBD_INLINE delete_favorite_now()
150 if constexpr (LocalModeTy::isModeManager)
152 return LocalModeTy::delete_favorite_now(*
this);
156 auto manager = modeManager.get_context();
157 return manager.delete_favorite_now();
162 auto LMBD_INLINE handle_scroll_modes(
const uint32_t holdDuration)
164 if constexpr (LocalModeTy::isModeManager)
166 return LocalModeTy::handle_scroll_modes(*
this, holdDuration);
170 auto manager = modeManager.get_context();
171 return manager.handle_scroll_modes(holdDuration);
176 auto LMBD_INLINE enter_hidden_group(
const uint8_t hiddenGroupIndex)
178 if constexpr (LocalModeTy::isModeManager)
180 return LocalModeTy::enter_hidden_group(*
this, hiddenGroupIndex);
184 auto manager = modeManager.get_context();
185 return manager.enter_hidden_group(hiddenGroupIndex);
190 auto LMBD_INLINE overlay_animate_ramp(
float holdDuration,
193 const uint32_t timeout = 0)
195 if constexpr (LocalModeTy::isModeManager)
197 return modeManager.overlay_animate_ramp(*
this, holdDuration, stepSize, palette, timeout);
201 auto manager = modeManager.get_context();
202 return manager.overlay_animate_ramp(holdDuration, stepSize, palette, timeout);
207 auto LMBD_INLINE overlay_animate_ramp(uint8_t progress,
const colors::PaletteTy& palette,
const uint32_t timeout = 0)
209 if constexpr (LocalModeTy::isModeManager)
211 return modeManager.overlay_animate_ramp(*
this, progress, palette, timeout);
215 auto manager = modeManager.get_context();
216 return manager.overlay_animate_ramp(progress, palette, timeout);
221 auto LMBD_INLINE get_groups_count() {
return modeManager.nbGroupsTotal; }
223 auto LMBD_INLINE get_accessible_groups_count() {
return modeManager.nbAccessibleGroups; }
225 auto LMBD_INLINE get_hidden_groups_count() {
return modeManager.hiddenGroupCount; }
228 auto LMBD_INLINE get_modes_count()
230 if constexpr (LocalModeTy::isModeManager)
232 return modeManager.get_modes_count(*
this);
236 auto manager = modeManager.get_context();
237 return manager.get_modes_count();
248 uint8_t groupIndex = modeManager.activeIndex.groupIndex;
249 return (groupIndex + 1) > maxValueWrap ? 0 : groupIndex;
255 if (value + 1 > maxValueWrap)
268 uint8_t modeIndex = modeManager.activeIndex.modeIndex;
269 return (modeIndex + 1) > maxValueWrap ? 0 : modeIndex;
275 if (value + 1 > maxValueWrap)
278 auto manager = modeManager.get_context();
282 manager.cancel_blip();
285 if (modeManager.activeIndex.modeIndex == value)
295 modeManager.quit_mode(manager);
297 modeManager.activeIndex.modeIndex = value;
299 modeManager.enter_mode(manager);
315 modeManager.activeIndex.rampIndex = value;
325 modeManager.activeIndex.customIndex = value;
334 template<
typename Mode> StateTyOf<Mode>&
get_state_of_mode() {
return modeManager.template getStateOf<Mode>(); }
339 return details::GroupIdFrom<Mode, typename ModeManagerTy::AllGroupsTy>;
345 return details::ModeIdFrom<Mode, typename ModeManagerTy::AllGroupsTy, get_group_id_of_mode<Mode>()>;
349 static constexpr int groupId = get_group_id_of_mode<LocalModeTy>();
352 static constexpr int modeId = get_mode_id<LocalModeTy>();
355 static constexpr auto prefix =
356 (isModeManager ? store::PrefixValues::managerKeys :
357 (isMode ? store::PrefixValues::generalKeys : store::PrefixValues::privateKeys));
360 using StoreEnum = StoreEnumOf<LocalModeTy>;
363 using LocalStore = store::KeyStore<StoreEnum, groupId, modeId, prefix>;
366 static constexpr bool hasStore = not std::is_same_v<StoreEnum, NoStoreHere>;
407 template<StoreEnum _key,
typename T>
struct KeyProxy
409 static_assert(std::is_same_v<T, std::conditional_t<hasStore, T, NoStoreId>>,
410 "KeyProxy can not be used when no storeId has been defined!");
413 static constexpr StoreEnum
key = _key;
422 LocalStore::template setValue<key, T>(value);
426 inline bool LMBD_INLINE
getValue() {
return LocalStore::template getValue<key, T>(
local); }
429 inline void LMBD_INLINE
getValue(T defVal) { LocalStore::template getValue<key, T>(
local, defVal); }
432 inline bool LMBD_INLINE
hasValue() {
return LocalStore::template hasValue<key, T>(); }
439 inline void LMBD_INLINE forceSave() { LocalStore::template setValue<key, T>(
local); }
457 template<StoreEnum key,
typename T = u
int32_t>
471 template<StoreEnum key,
typename T = u
int32_t>
static bool LMBD_INLINE
storageLoadOnly(LMBD_USED T& local)
473 return LocalStore::template getValue<key, T>(local);
477 template<StoreEnum key,
typename T = u
int32_t>
static void LMBD_INLINE
storageSaveOnly(LMBD_USED T& local)
479 return LocalStore::template setValue<key, T>(local);
492 auto ctx = modeManager.get_context();
496 ctx.state.rampHandler.rampSaturates = value;
499 ctx.state.clearStripOnModeChange = value;
502 ctx.state.rampHandler.animEffect = value;
505 assert(
false &&
"unsupported config key for booleans!");
516 auto ctx = modeManager.get_context();
520 ctx.state.rampHandler.stepSpeed = value;
523 ctx.state.rampHandler.animChoice = value;
526 assert(
false &&
"unsupported config key for u32!");
539 void blip(
const uint32_t duration)
541 auto ctx = modeManager.get_context();
543 ctx.state.skipNextFrameEffect = ceil(duration /
static_cast<float>(ctx.lamp.frameDurationMs));
545 ctx.lamp.blip(duration);
551 auto ctx = modeManager.get_context();
553 ctx.state.skipNextFrameEffect = 0;
554 ctx.lamp.cancel_blip();
560 auto ctx = modeManager.get_context();
561 return ctx.lamp.is_bliping();
574 auto ctx = modeManager.get_context();
575 ctx.lamp.config.skipFirstLedsForAmount = amount;
576 ctx.lamp.config.skipFirstLedsForEffect = count;
586 if constexpr (LocalModeTy::isModeManager)
588 LocalModeTy::enter_group(*
this, value);
592 auto& manager = modeManager.get_context();
593 return manager.enter_group(value);
600 if constexpr (LocalModeTy::isModeManager)
602 LocalModeTy::quit_group(*
this);
606 auto& manager = modeManager.get_context();
607 return manager.quit_group();
614 if constexpr (LocalModeTy::isModeManager)
616 LocalModeTy::enter_mode(*
this);
620 auto& manager = modeManager.get_context();
621 return manager.enter_mode();
628 if constexpr (LocalModeTy::isModeManager)
630 LocalModeTy::quit_mode(*
this);
634 auto& manager = modeManager.get_context();
635 return manager.quit_mode();
644 void LMBD_INLINE
loop() { LocalModeTy::loop(*
this); }
651 LocalStore::template migrateStoreIfNeeded<LocalModeTy::storeId>();
653 LocalModeTy::on_enter_mode(*
this);
660 LocalModeTy::on_exit_mode(*
this);
666 if constexpr (LocalModeTy::hasSunsetAnimation)
668 LocalModeTy::sunset_update(*
this, progress);
675 if constexpr (LocalModeTy::hasBrightCallback)
677 LocalModeTy::brightness_update(*
this, brightness);
684 if constexpr (LocalModeTy::isGroupManager)
686 LocalModeTy::custom_ramp_update(*
this, rampValue, timeout);
688 else if constexpr (LocalModeTy::hasCustomRamp)
690 LocalModeTy::custom_ramp_update(*
this, rampValue);
697 if constexpr (LocalModeTy::hasButtonCustomUI)
699 return LocalModeTy::custom_click(*
this, nbClick);
707 LMBD_USED
bool isEndOfHoldEvent,
708 LMBD_USED uint32_t holdDuration)
710 if constexpr (LocalModeTy::hasButtonCustomUI)
712 return LocalModeTy::custom_hold(*
this, nbClickAndHold, isEndOfHoldEvent, holdDuration);
718 template<
bool displayFavoriteNumber = true>
auto LMBD_INLINE animate_favorite_pick(
float holdDuration,
float stepSize)
720 if constexpr (LocalModeTy::isModeManager)
722 return modeManager.template animate_favorite_pick<displayFavoriteNumber>(*
this, holdDuration, stepSize);
726 auto& manager = modeManager.get_context();
727 return manager.template animate_favorite_pick<displayFavoriteNumber>(holdDuration, stepSize);
731 template<
bool displayFavoriteNumber = true>
732 auto LMBD_INLINE animate_favorite_delete(
float holdDuration,
float stepSize)
734 if constexpr (LocalModeTy::isModeManager)
736 return modeManager.template animate_favorite_delete<displayFavoriteNumber>(*
this, holdDuration, stepSize);
740 auto&
manager = modeManager.get_context();
741 return manager.template animate_favorite_delete<displayFavoriteNumber>(holdDuration, stepSize);
748 if constexpr (LocalModeTy::hasSystemCallbacks)
750 LocalModeTy::power_on_sequence(*
this);
757 if constexpr (LocalModeTy::hasSystemCallbacks)
759 LocalModeTy::power_off_sequence(*
this);
766 if constexpr (LocalModeTy::hasSystemCallbacks)
768 LocalModeTy::write_parameters(*
this);
775 if constexpr (LocalModeTy::hasSystemCallbacks)
777 LocalModeTy::read_parameters(*
this);
787 if constexpr (LocalModeTy::requireUserThread)
789 LocalModeTy::user_thread(*
this);
Filesystem interaction tools.
Define the main led strip interaction object.
AlertManager_t manager
Instanciation of the AlertManager.
Definition: alerts.cpp:27
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:408
void LMBD_INLINE getValue(T defVal)
(optional) Read key value, if not found, set local to defVal
Definition: context_type.hpp:429
void LMBD_INLINE setValue(T value)
(optional) Set local to value then write key to store
Definition: context_type.hpp:419
static constexpr StoreEnum key
Enumeration value uniquely identifying where local will be stored.
Definition: context_type.hpp:413
bool LMBD_INLINE getValue()
(optional) Read key from store, return True if local was written
Definition: context_type.hpp:426
T & local
Local variable reference bound to KeyProxy.
Definition: context_type.hpp:416
bool LMBD_INLINE hasValue()
(optional) Return True if key is set in store, False if unknown
Definition: context_type.hpp:432
KeyProxy(T &local)
Use ContextTy::storageFor to construct a KeyProxy bound to local.
Definition: context_type.hpp:446
Local context exposing system features to active BasicMode.
Definition: context_type.hpp:29
void LMBD_INLINE set_config_bool(bool value)
(setter) Set a configurable boolean to target value
Definition: context_type.hpp:490
void LMBD_INLINE power_on_sequence()
Binds to local BasicMode::power_on_sequence()
Definition: context_type.hpp:746
void LMBD_INLINE brightness_update(LMBD_USED brightness_t brightness)
Binds to local BasicMode::brightness_update()
Definition: context_type.hpp:673
void LMBD_INLINE enter_group(const uint8_t value)
Call when entering a group.
Definition: context_type.hpp:584
void LMBD_INLINE set_config_u32(uint32_t value)
(setter) Set a configurable integer (u32) to target value
Definition: context_type.hpp:514
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:706
void LMBD_INLINE on_exit_mode()
Binds to local BasicMode::on_exit_mode()
Definition: context_type.hpp:657
void LMBD_INLINE quit_group()
Call when quitting a group.
Definition: context_type.hpp:598
uint8_t LMBD_INLINE get_active_custom_index() const
(getter) Get active custom index (recalled when jumping favorites)
Definition: context_type.hpp:320
static constexpr bool hasStore
(store) True if LocalBasicMode has access to a local key store
Definition: context_type.hpp:366
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:313
void LMBD_INLINE read_parameters()
Binds to local BasicMode::read_parameters()
Definition: context_type.hpp:773
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:477
static constexpr int get_mode_id()
Return the.
Definition: context_type.hpp:343
uint8_t LMBD_INLINE get_active_custom_ramp() const
(getter) Get active custom ramp value (as configured by user)
Definition: context_type.hpp:307
void LMBD_INLINE loop()
Binds to local BasicMode::loop()
Definition: context_type.hpp:644
void LMBD_INLINE on_enter_mode()
Binds to local BasicMode::on_enter_mode()
Definition: context_type.hpp:647
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:273
void LMBD_INLINE write_parameters()
Binds to local BasicMode::write_parameters()
Definition: context_type.hpp:764
void LMBD_INLINE skipFirstLedsForFrames(uint8_t amount, uint8_t count=1)
Skip the first few LEDs update during several frames.
Definition: context_type.hpp:572
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:695
void cancel_blip() const
Cancel an ongoing blip of the ouput.
Definition: context_type.hpp:549
uint8_t LMBD_INLINE set_active_custom_index(uint8_t value)
(setter) Set active custom index (recalled when jumping favorites)
Definition: context_type.hpp:323
bool is_bliping() const
Return true if the systems is currently bliping the output.
Definition: context_type.hpp:558
void LMBD_INLINE power_off_sequence()
Binds to local BasicMode::power_off_sequence()
Definition: context_type.hpp:755
void LMBD_INLINE quit_mode()
Call when quitting a mode.
Definition: context_type.hpp:626
static auto LMBD_INLINE storageFor(LMBD_USED T &local)
(store) Get storage KeyProxy for key bound to local variable
Definition: context_type.hpp:458
StateTyOf< Mode > & get_state_of_mode()
Return the state of a given mode.
Definition: context_type.hpp:334
void blip(const uint32_t duration)
Turn off the output for a duration.
Definition: context_type.hpp:539
void LMBD_INLINE user_thread()
Binds to local BasicMode::user_thread()
Definition: context_type.hpp:785
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:266
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:664
hardware::LampTy & lamp
Interact with the lamp hardware.
Definition: context_type.hpp:797
static bool LMBD_INLINE storageLoadOnly(LMBD_USED T &local)
(store) Load key into local if available (single-shot)
Definition: context_type.hpp:471
void LMBD_INLINE enter_mode()
Call when entering a mode.
Definition: context_type.hpp:612
uint8_t LMBD_INLINE set_active_group(uint8_t value, uint8_t maxValueWrap=255)
(setter) Set active group index
Definition: context_type.hpp:253
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:246
StateTy & state
Interact with the current active mode state.
Definition: context_type.hpp:798
bool LMBD_INLINE should_spawn_thread()
Returns BasicMode::requireUserThread.
Definition: context_type.hpp:782
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:337
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:682
Main interface between the user and the hardware of the lamp.
Definition: lamp_type.hpp:114