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
15void button_clicked_default(const uint8_t clicks)
16{
17 // Handle default common behavior
19 {
20 // some event is already handled
21 return;
22 }
23
24 auto manager = get_context();
25
26 switch (clicks)
27 {
28 case 2:
29 if (manager.get_active_group() == 0)
30 {
31 // if at max brightness, go to saved brightness
32 if (manager.lamp.getBrightness() == manager.lamp.getMaxBrightness())
33 {
34 manager.lamp.restoreBrightness();
35 }
36 // else set max brightness
37 else
38 {
39 manager.lamp.tempBrightness(manager.lamp.getMaxBrightness());
40 }
41 }
42 else
43 manager.next_mode();
44 break;
45
46 case 3:
47 // 3C at max brightness will produce a light boost (dangerous for the strip if held for a long time)
48 if (manager.get_active_group() == 0 and
49 // check that brightness is at the absolute maximum level
50 manager.lamp.getBrightness() == ::lampda::brightness::absoluteMaximumBrightness)
51 {
52 // write a power boost (dangerous) for a limited time
53 physical::outputPower::write_temporary_output_limits(::lampda::stripInputMaxVoltage_mV * 1.2f, 5000, 5000);
54 }
55 else
56 {
57 manager.next_group();
58 }
59 break;
60
61 default:
62 break;
63 }
64
65#ifdef LMBD_SIMULATION
66 fprintf(stderr, "group %d *mode %d\n", manager.get_active_group(), manager.get_active_mode());
67#endif
68}
69
70void button_hold_default(const uint8_t clicks, const bool isEndOfHoldEvent, const uint32_t holdDuration)
71{
72 // Handle default common behavior
73 if (default_behaviors::button_hold(clicks, isEndOfHoldEvent, holdDuration))
74 {
75 // some event is already handled
76 return;
77 }
78
79 auto manager = get_context();
80 auto& rampHandler = manager.state.rampHandler;
81
82 switch (clicks)
83 {
84 // No special behavior
85 default:
86 break;
87 }
88}
89
90void handle_elk_command(const utils::ELK::Package& elkControlCommand)
91{
92 // Handle default common behavior
93 if (default_behaviors::handle_elk_command(elkControlCommand))
94 {
95 // some event is already handled
96 return;
97 }
98}
99
100} // namespace lampda::user
101
102#endif
AlertManager_t manager
Instanciation of the AlertManager.
Definition: alerts.cpp:27
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
void handle_elk_command(const utils::ELK::Package &elkControlCommand)
Handle a ELK BLE package.
Definition: indexable_behavior.hpp:228
void 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:118
void button_clicked_default(const uint8_t)
Called to handle button click events for default user mode behaviors.
Definition: indexable_behavior.hpp:18