Rezo
Well-known member
I have a fairly complex application that requires some reoccuring fucntion calls on a timed manner; GUI library, CAN bus transmits, SD writes, MTP loop etc
I am using some delays without delays to manage this in the main loop as follow:
Each one of these loops runs in different intervals:
1. 5sm
2. 25-30 ms
3. 25ms
4. 1s
Is there a better way of managing multiple tasks in parallel?
Perhaps replace some of these loop delays (such as CAN transmits or SD writes which are enabled/disabled by the users) with IntervalTimers and starting/stopping them where relevant?
Just looking for some insights as there more the app develops the more app contextual functions calls will be needed in timed intervals.
I am using some delays without delays to manage this in the main loop as follow:
Code:
if (millis() > loopTimeNow1 + loopDelay1) {
loopTimeNow1 = millis();
lv_timer_handler();
mtpLoop();
}
if ((millis() > loopTimeNow2 + loopDelay2) && canEnabled && canEnabledButton) {
loopTimeNow2 = millis();
if((millis() > canLoopTime + (loopDelay2 + (loopDelay2/2))) && !readyToTransmit){
readyToTransmit = true;
canTimeouts++;
}
canTransmit();
}
if ((millis() > loopTimeNow3 + loopDelay3) && readyToUpdate) {
loopTimeNow3 = millis();
updateGaugeScreen();
if(dataLogEnabled && dataLogHeaderReady){
logDataLine();
}
}
if(millis() > loopTimeNow4 + loopDelay4){
loopTimeNow4 = millis();
if(!dataLogEnabled){
isSdInserted = SD.mediaPresent();
}
if(autoBrightness){
getClusterBrightness();
}
}
Each one of these loops runs in different intervals:
1. 5sm
2. 25-30 ms
3. 25ms
4. 1s
Is there a better way of managing multiple tasks in parallel?
Perhaps replace some of these loop delays (such as CAN transmits or SD writes which are enabled/disabled by the users) with IntervalTimers and starting/stopping them where relevant?
Just looking for some insights as there more the app develops the more app contextual functions calls will be needed in timed intervals.