diff --git a/firmware/open_evse/J1772EvseController.cpp b/firmware/open_evse/J1772EvseController.cpp index 35cd1f9d..7eb37a27 100644 --- a/firmware/open_evse/J1772EvseController.cpp +++ b/firmware/open_evse/J1772EvseController.cpp @@ -276,14 +276,14 @@ void J1772EVSEController::chargingOn() Serial.print("relayHoldPwm: ");Serial.println(m_relayHoldPwm); // turn on charging pin to close relay digitalWrite(V6_CHARGING_PIN,HIGH); - digitalWrite(V6_CHARGING_PIN2,HIGH); + if (relay2Enable) {digitalWrite(V6_CHARGING_PIN2,HIGH); } delay(m_relayCloseMs); // switch to PWM to hold closed analogWrite(V6_CHARGING_PIN,m_relayHoldPwm); - analogWrite(V6_CHARGING_PIN2,m_relayHoldPwm); + if (relay2Enable) {analogWrite(V6_CHARGING_PIN2,m_relayHoldPwm);} #else // !RELAY_PWM digitalWrite(V6_CHARGING_PIN,HIGH); - digitalWrite(V6_CHARGING_PIN2,HIGH); + if (relay2Enable) {digitalWrite(V6_CHARGING_PIN2,HIGH);} #endif // RELAY_PWM } else { @@ -317,6 +317,8 @@ void J1772EVSEController::chargingOn() void J1772EVSEController::chargingOff() { // turn off charging current + //Note - we don't care if relay2 is enabled or not, + // in all cases we turn off both relays. #ifdef OEV6 if (isV6()) { #ifdef RELAY_AUTO_PWM_PIN diff --git a/firmware/open_evse/J1772EvseController.h b/firmware/open_evse/J1772EvseController.h index 03f542ca..ebe34c0b 100644 --- a/firmware/open_evse/J1772EvseController.h +++ b/firmware/open_evse/J1772EvseController.h @@ -233,6 +233,7 @@ class J1772EVSEController { #ifdef OEV6 uint8_t isV6() { return m_isV6; } + uint8_t relay2Enable = 1; //default to both relays enabled #endif #ifdef ADVPWR @@ -292,6 +293,7 @@ class J1772EVSEController { void Enable(); void Disable(); // panic stop - open relays abruptly void Sleep(); // graceful stop - e.g. waiting for timer to fire- give the EV time to stop charging first + void Relay2Enable(uint8_t relay2on) { relay2Enable = relay2on; } uint16_t GetFlags() { return m_wFlags; } uint16_t GetVFlags() { return m_wVFlags; } diff --git a/firmware/open_evse/main.cpp b/firmware/open_evse/main.cpp index c2d7d419..54a870e2 100644 --- a/firmware/open_evse/main.cpp +++ b/firmware/open_evse/main.cpp @@ -197,6 +197,10 @@ TempMonitor g_TempMonitor; AutoCurrentCapacityController g_ACCController; #endif +unsigned long OnboardDisplay::lastBacklightChangeMillis = 0; + + + //-- end global variables // watchdog-safe delay - use this when delay is longer than watchdog @@ -414,7 +418,6 @@ void OnboardDisplay::MakeChar(uint8_t n, PGM_P bytes) void OnboardDisplay::Init() { WDT_RESET(); - #ifdef RGBLCD m_bFlags = 0; #else @@ -985,6 +988,11 @@ void OnboardDisplay::Update(int8_t updmode) } } #endif // DELAYTIMER + + if ( g_OBD.lastBacklightChangeMillis < millis() + LCD_BL_TIMEOUT) { + //turn backlight off after 5 secs + LcdSetBacklightColor(0); + } #endif // LCD16X2 } @@ -2492,7 +2500,7 @@ uint8_t StateTransitionReqFunc(uint8_t curPilotState,uint8_t newPilotState,uint8 void setup() { wdt_disable(); - + delay(400); // give I2C devices time to be ready before running code that wants to initialize I2C devices. Otherwise a hang can occur upon powerup. Serial.begin(SERIAL_BAUD); @@ -2541,7 +2549,9 @@ void loop() #endif // PERIODIC_LCD_REFRESH_MS ProcessInputs(); - + + //BackLightTimeout(); + // Delay Timer Handler - GoldServe #ifdef DELAYTIMER g_DelayTimer.CheckTime(); diff --git a/firmware/open_evse/open_evse.h b/firmware/open_evse/open_evse.h index b2c514ad..373d007e 100644 --- a/firmware/open_evse/open_evse.h +++ b/firmware/open_evse/open_evse.h @@ -229,6 +229,7 @@ extern AutoCurrentCapacityController g_ACCController; //Adafruit RGBLCD (MCP23017) - can have RGB or monochrome backlight #define RGBLCD +#define LCD_BL_TIMEOUT 5000 //select default LCD backlight mode. can be overridden w/CLI/RAPI #define BKL_TYPE_MONO 0 #define BKL_TYPE_RGB 1 @@ -844,6 +845,7 @@ typedef union union4b { #define OBD_UPD_HARDFAULT 2 // update w/ hard fault class OnboardDisplay { + #ifdef RED_LED_REG DigitalPin pinRedLed; #endif @@ -865,6 +867,9 @@ class OnboardDisplay void MakeChar(uint8_t n, PGM_P bytes); public: + + static unsigned long lastBacklightChangeMillis ; + OnboardDisplay(); void Init(); @@ -937,6 +942,11 @@ class OnboardDisplay #endif // RGBLCD } void LcdSetBacklightColor(uint8_t c) { + static uint8_t lastColor = WHITE; + if (c != lastColor) { + lastBacklightChangeMillis = millis(); + lastColor = c; + } #ifdef RGBLCD if (IsLcdBacklightMono()) { if (c) c = WHITE; diff --git a/firmware/open_evse/rapi_proc.cpp b/firmware/open_evse/rapi_proc.cpp index e4a31bf7..ee0af98d 100644 --- a/firmware/open_evse/rapi_proc.cpp +++ b/firmware/open_evse/rapi_proc.cpp @@ -525,6 +525,20 @@ int EvseRapiProcessor::processCmd() } break; #endif // VOLTMETER + +#ifdef OEV6 + case 'R': //Relay2 enable + if (tokenCnt == 2) { + if ( (uint8_t)dtou32(tokens[1]) == 1 ) { + g_EvseController.Relay2Enable(1); + } else { + g_EvseController.Relay2Enable(0); + } + } + rc = 0; + break; +#endif //OEV6 + #ifdef DELAYTIMER case 'T': // timer if (tokenCnt == 5) {