mirror of
https://github.com/MrUnknownDE/OpenIris-ESPIDF.git
synced 2026-04-19 06:23:44 +02:00
Modernize the code a bit, clean up most compilation warnings
This commit is contained in:
@@ -4,7 +4,7 @@ const char *LED_MANAGER_TAG = "[LED_MANAGER]";
|
||||
|
||||
ledStateMap_t LEDManager::ledStateMap = {
|
||||
{
|
||||
LEDStates_e::_LedStateNone,
|
||||
LEDStates_e::LedStateNone,
|
||||
{
|
||||
false,
|
||||
false,
|
||||
@@ -12,7 +12,7 @@ ledStateMap_t LEDManager::ledStateMap = {
|
||||
},
|
||||
},
|
||||
{
|
||||
LEDStates_e::_LedStateStreaming,
|
||||
LEDStates_e::LedStateStreaming,
|
||||
{
|
||||
false,
|
||||
true,
|
||||
@@ -20,7 +20,7 @@ ledStateMap_t LEDManager::ledStateMap = {
|
||||
},
|
||||
},
|
||||
{
|
||||
LEDStates_e::_LedStateStoppedStreaming,
|
||||
LEDStates_e::LedStateStoppedStreaming,
|
||||
{
|
||||
false,
|
||||
true,
|
||||
@@ -28,7 +28,7 @@ ledStateMap_t LEDManager::ledStateMap = {
|
||||
},
|
||||
},
|
||||
{
|
||||
LEDStates_e::_Camera_Error,
|
||||
LEDStates_e::CameraError,
|
||||
{
|
||||
true,
|
||||
true,
|
||||
@@ -36,7 +36,7 @@ ledStateMap_t LEDManager::ledStateMap = {
|
||||
},
|
||||
},
|
||||
{
|
||||
LEDStates_e::_WiFiState_Connecting,
|
||||
LEDStates_e::WiFiStateConnecting,
|
||||
{
|
||||
false,
|
||||
true,
|
||||
@@ -44,15 +44,18 @@ ledStateMap_t LEDManager::ledStateMap = {
|
||||
},
|
||||
},
|
||||
{
|
||||
LEDStates_e::_WiFiState_Connected,
|
||||
LEDStates_e::WiFiStateConnected,
|
||||
{
|
||||
false,
|
||||
false,
|
||||
{{LED_ON, 200}, {LED_OFF, 200}, {LED_ON, 200}, {LED_OFF, 200}, {LED_ON, 200}, {LED_OFF, 200}, {LED_ON, 200}, {LED_OFF, 200}, {LED_ON, 200}, {LED_OFF, 200}},
|
||||
{
|
||||
{LED_ON, 200}, {LED_OFF, 200}, {LED_ON, 200}, {LED_OFF, 200}, {LED_ON, 200}, {LED_OFF, 200},
|
||||
{LED_ON, 200}, {LED_OFF, 200}, {LED_ON, 200}, {LED_OFF, 200}
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
LEDStates_e::_WiFiState_Error,
|
||||
LEDStates_e::WiFiStateError,
|
||||
{
|
||||
true,
|
||||
true,
|
||||
@@ -61,18 +64,19 @@ ledStateMap_t LEDManager::ledStateMap = {
|
||||
},
|
||||
};
|
||||
|
||||
LEDManager::LEDManager(gpio_num_t pin, gpio_num_t illumninator_led_pin, QueueHandle_t ledStateQueue) : blink_led_pin(pin),
|
||||
illumninator_led_pin(illumninator_led_pin), ledStateQueue(ledStateQueue), currentState(LEDStates_e::_LedStateNone)
|
||||
{
|
||||
LEDManager::LEDManager(gpio_num_t pin, gpio_num_t illumninator_led_pin,
|
||||
QueueHandle_t ledStateQueue) : blink_led_pin(pin),
|
||||
illumninator_led_pin(illumninator_led_pin),
|
||||
ledStateQueue(ledStateQueue),
|
||||
currentState(LEDStates_e::LedStateNone) {
|
||||
}
|
||||
|
||||
void LEDManager::setup()
|
||||
{
|
||||
ESP_LOGD(LED_MANAGER_TAG, "Setting up status led.");
|
||||
gpio_reset_pin(blink_led_pin);
|
||||
/* Set the GPIO as a push/pull output */
|
||||
gpio_set_direction(blink_led_pin, GPIO_MODE_OUTPUT);
|
||||
this->toggleLED(LED_OFF);
|
||||
void LEDManager::setup() {
|
||||
ESP_LOGD(LED_MANAGER_TAG, "Setting up status led.");
|
||||
gpio_reset_pin(blink_led_pin);
|
||||
/* Set the GPIO as a push/pull output */
|
||||
gpio_set_direction(blink_led_pin, GPIO_MODE_OUTPUT);
|
||||
this->toggleLED(LED_OFF);
|
||||
|
||||
#ifdef CONFIG_SUPPORTS_EXTERNAL_LED_CONTROL
|
||||
ESP_LOGD(LED_MANAGER_TAG, "Setting up illuminator led.");
|
||||
@@ -100,81 +104,68 @@ void LEDManager::setup()
|
||||
|
||||
ESP_ERROR_CHECK(ledc_channel_config(&ledc_channel));
|
||||
#endif
|
||||
ESP_LOGD(LED_MANAGER_TAG, "Done.");
|
||||
ESP_LOGD(LED_MANAGER_TAG, "Done.");
|
||||
}
|
||||
|
||||
void LEDManager::handleLED()
|
||||
{
|
||||
if (!this->finishedPattern)
|
||||
{
|
||||
displayCurrentPattern();
|
||||
return;
|
||||
}
|
||||
|
||||
if (xQueueReceive(this->ledStateQueue, &buffer, 10))
|
||||
{
|
||||
this->updateState(buffer);
|
||||
}
|
||||
else
|
||||
{
|
||||
// we've finished displaying the pattern, so let's check if it's repeatable and if so - reset it
|
||||
if (this->ledStateMap[this->currentState].isRepeatable || this->ledStateMap[this->currentState].isError)
|
||||
{
|
||||
this->currentPatternIndex = 0;
|
||||
this->finishedPattern = false;
|
||||
void LEDManager::handleLED() {
|
||||
if (!this->finishedPattern) {
|
||||
displayCurrentPattern();
|
||||
return;
|
||||
}
|
||||
|
||||
if (xQueueReceive(this->ledStateQueue, &buffer, 10)) {
|
||||
this->updateState(buffer);
|
||||
} else {
|
||||
// we've finished displaying the pattern, so let's check if it's repeatable and if so - reset it
|
||||
if (ledStateMap[this->currentState].isRepeatable || ledStateMap[this->currentState].isError) {
|
||||
this->currentPatternIndex = 0;
|
||||
this->finishedPattern = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void LEDManager::displayCurrentPattern()
|
||||
{
|
||||
BlinkPatterns_t ledState = this->ledStateMap[this->currentState].patterns[this->currentPatternIndex];
|
||||
this->toggleLED(ledState.state);
|
||||
this->timeToDelayFor = ledState.delayTime;
|
||||
void LEDManager::displayCurrentPattern() {
|
||||
auto [state, delayTime] = ledStateMap[this->currentState].patterns[this->currentPatternIndex];
|
||||
this->toggleLED(state);
|
||||
this->timeToDelayFor = delayTime;
|
||||
|
||||
if (!(this->currentPatternIndex >= this->ledStateMap[this->currentState].patterns.size() - 1))
|
||||
this->currentPatternIndex++;
|
||||
else
|
||||
{
|
||||
this->finishedPattern = true;
|
||||
this->toggleLED(LED_OFF);
|
||||
}
|
||||
if (this->currentPatternIndex < ledStateMap[this->currentState].patterns.size() - 1)
|
||||
this->currentPatternIndex++;
|
||||
else {
|
||||
this->finishedPattern = true;
|
||||
this->toggleLED(LED_OFF);
|
||||
}
|
||||
}
|
||||
|
||||
void LEDManager::updateState(LEDStates_e newState)
|
||||
{
|
||||
// we should change the displayed state
|
||||
// only if we finished displaying the current one - which is handled by the task
|
||||
// if the new state is not the same as the current one
|
||||
// and if can actually display the state
|
||||
void LEDManager::updateState(const LEDStates_e newState) {
|
||||
// we should change the displayed state
|
||||
// only if we finished displaying the current one - which is handled by the task
|
||||
// if the new state is not the same as the current one
|
||||
// and if can actually display the state
|
||||
|
||||
// if we've got an error state - that's it, we'll just keep repeating it indefinitely
|
||||
if (this->ledStateMap[this->currentState].isError)
|
||||
return;
|
||||
// if we've got an error state - that's it, we'll just keep repeating it indefinitely
|
||||
if (ledStateMap[this->currentState].isError)
|
||||
return;
|
||||
|
||||
if (newState == this->currentState)
|
||||
return;
|
||||
if (newState == this->currentState)
|
||||
return;
|
||||
|
||||
if (this->ledStateMap.contains(newState))
|
||||
{
|
||||
this->currentState = newState;
|
||||
this->currentPatternIndex = 0;
|
||||
this->finishedPattern = false;
|
||||
}
|
||||
if (ledStateMap.contains(newState)) {
|
||||
this->currentState = newState;
|
||||
this->currentPatternIndex = 0;
|
||||
this->finishedPattern = false;
|
||||
}
|
||||
}
|
||||
|
||||
void LEDManager::toggleLED(bool state) const
|
||||
{
|
||||
gpio_set_level(blink_led_pin, state);
|
||||
void LEDManager::toggleLED(const bool state) const {
|
||||
gpio_set_level(blink_led_pin, state);
|
||||
}
|
||||
|
||||
void HandleLEDDisplayTask(void *pvParameter)
|
||||
{
|
||||
LEDManager *ledManager = static_cast<LEDManager *>(pvParameter);
|
||||
void HandleLEDDisplayTask(void *pvParameter) {
|
||||
auto *ledManager = static_cast<LEDManager *>(pvParameter);
|
||||
|
||||
while (1)
|
||||
{
|
||||
ledManager->handleLED();
|
||||
vTaskDelay(ledManager->getTimeToDelayFor());
|
||||
}
|
||||
}
|
||||
while (true) {
|
||||
ledManager->handleLED();
|
||||
vTaskDelay(ledManager->getTimeToDelayFor());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user