Lamp-Da 0.1
A compact lantern project
Loading...
Searching...
No Matches
Enumerations | Functions | Variables
lampda::logic::button_bindings Namespace Reference

Handle the links between click counts and the configurable default behaviors. More...

Enumerations

enum class  Behavior : uint8_t {
  Favorite , QuickNavigation , Sunset , CustomRamp ,
  Indicator , Scroll , None
}
 Default behaviors that can be linked to a click count. More...
 
enum class  SetResult : uint8_t { Success , UnsupportedBehavior , ReservedClicks , SwapNotPossible }
 Result of a binding change. More...
 

Functions

static constexpr size_t to_index (const Behavior behavior)
 
static constexpr bool has_click_action (const Behavior behavior)
 
static constexpr bool has_hold_action (const Behavior behavior)
 
static constexpr bool share_an_action (const Behavior a, const Behavior b)
 Two behaviors using the same action cannot share a click count.
 
static bool is_allowed (const Behavior behavior, const uint8_t clicks)
 
static bool is_coherent (const std::array< uint8_t, behaviorCount > &clicks)
 Check that every behavior of this lamp is on an allowed click count, and alone on its actions.
 
uint8_t get_min_clicks (const Behavior behavior)
 Return the lowest click count this behavior can be linked to.
 
bool is_supported (const Behavior behavior)
 Return true if this lamp type has this behavior.
 
Behavior get_click_behavior (const uint8_t clicks)
 Return the behavior whose click action is linked to this click count, or Behavior::None.
 
Behavior get_hold_behavior (const uint8_t clicks)
 Return the behavior whose hold action is linked to this click count, or Behavior::None.
 
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.
 
const char * get_name (const Behavior behavior)
 Return the name of this behavior, as used by the command line.
 
Behavior get_behavior_from_name (const char *name)
 Find a behavior from its command line name.
 
SetResult set_binding (const Behavior behavior, const uint8_t clicks)
 Link a behavior to a click count.
 
void reset_to_defaults ()
 Restore the default links.
 
void load_from_memory ()
 Load the links from the user parameters. Missing or incoherent values give the default links.
 
void write_to_memory ()
 Store the links in the user parameters.
 

Variables

static constexpr uint32_t storageKey = utils::hash("btnBindings") & 0x7fffffffu
 Modes store their named keys on 31 bits, and their indexed keys above. Stay out of the indexed key space.
 
static constexpr size_t storedBitsPerBehavior = 4
 Number of stored bits per behavior, enough for maxClicks.
 
static constexpr std::array< uint8_t, behaviorCount > defaultClicks = {4, 6, 5, 3, 7, 6}
 
static constexpr std::array< const char *, behaviorCount > names
 
static std::array< uint8_t, behaviorCount > currentClicks = defaultClicks
 
static constexpr size_t behaviorCount = static_cast<size_t>(Behavior::None)
 Number of configurable behaviors.
 
static constexpr uint8_t maxClicks = 9
 Highest click count a behavior can be linked to.
 

Detailed Description

Handle the links between click counts and the configurable default behaviors.

Enumeration Type Documentation

◆ Behavior

enum class lampda::logic::button_bindings::Behavior : uint8_t
strong

Default behaviors that can be linked to a click count.

Enumerator
Favorite 

click: jump to the favorites. hold: add or remove a favorite

QuickNavigation 

click: jump to the first mode

Sunset 

hold: start or extend the sunset timer

CustomRamp 

hold: configure the custom ramp of the mode

Indicator 

click: next indicator brightness. hold: cycle the indicator brightness

Scroll 

hold: scroll across modes and groups

None 

no behavior, keep this value last

◆ SetResult

enum class lampda::logic::button_bindings::SetResult : uint8_t
strong

Result of a binding change.

Enumerator
Success 

the binding was changed

UnsupportedBehavior 

this lamp type does not have this behavior

ReservedClicks 

this click count is outside of [get_min_clicks(behavior), maxClicks]

SwapNotPossible 

a behavior on this click count cannot use the click count of this behavior

Function Documentation

◆ get_behavior_from_name()

Behavior lampda::logic::button_bindings::get_behavior_from_name ( const char *  name)

Find a behavior from its command line name.

Parameters
[in]nameThe behavior name
Returns
The behavior, or Behavior::None if the name is unknown

◆ set_binding()

SetResult lampda::logic::button_bindings::set_binding ( const Behavior  behavior,
const uint8_t  clicks 
)

Link a behavior to a click count.

The behaviors using the same actions on this click count swap with this behavior, if the result stays coherent.

Parameters
[in]behaviorThe behavior to move, with both its click and hold actions
[in]clicksThe new click count
Returns
Success if the binding changed, or else the reason why nothing changed

Variable Documentation

◆ names

constexpr std::array<const char*, behaviorCount> lampda::logic::button_bindings::names
staticconstexpr
Initial value:
= {
"favorite", "nav", "sunset", "ramp", "indicator", "scroll"}