Skip to content

Commit

Permalink
hopefully, fixing gfi retry
Browse files Browse the repository at this point in the history
  • Loading branch information
dlyubimov committed Jul 10, 2017
1 parent 0e5b25b commit c46138a
Showing 1 changed file with 9 additions and 51 deletions.
60 changes: 9 additions & 51 deletions Hydra_EVSE/Hydra_EVSE.ino
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ void error(unsigned int status)
unsigned int car = status & CAR_MASK;

// Cancel all pending events except for the relay test protection
// timeouts.sequential_pilot_timeout = 0;
// timeouts.sequential_pilot_timeout = 0;
timeouts.clear();

// kick off gfi retry timer (if under the allowed number of attempts).
Expand Down Expand Up @@ -692,14 +692,8 @@ void car_struct::sequential_mode_transition(unsigned int car_state)
{
them.setPilot(FULL);
displayStatus( them.car | STATUS_OFF );
// display.setCursor((them == CAR_A) ? 0 : 8, 1);
// display.print((them == CAR_A) ? "A" : "B");
// display.print(P(": off "));
}
displayStatus( car | STATUS_UNPLUGGED );
// display.setCursor((us == CAR_A) ? 0 : 8, 1);
// display.print((us == CAR_A) ? "A" : "B");
// display.print(P(": --- "));
// reset done state for all
seq_done = false;
them.seq_done = false;
Expand All @@ -720,16 +714,10 @@ void car_struct::sequential_mode_transition(unsigned int car_state)
them.setPilot(FULL);
}
displayStatus(them.car | ( them.seq_done ? STATUS_DONE : STATUS_OFF ));
// display.setCursor((them == CAR_A) ? 0 : 8, 1);
// display.print((them == CAR_A) ? "A" : "B");
// if (them_done) display.print(P(": done ")); else display.print(P(": off "));


// differentiated from "wait" because a C/D->B transition has occurred.
displayStatus(car | STATUS_DONE);
// display.setCursor((us == CAR_A) ? 0 : 8, 1);
// display.print((us == CAR_A) ? "A" : "B");
// display.print(P(": done ")); // differentiated from "wait" because a C/D->B transition has occurred.

// Disable future charges for this car until re-unpaused or re-plugged.
seq_done = true;
timeouts.sequential_pilot_timeout = millis(); // We're both now in B. Start flipping.
Expand All @@ -738,9 +726,6 @@ void car_struct::sequential_mode_transition(unsigned int car_state)
{

displayStatus(car | STATUS_OFF);
// display.setCursor((us == CAR_A) ? 0 : 8, 1);
// display.print((us == CAR_A) ? "A" : "B");
// display.print(P(": off "));
// their state is not B, so we're not "flipping"
timeouts.sequential_pilot_timeout = 0;
}
Expand All @@ -756,10 +741,6 @@ void car_struct::sequential_mode_transition(unsigned int car_state)
timeouts.sequential_pilot_timeout = 0;

displayStatus(car | STATUS_OFF );
// display.setCursor((us == CAR_A) ? 0 : 8, 1);
// display.print((us == CAR_A) ? "A" : "B");
// display.print(P(": off "));

break;
}
else if (their_state == STATE_B || their_state == DUNNO)
Expand All @@ -779,20 +760,11 @@ void car_struct::sequential_mode_transition(unsigned int car_state)
timeouts.sequential_pilot_timeout = millis();

