led flash not working ma vabbeh
This commit is contained in:
@@ -31,23 +31,27 @@ namespace drivers
|
|||||||
void Led::flashHandle(TimerHandle_t th)
|
void Led::flashHandle(TimerHandle_t th)
|
||||||
{
|
{
|
||||||
Led *led = (Led *)pvTimerGetTimerID(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
|
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");
|
return;
|
||||||
xTimerDelete(th, 0);
|
|
||||||
led->m_flashTimer = NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Led::flashColor(const uint16_t tOn, const color_t color)
|
void Led::flashColor(const uint16_t tOn, const color_t color)
|
||||||
{
|
{
|
||||||
std::lock_guard<std::mutex> lock(m_ledMutex);
|
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)
|
if (m_flashTimer == NULL)
|
||||||
{
|
{
|
||||||
blinkStop();
|
m_flashTimer = xTimerCreate("flasher", pdMS_TO_TICKS(tOn), pdFALSE, NULL, flashHandle);
|
||||||
rgbLedWrite(c_ledPin, color.g, color.r, color.b); // set color to flash
|
|
||||||
m_flashTimer = xTimerCreate("flasher", pdMS_TO_TICKS(tOn), pdFALSE, this, flashHandle);
|
|
||||||
xTimerStart(m_flashTimer, 0);
|
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -59,6 +59,8 @@ namespace drivers
|
|||||||
TaskHandle_t m_blinkTask;
|
TaskHandle_t m_blinkTask;
|
||||||
TimerHandle_t m_flashTimer;
|
TimerHandle_t m_flashTimer;
|
||||||
|
|
||||||
|
bool m_flashing;
|
||||||
|
|
||||||
std::mutex m_ledMutex;
|
std::mutex m_ledMutex;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
12
src/main.cpp
12
src/main.cpp
@@ -83,14 +83,14 @@ void loop()
|
|||||||
|
|
||||||
MQTTwrapper::MessageCallback onMessage = [&devices](const MQTTwrapper::Topic &topic, const MQTTwrapper::Message &message)
|
MQTTwrapper::MessageCallback onMessage = [&devices](const MQTTwrapper::Topic &topic, const MQTTwrapper::Message &message)
|
||||||
{
|
{
|
||||||
LOG_INFO("onMessage callback [", topic.c_str(),"]");
|
LOG_INFO("onMessage callback [", topic.c_str(), "]");
|
||||||
devices.led.flashColor(250, devices.led.COLOR_YELLOW);
|
devices.led.setColor(devices.led.COLOR_MAGENTA);
|
||||||
};
|
};
|
||||||
|
|
||||||
MQTTwrapper::MessageCallback onPublish = [&devices](const MQTTwrapper::Topic &topic, const MQTTwrapper::Message &message)
|
MQTTwrapper::MessageCallback onPublish = [&devices](const MQTTwrapper::Topic &topic, const MQTTwrapper::Message &message)
|
||||||
{
|
{
|
||||||
LOG_INFO("onPublish callback [", topic.c_str(),"]");
|
LOG_INFO("onPublish callback [", topic.c_str(), "]");
|
||||||
devices.led.flashColor(250, devices.led.COLOR_BLUE);
|
devices.led.setColor(devices.led.COLOR_SKYBLUE);
|
||||||
};
|
};
|
||||||
|
|
||||||
///////////// CRONJOB //////////////
|
///////////// CRONJOB //////////////
|
||||||
@@ -144,8 +144,8 @@ void loop()
|
|||||||
buzzer.beep(250, NOTE_B);
|
buzzer.beep(250, NOTE_B);
|
||||||
led.setColor(led.COLOR_GREEN);
|
led.setColor(led.COLOR_GREEN);
|
||||||
mqtt.subscribe(conf.m_mqttSubscribe["commands"], commandsCallback);
|
mqtt.subscribe(conf.m_mqttSubscribe["commands"], commandsCallback);
|
||||||
//mqtt.setOnMessageCb(onMessage);
|
mqtt.setOnMessageCb(onMessage);
|
||||||
//mqtt.setOnPublishCb(onPublish);
|
mqtt.setOnPublishCb(onPublish);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
delay(250);
|
delay(250);
|
||||||
|
|||||||
Reference in New Issue
Block a user