From 708a8087b1f9623b84d2c3605062dfce85b0dab2 Mon Sep 17 00:00:00 2001 From: rljonesau Date: Fri, 5 Apr 2019 06:39:58 +1100 Subject: [PATCH] Consolidated new generated run states into protocol handler, new JSON for suspend mode --- Arduino/BTCDieselHeater/BTCDieselHeater.ino | 10 --- .../BTCDieselHeater/src/OLED/BasicScreen.cpp | 49 +++++++------- .../src/OLED/DetailedScreen.cpp | 66 ++++++++----------- .../BTCDieselHeater/src/Protocol/Protocol.cpp | 22 ++++++- .../BTCDieselHeater/src/Protocol/Protocol.h | 1 + .../BTCDieselHeater/src/Protocol/helpers.h | 1 - .../BTCDieselHeater/src/Utility/BTC_JSON.cpp | 6 +- 7 files changed, 78 insertions(+), 77 deletions(-) diff --git a/Arduino/BTCDieselHeater/BTCDieselHeater.ino b/Arduino/BTCDieselHeater/BTCDieselHeater.ino index acf73c4..6a1ba6d 100644 --- a/Arduino/BTCDieselHeater/BTCDieselHeater.ino +++ b/Arduino/BTCDieselHeater/BTCDieselHeater.ino @@ -1223,13 +1223,3 @@ bool isCyclicActive() return bUserON && (NVstore.getCyclicMode() != 0); } -int getRunStateEx() -{ - int heaterstate = getHeaterInfo().getRunState(); - if(heaterstate == 0) { - if(isCyclicActive()) { - heaterstate = 10; // special state for cyclic suspended - } - } - return heaterstate; -} diff --git a/Arduino/BTCDieselHeater/src/OLED/BasicScreen.cpp b/Arduino/BTCDieselHeater/src/OLED/BasicScreen.cpp index e9b27b7..93cf8d4 100644 --- a/Arduino/BTCDieselHeater/src/OLED/BasicScreen.cpp +++ b/Arduino/BTCDieselHeater/src/OLED/BasicScreen.cpp @@ -180,8 +180,10 @@ CBasicScreen::keyHandler(uint8_t event) // impossible with 5 way switch! uint8_t doubleKey = key_Down | key_Up; if((event & doubleKey) == doubleKey) { - if(reqThermoToggle()) + if(reqThermoToggle()) { _showSetMode = millis() + 2000; + NVstore.save(); + } else _reqOEMWarning(); } @@ -208,21 +210,18 @@ CBasicScreen::keyHandler(uint8_t event) } // hold CENTRE to turn ON or OFF if(event & key_Centre) { - if(getHeaterInfo().getRunState()) { - // running, request OFF + int runstate = getHeaterInfo().getRunStateEx(); + if(runstate) { // running, including cyclic mode idle if(repeatCount > 5) { - repeatCount = -2; // prevent double handling - requestOff(); + repeatCount = -1; + requestOff(); } } - else { + else { // standard idle state // standby, request ON if(repeatCount > 3) { repeatCount = -1; - if(isCyclicActive()) - requestOff(); // actually shut off cyclic mode if already in idle - else - requestOn(); + requestOn(); } } } @@ -264,7 +263,7 @@ CBasicScreen::keyHandler(uint8_t event) void CBasicScreen::showRunState() { - int runstate = getHeaterInfo().getRunState(); + int runstate = getHeaterInfo().getRunStateEx(); int errstate = getHeaterInfo().getErrState(); if(errstate) errstate--; // correct for +1 biased return value @@ -272,8 +271,8 @@ CBasicScreen::showRunState() static bool toggle = false; const char* toPrint = NULL; _display.setTextColor(WHITE, BLACK); - if(runstate >= 0 && runstate <= 8) { - if(((runstate == 0) || (runstate > 5)) && errstate) { +// if(runstate >= 0 && runstate <= 8) { + if(errstate && ((runstate == 0) || (runstate > 5))) { // flash error code char msg[16]; @@ -293,22 +292,18 @@ CBasicScreen::showRunState() } else { if(runstate) { - if(runstate < 5) toPrint = "Starting"; - else if(runstate == 5) toPrint = "Running"; - else if(isCyclicActive()) { - if(runstate > 5) toPrint = "Suspending..."; - } - else { - if(runstate == 8) toPrint = "Cooling"; - else toPrint = "Shutting down"; + toPrint = getHeaterInfo().getRunStateStr(); + // simplify starting states + switch(runstate) { + case 1: + case 2: + case 3: + case 4: + toPrint = "Starting"; + break; } } - else { - if(isCyclicActive()) { - toPrint = "Suspended"; - } - } - } + // } } if(toPrint) { // locate at bottom centre diff --git a/Arduino/BTCDieselHeater/src/OLED/DetailedScreen.cpp b/Arduino/BTCDieselHeater/src/OLED/DetailedScreen.cpp index 1af41b8..c5bffc8 100644 --- a/Arduino/BTCDieselHeater/src/OLED/DetailedScreen.cpp +++ b/Arduino/BTCDieselHeater/src/OLED/DetailedScreen.cpp @@ -81,8 +81,8 @@ CDetailedScreen::show() const char* c = String(getTemperatureSensor()).c_str(); - int runstate = getHeaterInfo().getRunState();//HtrFrame.getRunState(); - int errstate = getHeaterInfo().getErrState(); //HtrFrame.getErrState(); + int runstate = getHeaterInfo().getRunStateEx(); + int errstate = getHeaterInfo().getErrState(); if(errstate) errstate--; // correct for +1 biased return value long tDelta = millis() - _showTarget; @@ -106,7 +106,7 @@ CDetailedScreen::show() _animatePump = false; _animateGlow = false; - if(runstate) { + if(runstate != 0 && runstate != 10) { // not idle modes float power = getHeaterInfo().getGlowPlug_Power(); if(power > 1) { showGlowPlug(power); @@ -188,7 +188,8 @@ CDetailedScreen::keyHandler(uint8_t event) if(_keyRepeatCount >= 0) { _keyRepeatCount++; if(event & key_Centre) { - if(getHeaterInfo().getRunState()) { + int runstate = getHeaterInfo().getRunStateEx(); + if(runstate) { // running, including cyclic mode idle if(_keyRepeatCount > 5) { _keyRepeatCount = -1; // prevent double handling requestOff(); @@ -197,17 +198,17 @@ CDetailedScreen::keyHandler(uint8_t event) else { if(_keyRepeatCount > 3) { _keyRepeatCount = -1; // prevent double handling - if(isCyclicActive()) - requestOff(); - else - requestOn(); + requestOn(); } } } if(event & key_Down) { if(_keyRepeatCount > 1) { // held Down - togle thermo/fixed mode _keyRepeatCount = -1; // prevent double handling - if(reqThermoToggle()) _showTarget = millis() + 3500; + if(reqThermoToggle()) { + _showTarget = millis() + 3500; + NVstore.save(); + } else _reqOEMWarning(); } } @@ -398,36 +399,27 @@ CDetailedScreen::showRunState(int runstate, int errstate) const char* toPrint = NULL; int yPos = 25; _display.setTextColor(WHITE, BLACK); - if(runstate >= 0 && runstate <= 8) { - if(errstate && ((runstate == 0) || (runstate > 5))) { - // an error is present in idle or states beyond running, show it - // create an "E-XX" message to display - char msg[16]; - sprintf(msg, "E-%02d", errstate); - if(runstate > 5) - yPos -= _display.textHeight(); - _display.setCursor(_display.xCentre(), yPos); - // flash error code - toggle = !toggle; - if(toggle) - _display.printCentreJustified(msg); - else { - _display.printCentreJustified(" "); - } - yPos += _display.textHeight(); - toPrint = getHeaterInfo().getErrStateStr(); - } + if(errstate && ((runstate == 0) || (runstate > 5))) { + // an error is present in idle or states beyond running, show it + // create an "E-XX" message to display + char msg[16]; + sprintf(msg, "E-%02d", errstate); + if(runstate > 5) + yPos -= _display.textHeight(); + _display.setCursor(_display.xCentre(), yPos); + // flash error code + toggle = !toggle; + if(toggle) + _display.printCentreJustified(msg); else { - // no errors, heater normal - if(isCyclicActive()) { - if(runstate == 0) toPrint = "Suspended"; - else if(runstate > 5) toPrint = "Suspending..."; - else toPrint = getHeaterInfo().getRunStateStr(); - } - else { - toPrint = getHeaterInfo().getRunStateStr(); - } + _display.printCentreJustified(" "); } + yPos += _display.textHeight(); + toPrint = getHeaterInfo().getErrStateStr(); + } + else { + // no errors, heater normal + toPrint = getHeaterInfo().getRunStateStr(); } if(toPrint) { _printMenuText(_display.xCentre(), yPos, toPrint, false, eCentreJustify); diff --git a/Arduino/BTCDieselHeater/src/Protocol/Protocol.cpp b/Arduino/BTCDieselHeater/src/Protocol/Protocol.cpp index a312f62..635a555 100644 --- a/Arduino/BTCDieselHeater/src/Protocol/Protocol.cpp +++ b/Arduino/BTCDieselHeater/src/Protocol/Protocol.cpp @@ -323,6 +323,24 @@ CProtocol::setSystemVoltage(float fVal) Controller.OperatingVoltage = val; } + +int CProtocolPackage::getRunStateEx() const +{ + int runstate = getRunState(); + if(isCyclicActive()) { + // special states for cyclic suspended + switch(runstate) { + case 0: runstate = 10; break; // standby, awaiting temperature drop + case 7: runstate = 11; break; // shutting down due to cyclic trip + case 8: runstate = 12; break; // cooling due to cyclic trip + } + } + if(runstate == 2 && getPump_Actual() == 0) { // split runstate 2 - glow, then fuel + runstate = 9; + } + return runstate; +} + const char* Runstates [] PROGMEM = { " Stopped/Ready ", // 0 "Starting...", // 1 @@ -335,6 +353,8 @@ const char* Runstates [] PROGMEM = { "Cooling", // 8 "Heating glow plug", // 9 - interpreted state - actually runstate 2 with no pump action! "Suspended", // 10 - interpreted state - cyclic mode has suspended heater + "Suspending...", // 11 - interpreted state - cyclic mode is suspending heater + "Suspend cooling", // 12 - interpreted state - cyclic mode is suspending heater "Unknown run state" }; @@ -344,7 +364,7 @@ const char* CProtocolPackage::getRunStateStr() const { uint8_t runstate = getRunStateEx(); - UPPERLIMIT(runstate, 10); + UPPERLIMIT(runstate, 13); if(runstate == 2 && getPump_Actual() == 0) { // split runstate 2 - glow, then fuel runstate = 9; } diff --git a/Arduino/BTCDieselHeater/src/Protocol/Protocol.h b/Arduino/BTCDieselHeater/src/Protocol/Protocol.h index bcc1e98..689f6d2 100644 --- a/Arduino/BTCDieselHeater/src/Protocol/Protocol.h +++ b/Arduino/BTCDieselHeater/src/Protocol/Protocol.h @@ -217,6 +217,7 @@ class CProtocolPackage { public: void set(const CProtocol& htr, const CProtocol& ctl) { Heater = htr; Controller = ctl; }; int getRunState() const { return Heater.getRunState(); }; + int getRunStateEx() const; // extra support for cyclic thermostat mode const char* getRunStateStr() const; int getErrState() const; const char* getErrStateStr() const; diff --git a/Arduino/BTCDieselHeater/src/Protocol/helpers.h b/Arduino/BTCDieselHeater/src/Protocol/helpers.h index 39ff466..8d519c7 100644 --- a/Arduino/BTCDieselHeater/src/Protocol/helpers.h +++ b/Arduino/BTCDieselHeater/src/Protocol/helpers.h @@ -56,7 +56,6 @@ extern bool hasOEMLCDcontroller(); extern int getBlueWireStat(); extern int getSmartError(); extern bool isCyclicActive(); -extern int getRunStateEx(); diff --git a/Arduino/BTCDieselHeater/src/Utility/BTC_JSON.cpp b/Arduino/BTCDieselHeater/src/Utility/BTC_JSON.cpp index 8ecc907..e98865b 100644 --- a/Arduino/BTCDieselHeater/src/Utility/BTC_JSON.cpp +++ b/Arduino/BTCDieselHeater/src/Utility/BTC_JSON.cpp @@ -86,6 +86,9 @@ void interpretJsonCommand(char* pLine) else if(strcmp("FanMax", it->key) == 0) { setFanMax(it->value.as()); } + else if(strcmp("ThermostatOvertemp", it->key) == 0) { + NVstore.setCyclicMode(it->value.as()); + } else if(strcmp("ThermostatMethod", it->key) == 0) { NVstore.setThermostatMethodMode(it->value.as()); } @@ -178,7 +181,7 @@ bool makeJSONString(CModerator& moderator, char* opStr, int len) bSend |= moderator.addJson("TempMax", getHeaterInfo().getTemperature_Max(), root); bSend |= moderator.addJson("TempBody", getHeaterInfo().getTemperature_HeatExchg(), root); // bSend |= moderator.addJson("RunState", getHeaterInfo().getRunState(), root); - bSend |= moderator.addJson("RunState", getRunStateEx(), root); + bSend |= moderator.addJson("RunState", getHeaterInfo().getRunStateEx(), root); bSend |= moderator.addJson("RunString", getHeaterInfo().getRunStateStr(), root); // verbose it up! bSend |= moderator.addJson("ErrorState", getHeaterInfo().getErrState(), root ); bSend |= moderator.addJson("ErrorString", getHeaterInfo().getErrStateStrEx(), root); // verbose it up! @@ -215,6 +218,7 @@ bool makeJSONStringEx(CModerator& moderator, char* opStr, int len) bSend |= moderator.addJson("ThermostatMethod", NVstore.getThermostatMethodMode(), root); bSend |= moderator.addJson("ThermostatWindow", NVstore.getThermostatMethodWindow(), root); + bSend |= moderator.addJson("ThermostatOvertemp", NVstore.getCyclicMode(), root); if(bSend) { root.printTo(opStr, len);