displayStatus (car | STATUS_OFF);
// display.setCursor((us == CAR_A) ? 0 : 8, 1);
// display.print((us == CAR_A) ? "A" : "B");
// display.print(P(": off "));
break;
}
}
// Either they are in state C/D or they're in state B and we lost the tiebreak.
displayStatus(car | ( seq_done ? STATUS_DONE : STATUS_WAIT));
// display.setCursor((us == CAR_A) ? 0 : 8, 1);
// display.print((us == CAR_A) ? "A" : "B");
// if ( us_done)
// display.print(P(": done "));
// else
// display.print(P(": wait "));
}
break;
case STATE_C:
Expand All @@ -810,9 +782,6 @@ void car_struct::sequential_mode_transition(unsigned int car_state)
// We're not both in state B anymore
timeouts.sequential_pilot_timeout = 0;
displayStatus(car | STATUS_ON );
// display.setCursor((us == CAR_A) ? 0 : 8, 1);
// display.print((us == CAR_A) ? "A" : "B");
// display.print(P(": ON "));
setRelay(HIGH); // turn on the juice
break;
case STATE_E:
Expand Down Expand Up @@ -840,9 +809,6 @@ void car_struct::shared_mode_transition(unsigned int car_state)
// setPilot(us, car_state == STATE_A ? HIGH : (isCarCharging(them) ? HALF : FULL));
setPilot(car_state == STATE_A ? HIGH : (them.isCarCharging() ? HALF : FULL));
displayStatus(car | (car_state == STATE_A ? STATUS_UNPLUGGED : STATUS_OFF));
// display.setCursor((us == CAR_A) ? 0 : 8, 1);
// display.print((us == CAR_A) ? "A" : "B");
// display.print(car_state == STATE_A ? ": --- " : ": off ");
request_time = 0;
#ifdef QUICK_CYCLING_WORKAROUND
if (!isCarCharging(them))
Expand Down Expand Up @@ -883,9 +849,6 @@ void car_struct::shared_mode_transition(unsigned int car_state)
them.setPilot(HALF); // *should* be redundant
setPilot(HALF); // redundant, unless we went straight from A to C.
displayStatus(us | STATUS_ON);
// display.setCursor((us == CAR_A) ? 0 : 8, 1);
// display.print((us == CAR_A) ? "A" : "B");
// display.print(P(": ON "));
setRelay(HIGH);
}
else
Expand All @@ -897,9 +860,6 @@ void car_struct::shared_mode_transition(unsigned int car_state)
them.setPilot(HALF);
setPilot(HALF); // this is redundant unless we are transitioning from A to C suddenly.
displayStatus(car | STATUS_WAIT);
// display.setCursor((us == CAR_A) ? 0 : 8, 1);
// display.print((us == CAR_A) ? "A" : "B");
// display.print(P(": wait "));
#ifdef QUICK_CYCLING_WORKAROUND
}
#endif
Expand All @@ -912,9 +872,6 @@ void car_struct::shared_mode_transition(unsigned int car_state)
setPilot(FULL); // this is redundant unless we are going directly from A to C.
request_time = 0;
displayStatus(car | STATUS_ON);
// display.setCursor((us == CAR_A) ? 0 : 8, 1);
// display.print((us == CAR_A) ? "A" : "B");
// display.print(P(": ON "));
setRelay(HIGH);
}
break;
Expand Down Expand Up @@ -1865,10 +1822,6 @@ void car_struct::loopCheckPilot(unsigned int car_state) {
sequential_mode_transition(car_state);
break;
}
} else if ( ! paused && timeouts.gfi_time > 0 && timeouts.gfi_time + GFI_CLEAR_MS < millis()) {
// timeouts.clear();
// enable transition next iteration
for (int i = 0; i < 2; i++ ) cars[i].last_state = DUNNO;
}

}
Expand Down Expand Up @@ -2006,7 +1959,6 @@ void loop()
if (gfiTriggered)
{
logInfo(P("GFI fault detected"));
// timeouts.clear();
error(BOTH | STATUS_ERR | STATUS_ERR_G);
gfiTriggered = false;
}
Expand Down Expand Up @@ -2093,7 +2045,7 @@ void loop()
{
// cancel all events except for relay check guarding period
timeouts.clear();

if (operatingMode == MODE_SEQUENTIAL)
{
// remember which car was active
Expand Down Expand Up @@ -2167,6 +2119,12 @@ void loop()
}
}

// GFI retry
if (timeouts.gfi_time + GFI_CLEAR_MS < millis()) {
timeouts.clear();
for (int i = 0; i < 2; i++) if (cars[i].last_state == STATE_E) cars[i].last_state = DUNNO;
}

// Is it essential that we keep differentiating between the new state and the last state?
// Some, if not all, logical paths are updating the last_state to the new state in those
// subroutines anyway. If yes, then we can probably remove car_x_state variables and just
Expand Down

0 comments on commit c46138a

Please sign in to comment.