Timer Temperature support added

Desired temperature requests are now managed via TimerManager to allow timer override of desired temperature.
Bug fix: crash checking for new firmware if no STA connection
Suppression of GPIO JSON if no or limited GPIO capability is installed.
This commit is contained in:
Ray Jones 2020-03-29 13:59:13 +11:00
parent 87b1704335
commit 8b8aaf0024
6 changed files with 104 additions and 41 deletions

View File

@ -396,12 +396,17 @@ void
esp32FOTA::execAsyncHTTPcheck()
{
_newVersion = 0;
if(_versionTest.readyState() == 0 || _versionTest.readyState() == 4) {
Serial.println("Querying firmware update server");
_versionTest.onReadyStateChange(FOTA_PollCallback, this);
_versionTest.onBuildHeaders(NULL);
_versionTest.onData(NULL);
_versionTest.open("GET", _checkURL.c_str());
if ((WiFi.status() == WL_CONNECTED)) {
if(_versionTest.readyState() == 0 || _versionTest.readyState() == 4) {
Serial.println("Querying firmware update server");
_versionTest.onReadyStateChange(FOTA_PollCallback, this);
_versionTest.onBuildHeaders(NULL);
_versionTest.onData(NULL);
_versionTest.open("GET", _checkURL.c_str());
}
}
else {
Serial.println("Firmware update check skipped = no STA");
}
}

View File

@ -117,6 +117,7 @@
#include <nvs.h>
#include "Utility/MQTTsetup.h"
#include <FreeRTOS.h>
#include "RTC/TimerManager.h"
// SSID & password now stored in NV storage - these are still the default values.
//#define AP_SSID "Afterburner"
@ -1128,7 +1129,8 @@ bool reqDemand(uint8_t newDemand, bool save)
// set and save the demand to NV storage
// note that we now maintain fixed Hz and Thermostat set points seperately
if(getThermostatModeActive()) {
RTC_Store.setDesiredTemp(newDemand);
// RTC_Store.setDesiredTemp(newDemand);
CTimerManager::setWorkingTemperature(newDemand);
}
else {
RTC_Store.setDesiredPump(newDemand);
@ -1142,7 +1144,8 @@ bool reqDemandDelta(int delta)
{
uint8_t newDemand;
if(getThermostatModeActive()) {
newDemand = RTC_Store.getDesiredTemp() + delta;
// newDemand = RTC_Store.getDesiredTemp() + delta;
newDemand = CTimerManager::getWorkingTemperature() + delta;
}
else {
newDemand = RTC_Store.getDesiredPump() + delta;
@ -1247,7 +1250,8 @@ void forceBootInit()
uint8_t getDemandDegC()
{
return RTC_Store.getDesiredTemp();
return CTimerManager::getWorkingTemperature();
// return RTC_Store.getDesiredTemp();
}
void setDemandDegC(uint8_t val)
@ -1255,7 +1259,8 @@ void setDemandDegC(uint8_t val)
uint8_t max = DefaultBTCParams.getTemperature_Max();
uint8_t min = DefaultBTCParams.getTemperature_Min();
BOUNDSLIMIT(val, min, max);
RTC_Store.setDesiredTemp(val);
// RTC_Store.setDesiredTemp(val);
CTimerManager::setWorkingTemperature(val);
}
uint8_t getDemandPump()
@ -1271,7 +1276,8 @@ float getTemperatureDesired()
}
else {
if(getThermostatModeActive())
return RTC_Store.getDesiredTemp();
// return RTC_Store.getDesiredTemp();
return CTimerManager::getWorkingTemperature();
else
return RTC_Store.getDesiredPump();
}

View File

@ -83,7 +83,7 @@ CSetTimerScreen::show()
else {
// start
xPos = 18;
yPos = 18;
yPos = 16;
_printMenuText(xPos, yPos, "On", false, eRightJustify);
_printMenuText(xPos+17, yPos, ":");
xPos += 6;
@ -95,7 +95,7 @@ CSetTimerScreen::show()
// stop
xPos = 82;
yPos = 18;
yPos = 16;
_printMenuText(xPos, yPos, "Off", false, eRightJustify);
_printMenuText(xPos+17, yPos, ":");
xPos += 6;
@ -110,13 +110,26 @@ CSetTimerScreen::show()
_printEnabledTimers();
xPos = _display.width() - border;
yPos = 35;
yPos = 28;
if(_timerInfo.repeat)
msg = "Repeat";
else
msg = "Once";
_printMenuText(xPos, yPos, msg, _rowSel==1 && _colSel==5, eRightJustify);
xPos = 18;
yPos = 40;
float fTemp = _timerInfo.temperature;
if(NVstore.getUserSettings().degF) {
fTemp = fTemp * 9 / 5 + 32;
sprintf(str, "%.0f`F", fTemp);
}
else {
sprintf(str, "%.0f`C", fTemp);
}
_printMenuText(_display.xCentre(), yPos, str, _rowSel==1 && _colSel==6, eCentreJustify);
// navigation line
yPos = 53;
xPos = _display.xCentre();
@ -160,7 +173,7 @@ CSetTimerScreen::keyHandler(uint8_t event)
case 1:
// select previous field
_colSel--;
WRAPLOWERLIMIT(_colSel, 0, 5);
WRAPLOWERLIMIT(_colSel, 0, 6);
break;
case 2:
// select previous day
@ -178,7 +191,7 @@ CSetTimerScreen::keyHandler(uint8_t event)
case 1:
// select next field
_colSel++;
WRAPUPPERLIMIT(_colSel, 5, 0);
WRAPUPPERLIMIT(_colSel, 6, 0);
break;
case 2:
// select next day
@ -335,6 +348,10 @@ CSetTimerScreen::_adjust(int dir)
case 5:
_timerInfo.repeat = !_timerInfo.repeat;
break;
case 6:
_timerInfo.temperature += dir;
BOUNDSLIMIT(_timerInfo.temperature, 8, 35);
break;
}
}
@ -343,7 +360,7 @@ CSetTimerScreen::_printEnabledTimers()
{
const int dayWidth = 10;
int xPos = border;
int yPos = 35;
int yPos = 28;
if(_timerInfo.enabled == 0x00 && _rowSel != 2) {
_printMenuText(xPos, yPos, "Disabled", _colSel==4);

View File

@ -44,6 +44,7 @@ int CTimerManager::_activeTimer = 0;
int CTimerManager::_activeDow = 0;
int CTimerManager::_nextTimer = 0;
int CTimerManager::_nextStart = 0;
uint8_t CTimerManager::_workingTemperature = 22;
bool CTimerManager::_timerChanged = false;
#define SET_MAPS() { \
@ -265,17 +266,23 @@ CTimerManager::manageTime(int _hour, int _minute, int _dow)
}
if(newID) {
DebugPort.println("Start of timer interval, starting heater");
sTimer timer;
// get timer settings
int ID = (newID & 0xf) - 1;
NVstore.getTimerInfo(ID, timer);
_workingTemperature = timer.temperature;
DebugPort.printf("Start of timer interval, starting heater @ %dC\r\n", _workingTemperature);
requestOn();
_activeDow = dow; // dow when timer interval start was detected
retval = 1;
}
else {
DebugPort.println("End of timer interval, stopping heater");
// if(!RTC_Store.getFrostOn() && !RTC_Store.getCyclicEngaged())
if(!RTC_Store.getFrostOn())
requestOff();
retval = 2;
_workingTemperature = RTC_Store.getDesiredTemp();
DebugPort.printf("End of timer interval, stopping heater & %dC\r\n", _workingTemperature);
}
_activeTimer = newID;
}
@ -414,3 +421,22 @@ CTimerManager::createOneShotMap(sTimer& timer, uint16_t* pTimerMap, uint16_t* pT
return false;
}
// Concept of timer working temperature is that when a timer runs, it installs
// the programmed temeprature for that timer as the new set point.
// When the timer stops, it reverts to the usual user set temperature.
//
// BUT, if a timer is running, the working temperature is updated with the new demand
// and the user temperature is also changed accordingly.
// The programmed timer temeprature is not altered and wil lrecur in the future when that time runs.
uint8_t
CTimerManager::getWorkingTemperature()
{
return _workingTemperature;
}
void
CTimerManager::setWorkingTemperature(uint8_t newDegC)
{
_workingTemperature = newDegC;
RTC_Store.setDesiredTemp(newDegC);
}

View File

@ -52,7 +52,10 @@ public:
static void getTimer(int idx, sTimer& timerInfo);
static int setTimer(sTimer& timerInfo);
static bool hasTimerChanged() { return _timerChanged; };
static uint8_t getWorkingTemperature();
static void setWorkingTemperature(uint8_t newDegC);
private:
static uint8_t _workingTemperature;
static int _activeTimer;
static int _activeDow;
static int _prevState;

View File

@ -37,6 +37,7 @@
#include <string.h>
#include "HourMeter.h"
#include "TempSense.h"
#include "BoardDetect.h"
extern CModerator MQTTmoderator;
@ -285,30 +286,35 @@ bool makeJSONStringGPIO(CModerator& moderator, char* opStr, int len)
bool bSend = false; // reset should send flag
sGPIO info;
getGPIOinfo(info);
if(getBoardRevision() != 0 && getBoardRevision() != BRD_V2_NOGPIO) { // has GPIO support
bSend |= moderator.addJson("GPin1", info.inState[0], root);
bSend |= moderator.addJson("GPin2", info.inState[1], root);
bSend |= moderator.addJson("GPout1", info.outState[0], root);
bSend |= moderator.addJson("GPout2", info.outState[1], root);
bSend |= moderator.addJson("GPanlg", info.algVal * 100 / 4096, root);
bSend |= moderator.addJson("GPmodeIn1", GPIOin1Names[info.in1Mode], root);
bSend |= moderator.addJson("GPmodeIn2", GPIOin2Names[info.in2Mode], root);
bSend |= moderator.addJson("GPmodeOut1", GPIOout1Names[info.out1Mode], root);
bSend |= moderator.addJson("GPmodeOut2", GPIOout2Names[info.out2Mode], root);
bSend |= moderator.addJson("GPoutThr1", NVstore.getUserSettings().GPIO.thresh[0], root);
bSend |= moderator.addJson("GPoutThr2", NVstore.getUserSettings().GPIO.thresh[1], root);
bSend |= moderator.addJson("GPmodeAnlg", GPIOalgNames[info.algMode], root);
bSend |= moderator.addJson("ExtThermoTmout", (uint32_t)NVstore.getUserSettings().ExtThermoTimeout, root);
const char* stop = getExternalThermostatHoldTime();
if(stop)
bSend |= moderator.addJson("ExtThermoStop", stop, root);
else
bSend |= moderator.addJson("ExtThermoStop", "Off", root);
sGPIO info;
getGPIOinfo(info);
if(bSend) {
root.printTo(opStr, len);
bSend |= moderator.addJson("GPin1", info.inState[0], root);
bSend |= moderator.addJson("GPin2", info.inState[1], root);
bSend |= moderator.addJson("GPout1", info.outState[0], root);
bSend |= moderator.addJson("GPout2", info.outState[1], root);
bSend |= moderator.addJson("GPmodeIn1", GPIOin1Names[info.in1Mode], root);
bSend |= moderator.addJson("GPmodeIn2", GPIOin2Names[info.in2Mode], root);
bSend |= moderator.addJson("GPmodeOut1", GPIOout1Names[info.out1Mode], root);
bSend |= moderator.addJson("GPmodeOut2", GPIOout2Names[info.out2Mode], root);
bSend |= moderator.addJson("GPoutThr1", NVstore.getUserSettings().GPIO.thresh[0], root);
bSend |= moderator.addJson("GPoutThr2", NVstore.getUserSettings().GPIO.thresh[1], root);
if(getBoardRevision() != BRD_V2_GPIO_NOALG && getBoardRevision() != BRD_V3_GPIO_NOALG) { // has GPIO support
bSend |= moderator.addJson("GPanlg", info.algVal * 100 / 4096, root);
bSend |= moderator.addJson("GPmodeAnlg", GPIOalgNames[info.algMode], root);
}
bSend |= moderator.addJson("ExtThermoTmout", (uint32_t)NVstore.getUserSettings().ExtThermoTimeout, root);
const char* stop = getExternalThermostatHoldTime();
if(stop)
bSend |= moderator.addJson("ExtThermoStop", stop, root);
else
bSend |= moderator.addJson("ExtThermoStop", "Off", root);
if(bSend) {
root.printTo(opStr, len);
}
}
return bSend;