Lamp-Da 0.1
A compact lantern project
Loading...
Searching...
No Matches
context_type.hpp
Go to the documentation of this file.
1#ifndef CONTEXT_TYPE_H
2#define CONTEXT_TYPE_H
3
9#include <cstdint>
10#include <type_traits>
11
13
17#include "src/modes/include/default_config.hpp"
18
19namespace lampda::modes {
20
25template<typename NewLocalMode> static auto context_as(auto& ctx) { return ctx.template context_as<NewLocalMode>(); }
26
28template<typename LocalBasicMode, typename ModeManager> struct ContextTy
29{
32
38 using LocalModeTy = LocalBasicMode;
40 using StateTy = StateTyOf<LocalModeTy>;
41
43 static constexpr bool isMode = is_mode<LocalModeTy>;
44
46 static constexpr bool isModeManager = std::is_same_v<LocalModeTy, ModeManagerTy>;
47 static constexpr bool isGroupManager = false;
48
49 // useful proxies (exposes mode properties)
50 static constexpr bool hasSunsetAnimation = LocalModeTy::hasSunsetAnimation;
51 static constexpr bool hasSunriseAnimation = LocalModeTy::hasSunriseAnimation;
52 static constexpr bool usesSunsetGravityDissolveMode = LocalModeTy::usesSunsetGravityDissolveMode;
53 static constexpr bool usesSunriseGravityAppearMode = LocalModeTy::usesSunriseGravityAppearMode;
54 static constexpr bool hasBrightCallback = LocalModeTy::hasBrightCallback;
55 static constexpr bool hasSystemCallbacks = LocalModeTy::hasSystemCallbacks;
56 static constexpr bool requireUserThread = LocalModeTy::requireUserThread;
57 static constexpr bool hasCustomRamp = LocalModeTy::hasCustomRamp;
58 static constexpr bool hasButtonCustomUI = LocalModeTy::hasButtonCustomUI;
59
60 // more proxies (exposes tables of mode properties)
61 static constexpr auto everySunsetCallback = LocalModeTy::everySunsetCallback;
62 static constexpr auto everySunriseCallback = LocalModeTy::everySunriseCallback;
63 static constexpr auto everyBrightCallback = LocalModeTy::everyBrightCallback;
64 static constexpr auto everySystemCallbacks = LocalModeTy::everySystemCallbacks;
65 static constexpr auto everyRequireUserThread = LocalModeTy::everyRequireUserThread;
66 static constexpr auto everyCustomRamp = LocalModeTy::everyCustomRamp;
67 static constexpr auto everyButtonCustomUI = LocalModeTy::everyButtonCustomUI;
68
69 //
70 // constructors
71 //
72
74 template<typename NewLocalMode> auto LMBD_INLINE context_as()
75 {
77 }
78
80 ContextTy(ModeManagerTy& modeManager) :
81 state {modeManager.template getStateOf<LocalModeTy>()},
82 lamp {modeManager.lamp},
83 modeManager {modeManager}
84 {
85 }
86
87 ContextTy() = delete;
88 ContextTy(const ContextTy&) = delete;
89 ContextTy& operator=(const ContextTy&) = delete;
90
91 //
92 // manager calls
93 //
94
96 auto LMBD_INLINE next_group()
97 {
98 if constexpr (LocalModeTy::isGroupManager)
99 {
100 LocalModeTy::next_group(*this);
101 }
102 else
103 {
104 auto manager = modeManager.get_context();
105 return manager.next_group();
106 }
107 }
108
110 auto LMBD_INLINE next_mode()
111 {
112 if constexpr (LocalModeTy::isModeManager)
113 {
114 LocalModeTy::next_mode(*this);
115 }
116 else
117 {
118 auto manager = modeManager.get_context();
119 return manager.next_mode();
120 }
121 }
122
123 void LMBD_INLINE jump_to_new_active_index(const auto& newActiveIndex,
124 const bool ignoreRampAndIndex = false,
125 const bool quitFavoriteGroup = false)
126 {
127 if constexpr (LocalModeTy::isGroupManager)
128 {
129 LocalModeTy::jump_to_new_active_index(*this, newActiveIndex, ignoreRampAndIndex, quitFavoriteGroup);
130 }
131 else
132 {
133 auto manager = modeManager.get_context();
134 manager.jump_to_new_active_index(newActiveIndex, ignoreRampAndIndex, quitFavoriteGroup);
135 }
136 }
137
139 bool LMBD_INLINE jump_to_favorite(uint8_t which_one, bool shouldSaveLastActiveIndex)
140 {
141 if constexpr (LocalModeTy::isModeManager)
142 {
143 return LocalModeTy::jump_to_favorite(*this, which_one, shouldSaveLastActiveIndex);
144 }
145 else
146 {
147 auto manager = modeManager.get_context();
148 return manager.jump_to_favorite(which_one, shouldSaveLastActiveIndex);
149 }
150 }
151
153 bool LMBD_INLINE exit_favorite_group(auto nextActiveIndex)
154 {
155 if constexpr (LocalModeTy::isModeManager)
156 {
157 return LocalModeTy::exit_favorite_group(*this, nextActiveIndex);
158 }
159 else
160 {
161 auto manager = modeManager.get_context();
162 return manager.exit_favorite_group(nextActiveIndex);
163 }
164 }
165
167 auto LMBD_INLINE set_favorite_at(uint8_t which_one, auto activeIndex)
168 {
169 if constexpr (LocalModeTy::isModeManager)
170 {
171 return LocalModeTy::set_favorite_at(*this, which_one, activeIndex);
172 }
173 else
174 {
175 auto manager = modeManager.get_context();
176 return manager.set_favorite_at(which_one, activeIndex);
177 }
178 }
179
181 auto LMBD_INLINE delete_favorite_now()
182 {
183 if constexpr (LocalModeTy::isModeManager)
184 {
185 return LocalModeTy::delete_favorite_now(*this);
186 }
187 else
188 {
189 auto manager = modeManager.get_context();
190 return manager.delete_favorite_now();
191 }
192 }
193
195 auto LMBD_INLINE handle_scroll_modes(const uint32_t holdDuration)
196 {
197 if constexpr (LocalModeTy::isModeManager)
198 {
199 return LocalModeTy::handle_scroll_modes(*this, holdDuration);
200 }
201 else
202 {
203 auto manager = modeManager.get_context();
204 return manager.handle_scroll_modes(holdDuration);
205 }
206 }
207
209 auto LMBD_INLINE enter_hidden_group(const uint8_t hiddenGroupIndex)
210 {
211 if constexpr (LocalModeTy::isModeManager)
212 {
213 return LocalModeTy::enter_hidden_group(*this, hiddenGroupIndex);
214 }
215 else
216 {
217 auto manager = modeManager.get_context();
218 return manager.enter_hidden_group(hiddenGroupIndex);
219 }
220 }
221
223 auto LMBD_INLINE overlay_animate_ramp(float holdDuration,
224 float stepSize,
225 const colors::PaletteTy& palette,
226 const uint32_t timeout = 0)
227 {
228 if constexpr (LocalModeTy::isModeManager)
229 {
230 return modeManager.overlay_animate_ramp(*this, holdDuration, stepSize, palette, timeout);
231 }
232 else
233 {
234 auto manager = modeManager.get_context();
235 return manager.overlay_animate_ramp(holdDuration, stepSize, palette, timeout);
236 }
237 }
238
240 auto LMBD_INLINE overlay_animate_ramp(uint8_t progress, const colors::PaletteTy& palette, const uint32_t timeout = 0)
241 {
242 if constexpr (LocalModeTy::isModeManager)
243 {
244 return modeManager.overlay_animate_ramp(*this, progress, palette, timeout);
245 }
246 else
247 {
248 auto manager = modeManager.get_context();
249 return manager.overlay_animate_ramp(progress, palette, timeout);
250 }
251 }
252
254 auto LMBD_INLINE get_groups_count() { return modeManager.nbGroupsTotal; }
256 auto LMBD_INLINE get_accessible_groups_count() { return modeManager.nbAccessibleGroups; }
258 auto LMBD_INLINE get_hidden_groups_count() { return modeManager.hiddenGroupCount; }
259
261 auto LMBD_INLINE get_modes_count()
262 {
263 if constexpr (LocalModeTy::isModeManager)
264 {
265 return modeManager.get_modes_count(*this);
266 }
267 else
268 {
269 auto manager = modeManager.get_context();
270 return manager.get_modes_count();
271 }
272 }
273
274 //
275 // getters / setters for activeIndex
276 //
277
279 uint8_t LMBD_INLINE get_active_group(uint8_t maxValueWrap = 255) const
280 {
281 uint8_t groupIndex = modeManager.activeIndex.groupIndex;
282 return (groupIndex + 1) > maxValueWrap ? 0 : groupIndex;
283 }
284
286 uint8_t LMBD_INLINE set_active_group(uint8_t value, uint8_t maxValueWrap = 255)
287 {
288 if (value + 1 > maxValueWrap)
289 value = 0;
290
291 // signal that we are quitting the group
292 quit_group();
293 // enter a new group
294 enter_group(value);
295 return value;
296 }
297
299 uint8_t LMBD_INLINE get_active_mode(uint8_t maxValueWrap = 255) const
300 {
301 uint8_t modeIndex = modeManager.activeIndex.modeIndex;
302 return (modeIndex + 1) > maxValueWrap ? 0 : modeIndex;
303 }
304
306 uint8_t LMBD_INLINE set_active_mode(uint8_t value, uint8_t maxValueWrap = 255)
307 {
308 if (value + 1 > maxValueWrap)
309 value = 0;
310
311 auto manager = modeManager.get_context();
312
313 // signal that we are quitting the mode
314 modeManager.quit_mode(manager);
315
316 // if next mode is the same as current one, add a blip to help user differenciate
317 if (modeManager.activeIndex.modeIndex == value)
318 {
319 // This is not complete, there is no group check, so the blip will be visible sometimes on modes with the same
320 // modeIndex in different groups
321
322 // blip to indicate a mode change to the same mode
323 manager.blip(100);
324 }
325
326 // switch mode
327 modeManager.activeIndex.modeIndex = value;
328 // signal that we entered a new mode
329 modeManager.enter_mode(manager);
330 return value;
331 }
332
337 uint8_t LMBD_INLINE get_active_custom_ramp() const { return modeManager.activeIndex.rampIndex; }
338
342 void update_sunset_drop_animation(float progress)
343 {
344 modeManager.sunsetHandler.update_suntimer_drop_animation(*this, progress);
345 }
346
350 void update_sunrise_drop_animation(float progress)
351 {
352 modeManager.sunriseHandler.update_suntimer_drop_animation(*this, progress);
353 }
354
359 uint8_t LMBD_INLINE set_active_custom_ramp(uint8_t value)
360 {
361 modeManager.activeIndex.rampIndex = value;
362 return value;
363 }
364
366 uint8_t LMBD_INLINE get_active_custom_index() const { return modeManager.activeIndex.customIndex; }
367
369 uint8_t LMBD_INLINE set_active_custom_index(uint8_t value)
370 {
371 modeManager.activeIndex.customIndex = value;
372 return value;
373 }
374
375 //
376 // store
377 //
378
380 template<typename Mode> StateTyOf<Mode>& get_state_of_mode() { return modeManager.template getStateOf<Mode>(); }
381
383 template<typename Mode> static constexpr int get_group_id_of_mode()
384 {
385 return details::GroupIdFrom<Mode, typename ModeManagerTy::AllGroupsTy>;
386 }
387
389 template<typename Mode> static constexpr int get_mode_id()
390 {
391 return details::ModeIdFrom<Mode, typename ModeManagerTy::AllGroupsTy, get_group_id_of_mode<Mode>()>;
392 }
393
395 static constexpr int groupId = get_group_id_of_mode<LocalModeTy>();
396
398 static constexpr int modeId = get_mode_id<LocalModeTy>();
399
401 static constexpr auto prefix =
402 (isModeManager ? store::PrefixValues::managerKeys :
403 (isMode ? store::PrefixValues::generalKeys : store::PrefixValues::privateKeys));
404
406 using StoreEnum = StoreEnumOf<LocalModeTy>;
407
409 using LocalStore = store::KeyStore<StoreEnum, groupId, modeId, prefix>;
410
412 static constexpr bool hasStore = not std::is_same_v<StoreEnum, NoStoreHere>;
413
453 template<StoreEnum _key, typename T> struct KeyProxy
454 {
455 static_assert(std::is_same_v<T, std::conditional_t<hasStore, T, NoStoreId>>,
456 "KeyProxy can not be used when no storeId has been defined!");
457
459 static constexpr StoreEnum key = _key;
460
463
465 inline void LMBD_INLINE setValue(T value)
466 {
467 local = value;
468 LocalStore::template setValue<key, T>(value);
469 };
470
472 inline bool LMBD_INLINE getValue() { return LocalStore::template getValue<key, T>(local); }
473
475 inline void LMBD_INLINE getValue(T defVal) { LocalStore::template getValue<key, T>(local, defVal); }
476
478 inline bool LMBD_INLINE hasValue() { return LocalStore::template hasValue<key, T>(); }
479
480 //
481 // private API
482 //
483
485 inline void LMBD_INLINE forceSave() { LocalStore::template setValue<key, T>(local); }
486
487 //
488 // constructors
489 //
490
493
494 KeyProxy() = delete;
495 KeyProxy(const KeyProxy&) = delete;
496 KeyProxy& operator=(const KeyProxy&) = delete;
497
499 ~KeyProxy() { forceSave(); }
500 };
501
503 template<StoreEnum key, typename T = uint32_t>
504 static auto LMBD_INLINE storageFor(LMBD_USED T& local) // requires storeId :)
505 {
506 if constexpr (hasStore)
507 {
508 return KeyProxy<key, T> {local};
509 }
510 else
511 {
512 return NoStoreId {};
513 }
514 }
515
517 template<StoreEnum key, typename T = uint32_t> static bool LMBD_INLINE storageLoadOnly(LMBD_USED T& local)
518 {
519 return LocalStore::template getValue<key, T>(local);
520 }
521
523 template<StoreEnum key, typename T = uint32_t>
524 static void LMBD_INLINE storageLoadOnly(LMBD_USED T& local, const T defaultValue)
525 {
526 LocalStore::template getValue<key, T>(local, defaultValue);
527 }
528
530 template<StoreEnum key, typename T = uint32_t> static void LMBD_INLINE storageSaveOnly(LMBD_USED T& local)
531 {
532 return LocalStore::template setValue<key, T>(local);
533 }
534
535 //
536 // manager config
537 //
538
543 template<ConfigKeys key> void LMBD_INLINE set_config_bool(bool value)
544 {
545 auto ctx = modeManager.get_context();
546 switch (key)
547 {
549 ctx.state.rampHandler.rampSaturates = value;
550 break;
552 ctx.state.clearStripOnModeChange = value;
553 break;
555 ctx.state.rampHandler.animEffect = value;
556 break;
557 default:
558 assert(false && "unsupported config key for booleans!");
559 break;
560 }
561 }
562
567 template<ConfigKeys key> void LMBD_INLINE set_config_u32(uint32_t value)
568 {
569 auto ctx = modeManager.get_context();
570 switch (key)
571 {
573 ctx.state.rampHandler.stepSpeed = value;
574 break;
576 ctx.state.rampHandler.animChoice = value;
577 break;
578 default:
579 assert(false && "unsupported config key for u32!");
580 break;
581 }
582 }
583
584 //
585 // special effects
586 //
587
592 void blip(const uint32_t duration)
593 {
594 auto ctx = modeManager.get_context();
595 // skip the next frames
596 ctx.state.skipNextFrameEffect = ceil(duration / static_cast<float>(ctx.lamp.frameDurationMs));
597 // turn off the output
598 ctx.lamp.blip(duration);
599 }
600
602 void cancel_blip() const
603 {
604 auto ctx = modeManager.get_context();
605 // cancel skip
606 ctx.state.skipNextFrameEffect = 0;
607 ctx.lamp.cancel_blip();
608 }
609
611 bool is_bliping() const
612 {
613 auto ctx = modeManager.get_context();
614 return ctx.lamp.is_bliping();
615 }
616
617 //
618 // Binder for group and mode enter/quit
619 //
620
622 void LMBD_INLINE enter_group(const uint8_t value)
623 {
624 if constexpr (LocalModeTy::isModeManager)
625 {
626 LocalModeTy::enter_group(*this, value);
627 }
628 else
629 {
630 auto& manager = modeManager.get_context();
631 return manager.enter_group(value);
632 }
633 }
634
636 void LMBD_INLINE quit_group()
637 {
638 if constexpr (LocalModeTy::isModeManager)
639 {
640 LocalModeTy::quit_group(*this);
641 }
642 else
643 {
644 auto& manager = modeManager.get_context();
645 return manager.quit_group();
646 }
647 }
648
650 void LMBD_INLINE enter_mode()
651 {
652 if constexpr (LocalModeTy::isModeManager)
653 {
654 LocalModeTy::enter_mode(*this);
655 }
656 else
657 {
658 auto& manager = modeManager.get_context();
659 return manager.enter_mode();
660 }
661 }
662
664 void LMBD_INLINE quit_mode()
665 {
666 if constexpr (LocalModeTy::isModeManager)
667 {
668 LocalModeTy::quit_mode(*this);
669 }
670 else
671 {
672 auto& manager = modeManager.get_context();
673 return manager.quit_mode();
674 }
675 }
676
677 //
678 // quick bindings to \p LocalModeTy
679 //
680
682 void LMBD_INLINE loop()
683 {
684 LocalModeTy::loop(*this);
685
686 // this mode special case
687 if constexpr (isMode)
688 {
689 auto manager = modeManager.get_context();
690
691 // this mode has sunset and internal sunset animation
692 if constexpr (LocalModeTy::hasSunsetAnimation && LocalModeTy::usesSunsetGravityDissolveMode)
693 {
694 manager.sunset_timer_animation_internal_loop();
695 }
696
697 // this mode has sunset and internal sunset animation
698 if constexpr (LocalModeTy::hasSunriseAnimation && LocalModeTy::usesSunriseGravityAppearMode)
699 {
700 manager.sunrise_timer_animation_internal_loop();
701 }
702 }
703 }
704
706 void LMBD_INLINE on_enter_mode()
707 {
708 if (hasStore)
709 {
710 LocalStore::template migrateStoreIfNeeded<LocalModeTy::storeId>();
711 }
712
713 // this mode special case
714 if constexpr (isMode)
715 {
716 auto manager = modeManager.get_context();
717
718 // this mode has sunset and internal sunset animation
719 if constexpr (LocalModeTy::hasSunsetAnimation && LocalModeTy::usesSunsetGravityDissolveMode)
720 {
721 manager.sunset_timer_internal_reset();
722 }
723
724 // this mode has sunset and internal sunset animation
725 if constexpr (LocalModeTy::hasSunriseAnimation && LocalModeTy::usesSunriseGravityAppearMode)
726 {
727 manager.sunrise_timer_internal_reset();
728 }
729 }
730
731 LocalModeTy::on_enter_mode(*this);
732 }
733
735 void LMBD_INLINE on_exit_mode()
736 {
737 //
738 LocalModeTy::on_exit_mode(*this);
739 }
740
742 void LMBD_INLINE sunset_update(LMBD_USED float progress)
743 {
744 if constexpr (LocalModeTy::hasSunsetAnimation)
745 {
746 if constexpr (isMode)
747 {
748 // special handle case if we specifically have a dissolve mode
749 if constexpr (LocalModeTy::usesSunsetGravityDissolveMode)
750 modeManager.get_context().update_sunset_drop_animation(progress);
751 }
752
753 LocalModeTy::sunset_update(*this, progress);
754 }
755 }
756
758 void LMBD_INLINE sunrise_update(LMBD_USED float progress)
759 {
760 if constexpr (LocalModeTy::hasSunriseAnimation)
761 {
762 if constexpr (isMode)
763 {
764 // special handle case if we specifically have a gravity appear mode
765 if constexpr (LocalModeTy::usesSunriseGravityAppearMode)
766 modeManager.get_context().update_sunrise_drop_animation(progress);
767 }
768
769 LocalModeTy::sunrise_update(*this, progress);
770 }
771 }
772
774 void LMBD_INLINE sunset_timer_animation_internal_loop() { LocalModeTy::sunset_timer_animation_internal_loop(*this); }
777 {
778 LocalModeTy::sunrise_timer_animation_internal_loop(*this);
779 }
780
784 void LMBD_INLINE sunset_timer_internal_reset() { LocalModeTy::sunset_timer_internal_reset(*this); }
785
789 void LMBD_INLINE sunrise_timer_internal_reset() { LocalModeTy::sunrise_timer_internal_reset(*this); }
790
792 void LMBD_INLINE brightness_update(LMBD_USED brightness_t brightness)
793 {
794 if constexpr (LocalModeTy::hasBrightCallback)
795 {
796 LocalModeTy::brightness_update(*this, brightness);
797 }
798 }
799
801 void LMBD_INLINE custom_ramp_update(LMBD_USED uint8_t rampValue, uint32_t timeout = 0)
802 {
803 if constexpr (LocalModeTy::isGroupManager)
804 {
805 LocalModeTy::custom_ramp_update(*this, rampValue, timeout);
806 }
807 else if constexpr (LocalModeTy::hasCustomRamp)
808 {
809 LocalModeTy::custom_ramp_update(*this, rampValue);
810 }
811 }
812
814 bool LMBD_INLINE custom_click(LMBD_USED uint8_t nbClick)
815 {
816 if constexpr (LocalModeTy::hasButtonCustomUI)
817 {
818 return LocalModeTy::custom_click(*this, nbClick);
819 }
820
821 return false;
822 }
823
825 bool LMBD_INLINE custom_hold(LMBD_USED uint8_t nbClickAndHold,
826 LMBD_USED bool isEndOfHoldEvent,
827 LMBD_USED uint32_t holdDuration)
828 {
829 if constexpr (LocalModeTy::hasButtonCustomUI)
830 {
831 return LocalModeTy::custom_hold(*this, nbClickAndHold, isEndOfHoldEvent, holdDuration);
832 }
833
834 return false;
835 }
836
837 void display_favorite_number_ramp(const uint8_t favoriteIndex,
838 const uint8_t maxFavoriteIndex,
839 const bool display = false,
840 const uint32_t timeout = 0)
841 {
842 if constexpr (LocalModeTy::isModeManager)
843 {
844 modeManager.template display_favorite_number_ramp(*this, favoriteIndex, maxFavoriteIndex, display, timeout);
845 }
846 else
847 {
848 auto& manager = modeManager.get_context();
849 manager.display_favorite_number_ramp(favoriteIndex, maxFavoriteIndex, display, timeout);
850 }
851 }
852
853 template<bool displayFavoriteNumber = true>
854 auto set_current_mode_as_favorite(uint8_t favoriteIndex, uint32_t displayTimeout_s = 0)
855 {
856 if constexpr (LocalModeTy::isModeManager)
857 {
858 modeManager.template set_current_mode_as_favorite<displayFavoriteNumber>(*this, favoriteIndex, displayTimeout_s);
859 }
860 else
861 {
862 auto& manager = modeManager.get_context();
863 manager.template set_current_mode_as_favorite<displayFavoriteNumber>(favoriteIndex, displayTimeout_s);
864 }
865 }
866
867 auto get_number_of_allowed_favorites()
868 {
869 if constexpr (LocalModeTy::isModeManager)
870 {
871 return modeManager.template get_number_of_allowed_favorites(*this);
872 }
873 else
874 {
875 auto& manager = modeManager.get_context();
876 return manager.get_number_of_allowed_favorites(*this);
877 }
878 }
879
880 bool is_in_favorite_group()
881 {
882 if constexpr (LocalModeTy::isGroupManager)
883 {
884 return modeManager.template is_in_favorite_group(*this);
885 }
886 else
887 {
888 auto manager = modeManager.get_context();
889 return manager.is_in_favorite_group();
890 }
891 }
892
893 template<bool displayFavoriteNumber = true>
894 auto LMBD_INLINE animate_favorite_pick(float holdDuration, float stepSize, bool isEndOfHold)
895 {
896 if constexpr (LocalModeTy::isModeManager)
897 {
898 return modeManager.template animate_favorite_pick<displayFavoriteNumber>(
899 *this, holdDuration, stepSize, isEndOfHold);
900 }
901 else
902 {
903 auto& manager = modeManager.get_context();
904 return manager.template animate_favorite_pick<displayFavoriteNumber>(holdDuration, stepSize, isEndOfHold);
905 }
906 }
907
908 template<bool displayFavoriteNumber = true>
909 auto LMBD_INLINE animate_favorite_delete(float holdDuration, float stepSize, bool isEndOfHold)
910 {
911 if constexpr (LocalModeTy::isModeManager)
912 {
913 return modeManager.template animate_favorite_delete<displayFavoriteNumber>(
914 *this, holdDuration, stepSize, isEndOfHold);
915 }
916 else
917 {
918 auto& manager = modeManager.get_context();
919 return manager.template animate_favorite_delete<displayFavoriteNumber>(holdDuration, stepSize, isEndOfHold);
920 }
921 }
922
924 auto LMBD_INLINE get_custom_ramp_default_value() { return LocalModeTy::get_custom_ramp_default_value(*this); }
925
927 void LMBD_INLINE power_on_sequence()
928 {
929 if constexpr (LocalModeTy::hasSystemCallbacks)
930 {
931 LocalModeTy::power_on_sequence(*this);
932 }
933 }
934
936 void LMBD_INLINE power_off_sequence()
937 {
938 if constexpr (LocalModeTy::hasSystemCallbacks)
939 {
940 LocalModeTy::power_off_sequence(*this);
941 }
942 }
943
945 void LMBD_INLINE write_parameters()
946 {
947 if constexpr (LocalModeTy::hasSystemCallbacks)
948 {
949 LocalModeTy::write_parameters(*this);
950 }
951 }
952
954 void LMBD_INLINE read_parameters()
955 {
956 if constexpr (LocalModeTy::hasSystemCallbacks)
957 {
958 LocalModeTy::read_parameters(*this);
959 }
960 }
961
963 bool LMBD_INLINE should_spawn_thread() { return LocalModeTy::requireUserThread; }
964
966 void LMBD_INLINE user_thread()
967 {
968 if constexpr (LocalModeTy::requireUserThread)
969 {
970 LocalModeTy::user_thread(*this);
971 }
972 }
973
974 //
975 // context members for direct access
976 //
977
980
981private:
982 ModeManagerTy& modeManager;
983};
984
985} // namespace lampda::modes
986
987#endif
Filesystem interaction tools.
Define the main led strip interaction object.
AlertManager_t manager
Instanciation of the AlertManager.
Definition: alerts.cpp:30
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:14
@ 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:151
(store) Binds a local variable of type T to key in storage (with automatic read & save)
Definition: context_type.hpp:454
void LMBD_INLINE getValue(T defVal)
(optional) Read key value, if not found, set local to defVal
Definition: context_type.hpp:475
void LMBD_INLINE setValue(T value)
(optional) Set local to value then write key to store
Definition: context_type.hpp:465
static constexpr StoreEnum key
Enumeration value uniquely identifying where local will be stored.
Definition: context_type.hpp:459
bool LMBD_INLINE getValue()
(optional) Read key from store, return True if local was written
Definition: context_type.hpp:472
T & local
Local variable reference bound to KeyProxy.
Definition: context_type.hpp:462
bool LMBD_INLINE hasValue()
(optional) Return True if key is set in store, False if unknown
Definition: context_type.hpp:478
KeyProxy(T &local)
Use ContextTy::storageFor to construct a KeyProxy bound to local.
Definition: context_type.hpp:492
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:524
void LMBD_INLINE set_config_bool(bool value)
(setter) Set a configurable boolean to target value
Definition: context_type.hpp:543
void update_sunset_drop_animation(float progress)
Update the sunset timer drop animation.
Definition: context_type.hpp:342
void LMBD_INLINE power_on_sequence()
Binds to local BasicMode::power_on_sequence()
Definition: context_type.hpp:927
void LMBD_INLINE brightness_update(LMBD_USED brightness_t brightness)
Binds to local BasicMode::brightness_update()
Definition: context_type.hpp:792
void LMBD_INLINE enter_group(const uint8_t value)
Call when entering a group.
Definition: context_type.hpp:622
void LMBD_INLINE sunset_timer_animation_internal_loop()
Run the internal sunset animation loop.
Definition: context_type.hpp:774
void LMBD_INLINE set_config_u32(uint32_t value)
(setter) Set a configurable integer (u32) to target value
Definition: context_type.hpp:567
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:825
void LMBD_INLINE on_exit_mode()
Binds to local BasicMode::on_exit_mode()
Definition: context_type.hpp:735
void LMBD_INLINE quit_group()
Call when quitting a group.
Definition: context_type.hpp:636
uint8_t LMBD_INLINE get_active_custom_index() const
(getter) Get active custom index (recalled when jumping favorites)
Definition: context_type.hpp:366
static constexpr bool hasStore
(store) True if LocalBasicMode has access to a local key store
Definition: context_type.hpp:412
void LMBD_INLINE sunset_timer_internal_reset()
Signal a end of sunset timer event.
Definition: context_type.hpp:784
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:359
void LMBD_INLINE read_parameters()
Binds to local BasicMode::read_parameters()
Definition: context_type.hpp:954
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:530
static constexpr int get_mode_id()
Return the.
Definition: context_type.hpp:389
uint8_t LMBD_INLINE get_active_custom_ramp() const
(getter) Get active custom ramp value (as configured by user)
Definition: context_type.hpp:337
void LMBD_INLINE sunrise_update(LMBD_USED float progress)
Binds to local BasicMode::sunrise_update()
Definition: context_type.hpp:758
void LMBD_INLINE loop()
Binds to local BasicMode::loop()
Definition: context_type.hpp:682
void LMBD_INLINE on_enter_mode()
Binds to local BasicMode::on_enter_mode()
Definition: context_type.hpp:706
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:306
void LMBD_INLINE write_parameters()
Binds to local BasicMode::write_parameters()
Definition: context_type.hpp:945
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:814
void cancel_blip() const
Cancel an ongoing blip of the ouput.
Definition: context_type.hpp:602
uint8_t LMBD_INLINE set_active_custom_index(uint8_t value)
(setter) Set active custom index (recalled when jumping favorites)
Definition: context_type.hpp:369
bool is_bliping() const
Return true if the systems is currently bliping the output.
Definition: context_type.hpp:611
void LMBD_INLINE sunrise_timer_animation_internal_loop()
Run the internal sunrise animation loop.
Definition: context_type.hpp:776
void LMBD_INLINE power_off_sequence()
Binds to local BasicMode::power_off_sequence()
Definition: context_type.hpp:936
void LMBD_INLINE quit_mode()
Call when quitting a mode.
Definition: context_type.hpp:664
static auto LMBD_INLINE storageFor(LMBD_USED T &local)
(store) Get storage KeyProxy for key bound to local variable
Definition: context_type.hpp:504
StateTyOf< Mode > & get_state_of_mode()
Return the state of a given mode.
Definition: context_type.hpp:380
void blip(const uint32_t duration)
Turn off the output for a duration.
Definition: context_type.hpp:592
void LMBD_INLINE user_thread()
Binds to local BasicMode::user_thread()
Definition: context_type.hpp:966
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:299
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:742
void update_sunrise_drop_animation(float progress)
Update the sunrise timer drop animation.
Definition: context_type.hpp:350
hardware::LampTy & lamp
Interact with the lamp hardware.
Definition: context_type.hpp:978
static bool LMBD_INLINE storageLoadOnly(LMBD_USED T &local)
(store) Load key into local if available (single-shot)
Definition: context_type.hpp:517
void LMBD_INLINE enter_mode()
Call when entering a mode.
Definition: context_type.hpp:650
uint8_t LMBD_INLINE set_active_group(uint8_t value, uint8_t maxValueWrap=255)
(setter) Set active group index
Definition: context_type.hpp:286
auto LMBD_INLINE context_as()
Get the same context, but for another mode, see modes::context_as()
Definition: context_type.hpp:74
uint8_t LMBD_INLINE get_active_group(uint8_t maxValueWrap=255) const
(getter) Get active group index
Definition: context_type.hpp:279
void LMBD_INLINE sunrise_timer_internal_reset()
Signal a end of sunrise timer event.
Definition: context_type.hpp:789
StateTy & state
Interact with the current active mode state.
Definition: context_type.hpp:979
bool LMBD_INLINE should_spawn_thread()
Returns BasicMode::requireUserThread.
Definition: context_type.hpp:963
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:383
auto LMBD_INLINE get_custom_ramp_default_value()
Return the default ramp values for all the modes under this group.
Definition: context_type.hpp:924
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:801
Main interface between the user and the hardware of the lamp.
Definition: lamp_type.hpp:120
Convertion header to use the text out functions from C code.
Define templated tools to analyze the manager objects.