Added Fuel Reset GPIO input option

This commit is contained in:
Ray Jones 2020-03-31 19:46:25 +11:00
parent 8ec438e02a
commit 9c100f1954
10 changed files with 79 additions and 32 deletions

View File

@ -1073,6 +1073,7 @@ bool validateFrame(const CProtocol& frame, const char* name)
int requestOn(bool checkTemp)
{
DebugPort.println("Start Request!");
bool fuelOK = 2 != SmartError.checkfuelUsage();
if(!fuelOK) {
return -4;
@ -1101,6 +1102,7 @@ int requestOn(bool checkTemp)
void requestOff()
{
DebugPort.println("Stop Request!");
heaterOff();
RTC_Store.setCyclicEngaged(false); // for cyclic mode
RTC_Store.setFrostOn(false); // cancel active frost mode

View File

@ -232,7 +232,7 @@ CDetailedScreen::keyHandler(uint8_t event)
}
}
if(event & key_Down) {
if(_keyRepeatCount > 1) { // held Down - togle thermo/fixed mode
if(_keyRepeatCount > 1) { // held Down - toggle thermo/fixed mode
_keyRepeatCount = -1; // prevent double handling
if(reqThermoToggle()) {
_showTarget = millis() + 3500;

View File

@ -90,7 +90,7 @@ CGPIOInfoScreen::animate()
}
#if USE_JTAG == 0
//CANNOT USE GPIO WITH JTAG DEBUG
_drawBitmap(40, 16, GPIOin.getState(0) ? CloseIconInfo : OpenIconInfo);
_drawBitmap(42, 16, GPIOin.getState(0) ? CloseIconInfo : OpenIconInfo);
#endif
switch(NVstore.getUserSettings().GPIO.in2Mode) {
@ -103,10 +103,14 @@ CGPIOInfoScreen::animate()
case CGPIOin2::Thermostat:
_printMenuText(23, 27, "\352T");
break;
case CGPIOin2::FuelReset:
_drawBitmap(20, 26, BowserIconInfo);
_printMenuText(32, 30, "0");
break;
}
#if USE_JTAG == 0
//CANNOT USE GPIO WITH JTAG DEBUG
_drawBitmap(40, 28, GPIOin.getState(1) ? CloseIconInfo : OpenIconInfo);
_drawBitmap(42, 28, GPIOin.getState(1) ? CloseIconInfo : OpenIconInfo);
#endif
int bulbmode = 0;

View File

@ -94,11 +94,11 @@ CGPIOSetupScreen::show()
{
const char* msgText = NULL;
switch(_GPIOparams.in1Mode) {
case CGPIOin1::Disabled: msgText = " --- "; break;
case CGPIOin1::Start: msgText = "Start"; break;
case CGPIOin1::Run: msgText = "Run "; break;
case CGPIOin1::StartStop: msgText = animated ? "Start" : "Stop "; break;
case CGPIOin1::Stop: msgText = "Stop "; break;
case CGPIOin1::Disabled: msgText = " --- "; break;
case CGPIOin1::Start: msgText = "Start "; break;
case CGPIOin1::Run: msgText = "Run "; break;
case CGPIOin1::StartStop: msgText = animated ? "Start " : "Stop "; break;
case CGPIOin1::Stop: msgText = "Stop "; break;
}
if(msgText)
_printMenuText(Column1, Line3, msgText, _rowSel == 4);
@ -108,9 +108,10 @@ CGPIOSetupScreen::show()
{
const char* msgText = NULL;
switch(_GPIOparams.in2Mode) {
case CGPIOin2::Disabled: msgText = " --- "; break;
case CGPIOin2::Stop: msgText = "Stop "; break;
case CGPIOin2::Thermostat: msgText = "\352T"; break;
case CGPIOin2::Disabled: msgText = " --- "; break;
case CGPIOin2::Stop: msgText = "Stop "; break;
case CGPIOin2::Thermostat: msgText = "\352T "; break;
case CGPIOin2::FuelReset: msgText = "Fuel 0"; break;
}
if(msgText)
_printMenuText(Column1, Line2, msgText, _rowSel == 2);
@ -225,6 +226,7 @@ CGPIOSetupScreen::animate()
case CGPIOin2::Disabled: pMsg = " Input 2: DISABLED. "; break;
case CGPIOin2::Stop: pMsg = " Input 2: Stops heater upon closure. "; break;
case CGPIOin2::Thermostat: pMsg = " Input 2: External thermostat. Max fuel when closed, min fuel when open. "; break;
case CGPIOin2::FuelReset: pMsg = " Input 2: 1 second hold resets fuel usage counter. "; break;
}
if(pMsg)
_scrollMessage(56, pMsg, _scrollChar);
@ -461,7 +463,7 @@ CGPIOSetupScreen::_adjust(int dir)
case 2:
tVal = _GPIOparams.in2Mode;
tVal += dir;
WRAPLIMITS(tVal, 0, 2);
WRAPLIMITS(tVal, 0, 3);
_GPIOparams.in2Mode = (CGPIOin2::Modes)tVal;
break;
case 3:

View File

@ -42,7 +42,8 @@ const char* GPIOin1Names[] = {
const char* GPIOin2Names[] = {
"Disabled",
"Mom Off",
"Ext Thermo"
"Ext Thermo",
"Fuel Reset"
};
@ -98,11 +99,23 @@ CGPIOin1::manage(bool active)
}
}
// mode where you can start the heater with a short press
// stop the heater with a long press
void
CGPIOin1::_doStart(bool active)
{
if(active) {
requestOn();
if(active && !_prevActive) {
_holdoff = millis();
}
if(!active && _prevActive) {
unsigned long tDelta = millis() - _holdoff;
if(tDelta > 50) {
if(tDelta < 1500) // longer or shorter than 1.5 seconds?
requestOn(); // short press is start
else
requestOff(); // long press is stop
}
}
}
@ -144,7 +157,7 @@ CGPIOin2::CGPIOin2()
{
_Mode = Disabled;
_prevActive = false;
_OffHoldoff = 0;
_holdoff = 0;
}
void
@ -165,7 +178,9 @@ CGPIOin2::manage(bool active)
case Disabled: break;
case Stop: _doStop(active); break;
case Thermostat: _doThermostat(active); break;
case FuelReset: _doFuelReset(active); break;
}
_prevActive = active;
}
void
@ -175,7 +190,6 @@ CGPIOin2::_doStop(bool active)
if(active) {
requestOff();
}
_prevActive = active;
}
}
@ -191,11 +205,11 @@ CGPIOin2::_doThermostat(bool active)
requestOn(); // request heater to start upon closure of thermostat input
}
if(!active && _prevActive) { // initial switch off of thermostat input
_OffHoldoff = (millis() + NVstore.getUserSettings().ExtThermoTimeout) | 1;
_holdoff = (millis() + NVstore.getUserSettings().ExtThermoTimeout) | 1;
DebugPort.printf("thermostat contact opened - will stop in %ldms\r\n", NVstore.getUserSettings().ExtThermoTimeout);
}
if(active) {
_OffHoldoff = 0;
_holdoff = 0;
int runstate = getHeaterInfo().getRunStateEx();
int errstate = getHeaterInfo().getErrState();
if(runstate == 0 && errstate == 0) {
@ -203,27 +217,47 @@ CGPIOin2::_doThermostat(bool active)
}
}
else {
if(_OffHoldoff) {
long tDelta = millis() - _OffHoldoff;
if(_holdoff) {
long tDelta = millis() - _holdoff;
if(tDelta >= 0) {
DebugPort.println("stopping heater due to thermostat contact being open for required dwell");
requestOff(); // request heater to stop after thermostat input has stayed open for interval
_OffHoldoff = 0;
_holdoff = 0;
}
}
}
_prevActive = active;
}
// handling actually performed at Tx Manage for setting the fuel rate
}
void
CGPIOin2::_doFuelReset(bool active)
{
if(active) {
if(!_prevActive) {
_holdoff = millis() + 1000; // require 1 second hold to reset fuel gauge
}
if(_holdoff) {
long tDelta = millis() - _holdoff;
if(tDelta > 0) { // 1 second has expired
resetFuelGauge();
_holdoff = 0;
}
}
}
else {
_holdoff = 0; // ensure fresh
}
}
const char*
CGPIOin2:: getExtThermTime()
{
if((_OffHoldoff == 0) || (NVstore.getUserSettings().ThermostatMethod != 3) || (NVstore.getUserSettings().ExtThermoTimeout == 0))
if((_holdoff == 0) || (NVstore.getUserSettings().ThermostatMethod != 3) || (NVstore.getUserSettings().ExtThermoTimeout == 0))
return NULL;
long tDelta = _OffHoldoff - millis();
long tDelta = _holdoff - millis();
if(tDelta < 0)
return NULL;

View File

@ -52,6 +52,7 @@ public:
private:
Modes _Mode;
bool _prevActive;
unsigned long _holdoff;
void _doStart(bool active);
void _doRun(bool active);
void _doStartStop(bool active);
@ -63,7 +64,8 @@ public:
enum Modes {
Disabled,
Stop, // input 2 closure stops heater
Thermostat // input 2 used to max/min heater if closed/open
Thermostat, // input 2 used to max/min heater if closed/open
FuelReset
};
CGPIOin2();
void setMode(Modes mode) { _Mode = mode; };
@ -74,9 +76,10 @@ public:
private:
Modes _Mode;
bool _prevActive;
unsigned long _OffHoldoff;
unsigned long _holdoff;
void _doStop(bool active);
void _doThermostat(bool active);
void _doFuelReset(bool active);
};
class CGPIOin {

View File

@ -219,7 +219,7 @@ bool makeJSONStringEx(CModerator& moderator, char* opStr, int len)
bSend |= moderator.addJson("CyclicOn", NVstore.getUserSettings().cyclic.Start, root); // threshold of under temp for cyclic mode
bSend |= moderator.addJson("FrostOn", NVstore.getUserSettings().FrostOn, root); // temp drops below this, auto start - 0 = disable
bSend |= moderator.addJson("FrostRise", NVstore.getUserSettings().FrostRise, root); // temp rise in frost mode till auto off
bSend |= moderator.addJson("PumpCount", RTC_Store.getFuelGauge(), root, 10000); // running count of pump strokes
bSend |= moderator.addJson("PumpCount", RTC_Store.getFuelGauge(), root, 10000); // running count of pump strokes
bSend |= moderator.addJson("PumpCal", NVstore.getHeaterTuning().pumpCal, root); // mL/stroke
bSend |= moderator.addJson("LowVoltCutout", NVstore.getHeaterTuning().getLVC(), root); // low voltage cutout
if(getTempSensor().getBME280().getCount()) {

View File

@ -41,11 +41,13 @@ CFuelGauge::init(float fuelUsed)
_pumpStrokes = fuelUsed;
DebugPort.printf("Initialising fuel gauge with %.2f strokes\r\n", _pumpStrokes);
_lastStoredVal = _pumpStrokes;
RTC_Store.setFuelGauge(_pumpStrokes); // uses RTC registers to store this
}
void
CFuelGauge::reset()
{
DebugPort.println("resetting fuel gauge");
_pumpStrokes = 0;
_lastStoredVal = _pumpStrokes;
RTC_Store.setFuelGauge(_pumpStrokes); // uses RTC registers to store this

View File

@ -469,8 +469,8 @@ sUserSettings::load()
preferences.putUChar("GPIOin1Mode", GPIO.in1Mode); // set new
preferences.putUChar("GPIOin2Mode", GPIO.in2Mode); // set new
}
validatedLoad("GPIOin1Mode", tVal, 0, u8inBounds, 0, 3); GPIO.in1Mode = (CGPIOin1::Modes)tVal;
validatedLoad("GPIOin2Mode", tVal, 0, u8inBounds, 0, 2); GPIO.in2Mode = (CGPIOin2::Modes)tVal;
validatedLoad("GPIOin1Mode", tVal, 0, u8inBounds, 0, 4); GPIO.in1Mode = (CGPIOin1::Modes)tVal;
validatedLoad("GPIOin2Mode", tVal, 0, u8inBounds, 0, 3); GPIO.in2Mode = (CGPIOin2::Modes)tVal;
validatedLoad("GPIOoutMode", tVal, 0, u8inBounds, 0, 255);
if(tVal <= 2) {
// migrate old GPIO output mode

View File

@ -445,12 +445,12 @@ void DecodeCmd(const char* cmd, String& payload)
else if(strcmp("LoadWebContent", cmd) == 0) {
getWebContent(true);
}
/* // TESTO hook - make sure removed for production
// TESTO hook - make sure removed for production
else if(strcmp("testo", cmd) == 0) {
val = payload.toInt();
FuelGauge.init(val);
DebugPort.printf("Set Fuel usage to %d => %f\r\n", val, FuelGauge.Used_mL());
}*/
}
}
void setHoldoff(unsigned long& holdoff, unsigned long period)