Reformat project using clang-format

This commit is contained in:
Lorow
2026-01-06 22:51:24 +01:00
parent 567d3ebd75
commit 555e290d71
70 changed files with 3282 additions and 3428 deletions

View File

@@ -1,6 +1,6 @@
#include "LEDManager.hpp"
const char *LED_MANAGER_TAG = "[LED_MANAGER]";
const char* LED_MANAGER_TAG = "[LED_MANAGER]";
// Pattern design rules:
// - Error states: isError=true, repeat indefinitely, easily distinguishable (avoid overlap).
@@ -8,25 +8,25 @@ const char *LED_MANAGER_TAG = "[LED_MANAGER]";
// - Non-repeating notification (e.g. Connected) gives user a brief confirmation burst then turns off.
// Durations in ms.
ledStateMap_t LEDManager::ledStateMap = {
{ LEDStates_e::LedStateNone, { /*isError*/false, /*repeat*/false, {{LED_OFF, 1000}} } },
{ LEDStates_e::LedStateStreaming, { false, /*repeat steady*/true, {{LED_ON, 1000}} } },
{ LEDStates_e::LedStateStoppedStreaming, { false, true, {{LED_OFF, 1000}} } },
{LEDStates_e::LedStateNone, {/*isError*/ false, /*repeat*/ false, {{LED_OFF, 1000}}}},
{LEDStates_e::LedStateStreaming, {false, /*repeat steady*/ true, {{LED_ON, 1000}}}},
{LEDStates_e::LedStateStoppedStreaming, {false, true, {{LED_OFF, 1000}}}},
// CameraError: double blink pattern repeating
{ LEDStates_e::CameraError, { true, true, {{ {LED_ON,300}, {LED_OFF,300}, {LED_ON,300}, {LED_OFF,700} }} } },
{LEDStates_e::CameraError, {true, true, {{{LED_ON, 300}, {LED_OFF, 300}, {LED_ON, 300}, {LED_OFF, 700}}}}},
// WiFiStateConnecting: balanced slow blink 400/400
{ LEDStates_e::WiFiStateConnecting, { false, true, {{ {LED_ON,400}, {LED_OFF,400} }} } },
{LEDStates_e::WiFiStateConnecting, {false, true, {{{LED_ON, 400}, {LED_OFF, 400}}}}},
// WiFiStateConnected: short 3 quick flashes then done (was long noisy burst before)
{ LEDStates_e::WiFiStateConnected, { false, false, {{ {LED_ON,150}, {LED_OFF,150}, {LED_ON,150}, {LED_OFF,150}, {LED_ON,150}, {LED_OFF,600} }} } },
{LEDStates_e::WiFiStateConnected, {false, false, {{{LED_ON, 150}, {LED_OFF, 150}, {LED_ON, 150}, {LED_OFF, 150}, {LED_ON, 150}, {LED_OFF, 600}}}}},
// WiFiStateError: asymmetric attention pattern (fast, pause, long, pause, fast)
{ LEDStates_e::WiFiStateError, { true, true, {{ {LED_ON,200}, {LED_OFF,100}, {LED_ON,500}, {LED_OFF,300} }} } },
{LEDStates_e::WiFiStateError, {true, true, {{{LED_ON, 200}, {LED_OFF, 100}, {LED_ON, 500}, {LED_OFF, 300}}}}},
};
LEDManager::LEDManager(gpio_num_t pin, gpio_num_t illumninator_led_pin,
QueueHandle_t ledStateQueue, std::shared_ptr<ProjectConfig> deviceConfig) : blink_led_pin(pin),
illumninator_led_pin(illumninator_led_pin),
ledStateQueue(ledStateQueue),
currentState(LEDStates_e::LedStateNone),
deviceConfig(deviceConfig)
LEDManager::LEDManager(gpio_num_t pin, gpio_num_t illumninator_led_pin, QueueHandle_t ledStateQueue, std::shared_ptr<ProjectConfig> deviceConfig)
: blink_led_pin(pin),
illumninator_led_pin(illumninator_led_pin),
ledStateQueue(ledStateQueue),
currentState(LEDStates_e::LedStateNone),
deviceConfig(deviceConfig)
{
}
@@ -52,22 +52,17 @@ void LEDManager::setup()
ESP_LOGI(LED_MANAGER_TAG, "Setting dutyCycle to: %lu ", dutyCycle);
ledc_timer_config_t ledc_timer = {
.speed_mode = LEDC_LOW_SPEED_MODE,
.duty_resolution = resolution,
.timer_num = LEDC_TIMER_0,
.freq_hz = freq,
.clk_cfg = LEDC_AUTO_CLK};
.speed_mode = LEDC_LOW_SPEED_MODE, .duty_resolution = resolution, .timer_num = LEDC_TIMER_0, .freq_hz = freq, .clk_cfg = LEDC_AUTO_CLK};
ESP_ERROR_CHECK(ledc_timer_config(&ledc_timer));
ledc_channel_config_t ledc_channel = {
.gpio_num = this->illumninator_led_pin,
.speed_mode = LEDC_LOW_SPEED_MODE,
.channel = LEDC_CHANNEL_0,
.intr_type = LEDC_INTR_DISABLE,
.timer_sel = LEDC_TIMER_0,
.duty = dutyCycle,
.hpoint = 0};
ledc_channel_config_t ledc_channel = {.gpio_num = this->illumninator_led_pin,
.speed_mode = LEDC_LOW_SPEED_MODE,
.channel = LEDC_CHANNEL_0,
.intr_type = LEDC_INTR_DISABLE,
.timer_sel = LEDC_TIMER_0,
.duty = dutyCycle,
.hpoint = 0};
ESP_ERROR_CHECK(ledc_channel_config(&ledc_channel));
#endif
@@ -190,14 +185,14 @@ void LEDManager::setExternalLEDDutyCycle(uint8_t dutyPercent)
ESP_ERROR_CHECK_WITHOUT_ABORT(ledc_set_duty(LEDC_LOW_SPEED_MODE, LEDC_CHANNEL_0, dutyCycle));
ESP_ERROR_CHECK_WITHOUT_ABORT(ledc_update_duty(LEDC_LOW_SPEED_MODE, LEDC_CHANNEL_0));
#else
(void)dutyPercent; // unused
(void)dutyPercent; // unused
ESP_LOGW(LED_MANAGER_TAG, "CONFIG_LED_EXTERNAL_CONTROL not enabled; ignoring duty update");
#endif
}
void HandleLEDDisplayTask(void *pvParameter)
void HandleLEDDisplayTask(void* pvParameter)
{
auto *ledManager = static_cast<LEDManager *>(pvParameter);
auto* ledManager = static_cast<LEDManager*>(pvParameter);
TickType_t lastWakeTime = xTaskGetTickCount();
while (true)

View File

@@ -11,13 +11,13 @@
#endif
#include <esp_log.h>
#include <ProjectConfig.hpp>
#include <StateManager.hpp>
#include <algorithm>
#include <cstdint>
#include <helpers.hpp>
#include <unordered_map>
#include <vector>
#include <StateManager.hpp>
#include <ProjectConfig.hpp>
#include <helpers.hpp>
// it kinda looks like different boards have these states swapped
#define LED_OFF 1
@@ -25,57 +25,62 @@
struct BlinkPatterns_t
{
int state;
int delayTime;
int state;
int delayTime;
};
struct LEDStage
{
bool isError;
bool isRepeatable;
std::vector<BlinkPatterns_t> patterns;
bool isError;
bool isRepeatable;
std::vector<BlinkPatterns_t> patterns;
};
typedef std::unordered_map<LEDStates_e, LEDStage>
ledStateMap_t;
typedef std::unordered_map<LEDStates_e, LEDStage> ledStateMap_t;
class LEDManager
{
public:
LEDManager(gpio_num_t blink_led_pin, gpio_num_t illumninator_led_pin, QueueHandle_t ledStateQueue, std::shared_ptr<ProjectConfig> deviceConfig);
public:
LEDManager(gpio_num_t blink_led_pin, gpio_num_t illumninator_led_pin, QueueHandle_t ledStateQueue, std::shared_ptr<ProjectConfig> deviceConfig);
void setup();
void handleLED();
size_t getTimeToDelayFor() const { return timeToDelayFor; }
void setup();
void handleLED();
size_t getTimeToDelayFor() const
{
return timeToDelayFor;
}
// Apply new external LED PWM duty cycle immediately (0-100)
void setExternalLEDDutyCycle(uint8_t dutyPercent);
uint8_t getExternalLEDDutyCycle() const { return deviceConfig ? deviceConfig->getDeviceConfig().led_external_pwm_duty_cycle : 0; }
// Apply new external LED PWM duty cycle immediately (0-100)
void setExternalLEDDutyCycle(uint8_t dutyPercent);
uint8_t getExternalLEDDutyCycle() const
{
return deviceConfig ? deviceConfig->getDeviceConfig().led_external_pwm_duty_cycle : 0;
}
private:
void toggleLED(bool state) const;
void displayCurrentPattern();
void updateState(LEDStates_e newState);
private:
void toggleLED(bool state) const;
void displayCurrentPattern();
void updateState(LEDStates_e newState);
gpio_num_t blink_led_pin;
gpio_num_t illumninator_led_pin;
QueueHandle_t ledStateQueue;
gpio_num_t blink_led_pin;
gpio_num_t illumninator_led_pin;
QueueHandle_t ledStateQueue;
static ledStateMap_t ledStateMap;
static ledStateMap_t ledStateMap;
LEDStates_e buffer;
LEDStates_e currentState;
std::shared_ptr<ProjectConfig> deviceConfig;
LEDStates_e buffer;
LEDStates_e currentState;
std::shared_ptr<ProjectConfig> deviceConfig;
size_t currentPatternIndex = 0;
size_t timeToDelayFor = 100;
bool finishedPattern = false;
size_t currentPatternIndex = 0;
size_t timeToDelayFor = 100;
bool finishedPattern = false;
#if defined(CONFIG_LED_EXTERNAL_CONTROL) && defined(CONFIG_LED_EXTERNAL_AS_DEBUG)
bool hasStoredExternalDuty = false;
uint32_t storedExternalDuty = 0; // raw 0-255
bool hasStoredExternalDuty = false;
uint32_t storedExternalDuty = 0; // raw 0-255
#endif
};
void HandleLEDDisplayTask(void *pvParameter);
void HandleLEDDisplayTask(void* pvParameter);
#endif