ISR modified ...

This commit is contained in:
Fenoglio 2018-07-07 23:13:48 +02:00
parent f6132f1c85
commit d0e04a5ee6

View file

@ -250,26 +250,38 @@ void loop(void) {
//calculate the run_time and switch to WAIT //calculate the run_time and switch to WAIT
run_time = (radio_data.topbuttonpressedtime - running_time_offset) - start_time; run_time = (radio_data.topbuttonpressedtime - running_time_offset) - start_time;
runner_run_time = runner_start_time - run_time; runner_run_time = runner_start_time - run_time;
timer_new_state = TIMER_WAIT; delay(10);
if(digitalRead(CANCELBUTTON_IN) != CANCELBUTTON_PRESSED){
timer_new_state = TIMER_WAIT;
}
break; break;
case TIMER_FAIL: case TIMER_FAIL:
//fail start case .... //fail start case ....
failSequence(); failSequence();
run_time = 99999; run_time = 99999;
runner_run_time = runner_start_time - start_time; runner_run_time = runner_start_time - start_time;
timer_new_state = TIMER_WAIT; delay(10);
if(digitalRead(CANCELBUTTON_IN) != CANCELBUTTON_PRESSED){
timer_new_state = TIMER_WAIT;
}
break; break;
case TIMER_CANCELLED: case TIMER_CANCELLED:
// what to do in chancel mode ? // what to do in chancel mode ?
run_time = 99999; run_time = 99999;
runner_run_time = runner_start_time - start_time; runner_run_time = runner_start_time - start_time;
timer_new_state = TIMER_WAIT; delay(10);
if(digitalRead(CANCELBUTTON_IN) != CANCELBUTTON_PRESSED){
timer_new_state = TIMER_WAIT;
}
break; break;
case TIMER_TIMEDOUT: case TIMER_TIMEDOUT:
// time out // time out
run_time = millis() - start_time; run_time = millis() - start_time;
runner_run_time = runner_start_time - start_time; runner_run_time = runner_start_time - start_time;
timer_new_state = TIMER_WAIT; delay(10);
if(digitalRead(CANCELBUTTON_IN) != CANCELBUTTON_PRESSED){
timer_new_state = TIMER_WAIT;
}
break; break;
case TIMER_WAIT: case TIMER_WAIT:
// disable interrupt if not already done // disable interrupt if not already done
@ -439,20 +451,24 @@ void startSequence(void)
Serial.print("Start time is: "); Serial.print("Start time is: ");
Serial.println(start_time); Serial.println(start_time);
// this is sequence of usually three tones after a wait time 1sec , in between the tones there is also a delay of 1 sec. Each tone is 200ms seconds long, except the last // this is sequence of usually three tones after a wait time 1sec , in between the tones there is also a delay of 1 sec. Each tone is 200ms seconds long, except the last
update_statemessage(timer_new_state);
if(timer_new_state == TIMER_RUNNING){ if(timer_new_state == TIMER_RUNNING){
delay(STARTSEQ_STARTPAUSE_MS); delay(STARTSEQ_STARTPAUSE_MS);
} }
// first tone // first tone
update_statemessage(timer_new_state);
if(timer_new_state == TIMER_RUNNING){ if(timer_new_state == TIMER_RUNNING){
tone(PIEZO_PIN, STARTSEQ_TON_1_2_FREQUENCY,STARTSEQ_TON_1_2_LENGTH_MS ); tone(PIEZO_PIN, STARTSEQ_TON_1_2_FREQUENCY,STARTSEQ_TON_1_2_LENGTH_MS );
delay(STARTSEQ_TONEPAUSE_MS); delay(STARTSEQ_TONEPAUSE_MS);
} }
//second tone //second tone
update_statemessage(timer_new_state);
if(timer_new_state == TIMER_RUNNING){ if(timer_new_state == TIMER_RUNNING){
tone(PIEZO_PIN, STARTSEQ_TON_1_2_FREQUENCY,STARTSEQ_TON_1_2_LENGTH_MS ); tone(PIEZO_PIN, STARTSEQ_TON_1_2_FREQUENCY,STARTSEQ_TON_1_2_LENGTH_MS );
delay(STARTSEQ_TONEPAUSE_MS); delay(STARTSEQ_TONEPAUSE_MS);
} }
//third tone //third tone
update_statemessage(timer_new_state);
if(timer_new_state == TIMER_RUNNING){ if(timer_new_state == TIMER_RUNNING){
tone(PIEZO_PIN, STARTSEQ_TON_3_FREQUENCY,STARTSEQ_TON_3_LENGTH_MS ); tone(PIEZO_PIN, STARTSEQ_TON_3_FREQUENCY,STARTSEQ_TON_3_LENGTH_MS );
delay(STARTSEQ_TON_3_LENGTH_MS); delay(STARTSEQ_TON_3_LENGTH_MS);
@ -476,10 +492,12 @@ void false_start_isr(void)
// this will save the time when the runner is really started // this will save the time when the runner is really started
Serial.println("** Interrupt service routine started: false_start_ISR **"); Serial.println("** Interrupt service routine started: false_start_ISR **");
runner_start_time = millis(); runner_start_time = millis();
if((timer_state == TIMER_STARTED) & (timer_new_state == TIMER_STARTED)){ if((timer_state == TIMER_STARTED) & (timer_new_state == TIMER_RUNNING)){
timer_new_state = TIMER_FAIL; timer_new_state = TIMER_FAIL;
detachInterrupt(digitalPinToInterrupt(FAILSTARTBUTTON_IN));
noTone(PIEZO_PIN); noTone(PIEZO_PIN);
Serial.println("** Interrupt service routine detected false_start. Set new state to TIMER_FAIL **");
update_statemessage(timer_new_state);
detachInterrupt(digitalPinToInterrupt(FAILSTARTBUTTON_IN));
} else { } else {
if((timer_state == TIMER_RUNNING) | (timer_new_state == TIMER_RUNNING) ){ if((timer_state == TIMER_RUNNING) | (timer_new_state == TIMER_RUNNING) ){
// disable this interrupt; // disable this interrupt;