Skip to content

Commit 04da0ca

Browse files
Cleanup
1 parent b4e86c0 commit 04da0ca

File tree

1 file changed

+32
-32
lines changed

1 file changed

+32
-32
lines changed

src/dimmerTask.cpp

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,16 @@ static unsigned long long msSinceMidnight()
2323

2424
void dimmerTask(void *parameter)
2525
{
26-
static constexpr const uint8_t ledPin[NUMBER_OF_CHANNELS] =
26+
static constexpr uint8_t ledPin[NUMBER_OF_CHANNELS] =
2727
{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] =
2929
{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;
3333

3434
#ifdef LGFX_M5STACK
35-
static constexpr const int BACKLIGHT_PIN = 32;
35+
static constexpr int BACKLIGHT_PIN = 32;
3636
if (!ledcChangeFrequency(BACKLIGHT_PIN, freq, PWM_BITDEPTH) ||
3737
!ledcWrite(BACKLIGHT_PIN, LEDC_MAX_VALUE >> 5))
3838
log_w("Could not capture M5Stack backlight");
@@ -57,8 +57,8 @@ void dimmerTask(void *parameter)
5757
xQueueSend(lcdQueue, &msg, portMAX_DELAY);
5858
}
5959

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);
6262
TickType_t xLastWakeTime = xTaskGetTickCount();
6363

6464
while (1)
@@ -70,39 +70,39 @@ void dimmerTask(void *parameter)
7070

7171
const auto msElapsedToday = msSinceMidnight();
7272

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++)
7477
{
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++;
8081

81-
currentTimer = (currentTimer >= channel[index].size()) ? channel[index].size() - 1 : currentTimer;
82+
currentTimer = (currentTimer >= channel[index].size()) ? channel[index].size() - 1 : currentTimer;
8283

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;
9192

92-
const float currentMoonLevel = fullMoonLevel[index] * moon.percentLit;
93+
const float currentMoonLevel = fullMoonLevel[index] * moon.percentLit;
9394

94-
currentPercentage[index] = newPercentage < currentMoonLevel ? currentMoonLevel : newPercentage;
95+
currentPercentage[index] = newPercentage < currentMoonLevel ? currentMoonLevel : newPercentage;
9596

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);
9798

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]);
101101
}
102102
}
103103

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;
106106
static unsigned long lastLcdRefresh = 0;
107107
if (millis() - lastLcdRefresh >= LCD_WAIT_TIME)
108108
{
@@ -112,7 +112,7 @@ void dimmerTask(void *parameter)
112112
lastLcdRefresh = millis();
113113
}
114114

115-
constexpr const int MOON_UPDATE_INTERVAL_SECONDS = 5;
115+
constexpr int MOON_UPDATE_INTERVAL_SECONDS = 5;
116116
static time_t lastMoonUpdate = time(NULL);
117117
if (time(NULL) - lastMoonUpdate >= MOON_UPDATE_INTERVAL_SECONDS)
118118
{

0 commit comments

Comments
 (0)