led flash not working ma vabbeh

This commit is contained in:
Emanuele Trabattoni
2025-08-02 17:39:02 +02:00
parent 0e842294be
commit 25251785fa
3 changed files with 20 additions and 14 deletions

View File

@@ -31,23 +31,27 @@ namespace drivers
void Led::flashHandle(TimerHandle_t th)
{
Led *led = (Led *)pvTimerGetTimerID(th);
std::lock_guard<std::mutex> lock(led->m_ledMutex);
rgbLedWrite(led->c_ledPin, led->m_colorDefault.g, led->m_colorDefault.r, led->m_colorDefault.b); // reset color to saved color
LOG_DEBUG("Led Flash timer expired");
xTimerDelete(th, 0);
led->m_flashTimer = NULL;
return;
}
void Led::flashColor(const uint16_t tOn, const color_t color)
{
std::lock_guard<std::mutex> lock(m_ledMutex);
rgbLedWrite(c_ledPin, color.g, color.r, color.b); // set color to flash
if (m_flashTimer == NULL)
{
blinkStop();
rgbLedWrite(c_ledPin, color.g, color.r, color.b); // set color to flash
m_flashTimer = xTimerCreate("flasher", pdMS_TO_TICKS(tOn), pdFALSE, this, flashHandle);
m_flashTimer = xTimerCreate("flasher", pdMS_TO_TICKS(tOn), pdFALSE, NULL, flashHandle);
xTimerStart(m_flashTimer, 0);
LOG_DEBUG("Led Flash timer created");
LOG_INFO("Led Flash timer created");
return;
}
xTimerStop(m_flashTimer, 0);
if (!xTimerChangePeriod(m_flashTimer, pdMS_TO_TICKS(tOn), pdMS_TO_TICKS(1)) || !xTimerReset(m_flashTimer, pdMS_TO_TICKS(1)))
{
LOG_ERROR("Led Flash timer failed reset");
xTimerDelete(m_flashTimer, 0);
m_flashTimer = NULL;
}
}

View File

@@ -59,6 +59,8 @@ namespace drivers
TaskHandle_t m_blinkTask;
TimerHandle_t m_flashTimer;
bool m_flashing;
std::mutex m_ledMutex;
};

View File

@@ -83,14 +83,14 @@ void loop()
MQTTwrapper::MessageCallback onMessage = [&devices](const MQTTwrapper::Topic &topic, const MQTTwrapper::Message &message)
{
LOG_INFO("onMessage callback [", topic.c_str(),"]");
devices.led.flashColor(250, devices.led.COLOR_YELLOW);
LOG_INFO("onMessage callback [", topic.c_str(), "]");
devices.led.setColor(devices.led.COLOR_MAGENTA);
};
MQTTwrapper::MessageCallback onPublish = [&devices](const MQTTwrapper::Topic &topic, const MQTTwrapper::Message &message)
{
LOG_INFO("onPublish callback [", topic.c_str(),"]");
devices.led.flashColor(250, devices.led.COLOR_BLUE);
LOG_INFO("onPublish callback [", topic.c_str(), "]");
devices.led.setColor(devices.led.COLOR_SKYBLUE);
};
///////////// CRONJOB //////////////
@@ -144,8 +144,8 @@ void loop()
buzzer.beep(250, NOTE_B);
led.setColor(led.COLOR_GREEN);
mqtt.subscribe(conf.m_mqttSubscribe["commands"], commandsCallback);
//mqtt.setOnMessageCb(onMessage);
//mqtt.setOnPublishCb(onPublish);
mqtt.setOnMessageCb(onMessage);
mqtt.setOnPublishCb(onPublish);
break;
}
delay(250);