Lamp-Da 0.1
A compact lantern project
Loading...
Searching...
No Matches
simple_behavior.hpp
Go to the documentation of this file.
1
5#ifndef SIMPLE_BEHAVIOR_MANAGER_H
6#define SIMPLE_BEHAVIOR_MANAGER_H
7
8//
9// note: this code is included as-is by:
10// - user/simple_functions.h
11//
12
13namespace lampda::user {
14
15bool button_clicked_default(const uint8_t clicks)
16{
17 // Handle default common behavior
19 {
20 // some event is already handled
21 return true;
22 }
23
24 auto manager = get_context();
25
26 switch (clicks)
27 {
28 case 2:
29 {
30 if (manager.get_active_group() == 0)
31 {
32 // if at max brightness, go to saved brightness
33 if (manager.lamp.getBrightness() == manager.lamp.getMaxBrightness())
34 {
35 manager.lamp.restoreBrightness();
36 }
37 // else set max brightness
38 else
39 {
40 manager.lamp.tempBrightness(manager.lamp.getMaxBrightness());
41 }
42 }
43 else
44 {
45 manager.next_mode();
46
47#ifdef LMBD_SIMULATION
48 fprintf(stderr, "group %d *mode %d\n", manager.get_active_group(), manager.get_active_mode());
49#endif
50 }
51 return true;
52 }
53
54 case 3:
55 {
56 // 3C at max brightness will produce a light boost (dangerous for the strip if held for a long time)
57 if (manager.get_active_group() == 0 and
58 // check that brightness is at the absolute maximum level
59 manager.lamp.getBrightness() == ::lampda::brightness::absoluteMaximumBrightness)
60 {
61 // write a power boost (dangerous) for a limited time
62 physical::outputPower::write_temporary_output_limits(::lampda::stripInputMaxVoltage_mV * 1.2f, 5000, 5000);
63 }
64 else
65 {
66 manager.next_group();
67
68#ifdef LMBD_SIMULATION
69 fprintf(stderr, "group %d *mode %d\n", manager.get_active_group(), manager.get_active_mode());
70#endif
71 }
72 return true;
73 }
74
75 default:
76 break;
77 }
78 return false;
79}
80
81bool button_hold_default(const uint8_t clicks, const bool isEndOfHoldEvent, const uint32_t holdDuration)
82{
83 // Handle default common behavior
84 if (default_behaviors::button_hold(clicks, isEndOfHoldEvent, holdDuration))
85 {
86 // some event is already handled
87 return true;
88 }
89
90 auto manager = get_context();
91 auto& rampHandler = manager.state.rampHandler;
92
93 switch (clicks)
94 {
95 // No special behavior
96 default:
97 break;
98 }
99 return false;
100}
101
102void handle_elk_command(const utils::ELK::Package& elkControlCommand)
103{
104 // Handle default common behavior
105 if (default_behaviors::handle_elk_command(elkControlCommand))
106 {
107 // some event is already handled
108 return;
109 }
110}
111
112} // namespace lampda::user
113
114#endif
AlertManager_t manager
Instanciation of the AlertManager.
Definition: alerts.cpp:28
void write_temporary_output_limits(const uint16_t voltage_mv, const uint16_t current_ma, const uint32_t timeout_ms)
overwrite the output characteristics for a given duration. Gets back to the previous settings after t...
Definition: output_power.cpp:32
bool button_hold(const uint8_t clicks, const bool isEndOfHoldEvent, const uint32_t holdDuration)
must be called by the lampda::user::button_hold_default
Definition: default_behavior.hpp:197
bool button_clicked(const uint8_t clicks)
must be called by the lampda::user::button_clicked_default
Definition: default_behavior.hpp:172
Contains code handling custom user mode functions for indexable strips.
Definition: default_behavior.hpp:15
bool button_clicked_default(const uint8_t)
Called to handle button click events for default user mode behaviors.
Definition: indexable_behavior.hpp:18
bool button_hold_default(const uint8_t, const bool, const uint32_t)
Called to handle button click+hold events for user mode behaviors.
Definition: indexable_behavior.hpp:168
void handle_elk_command(const utils::ELK::Package &elkControlCommand)
Handle a ELK BLE package.
Definition: indexable_behavior.hpp:283