Lamp-Da 0.1
A compact lantern project
Loading...
Searching...
No Matches
manager_type.hpp
Go to the documentation of this file.
1#ifndef MANAGER_TYPE_H
2#define MANAGER_TYPE_H
3
9#include <cstdint>
10#include <utility>
11#include <tuple>
12#include <array>
13
17
19
21
24#include "src/modes/include/default_config.hpp"
27
30
31namespace lampda::modes {
32
34union ActiveIndexTy
35{
36 struct
37 {
39 uint8_t groupIndex; // group id (as ordered in the manager)
40 uint8_t modeIndex; // mode id (as ordered in its group)
42
43 uint8_t rampIndex; // ramp value (as set by the user)
44 uint8_t customIndex; // custom (as set by the mode)
45 };
46
47 uint32_t rawIndex;
48
49 // static constructors
50 //
51 static constexpr auto from(const uint8_t* arr)
52 {
53 ActiveIndexTy index = {arr[0], arr[1], arr[2], arr[3]};
54 return index;
55 }
56 static constexpr auto from(const std::array<uint8_t, 4>& arr) { return ActiveIndexTy::from(arr.data()); }
57};
58
60template<typename Config> struct RampHandlerTy
61{
62 using ConfigTy = Config;
63 static constexpr uint32_t startPeriod = Config::rampStartPeriodMs;
64
65 // \in stepSpeed how long to wait before incrementing (ms)
66 // \in rampSaturates does the ramp saturates, or else wrap around?
67 RampHandlerTy(uint32_t stepSpeed, bool rampSaturates = Config::defaultRampSaturates) :
68 stepSpeed {stepSpeed},
70 lastTimeMeasured {1000},
71 isForward {true},
72 animEffect {Config::defaultCustomRampAnimEffect},
73 animChoice {Config::defaultCustomRampAnimChoice}
74 {
75 }
76
77 void LMBD_INLINE reset()
78 {
79 isForward = true;
80 stepSpeed = Config::defaultCustomRampStepSpeedMs;
81 rampSaturates = Config::defaultRampSaturates;
82 animEffect = Config::defaultCustomRampAnimEffect;
83 animChoice = Config::defaultCustomRampAnimChoice;
84 }
85
86 void LMBD_INLINE update_ramp(uint8_t rampValue, uint32_t holdTime, auto callback)
87 {
88 // restart the rampage
89 if (holdTime < lastTimeMeasured)
90 {
91 lastTimeMeasured = holdTime;
92
93 if (holdTime < startPeriod)
94 {
95 // toggle forward / backward direction
96 isForward = !isForward;
97 if (rampSaturates)
98 {
99 if (rampValue == 0)
100 isForward = true;
101 if (rampValue == 255)
102 isForward = false;
103 }
104 }
105 return;
106 }
107
108 // count how many step we advanced
109 uint32_t lastCounter = lastTimeMeasured / stepSpeed;
110 uint32_t nextCounter = holdTime / stepSpeed;
111 if (nextCounter <= lastCounter)
112 return;
113
114 // apply steps
115 for (uint32_t I = 0; I < nextCounter - lastCounter; ++I)
116 {
117 // increment iff possible
118 if (isForward && (!rampSaturates || rampValue < 255))
119 rampValue += 1;
120
121 // decrement iff possible
122 if (!isForward && (!rampSaturates || rampValue > 0))
123 rampValue -= 1;
124
125 // forward value to callback
126 callback(rampValue);
127 }
128
129 lastTimeMeasured = holdTime;
130 }
131
132 uint32_t stepSpeed;
133 bool rampSaturates;
134 bool animEffect;
135 bool animChoice;
136 uint32_t lastTimeMeasured;
137 bool isForward;
138};
139
143template<typename Config, typename AllGroups, uint8_t hiddenGroupsCount> struct ModeManagerTy
144{
145 using SelfTy = ModeManagerTy<Config, AllGroups, hiddenGroupsCount>;
146 using ConfigTy = Config;
147 using AllGroupsTy = AllGroups;
148 using AllStatesTy = details::StateTyFrom<AllGroups>;
149
151 static constexpr uint8_t nbGroupsTotal {std::tuple_size_v<AllGroupsTy>};
152 static constexpr uint8_t hiddenGroupCount = hiddenGroupsCount;
153
154 static_assert(nbGroupsTotal >= hiddenGroupsCount, "Manager cannot operate without accessible groups");
155
157 static constexpr uint8_t nbAccessibleGroups = nbGroupsTotal - hiddenGroupsCount;
158
159 // last group index must not collide with modes::store::noGroupIndex
160 static_assert(nbGroupsTotal <= 15, "Maximum of 15 groups has been exceeded.");
161
162 template<uint8_t Idx> using GroupAt = std::tuple_element_t<Idx, AllGroupsTy>;
163
164 // required to support manager-level context
165 using HasAnyGroup = details::anyOf<AllGroupsTy>;
166 static constexpr bool hasSunsetAnimation = HasAnyGroup::hasSunsetAnimation;
167 static constexpr bool hasSunriseAnimation = HasAnyGroup::hasSunriseAnimation;
168 static constexpr bool hasBrightCallback = HasAnyGroup::hasBrightCallback;
169 static constexpr bool requireUserThread = HasAnyGroup::requireUserThread;
170 static constexpr bool hasCustomRamp = HasAnyGroup::hasCustomRamp;
171 static constexpr bool hasSystemCallbacks = hasCustomRamp || HasAnyGroup::hasSystemCallbacks;
172 static constexpr bool hasButtonCustomUI = HasAnyGroup::hasButtonCustomUI;
173
174 // useful for runtime tests of mode properties
175 using EveryModeBool = details::asTableFor<AllGroupsTy>;
176 static constexpr auto everySunsetCallback = EveryModeBool::everySunsetCallback;
177 static constexpr auto everySunriseCallback = EveryModeBool::everySunriseCallback;
178 static constexpr auto everyBrightCallback = EveryModeBool::everyBrightCallback;
179 static constexpr auto everyRequireUserThread = EveryModeBool::everyRequireUserThread;
180 static constexpr auto everyCustomRamp = EveryModeBool::everyCustomRamp;
181 static constexpr auto everySystemCallbacks = EveryModeBool::everySystemCallbacks;
182 static constexpr auto everyButtonCustomUI = EveryModeBool::everyButtonCustomUI;
183
184 // constructors
185 ModeManagerTy(hardware::LampTy& lamp) : activeIndex {ActiveIndexTy::from(Config::initialActiveIndex)}, lamp {lamp} {}
186
187 ModeManagerTy() = delete;
188 ModeManagerTy(const ModeManagerTy&) = delete;
189 ModeManagerTy& operator=(const ModeManagerTy&) = delete;
190
192 auto get_context() { return ContextTy<SelfTy, SelfTy>(*this); }
193
195 template<typename CallBack> static void LMBD_INLINE dispatch_group(auto& ctx, CallBack&& cb)
196 {
197 uint8_t groupId = ctx.get_active_group(nbGroupsTotal);
198
199 details::unroll<nbGroupsTotal>([&](auto Idx) LMBD_INLINE {
200 if (Idx == groupId)
201 {
202 cb(context_as<GroupAt<Idx>>(ctx));
203 }
204 });
205 }
206
208 template<bool systemCallbacksOnly, typename CallBack> static void LMBD_INLINE foreach_group(auto& ctx, CallBack&& cb)
209 {
210 if constexpr (systemCallbacksOnly)
211 {
212 details::unroll<nbGroupsTotal>([&](auto Idx) LMBD_INLINE {
213 using GroupHere = GroupAt<Idx>;
214 constexpr bool hasCallbacks = GroupHere::hasSystemCallbacks;
215
216 if constexpr (hasCallbacks)
217 {
218 cb(context_as<GroupAt<Idx>>(ctx));
219 }
220 });
221 }
222 else
223 {
224 details::unroll<nbGroupsTotal>([&](auto Idx) LMBD_INLINE {
225 cb(context_as<GroupAt<Idx>>(ctx));
226 });
227 }
228 }
229
230 //
231 // store
232 //
233
234 // persistent values
235 enum class Store : uint16_t
236 {
237 lastActive,
238 modeMemory,
239 usedFavoriteCount,
240 favoriteModes,
241 lastUsedFavorite,
242 isInFavoriteGroup
243 };
244
245 static constexpr uint32_t storeId = modes::store::derivateStoreId<modes::store::hash("ManagerStoreId"), AllGroupsTy>;
246
247 //
248 // state
249 //
250
251 struct StateTy
252 {
254 AllStatesTy groupStates;
255
257 std::array<uint8_t, nbGroupsTotal> lastModeMemory = {};
258
260 static constexpr uint8_t maxFavoriteCount = 8;
262 std::array<ActiveIndexTy, maxFavoriteCount> favorites = {};
263 uint8_t usedFavoriteCount = 0;
264
266 static constexpr uint8_t defaultFavoriteCount_indexable = 6;
268 static constexpr std::array<ActiveIndexTy, maxFavoriteCount> defaultFavorites_indexable = {
270 ActiveIndexTy::from({0, 2, 80, 0}),
272 ActiveIndexTy::from({0, 2, 165, 0}),
274 ActiveIndexTy::from({0, 2, 0, 0}),
276 ActiveIndexTy::from({0, 0, 0, 0}),
278 ActiveIndexTy::from({0, 0, 128, 0}),
280 ActiveIndexTy::from({0, 0, 255, 0}),
281 };
282
284 static constexpr uint8_t defaultFavoriteCount_simple = 0;
286 static constexpr std::array<ActiveIndexTy, maxFavoriteCount> defaultFavorites_simple = {};
287
288 static_assert(maxFavoriteCount < 16, "Maximum of 15 favorite as been exceeded");
289
290 // (variables for pending favorite state machine)
291 bool isInDeleteFavorite = false;
292 uint8_t lastFavoriteStep = 0;
293
295 {
296 enum class FavoriteAction : uint8_t
297 {
298 None,
299 Add,
300 Delete
301 };
302
303 FavoriteAction action = FavoriteAction::None;
304 uint8_t slot = 0;
305 ActiveIndexTy snapshot {};
306 };
307
309
313
315 uint32_t lastScrollStopped = 0;
316
318 RampHandlerTy<Config> rampHandler = {Config::defaultCustomRampStepSpeedMs};
320 RampHandlerTy<Config> scrollHandler = {Config::scrollRampStepSpeedMs};
322 bool clearStripOnModeChange = Config::defaultClearStripOnModeChange;
323
324 // special effects
326
328 void reset()
329 {
330 lastModeMemory = {};
331
332 favorites = {};
334
335 pendingFavorite = {};
336 isInDeleteFavorite = false;
337
339 isInFavoriteMockGroup = false;
340 beforeFavoriteActiveIndex = ActiveIndexTy();
342
345
347 }
348
350 static void LMBD_INLINE before_enter_mode(auto& ctx)
351 {
352 auto& self = ctx.state;
353 self.rampHandler.reset();
354 self.clearStripOnModeChange = Config::defaultClearStripOnModeChange;
355 }
356
358 static void LMBD_INLINE after_enter_mode(auto& ctx)
359 {
360 auto& self = ctx.state;
361 if (self.clearStripOnModeChange)
362 {
363 ctx.lamp.clear();
364 }
365 // reset masking
366 ctx.lamp.forceDisableLedDitherMask = false;
367 }
368
369 static void LMBD_INLINE on_favorite_hold_end(auto& ctx, bool shouldExecuteAction)
370 {
371 auto& p = ctx.state.pendingFavorite;
372 if (shouldExecuteAction)
373 {
374 if (p.action == PendingFavorite::FavoriteAction::Add && p.slot <= ctx.state.usedFavoriteCount)
375 ctx.set_favorite_at(p.slot, p.snapshot); // store the press-time snapshot
376 else if (p.action == PendingFavorite::FavoriteAction::Delete)
377 ctx.delete_favorite_now();
378 }
379 p = {}; // single point of reset
380 }
381 };
382
384 template<typename Group> StateTyOf<Group>* LMBD_INLINE getStateGroupOf()
385 {
386 using StateTy = StateTyOf<Group>;
387 using OptionalTy = std::optional<StateTy>;
388
389 StateTy* substate = nullptr;
390 details::unroll<nbGroupsTotal>([&](auto Idx) LMBD_INLINE {
391 using GroupHere = GroupAt<Idx>;
392 constexpr bool IsHere = std::is_same_v<GroupHere, Group>;
393
394 if constexpr (IsHere)
395 {
396 OptionalTy& opt = std::get<OptionalTy>(state.groupStates);
397 if (!opt.has_value())
398 {
399 opt.emplace();
400 }
401
402 StateTy& stateHere = *opt;
403 substate = &stateHere;
404 }
405 });
406 assert(substate != nullptr && "this should not have compiled at all!");
407
408 static_assert(details::ModeBelongsTo<Group, AllGroups>);
409 return substate;
410 }
411
413 template<typename Mode> StateTyOf<Mode>& LMBD_INLINE getStateOf()
414 {
415 using TargetStateTy = StateTyOf<Mode>;
416
417 // Mode is unknown / as no state, return placeholder
418 if constexpr (std::is_same_v<TargetStateTy, NoState>)
419 {
420 return placeholder;
421
422 // Mode is ManagerTy, return our own state
423 }
424 else if constexpr (std::is_same_v<TargetStateTy, StateTy>)
425 {
426 return state;
427
428 // Mode is GroupTy, return the state of the group
429 }
430 else if constexpr (details::GroupBelongsTo<Mode, AllGroups>)
431 {
432 TargetStateTy* substate = getStateGroupOf<Mode>();
433
434 if (substate == nullptr)
435 {
436 substate = (TargetStateTy*)&placeholder;
437 assert(false && "this code should be unreachable, but is it?");
438 }
439
440 return *substate;
441 }
442 else
443 {
444 static_assert(details::ModeExists<Mode, AllGroups>);
445
446 // Mode is somewhere in a group, search for it, return its state
447 TargetStateTy* substate = nullptr;
448
449 details::unroll<nbGroupsTotal>([&](auto Idx) LMBD_INLINE {
450 using Group = GroupAt<Idx>;
451 using AllModes = typename Group::AllModesTy;
452 if constexpr (details::ModeBelongsTo<Mode, AllModes>)
453 {
454 substate = Group::template getStateOf<Mode>(*this);
455 }
456 });
457 assert(substate != nullptr && "this should not have compiled at all!");
458
459 if (substate == nullptr)
460 {
461 substate = (TargetStateTy*)&placeholder;
462 assert(false && "this code should be unreachable, but is it?");
463 }
464
465 return *substate;
466 }
467 }
468
469 //
470 // navigation
471 //
472
473 static constexpr bool isGroupManager = true;
474 static constexpr bool isModeManager = true;
475
477 static void next_group(auto& ctx)
478 {
479 // change current group: Limited to accessible groups
480 uint8_t groupIdBefore = ctx.get_active_group(nbAccessibleGroups);
481 ctx.set_active_group(groupIdBefore + 1, nbAccessibleGroups);
482 }
483
485 static void next_mode(auto& ctx)
486 {
487 dispatch_group(ctx, [](auto group) {
488 group.next_mode();
489 });
490 }
491
499 static void jump_to_new_active_index(auto& ctx,
500 const ActiveIndexTy& newActiveIndex,
501 const bool ignoreRampAndIndex = false,
502 const bool quitFavoriteGroup = false)
503 {
504 // Favorite switches used to call set_active_group then set_active_mode.
505 // Each of those enters the mode once, so one favorite step fired two
506 // $mode user actions while only switching once (#569). Quit once, apply
507 // the full index, enter once.
508 auto manager = ctx.modeManager.get_context();
509 manager.cancel_blip();
510
511 // Persist last mode for the group we leave (set_active_group → quit_group).
512 ctx.quit_group();
513 ctx.modeManager.quit_mode(manager);
514
515 ctx.modeManager.activeIndex.groupIndex = newActiveIndex.groupIndex;
516 ctx.modeManager.activeIndex.modeIndex = newActiveIndex.modeIndex;
517
518 ctx.modeManager.enter_mode(manager);
519
520 // call AFTER the mode switch
521 if (quitFavoriteGroup)
522 {
523 ctx.state.isInFavoriteMockGroup = false;
524 }
525
526 // compare before copying, or ramps loaded in enter_mode would always match the favorite
527 const bool isRampRestored =
528 (not ignoreRampAndIndex) and ctx.modeManager.activeIndex.rawIndex == newActiveIndex.rawIndex;
529
530 if (not ignoreRampAndIndex)
531 {
532 // just copy the other values
533 ctx.modeManager.activeIndex.customIndex = newActiveIndex.customIndex;
534 ctx.modeManager.activeIndex.rampIndex = newActiveIndex.rampIndex;
535 }
536
537 // if ramps loaded in enter_mode != ones saved as favorite, emulate update
538 if (not isRampRestored)
539 {
540 custom_ramp_update(ctx, ctx.get_active_custom_ramp());
541 }
542 }
543
551 static bool jump_to_favorite(auto& ctx, uint8_t which_one, bool shouldSaveLastActiveIndex)
552 {
553 // sanity check
554 if (ctx.state.usedFavoriteCount <= 0)
555 return false;
556
557 // wrap back to max number of favorites
558 which_one = (which_one % ctx.state.usedFavoriteCount);
559 ctx.state.lastFavoriteStep = which_one;
560
561 // store last active index before jump, only when entering the favorite group:
562 // inside it, the active index is a favorite and would overwrite the mode to return to
563 if (shouldSaveLastActiveIndex and not ctx.state.isInFavoriteMockGroup)
564 {
565 ctx.state.beforeFavoriteActiveIndex = ctx.modeManager.activeIndex;
566 }
567
568 if (which_one >= ctx.state.maxFavoriteCount)
569 return false;
570
571 if (not ctx.state.isInFavoriteMockGroup)
572 {
573 // not already in favorite group : save the latest mode & group parameters
574 ctx.quit_group();
575 auto manager = ctx.modeManager.get_context();
576 ctx.modeManager.quit_mode(manager);
577
578 // indicate that we are now in a favorite group BEFORE the state switch
579 ctx.state.isInFavoriteMockGroup = true;
580 }
581
582 const auto targetFavorite = ctx.state.favorites[which_one];
583 // reset once with the right mode
584 jump_to_new_active_index(ctx, targetFavorite);
585
586 // show which favorite is currently set
587 overlay.clear();
588 display_favorite_number_ramp(ctx, which_one, ctx.state.usedFavoriteCount, true, 1000);
589
590 // indicate favorite mode entry
591 ctx.blip(250);
592
593 return true;
594 }
595
599 static bool exit_favorite_group(auto& ctx, ActiveIndexTy newActiveIndex)
600 {
601 if (not ctx.state.isInFavoriteMockGroup)
602 return false;
603
604#ifdef LMBD_SIMULATION
605 fprintf(stderr, "Exit fake favorite group\n");
606#endif
607 // return to previous state, with the saved ramps of the target mode
608 jump_to_new_active_index(ctx, newActiveIndex, false, true);
609
610 // blip to indicate favorite mode exit
611 ctx.blip(250);
612
613 return true;
614 }
615
623 static bool set_favorite_at(auto& ctx, uint8_t which_one, ActiveIndexTy desiredFavorite)
624 {
625 // new favorite added
626 if (which_one != ctx.state.maxFavoriteCount && which_one == ctx.state.usedFavoriteCount)
627 {
628 // augment favorite count until we reach the max
629 ctx.state.usedFavoriteCount = std::min<uint8_t>(ctx.state.usedFavoriteCount + 1, ctx.state.maxFavoriteCount);
630 }
631
632 if (which_one < ctx.state.maxFavoriteCount)
633 {
634 ctx.state.favorites[which_one] = desiredFavorite;
635
636 logic::alerts::manager.raise(logic::alerts::Type::FAVORITE_SET);
637 return true;
638 }
639 return false;
640 }
641
647 static bool delete_favorite_now(auto& ctx)
648 {
649 // delete current
650 const auto which_one = ctx.state.lastFavoriteStep;
651 if (ctx.state.usedFavoriteCount > 0 and which_one < ctx.state.maxFavoriteCount)
652 {
653 ctx.state.usedFavoriteCount -= 1;
654
655 for (uint8_t i = which_one; i < ctx.state.maxFavoriteCount - 1; ++i)
656 {
657 // make them all go down one spot
658 ctx.state.favorites[i] = ctx.state.favorites[i + 1];
659 }
660 // changed favorite index, jump
661 if (ctx.state.usedFavoriteCount > 0)
662 {
663 jump_to_favorite(ctx, which_one, false);
664 }
665 else
666 {
667 // no more favorite, restore last used mode
668 exit_favorite_group(ctx, ctx.state.beforeFavoriteActiveIndex);
669 }
670 return true;
671 }
672 return false;
673 }
674
680 static void handle_scroll_modes(auto& ctx, uint32_t holdDuration)
681 {
682 auto& scrollHandler = ctx.state.scrollHandler;
683 scrollHandler.isForward = false; // (always scroll modes backward)
684
685 static constexpr uint32_t scrollActivationTiming = 750;
686 if (holdDuration <= scrollActivationTiming)
687 {
688 // display the ramp and do nothing else
689 overlay_animate_ramp(
690 ctx, holdDuration, scrollActivationTiming, colors::PaletteGradient<colors::White, colors::Cyan>);
691 return;
692 }
693
694 scrollHandler.update_ramp(128, holdDuration, [&](uint8_t rampValue) {
695 uint8_t modeIndex = ctx.get_active_mode();
696 uint8_t groupIndex = ctx.get_active_group();
697 uint8_t modeCount = ctx.get_modes_count();
698
699 ctx.state.isLastScrollAGroupChange = false;
700
701 // we are going backward
702 //
703 if (rampValue < 128)
704 {
705 // if modeIndex is not the first, just decrement it
706 if (modeIndex > 0)
707 {
708 ctx.set_active_mode(modeIndex - 1, modeCount);
709
710 // or else decrement group, then set mode to last one
711 }
712 else
713 {
714 ctx.state.isLastScrollAGroupChange = true;
715 // if groupIndex is not the first, just decrement it
716 if (groupIndex > 0)
717 {
718 // can only access visible modes
719 ctx.set_active_group(groupIndex - 1, nbAccessibleGroups);
720
721 // else wrap to last group
722 }
723 else
724 {
725 // can only access visible modes
726 ctx.set_active_group(nbAccessibleGroups - 1, nbAccessibleGroups);
727 }
728
729 // backward scroll: set mode to last one on group change
730 modeCount = ctx.get_modes_count();
731 ctx.set_active_mode(modeCount - 1, modeCount);
732 }
733
734 // we are going forward
735 //
736 }
737 else
738 {
739 // if modeIndex is not the last, just increment it
740 if (modeIndex + 1 < modeCount)
741 {
742 ctx.next_mode();
743
744 // or else increment group
745 }
746 else
747 {
748 ctx.state.isLastScrollAGroupChange = true;
749 // if groupIndex is not the last, just increment it
750 if (groupIndex + 1 < nbAccessibleGroups)
751 {
752 ctx.next_group();
753
754 // else wrap to first group
755 }
756 else
757 {
758 ctx.set_active_group(0, nbAccessibleGroups);
759 }
760
761 // forward scroll: set mode to first one on group change
762 ctx.set_active_mode(0, modeCount);
763 }
764 }
765 });
766 }
767
773 static void enter_hidden_group(auto& ctx, uint8_t index)
774 {
775 assert(index < hiddenGroupsCount);
776 ctx.set_active_group(nbAccessibleGroups + index, nbGroupsTotal);
777 }
778
780 static bool overlay_animate_ramp(
781 auto& ctx, float holdDuration, float stepSize, const colors::PaletteTy& palette, const uint32_t timeout = 0)
782 {
783 // where we are: 0-255 rampColorRing
784 const uint32_t stepProgress = floor((holdDuration * 256.0) / stepSize);
785 return overlay_animate_ramp(ctx, stepProgress % 256, palette);
786 }
787 static bool overlay_animate_ramp(auto& ctx,
788 uint8_t progress,
789 const colors::PaletteTy& palette,
790 const uint32_t timeout = 0)
791 {
792 // only display on indexable
793 if constexpr (ctx.lamp.flavor == hardware::LampTypes::indexable)
794 {
795 // if first display failed, add a new ramp and try again
796 if (not overlay.update_type(ctx, draw::overlay::ElementType::RAMP, 0, progress, palette))
797 {
798 // add new ramp element
799 overlay.add_ui_element(ctx, draw::overlay::ElementType::RAMP, palette, 0, 0, progress);
800 }
801
802 // if timeout is requested, update it
803 if (timeout > 0)
804 overlay.update_type_timeout(ctx, draw::overlay::ElementType::RAMP, 0, timeout);
805 }
806 else if constexpr (ctx.lamp.flavor == hardware::LampTypes::simple)
807 {
808 // blip at the ramp end
809 if (progress >= 250)
810 ctx.blip(100);
811 }
812 return (progress >= 250);
813 }
814
816 static void overlay_animate_dot(auto& ctx,
817 uint16_t index,
818 uint16_t positionX,
819 uint8_t progress,
820 const auto& palette,
821 const uint32_t timeout = 0)
822 {
823 // only display on indexable
824 if constexpr (ctx.lamp.flavor == hardware::LampTypes::indexable)
825 {
826 // if first display failed, add a new ramp and try again
827 if (not overlay.update_type(ctx, draw::overlay::ElementType::DOT, index, progress, palette))
828 {
829 // add new element
830 overlay.add_ui_element(ctx, draw::overlay::ElementType::DOT, palette, positionX, 0, progress);
831 }
832
833 // if timeout is requested, update it
834 if (timeout > 0)
835 overlay.update_type_timeout(ctx, draw::overlay::ElementType::DOT, index, timeout);
836 }
837 }
838
840 static uint8_t get_modes_count(auto& ctx)
841 {
842 uint8_t value = 0;
843 dispatch_group(ctx, [&](auto group) {
844 value = decltype(group)::LocalModeTy::nbModes;
845 });
846 return value;
847 }
848
850 static void enter_group(auto& ctx, const uint8_t value)
851 {
852 // prevent value overflow
853 assert(value < nbGroupsTotal);
854
855 auto manager = ctx.modeManager.get_context();
856
857 // signal that we are quitting the mode
858 ctx.modeManager.quit_mode(manager);
859
860 // switch group (after quit mode)
861 ctx.modeManager.activeIndex.groupIndex = value;
862 // switch mode (restore last stored id)
863 ctx.modeManager.activeIndex.modeIndex = ctx.state.lastModeMemory[value];
864
865 // signal that we entered a new mode
866 ctx.modeManager.enter_mode(manager);
867 }
868
870 static void quit_group(auto& ctx)
871 {
872 // only save while out of favorites
873 if (not ctx.state.isInFavoriteMockGroup)
874 {
875 //
876 uint8_t modeIdBefore = ctx.get_active_mode();
877
878 // changes to lastModeMemory made in this function will be persistent
879 auto keyModeMemory = ctx.template storageFor<Store::modeMemory>(ctx.state.lastModeMemory);
880
881 // save last mode used in group, before switching
882 uint8_t groupIdBefore = ctx.get_active_group(nbGroupsTotal);
883 ctx.state.lastModeMemory[groupIdBefore] = modeIdBefore;
884 }
885 }
886
888 static void enter_mode(auto& ctx)
889 {
890 ctx.state.before_enter_mode(ctx);
891
892 // enter mode
893 dispatch_group(ctx, [](auto group) {
894 group.enter_mode();
895 });
896
897 ctx.state.after_enter_mode(ctx);
898
899 const uint8_t groupId = ctx.get_active_group();
900 const uint8_t modeId = ctx.get_active_mode();
901 logic::user_signals::send_mode(groupId, modeId);
902 // entering a mode restores its saved ramp without calling custom_ramp_update
903 if (ctx.everyCustomRamp[groupId][modeId])
904 logic::user_signals::send_ramp(ctx.get_active_custom_ramp(), true);
905 }
906
908 static void quit_mode(auto& ctx)
909 {
910 dispatch_group(ctx, [](auto group) {
911 group.quit_mode();
912 });
913
914 // cancel any blip
915 auto manager = ctx.modeManager.get_context();
916 manager.cancel_blip();
917 }
918
919 //
920 // all the callbacks
921 //
922
924 static void loop(auto& ctx)
925 {
926 // handle the sunset timer update
927 if (ctx.state.isSunsetTimingPending > 0)
928 {
929 ctx.state.isSunsetTimingPending -= 1;
930 if (ctx.state.isSunsetTimingPending == 0)
931 {
932 // set and update sunset timer
934 // blip AFTER the update
935 ctx.blip(50);
936 }
937 }
938
939 if (ctx.state.skipNextFrameEffect > 0)
940 {
941 ctx.state.skipNextFrameEffect -= 1;
942
943 // reached last skip frame, restore mode
944 if (ctx.state.skipNextFrameEffect == 0)
945 {
946 ctx.lamp.restoreBrightnessNow();
947 }
948 return;
949 }
950
951 ctx.lamp.refresh_tick_value();
952
953 // udpate modes and groups
954 dispatch_group(ctx, [](auto group) {
955 group.loop();
956 });
957
958 // apply low level brigthness mask, is enabled
959 ctx.lamp.apply_low_brightness_mask();
960
961 // display the overlay after the group update
962 overlay.display_update(ctx);
963
964 // a full frame is ready: the leds can come back, unless this frame started a new blip
965 if (ctx.state.skipNextFrameEffect == 0)
966 ctx.lamp.end_blackout();
967 }
968
974 static void sunset_update(auto& ctx, float progress)
975 {
976 dispatch_group(ctx, [&](auto group) {
977 group.sunset_update(progress);
978 });
979 }
980
986 static void sunrise_update(auto& ctx, float progress)
987 {
988 dispatch_group(ctx, [&](auto group) {
989 group.sunrise_update(progress);
990 });
991 }
992
996 static void sunset_timer_animation_internal_loop(auto& ctx)
997 {
999 {
1000 ctx.modeManager.sunsetHandler.loop_suntimer_animation(ctx);
1001 ctx.lamp.forceDisableLedDitherMask = true;
1002 }
1003 }
1004
1008 static void sunset_timer_internal_reset(auto& ctx)
1009 {
1010 ctx.modeManager.sunsetHandler.reset_suntimer_animation(ctx);
1011 ctx.lamp.forceDisableLedDitherMask = false;
1012 }
1013
1017 static void sunrise_timer_animation_internal_loop(auto& ctx)
1018 {
1019 if (logic::sunrise_timer.is_enabled())
1020 {
1021 ctx.modeManager.sunriseHandler.loop_suntimer_animation(ctx);
1022 ctx.lamp.forceDisableLedDitherMask = true;
1023 }
1024 }
1025
1029 static void sunrise_timer_internal_reset(auto& ctx)
1030 {
1031 ctx.modeManager.sunriseHandler.reset_suntimer_animation(ctx);
1032 ctx.lamp.forceDisableLedDitherMask = false;
1033 }
1034
1040 static void brightness_update(auto& ctx, brightness_t brightness)
1041 {
1042 dispatch_group(ctx, [&](auto group) {
1043 group.brightness_update(brightness);
1044 });
1045 }
1046
1048 static void power_on_sequence(auto& ctx)
1049 {
1050 // start with tick value
1051 ctx.lamp.refresh_tick_value();
1052
1053 // start by reseting the sun timers animations, clear masks if we did not wake up with a sunrise
1054 ctx.sunset_timer_internal_reset();
1055 ctx.sunrise_timer_internal_reset();
1056
1057 foreach_group<true>(ctx, [](auto group) {
1058 group.power_on_sequence();
1059 });
1060
1061 // activate last used favorite, in the favorite group
1062 if (ctx.state.isInFavoriteMockGroup and jump_to_favorite(ctx, ctx.state.lastFavoriteStep, false))
1063 {
1064 // success jump to favorite
1065 }
1066 else
1067 {
1068 // activate current mode
1069 uint8_t groupIdBefore = ctx.get_active_group(nbGroupsTotal);
1070 ctx.set_active_group(groupIdBefore);
1071 }
1072 }
1073
1075 static void power_off_sequence(auto& ctx)
1076 {
1077 foreach_group<true>(ctx, [](auto group) {
1078 group.power_off_sequence();
1079 });
1080
1081 ctx.lamp.forceDisableLedDitherMask = false;
1082 }
1083
1085 static void write_parameters(auto& ctx)
1086 {
1087 // clear the stored parameters, before storing ours.
1089
1090 // this scope is the only one where parameters will be kept
1091 ctx.template storageSaveOnly<Store::lastActive>(ctx.modeManager.activeIndex);
1092
1093 // save the maxFavoriteCount possible favorites
1094 ctx.template storageSaveOnly<Store::usedFavoriteCount>(ctx.modeManager.state.usedFavoriteCount);
1095 ctx.template storageSaveOnly<Store::favoriteModes>(ctx.modeManager.state.favorites);
1096 ctx.template storageSaveOnly<Store::lastUsedFavorite>(ctx.modeManager.state.lastFavoriteStep);
1097 ctx.template storageSaveOnly<Store::isInFavoriteGroup>(ctx.state.isInFavoriteMockGroup);
1098 ctx.template storageSaveOnly<Store::modeMemory>(ctx.state.lastModeMemory);
1099
1100 foreach_group<not hasCustomRamp>(ctx, [&ctx](auto group) {
1101 if constexpr (group.hasCustomRamp)
1102 {
1103 using StoreHere = typename decltype(group)::StoreEnum;
1104 group.template storageSaveOnly<StoreHere::rampMemory>(group.state.customRampMemory);
1105 group.template storageSaveOnly<StoreHere::indexMemory>(group.state.customIndexMemory);
1106 }
1107
1108 group.write_parameters();
1109 });
1110 }
1111
1113 static void read_parameters(auto& ctx)
1114 {
1115 // Reset the states before reading the parameters
1116 ctx.state.reset();
1117
1118 // remove old filesystem data if we detect obsolete "storeId" serial
1119 using LocalStore = details::LocalStoreOf<decltype(ctx)>;
1120 LocalStore::template migrateStoreIfNeeded<storeId>();
1121
1122 // load last active mode and active ramp, or default index
1123 ctx.template storageLoadOnly<Store::lastActive>(ctx.modeManager.activeIndex,
1124 ActiveIndexTy::from(Config::initialActiveIndex));
1125
1126 if constexpr (ctx.lamp.flavor == hardware::LampTypes::indexable)
1127 {
1128 // load the maxFavoriteCount possible favorites, or default favorites, for indexable
1129 ctx.template storageLoadOnly<Store::usedFavoriteCount>(ctx.modeManager.state.usedFavoriteCount,
1130 ctx.modeManager.state.defaultFavoriteCount_indexable);
1131 ctx.template storageLoadOnly<Store::favoriteModes>(ctx.state.favorites,
1132 ctx.modeManager.state.defaultFavorites_indexable);
1133 }
1134 else if constexpr (ctx.lamp.flavor == hardware::LampTypes::simple)
1135 {
1136 // load the maxFavoriteCount possible favorites, or default favorites, for simple
1137 ctx.template storageLoadOnly<Store::usedFavoriteCount>(ctx.modeManager.state.usedFavoriteCount,
1138 ctx.modeManager.state.defaultFavoriteCount_simple);
1139 ctx.template storageLoadOnly<Store::favoriteModes>(ctx.state.favorites,
1140 ctx.modeManager.state.defaultFavorites_simple);
1141 }
1142
1143 ctx.template storageLoadOnly<Store::lastUsedFavorite>(ctx.modeManager.state.lastFavoriteStep);
1144 ctx.template storageLoadOnly<Store::isInFavoriteGroup>(ctx.state.isInFavoriteMockGroup);
1145 ctx.template storageLoadOnly<Store::modeMemory>(ctx.state.lastModeMemory);
1146
1147 // for each group, migrate & handle custom ramp memory
1148 foreach_group<not hasCustomRamp>(ctx, [&ctx](auto group) {
1149 using LocalStore = details::LocalStoreOf<decltype(group)>;
1150 LocalStore::template migrateStoreIfNeeded<storeId>();
1151
1152 if constexpr (group.hasCustomRamp)
1153 {
1154 using StoreHere = typename LocalStore::EnumTy;
1155 // Get saved ramp values, or default values pulled from modes
1156 group.template storageLoadOnly<StoreHere::rampMemory>(group.state.customRampMemory,
1157 group.template get_custom_ramp_default_value());
1158 group.template storageLoadOnly<StoreHere::indexMemory>(group.state.customIndexMemory);
1159 }
1160
1161 group.read_parameters();
1162 });
1163 }
1164
1166 static void user_thread(auto& ctx)
1167 {
1168 dispatch_group(ctx, [](auto group) {
1169 group.user_thread();
1170 });
1171 }
1172
1179 static void custom_ramp_update(auto& ctx, uint8_t rampValue, uint32_t timeout = 0)
1180 {
1181 uint8_t groupId = ctx.get_active_group();
1182 uint8_t modeId = ctx.get_active_mode();
1183
1184 if (ctx.everyCustomRamp[groupId][modeId] && ctx.state.rampHandler.animEffect)
1185 {
1186 switch (ctx.state.rampHandler.animChoice)
1187 {
1188 case 0:
1189 overlay_animate_ramp(ctx, rampValue, modes::colors::PaletteBlackBodyColors, timeout);
1190 break;
1191
1192 case 1:
1193 overlay_animate_ramp(ctx, rampValue, modes::colors::PaletteRainbowColors, timeout);
1194 break;
1195 }
1196 }
1197
1198 dispatch_group(ctx, [&](auto group) {
1199 group.custom_ramp_update(rampValue);
1200 });
1201
1202 if (ctx.everyCustomRamp[groupId][modeId])
1203 logic::user_signals::send_ramp(rampValue);
1204 }
1205
1207 static bool custom_click(auto& ctx, uint8_t nbClick)
1208 {
1209 bool retVal = false;
1210 dispatch_group(ctx, [&](auto group) {
1211 retVal = group.custom_click(nbClick);
1212 });
1213 return retVal;
1214 }
1215
1217 static bool custom_hold(auto& ctx, uint8_t nbClickAndHold, bool isEndOfHoldEvent, uint32_t holdDuration)
1218 {
1219 bool retVal = false;
1220 dispatch_group(ctx, [&](auto group) {
1221 retVal = group.custom_hold(nbClickAndHold, isEndOfHoldEvent, holdDuration);
1222 });
1223 return retVal;
1224 }
1225
1226 //
1227 // Private action functions
1228 //
1229
1238 static void display_favorite_number_ramp(auto& ctx,
1239 const uint8_t favoriteIndex,
1240 const uint8_t maxFavoriteIndex,
1241 const bool display = false,
1242 const uint32_t timeout = 0)
1243 {
1244 const uint8_t maxPixelDisplay = std::min<uint8_t>(ctx.state.maxFavoriteCount, maxFavoriteIndex);
1245 for (uint8_t i = 0; i < maxPixelDisplay; ++i)
1246 {
1247 const bool shouldDisplay = (display and i <= favoriteIndex);
1248 overlay_animate_dot(
1249 ctx, i, i, shouldDisplay ? 255 : 0, colors::PaletteGradient<colors::Black, colors::Cyan>, timeout);
1250 }
1251 }
1252
1253 static uint8_t get_number_of_allowed_favorites(auto& ctx)
1254 {
1255 // user as a number of favorite set
1256 // occasional +1 if not all favorite are set (allow a new favorite)
1257 return ctx.state.usedFavoriteCount + ((ctx.state.usedFavoriteCount < ctx.state.maxFavoriteCount) ? 1 : 0);
1258 }
1259
1261 static bool is_in_favorite_group(auto& ctx) { return ctx.state.isInFavoriteMockGroup; }
1262
1267 template<bool displayFavoriteNumber = true>
1268 static void set_current_mode_as_favorite(auto& ctx, uint8_t favoriteIndex, uint32_t displayTimeout_s = 0)
1269 {
1270 const uint8_t numberOfFavoriteSet = get_number_of_allowed_favorites(ctx);
1271 if (favoriteIndex >= numberOfFavoriteSet)
1272 {
1274 "Cannot set a favorite at index %d, max index must be less than %d", favoriteIndex, numberOfFavoriteSet);
1275 return;
1276 }
1277
1278 // extra display on the first pixels (count pixels to know fav no)
1279 if constexpr (displayFavoriteNumber)
1280 {
1281 // display the set favorite ramp
1282 display_favorite_number_ramp(
1283 ctx, favoriteIndex, numberOfFavoriteSet, favoriteIndex < numberOfFavoriteSet, displayTimeout_s);
1284 }
1285
1286 ctx.state.pendingFavorite.action = StateTy::PendingFavorite::FavoriteAction::Add;
1287 ctx.state.pendingFavorite.slot = favoriteIndex;
1288 ctx.state.pendingFavorite.snapshot = ctx.modeManager.activeIndex;
1289
1290 ctx.state.on_favorite_hold_end(ctx, true);
1291 }
1292
1300 template<bool displayFavoriteNumber = true>
1301 static void animate_favorite_pick(auto& ctx, float holdDuration, float stepSize, bool isEndOfHold)
1302 {
1303 const uint8_t numberOfFavoriteSet = get_number_of_allowed_favorites(ctx);
1304
1305 // up to maxFavoriteCount step state: "which_one" is [0, 1, 2, 3, ...] and "do not set" is the max index + 1
1306 uint32_t stepCount = numberOfFavoriteSet + floor(holdDuration / stepSize);
1307 stepCount = stepCount % (numberOfFavoriteSet + 1);
1308
1309 // display ramp to show where user is standing
1310 if (stepCount >= numberOfFavoriteSet)
1311 {
1312 // display ramp for the first time to allow the user to cancel the action
1313 if (holdDuration <= 2 * stepSize)
1314 {
1315 overlay_animate_ramp(ctx, holdDuration, stepSize, colors::PaletteGradient<colors::White, colors::Cyan>);
1316 }
1317 }
1318 else
1319 {
1320 // green ramp : favorites
1321 overlay_animate_ramp(ctx, holdDuration, stepSize, colors::PaletteGradient<colors::Green, colors::White>);
1322 // display target favorite
1323 if constexpr (displayFavoriteNumber)
1324 {
1325 display_favorite_number_ramp(ctx, stepCount, numberOfFavoriteSet, stepCount < numberOfFavoriteSet);
1326 }
1327 }
1328
1329 // user lets go of the button: action on the favorite
1330 if (isEndOfHold)
1331 {
1332 // favorite in correct range: add new favorite !
1333 if (stepCount < numberOfFavoriteSet)
1334 set_current_mode_as_favorite(ctx, stepCount);
1335 else // cancel the new favorite: outside of range
1336 ctx.state.on_favorite_hold_end(ctx, false);
1337 }
1338 }
1339
1347 template<bool displayFavoriteNumber = true>
1348 static void animate_favorite_delete(auto& ctx, float holdDuration, float stepSize, bool isEndOfHold)
1349 {
1350 // no favorite deletion if no favorites
1351 if (ctx.state.usedFavoriteCount <= 0)
1352 return;
1353 // end of hold,
1354 if (isEndOfHold)
1355 {
1356 ctx.state.on_favorite_hold_end(ctx, false);
1357 return;
1358 }
1359
1360 ctx.state.isInDeleteFavorite = true;
1361
1362 uint32_t stepCount = floor(holdDuration / stepSize);
1363 stepCount = stepCount % 2;
1364
1365 // detect the state switch
1366 const bool justSwitched = stepCount != ctx.state.pendingFavorite.slot;
1367 if (stepCount == 0)
1368 {
1369 overlay_animate_ramp(ctx, holdDuration, stepSize, colors::PaletteGradient<colors::Orange, colors::Red>);
1370 // extra display on the first pixels (count pixels to know fav no)
1371 if constexpr (displayFavoriteNumber)
1372 {
1373 // display ramp
1374 display_favorite_number_ramp(ctx, ctx.state.lastFavoriteStep, ctx.state.usedFavoriteCount, true);
1375 }
1376 }
1377 else
1378 {
1380 if (justSwitched)
1381 {
1382 // delete now on ramp saturation. This
1383 ctx.state.pendingFavorite.action = StateTy::PendingFavorite::FavoriteAction::Delete;
1384 ctx.state.on_favorite_hold_end(ctx, true);
1385 }
1386 }
1387
1388 // update state pending LAST: it could have been resetted by favorite handle
1389 ctx.state.pendingFavorite.slot = stepCount;
1390 }
1391
1392 //
1393 // members with direct access
1394 //
1395
1397 ActiveIndexTy activeIndex;
1398
1400 hardware::LampTy& lamp;
1401
1403 inline static draw::overlay::Manager<> overlay;
1404
1409 template<typename Animation> struct SunTimerHandling
1410 {
1411 // define the shared suntimer animation
1412 Animation animation;
1414 void update_suntimer_drop_animation(auto& ctx, float progress) { animation.update_progress_rate(ctx, progress); }
1416 void reset_suntimer_animation(auto& ctx) { animation.reset(ctx); }
1418 void loop_suntimer_animation(auto& ctx) { animation.loop(ctx); }
1419 };
1420
1421 // sunset drop animation handle
1422 SunTimerHandling<anims::fadeout::GravityDissolve<>> sunsetHandler;
1423 SunTimerHandling<anims::fadein::GravityFadeIn<>> sunriseHandler;
1424
1425 //
1426 // private members
1427 //
1428
1429private:
1431 NoState placeholder;
1433 StateTy state;
1434};
1435
1440template<typename ManagerConfig, typename... Groups> using ManagerForConfig =
1441 ModeManagerTy<ManagerConfig, std::tuple<Groups...>, 0>;
1442
1451template<typename... Groups> using ManagerFor = ModeManagerTy<DefaultManagerConfig, std::tuple<Groups...>, 0>;
1452
1462template<uint8_t hiddenGroupCnt, typename... Groups> using ManagerForHiddenGroups =
1463 ModeManagerTy<DefaultManagerConfig, std::tuple<Groups...>, hiddenGroupCnt>;
1464
1469template<uint8_t hiddenGroupCnt, typename ManagerConfig, typename... Groups> using ManagerFoHiddenConfig =
1470 ModeManagerTy<ManagerConfig, std::tuple<Groups...>, hiddenGroupCnt>;
1471
1472} // namespace lampda::modes
1473
1474#endif
Handle the main alerts behavior.
Define assertions helpers.
void add_time_minutes(const uint8_t time_minutes)
Add some time to the current timer, or start it with a target time in minutes. This time cannot be sh...
Definition: sun_timers.cpp:101
void raise(const Type type)
Raise an alert.
Definition: alerts.cpp:1031
ContextTy and associated definitions.
Define some animations to fade in modes.
Define some animations to fade out modes.
Filesystem interaction tools.
Define the main led strip interaction object.
void lampda_print(const char *format,...)
C linkage to print functions.
Definition: text_out.cpp:336
AlertManager_t manager
Instanciation of the AlertManager.
Definition: alerts.cpp:30
SunsetTimer sunset_timer
object to access to control the timers
Definition: sun_timers.cpp:237
static constexpr PaletteTy PaletteBlackBodyColors
Black body radiation, with the high end changed to be nicer.
Definition: palettes.hpp:396
std::array< uint32_t, 16 > PaletteTy
Palette types.
Definition: palettes.hpp:18
static constexpr PaletteTy PaletteRainbowColors
HSV Rainbow.
Definition: palettes.hpp:360
@ indexable
Equivalent to LMBD_LAMP_TYPE__INDEXABLE.
@ simple
Equivalent to LMBD_LAMP_TYPE__SIMPLE.
static void clear_stored()
Force clear the stored parameters.
Definition: keystore.hpp:75
Contains basic interface types to implement custom user modes.
Definition: control_fixed_modes.hpp:14
ModeManagerTy< ManagerConfig, std::tuple< Groups... >, hiddenGroupCnt > ManagerFoHiddenConfig
Same as modes::ManagerFor but with custom defaults, and additional hidden groups.
Definition: manager_type.hpp:1470
ModeManagerTy< DefaultManagerConfig, std::tuple< Groups... >, hiddenGroupCnt > ManagerForHiddenGroups
Group together several mode groups defined through modes::GroupFor. Will use the last hiddenGroupCnt ...
Definition: manager_type.hpp:1463
ModeManagerTy< ManagerConfig, std::tuple< Groups... >, 0 > ManagerForConfig
Same as modes::ManagerFor but with custom defaults.
Definition: manager_type.hpp:1441
@ rampSaturates
(bool) Mode saturates on custom ramp, or else wrap?
ModeManagerTy< DefaultManagerConfig, std::tuple< Groups... >, 0 > ManagerFor
Group together several mode groups defined through modes::GroupFor.
Definition: manager_type.hpp:1451
static auto context_as(auto &ctx)
Bind provided context to another modes::BasicMode.
Definition: context_type.hpp:25
void brightness_update(const brightness_t brightness)
Called when the system changes the LED strip brightness.
Definition: default_behavior.hpp:64
void user_thread()
Called at each tick of the secondary thread.
Definition: default_behavior.hpp:199
void read_parameters()
Called when system wants to read parameters from filesystem.
Definition: default_behavior.hpp:94
void power_on_sequence()
Called when the system powers on (must be non blocking function!)
Definition: default_behavior.hpp:39
void write_parameters()
Called when system wants to write parameters to filesystem.
Definition: default_behavior.hpp:88
void power_off_sequence()
Called when the system powers off (must be non blocking function!)
Definition: default_behavior.hpp:50
void loop()
Called at each tick of the main loop.
Definition: default_behavior.hpp:179
uint16_t brightness_t
Define the type of the brightness parameters.
Definition: constants.h:151
GlobalSimStateTy state
Store the global simulation state.
Definition: simulator_state.cpp:7
Lamp overlay manager.
Default manager configuration, enables you to customize defaults.
Definition: default_config.hpp:42
FavoriteAction action
action on this favorite
Definition: manager_type.hpp:303
ActiveIndexTy snapshot
current active index
Definition: manager_type.hpp:305
uint8_t slot
index of the favorite to add/remove
Definition: manager_type.hpp:304
Definition: manager_type.hpp:252
RampHandlerTy< Config > scrollHandler
Ramp handlers: mode scroll ramp.
Definition: manager_type.hpp:320
static constexpr uint8_t defaultFavoriteCount_simple
By default, the system will have X favorites.
Definition: manager_type.hpp:284
static constexpr std::array< ActiveIndexTy, maxFavoriteCount > defaultFavorites_indexable
The default favorites are defined below :
Definition: manager_type.hpp:268
bool clearStripOnModeChange
Should clear the strip before switching mode.
Definition: manager_type.hpp:322
RampHandlerTy< Config > rampHandler
Ramp handlers: custom ramp (or "color ramp")
Definition: manager_type.hpp:318
bool isInFavoriteMockGroup
Indicates that we are in the fake favorite page.
Definition: manager_type.hpp:310
static constexpr uint8_t defaultFavoriteCount_indexable
By default, the system will have X favorites.
Definition: manager_type.hpp:266
uint8_t lastFavoriteStep
last used favorite index
Definition: manager_type.hpp:292
AllStatesTy groupStates
All group states, containing all modes individual states.
Definition: manager_type.hpp:254
ActiveIndexTy beforeFavoriteActiveIndex
store the index we need to go to when quitting the favorite page
Definition: manager_type.hpp:311
static constexpr std::array< ActiveIndexTy, maxFavoriteCount > defaultFavorites_simple
The default favorites are defined below :
Definition: manager_type.hpp:286
uint8_t usedFavoriteCount
number of favorite set by user [0, maxFavoriteCount]
Definition: manager_type.hpp:263
bool isLastScrollAGroupChange
last mode change in scroll changed group
Definition: manager_type.hpp:314
uint32_t lastScrollStopped
keep track of the last scrool release time
Definition: manager_type.hpp:315
static void LMBD_INLINE before_enter_mode(auto &ctx)
configuration-related actions done before entering mode
Definition: manager_type.hpp:350
uint8_t isSunsetTimingPending
Indicates that a sunset timer ramp is active.
Definition: manager_type.hpp:312
void reset()
Reset the stored variable states.
Definition: manager_type.hpp:328
std::array< ActiveIndexTy, maxFavoriteCount > favorites
Store the active index of every favorite.
Definition: manager_type.hpp:262
uint8_t skipNextFrameEffect
should the next .loop() mode be skipped?
Definition: manager_type.hpp:325
std::array< uint8_t, nbGroupsTotal > lastModeMemory
When switching group, remember which mode was on last time we visited it.
Definition: manager_type.hpp:257
static constexpr uint8_t maxFavoriteCount
Maximum allowed favorite count.
Definition: manager_type.hpp:260
static void LMBD_INLINE after_enter_mode(auto &ctx)
configuration-related actions done after mode entering
Definition: manager_type.hpp:358
PendingFavorite pendingFavorite
store the pending favorite to add or delete
Definition: manager_type.hpp:308
bool isInDeleteFavorite
indicates that we are in a favorite deletion process
Definition: manager_type.hpp:291
Definition: manager_type.hpp:1410
void loop_suntimer_animation(auto &ctx)
loop suntimer animations
Definition: manager_type.hpp:1418
void reset_suntimer_animation(auto &ctx)
Reset the sunset animations.
Definition: manager_type.hpp:1416
void update_suntimer_drop_animation(auto &ctx, float progress)
Update the sunset drop animation.
Definition: manager_type.hpp:1414
Handle the sun timers: sunset to auto shutdown the system and sunrise for auto turn on.
Define templated tools to analyze the manager objects.
Output user action signals on the serial and bluetooth links.