i need to make a function to stop, jumpTo and disableTimer,. I tried to make them already but the disable timer is not working. I cant tell if there are any check to see if a timer is enabled before turning on the outputs. if i set a Timer[Number].status to 0 it breaks the whole program. what do i need to do in order to make these 3 function work properly?
byte jumpToTimer(int newStep) {
digitalWrite(pins[currentStep], HIGH);
clrFlags(currentStep, tiOnPhase);
clrFlags(currentStep, tiRunning);
currentStep = newStep ;
setNewState(tsCheckHighPhase);
setFlags(currentStep, tiRunning);
}
byte StopTimer() {
if (digitalRead(pins[currentStep]) == LOW) {
digitalWrite(pins[currentStep], HIGH);
clrFlags(currentStep, tiOnPhase);
}
}
byte disableTimer(int timerNumber) {
clrFlags(timerNumber, tiOnPhase);
clrFlags(timerNumber, tiEnabled);
Timers[timerNumber].status = 0;
if (digitalRead(pins[timerNumber]) == LOW) {
digitalWrite(pins[timerNumber], HIGH); //turn it off
}
}
void process() {
if (runTimer) {
now = millis();
switch (timerState) {
case tsPowerUp:
stateDuration = startupDelay;
timeBase = now;
setNewState(tsStartUpWait);
break;
case tsStartUpWait:
if (now - timeBase >= stateDuration) {
currentStep = 0;
setNewState(tsCheckStep);
}
break;
case tsCheckStep:
if (noValidStep(currentStep)) {
setNewState(tsNoTasks);
} else {
setFlags(currentStep, tiRunning);
setNewState(tsCheckHighPhase);
}
break;
case tsCheckHighPhase:
if (Timers[currentStep].onTime) {
setFlags(currentStep, tiOnPhase);
timeBase = now;
stateDuration = Timers[currentStep].onTime * conversionFactor;
digitalWrite(pins[currentStep], LOW);
setNewState(tsExecHighPhase);
} else {
setNewState(tsCheckLowPhase);
}
break;
case tsExecHighPhase:
if (now - timeBase >= stateDuration) {
digitalWrite(pins[currentStep], HIGH);
clrFlags(currentStep, tiOnPhase);
setNewState(tsCheckLowPhase);
}
break;
case tsCheckLowPhase:
if ((Timers[currentStep].status & tiEnabled) && Timers[currentStep].offTime) {
timeBase = now;
stateDuration = Timers[currentStep].offTime * conversionFactor;
setNewState(tsExecLowPhase);
} else {
setNewState(tsNextStep);
}
break;
case tsExecLowPhase:
if (now - timeBase >= stateDuration) {
setNewState(tsNextStep);
}
break;
case tsNextStep:
Serial.print(currentStep);
clrFlags(currentStep, tiRunning);
currentStep++;
setNewState(tsCheckStep);
break;
case tsNoTasks:
if (!noValidStep(currentStep)) {
setNewState(tsCheckHighPhase);
}
break;
default:
Serial.print(F("bad state reached "));
Serial.println(timerState);
runTimer = false;
}
}
if (announce.checkTimeout()) {
writeTo('*', this, sizeof(TimerInfos), true);
Serial.print(F(" at> "));
disp();
incId();
clrUpdated();
}
}
};
i think jumpTo and stopTimer work but disable is not. and im not sure if i made any of them right.
For example i want to disable Timer[0] while its running. it should turn off the output and continue and start Timer[1]. or i might disable Timer[3] while some other timer is on and itnot break the state machine. the timer operate in order 1,2,3,4 and repeat forever. Unless i disable timer 2 it should run 1,3,4 or if i disable timer 4 1,2,3