yield update task during cycle inactivity.

This commit is contained in:
Kevin Matz 2020-12-07 08:46:23 -05:00
parent 73815a878c
commit b466cf1aaf

View File

@ -86,7 +86,9 @@ bool Strobe::begin(uint8_t pin, uint8_t pwm) {
void Strobe::update(void * param) {
Strobe *tThis = (Strobe *) param;
uint32_t last_time = 0;
TickType_t xDelay;
for (;;) {
xDelay = (1000 / 40.0) / portTICK_PERIOD_MS; // sleep 1 dmx frame
// intensity changes start/stop the cycle
uint16_t intensity = tThis->profile_.intensity << 8 |
tThis->profile_.intensity >> 8;
@ -114,9 +116,21 @@ void Strobe::update(void * param) {
// cycle restarts
tThis->state_ = STROBE_ACTIVE_ON;
last_time = now;
// yield task until end of duration
xDelay = std::min(xDelay, dur / portTICK_PERIOD_MS);
} else if (elapsed > dur) { // durration period completed
// cycle enters dark phase
tThis->state_ = STROBE_ACTIVE_OFF;
// yield task until end of period
xDelay = std::min(xDelay, (period - dur) / portTICK_PERIOD_MS);
} else {
if (tThis->state_ = STROBE_ACTIVE_ON) {
// yield task for remainder of duration
xDelay = std::min(xDelay, (dur - elapsed) / portTICK_PERIOD_MS);
} else {
// yield task for remainder of period
xDelay = std::min(xDelay, (period - elapsed) / portTICK_PERIOD_MS);
}
}
}
@ -126,7 +140,11 @@ void Strobe::update(void * param) {
} else {
tThis->setLevel(0);
}
// yield task
vTaskDelay(xDelay);
}
vTaskDelete( NULL );
}