Lamp-Da 0.1
A compact lantern project
Loading...
Searching...
No Matches
button_bindings.h
Go to the documentation of this file.
1
12#ifndef BUTTON_BINDINGS_H
13#define BUTTON_BINDINGS_H
14
15#include <cstddef>
16#include <cstdint>
17
18namespace lampda {
19namespace logic {
21namespace button_bindings {
22
24enum class Behavior : uint8_t
25{
26 Favorite,
28 Sunset,
30 Indicator,
31 Scroll,
32 None,
33};
34
36static constexpr size_t behaviorCount = static_cast<size_t>(Behavior::None);
37
39static constexpr uint8_t maxClicks = 9;
40
42enum class SetResult : uint8_t
43{
44 Success,
48};
49
51Behavior get_click_behavior(const uint8_t clicks);
52
54Behavior get_hold_behavior(const uint8_t clicks);
55
57uint8_t get_clicks(const Behavior behavior);
58
60uint8_t get_min_clicks(const Behavior behavior);
61
63bool is_supported(const Behavior behavior);
64
66const char* get_name(const Behavior behavior);
67
73Behavior get_behavior_from_name(const char* name);
74
84SetResult set_binding(const Behavior behavior, const uint8_t clicks);
85
88
90void load_from_memory();
91
93void write_to_memory();
94
95} // namespace button_bindings
96} // namespace logic
97} // namespace lampda
98
99#endif
Behavior get_behavior_from_name(const char *name)
Find a behavior from its command line name.
Definition: button_bindings.cpp:132
SetResult set_binding(const Behavior behavior, const uint8_t clicks)
Link a behavior to a click count.
Definition: button_bindings.cpp:142
uint8_t get_clicks(const Behavior behavior)
Return the click count linked to this behavior, or 0 if this lamp type does not have this behavior.
Definition: button_bindings.cpp:125
SetResult
Result of a binding change.
Definition: button_bindings.h:43
@ ReservedClicks
this click count is outside of [get_min_clicks(behavior), maxClicks]
@ UnsupportedBehavior
this lamp type does not have this behavior
@ SwapNotPossible
a behavior on this click count cannot use the click count of this behavior
void reset_to_defaults()
Restore the default links.
Definition: button_bindings.cpp:168
static constexpr size_t behaviorCount
Number of configurable behaviors.
Definition: button_bindings.h:36
Behavior get_click_behavior(const uint8_t clicks)
Return the behavior whose click action is linked to this click count, or Behavior::None.
Definition: button_bindings.cpp:103
const char * get_name(const Behavior behavior)
Return the name of this behavior, as used by the command line.
Definition: button_bindings.cpp:127
void write_to_memory()
Store the links in the user parameters.
Definition: button_bindings.cpp:188
void load_from_memory()
Load the links from the user parameters. Missing or incoherent values give the default links.
Definition: button_bindings.cpp:170
Behavior
Default behaviors that can be linked to a click count.
Definition: button_bindings.h:25
@ Favorite
click: jump to the favorites. hold: add or remove a favorite
@ Scroll
hold: scroll across modes and groups
@ QuickNavigation
click: jump to the first mode
@ Indicator
click: next indicator brightness. hold: cycle the indicator brightness
@ None
no behavior, keep this value last
@ Sunset
hold: start or extend the sunset timer
@ CustomRamp
hold: configure the custom ramp of the mode
uint8_t get_min_clicks(const Behavior behavior)
Return the lowest click count this behavior can be linked to.
Definition: button_bindings.cpp:69
bool is_supported(const Behavior behavior)
Return true if this lamp type has this behavior.
Definition: button_bindings.cpp:80
static constexpr uint8_t maxClicks
Highest click count a behavior can be linked to.
Definition: button_bindings.h:39
Behavior get_hold_behavior(const uint8_t clicks)
Return the behavior whose hold action is linked to this click count, or Behavior::None.
Definition: button_bindings.cpp:114
Program scope.
Definition: control_fixed_modes.hpp:14