@@ -23,16 +23,16 @@ static unsigned long long msSinceMidnight()
23
23
24
24
void dimmerTask (void *parameter)
25
25
{
26
- static constexpr const uint8_t ledPin[NUMBER_OF_CHANNELS] =
26
+ static constexpr uint8_t ledPin[NUMBER_OF_CHANNELS] =
27
27
{LEDPIN_0, LEDPIN_1, LEDPIN_2, LEDPIN_3, LEDPIN_4};
28
- static constexpr const float fullMoonLevel[NUMBER_OF_CHANNELS] =
28
+ static constexpr float fullMoonLevel[NUMBER_OF_CHANNELS] =
29
29
{0 , 0 , 0 , 0 , 0.06 };
30
- static constexpr const int PWM_BITDEPTH = min (SOC_LEDC_TIMER_BIT_WIDTH, 16 );
31
- static constexpr const int LEDC_MAX_VALUE = (1 << PWM_BITDEPTH) - 1 ;
32
- static constexpr const int freq = 1220 ;
30
+ static constexpr int PWM_BITDEPTH = min (SOC_LEDC_TIMER_BIT_WIDTH, 16 );
31
+ static constexpr int LEDC_MAX_VALUE = (1 << PWM_BITDEPTH) - 1 ;
32
+ static constexpr int freq = 1220 ;
33
33
34
34
#ifdef LGFX_M5STACK
35
- static constexpr const int BACKLIGHT_PIN = 32 ;
35
+ static constexpr int BACKLIGHT_PIN = 32 ;
36
36
if (!ledcChangeFrequency (BACKLIGHT_PIN, freq, PWM_BITDEPTH) ||
37
37
!ledcWrite (BACKLIGHT_PIN, LEDC_MAX_VALUE >> 5 ))
38
38
log_w (" Could not capture M5Stack backlight" );
@@ -57,8 +57,8 @@ void dimmerTask(void *parameter)
57
57
xQueueSend (lcdQueue, &msg, portMAX_DELAY);
58
58
}
59
59
60
- constexpr const int TICK_RATE_HZ = 100 ;
61
- const TickType_t ticksToWait = pdTICKS_TO_MS (1000 / TICK_RATE_HZ);
60
+ constexpr int TICK_RATE_HZ = 100 ;
61
+ constexpr TickType_t ticksToWait = pdTICKS_TO_MS (1000 / TICK_RATE_HZ);
62
62
TickType_t xLastWakeTime = xTaskGetTickCount ();
63
63
64
64
while (1 )
@@ -70,39 +70,39 @@ void dimmerTask(void *parameter)
70
70
71
71
const auto msElapsedToday = msSinceMidnight ();
72
72
73
- if (msElapsedToday) /* to prevent flashing at 00:00:000 due to the fact that the first timer has no predecessor at this time */
73
+ if (!msElapsedToday) /* to prevent flashing lights at 00:00:000 */
74
+ continue ;
75
+
76
+ for (int index = 0 ; index < NUMBER_OF_CHANNELS; index++)
74
77
{
75
- for (int index = 0 ; index < NUMBER_OF_CHANNELS; index++)
76
- {
77
- int currentTimer = 0 ;
78
- while (channel[index][currentTimer].time * 1000U < msElapsedToday)
79
- currentTimer++;
78
+ int currentTimer = 0 ;
79
+ while (channel[index][currentTimer].time * 1000U < msElapsedToday)
80
+ currentTimer++;
80
81
81
- currentTimer = (currentTimer >= channel[index].size ()) ? channel[index].size () - 1 : currentTimer;
82
+ currentTimer = (currentTimer >= channel[index].size ()) ? channel[index].size () - 1 : currentTimer;
82
83
83
- const float newPercentage =
84
- (currentTimer > 0 && channel[index][currentTimer].percentage != channel[index][currentTimer - 1 ].percentage )
85
- ? mapf (msElapsedToday,
86
- channel[index][currentTimer - 1 ].time * 1000U ,
87
- channel[index][currentTimer].time * 1000U ,
88
- channel[index][currentTimer - 1 ].percentage ,
89
- channel[index][currentTimer].percentage )
90
- : channel[index][currentTimer].percentage ;
84
+ const float newPercentage =
85
+ (currentTimer > 0 && channel[index][currentTimer].percentage != channel[index][currentTimer - 1 ].percentage )
86
+ ? mapf (msElapsedToday,
87
+ channel[index][currentTimer - 1 ].time * 1000U ,
88
+ channel[index][currentTimer].time * 1000U ,
89
+ channel[index][currentTimer - 1 ].percentage ,
90
+ channel[index][currentTimer].percentage )
91
+ : channel[index][currentTimer].percentage ;
91
92
92
- const float currentMoonLevel = fullMoonLevel[index] * moon.percentLit ;
93
+ const float currentMoonLevel = fullMoonLevel[index] * moon.percentLit ;
93
94
94
- currentPercentage[index] = newPercentage < currentMoonLevel ? currentMoonLevel : newPercentage;
95
+ currentPercentage[index] = newPercentage < currentMoonLevel ? currentMoonLevel : newPercentage;
95
96
96
- const int dutyCycle = mapf (currentPercentage[index], 0 , 100 , 0 , LEDC_MAX_VALUE);
97
+ const int dutyCycle = mapf (currentPercentage[index], 0 , 100 , 0 , LEDC_MAX_VALUE);
97
98
98
- if (!ledcWrite (ledPin[index], dutyCycle))
99
- log_w (" Error setting duty cycle %i on pin %i" , dutyCycle, ledPin[index]);
100
- }
99
+ if (!ledcWrite (ledPin[index], dutyCycle))
100
+ log_w (" Error setting duty cycle %i on pin %i" , dutyCycle, ledPin[index]);
101
101
}
102
102
}
103
103
104
- constexpr const int REFRESHRATE_LCD_HZ = 5 ;
105
- constexpr const int LCD_WAIT_TIME = 1000 / REFRESHRATE_LCD_HZ;
104
+ constexpr int REFRESHRATE_LCD_HZ = 5 ;
105
+ constexpr int LCD_WAIT_TIME = 1000 / REFRESHRATE_LCD_HZ;
106
106
static unsigned long lastLcdRefresh = 0 ;
107
107
if (millis () - lastLcdRefresh >= LCD_WAIT_TIME)
108
108
{
@@ -112,7 +112,7 @@ void dimmerTask(void *parameter)
112
112
lastLcdRefresh = millis ();
113
113
}
114
114
115
- constexpr const int MOON_UPDATE_INTERVAL_SECONDS = 5 ;
115
+ constexpr int MOON_UPDATE_INTERVAL_SECONDS = 5 ;
116
116
static time_t lastMoonUpdate = time (NULL );
117
117
if (time (NULL ) - lastMoonUpdate >= MOON_UPDATE_INTERVAL_SECONDS)
118
118
{
0 commit comments