@@ -21,6 +21,54 @@ uint16_t irTimesRepeated = 0;
2121uint8_t lastIR6ColourIdx = 0 ;
2222
2323
24+ // brightnessSteps: a static array of brightness levels following a geometric
25+ // progression. Can be generated from the following Python, adjusting the
26+ // arbitrary 4.5 value to taste:
27+ //
28+ // def values(level):
29+ // while level >= 5:
30+ // yield int(level)
31+ // level -= level / 4.5
32+ // result = [v for v in reversed(list(values(255)))]
33+ // print("%d values: %s" % (len(result), result))
34+ //
35+ // It would be hard to maintain repeatable steps if calculating this on the fly.
36+ const byte brightnessSteps[] = {
37+ 5 , 7 , 9 , 12 , 16 , 20 , 26 , 34 , 43 , 56 , 72 , 93 , 119 , 154 , 198 , 255
38+ };
39+ const size_t numBrightnessSteps = sizeof (brightnessSteps) / sizeof (uint8_t );
40+
41+ // increment `bri` to the next `brightnessSteps` value
42+ void incBrightness ()
43+ {
44+ // dumb incremental search is efficient enough for so few items
45+ for (int index = 0 ; index < numBrightnessSteps; ++index)
46+ {
47+ if (brightnessSteps[index] > bri)
48+ {
49+ bri = brightnessSteps[index];
50+ lastRepeatableAction = ACTION_BRIGHT_UP;
51+ break ;
52+ }
53+ }
54+ }
55+
56+ // decrement `bri` to the next `brightnessSteps` value
57+ void decBrightness ()
58+ {
59+ // dumb incremental search is efficient enough for so few items
60+ for (int index = numBrightnessSteps - 1 ; index >= 0 ; --index)
61+ {
62+ if (brightnessSteps[index] < bri)
63+ {
64+ bri = brightnessSteps[index];
65+ lastRepeatableAction = ACTION_BRIGHT_DOWN;
66+ break ;
67+ }
68+ }
69+ }
70+
71+
2472// Add what your custom IR codes should trigger here. Guide: https://github.com/Aircoookie/WLED/wiki/Infrared-Control
2573// IR codes themselves can be defined directly after "case" or in "ir_codes.h"
2674bool decodeIRCustom (uint32_t code)
@@ -47,16 +95,6 @@ void relativeChange(byte* property, int8_t amount, byte lowerBoundary, byte high
4795 *property = (byte)constrain (new_val,0.1 ,255.1 );
4896}
4997
50- void changeBrightness (int8_t amount)
51- {
52- int16_t new_val = bri + amount;
53- if (new_val < 5 ) new_val = 5 ; // minimum brightness A=5
54- bri = (byte)constrain (new_val,0.1 ,255.1 );
55- if (amount > 0 ) lastRepeatableAction = ACTION_BRIGHT_UP;
56- if (amount < 0 ) lastRepeatableAction = ACTION_BRIGHT_DOWN;
57- lastRepeatableValue = amount;
58- }
59-
6098void changeEffectSpeed (int8_t amount)
6199{
62100 if (effectCurrent != 0 ) {
@@ -142,11 +180,11 @@ void applyRepeatActions(){
142180
143181 if (lastRepeatableAction == ACTION_BRIGHT_UP)
144182 {
145- changeBrightness (lastRepeatableValue ); colorUpdated (NOTIFIER_CALL_MODE_BUTTON);
183+ incBrightness ( ); colorUpdated (NOTIFIER_CALL_MODE_BUTTON);
146184 }
147185 else if (lastRepeatableAction == ACTION_BRIGHT_DOWN )
148186 {
149- changeBrightness (lastRepeatableValue ); colorUpdated (NOTIFIER_CALL_MODE_BUTTON);
187+ decBrightness ( ); colorUpdated (NOTIFIER_CALL_MODE_BUTTON);
150188 }
151189
152190 if (lastRepeatableAction == ACTION_SPEED_UP)
@@ -187,8 +225,8 @@ void applyRepeatActions(){
187225void decodeIR24 (uint32_t code)
188226{
189227 switch (code) {
190- case IR24_BRIGHTER : changeBrightness ( 10 ); break ;
191- case IR24_DARKER : changeBrightness (- 10 ); break ;
228+ case IR24_BRIGHTER : incBrightness (); break ;
229+ case IR24_DARKER : decBrightness (); break ;
192230 case IR24_OFF : briLast = bri; bri = 0 ; break ;
193231 case IR24_ON : bri = briLast; break ;
194232 case IR24_RED : colorFromUint32 (COLOR_RED); break ;
@@ -219,8 +257,8 @@ void decodeIR24(uint32_t code)
219257void decodeIR24OLD (uint32_t code)
220258{
221259 switch (code) {
222- case IR24_OLD_BRIGHTER : changeBrightness ( 10 ); break ;
223- case IR24_OLD_DARKER : changeBrightness (- 10 ); break ;
260+ case IR24_OLD_BRIGHTER : incBrightness (); break ;
261+ case IR24_OLD_DARKER : decBrightness (); break ;
224262 case IR24_OLD_OFF : briLast = bri; bri = 0 ; break ;
225263 case IR24_OLD_ON : bri = briLast; break ;
226264 case IR24_OLD_RED : colorFromUint32 (COLOR_RED); break ;
@@ -252,8 +290,8 @@ void decodeIR24OLD(uint32_t code)
252290void decodeIR24CT (uint32_t code)
253291{
254292 switch (code) {
255- case IR24_CT_BRIGHTER : changeBrightness ( 10 ); break ;
256- case IR24_CT_DARKER : changeBrightness (- 10 ); break ;
293+ case IR24_CT_BRIGHTER : incBrightness (); break ;
294+ case IR24_CT_DARKER : decBrightness (); break ;
257295 case IR24_CT_OFF : briLast = bri; bri = 0 ; break ;
258296 case IR24_CT_ON : bri = briLast; break ;
259297 case IR24_CT_RED : colorFromUint32 (COLOR_RED); break ;
@@ -287,8 +325,8 @@ void decodeIR24CT(uint32_t code)
287325void decodeIR40 (uint32_t code)
288326{
289327 switch (code) {
290- case IR40_BPLUS : changeBrightness ( 10 ); break ;
291- case IR40_BMINUS : changeBrightness (- 10 ); break ;
328+ case IR40_BPLUS : incBrightness (); break ;
329+ case IR40_BMINUS : decBrightness (); break ;
292330 case IR40_OFF : briLast = bri; bri = 0 ; break ;
293331 case IR40_ON : bri = briLast; break ;
294332 case IR40_RED : colorFromUint24 (COLOR_RED); break ;
@@ -344,8 +382,8 @@ void decodeIR40(uint32_t code)
344382void decodeIR44 (uint32_t code)
345383{
346384 switch (code) {
347- case IR44_BPLUS : changeBrightness ( 10 ); break ;
348- case IR44_BMINUS : changeBrightness (- 10 ); break ;
385+ case IR44_BPLUS : incBrightness (); break ;
386+ case IR44_BMINUS : decBrightness (); break ;
349387 case IR44_OFF : briLast = bri; bri = 0 ; break ;
350388 case IR44_ON : bri = briLast; break ;
351389 case IR44_RED : colorFromUint24 (COLOR_RED); break ;
@@ -407,8 +445,8 @@ void decodeIR44(uint32_t code)
407445void decodeIR21 (uint32_t code)
408446{
409447 switch (code) {
410- case IR21_BRIGHTER: changeBrightness ( 10 ); break ;
411- case IR21_DARKER: changeBrightness (- 10 ); break ;
448+ case IR21_BRIGHTER: incBrightness (); break ;
449+ case IR21_DARKER: decBrightness (); break ;
412450 case IR21_OFF: briLast = bri; bri = 0 ; break ;
413451 case IR21_ON: bri = briLast; break ;
414452 case IR21_RED: colorFromUint32 (COLOR_RED); break ;
@@ -437,8 +475,8 @@ void decodeIR6(uint32_t code)
437475{
438476 switch (code) {
439477 case IR6_POWER: toggleOnOff (); break ;
440- case IR6_CHANNEL_UP: changeBrightness ( 10 ); break ;
441- case IR6_CHANNEL_DOWN: changeBrightness (- 10 ); break ;
478+ case IR6_CHANNEL_UP: incBrightness (); break ;
479+ case IR6_CHANNEL_DOWN: decBrightness (); break ;
442480 case IR6_VOLUME_UP: relativeChange (&effectCurrent, 1 , 0 , MODE_COUNT); break ; // next effect
443481 case IR6_VOLUME_DOWN: // next palette
444482 relativeChange (&effectPalette, 1 , 0 , strip.getPaletteCount () -1 );
@@ -472,8 +510,8 @@ void decodeIR9(uint32_t code)
472510 case IR9_A : if (!applyPreset (1 )) effectCurrent = FX_MODE_COLORTWINKLE; break ;
473511 case IR9_B : if (!applyPreset (2 )) effectCurrent = FX_MODE_RAINBOW_CYCLE; break ;
474512 case IR9_C : if (!applyPreset (3 )) effectCurrent = FX_MODE_BREATH; break ;
475- case IR9_UP : changeBrightness ( 16 ); break ;
476- case IR9_DOWN : changeBrightness (- 16 ); break ;
513+ case IR9_UP : incBrightness (); break ;
514+ case IR9_DOWN : decBrightness (); break ;
477515 // case IR9_UP : changeEffectIntensity(16); break;
478516 // case IR9_DOWN : changeEffectIntensity(-16); break;
479517 case IR9_LEFT : changeEffectSpeed (-16 ); break ;
0 commit comments