Use a FreeRTOS task to update strobe.
This commit is contained in:
parent
525970bbf9
commit
efad085a2a
@ -71,53 +71,64 @@ bool Strobe::begin(uint8_t pin, uint8_t pwm) {
|
|||||||
ledcSetup(m_pwm, 2400, 15); // 2.4KHz PWM, 15 bit resolutio
|
ledcSetup(m_pwm, 2400, 15); // 2.4KHz PWM, 15 bit resolutio
|
||||||
ledcWrite(m_pwm, m_level); // LED to 0%
|
ledcWrite(m_pwm, m_level); // LED to 0%
|
||||||
|
|
||||||
|
// start update task
|
||||||
|
xTaskCreate(this->update, // function name
|
||||||
|
"StrobeUpdateThread", // task name
|
||||||
|
2048, // stack size (bytes)
|
||||||
|
this, // parameter to pass
|
||||||
|
1, // task priority
|
||||||
|
NULL); // task handle
|
||||||
|
|
||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Strobe::update(void * args) {
|
void Strobe::update(void * param) {
|
||||||
// stop stobing on sACN loss of signal
|
Strobe *tThis = (Strobe *) param;
|
||||||
// if (millis() - m_e131->stats.last_seen > 10000) {
|
for (;;) {
|
||||||
// Serial.println("No Signal!");
|
// stop stobing on sACN loss of signal
|
||||||
// m_int = 0;
|
// if (millis() - m_e131->stats.last_seen > 10000) {
|
||||||
// }
|
// Serial.println("No Signal!");
|
||||||
|
// m_int = 0;
|
||||||
|
// }
|
||||||
|
|
||||||
// intensity changes start/stop the cycle
|
// intensity changes start/stop the cycle
|
||||||
if (m_int == 0) {
|
if (tThis->m_int == 0) {
|
||||||
// intensity off breaks the cycle
|
// intensity off breaks the cycle
|
||||||
m_state = STROBE_INACTIVE;
|
tThis->m_state = STROBE_INACTIVE;
|
||||||
} else {
|
} else {
|
||||||
if (m_state == STROBE_INACTIVE) {
|
if (tThis->m_state == STROBE_INACTIVE) {
|
||||||
// going active
|
// going active
|
||||||
m_state = STROBE_ACTIVE_ON;
|
tThis->m_state = STROBE_ACTIVE_ON;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// time based cycle changes
|
// time based cycle changes
|
||||||
if (m_state == STROBE_ACTIVE_ON ||
|
if (tThis->m_state == STROBE_ACTIVE_ON ||
|
||||||
m_state == STROBE_ACTIVE_OFF) {
|
tThis->m_state == STROBE_ACTIVE_OFF) {
|
||||||
uint32_t now, elapsed, period, durr;
|
uint32_t now, elapsed, period, durr;
|
||||||
now = micros();
|
now = micros();
|
||||||
|
|
||||||
elapsed = now - m_time;
|
|
||||||
period = hz_to_micros(m_rat);
|
|
||||||
durr = dr_to_micros(m_dur);
|
|
||||||
|
|
||||||
if (elapsed > period || // hz period completed
|
elapsed = now - tThis->m_time;
|
||||||
now < m_time) { // micros() wraps 32 bits every ~70 min.
|
period = hz_to_micros(tThis->m_rat);
|
||||||
// cycle restarts
|
durr = dr_to_micros(tThis->m_dur);
|
||||||
m_state = STROBE_ACTIVE_ON;
|
|
||||||
m_time = now;
|
if (elapsed > period || // hz period completed
|
||||||
} else if (elapsed > durr) { // durration period completed
|
now < tThis->m_time) { // micros() wraps 32 bits every ~70 min.
|
||||||
// cycle enters dark phase
|
// cycle restarts
|
||||||
m_state = STROBE_ACTIVE_OFF;
|
tThis->m_state = STROBE_ACTIVE_ON;
|
||||||
|
tThis->m_time = now;
|
||||||
|
} else if (elapsed > durr) { // durration period completed
|
||||||
|
// cycle enters dark phase
|
||||||
|
tThis->m_state = STROBE_ACTIVE_OFF;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// set LED output
|
// set LED output
|
||||||
if (m_state == STROBE_ACTIVE_ON) {
|
if (tThis->m_state == STROBE_ACTIVE_ON) {
|
||||||
setLevel(m_int);
|
tThis->setLevel(tThis->m_int);
|
||||||
} else {
|
} else {
|
||||||
setLevel(0);
|
tThis->setLevel(0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -44,10 +44,7 @@ class Strobe {
|
|||||||
Strobe(uint16_t universe = 1, uint16_t address = 1);
|
Strobe(uint16_t universe = 1, uint16_t address = 1);
|
||||||
|
|
||||||
bool begin(uint8_t pin, uint8_t pwm); // call in setup()
|
bool begin(uint8_t pin, uint8_t pwm); // call in setup()
|
||||||
|
static void update(void * param); // update task
|
||||||
void update(void *args = NULL); // update task
|
|
||||||
|
|
||||||
const uint8_t profile = 4; // DMX profile length
|
|
||||||
|
|
||||||
void recvData(e131_packet_t *packet); // data recieved callback
|
void recvData(e131_packet_t *packet); // data recieved callback
|
||||||
|
|
||||||
|
@ -150,8 +150,6 @@ void loop() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
strobe->update();
|
|
||||||
|
|
||||||
// Be a remote trigger
|
// Be a remote trigger
|
||||||
//
|
//
|
||||||
bool val = !digitalRead(button);
|
bool val = !digitalRead(button);
|
||||||
|
Loading…
Reference in New Issue
Block a user