2018-11-26 11:58:15 +00:00
|
|
|
/*
|
|
|
|
* This file is part of the "bluetoothheater" distribution
|
|
|
|
* (https://gitlab.com/mrjones.id.au/bluetoothheater)
|
|
|
|
*
|
|
|
|
* Copyright (C) 2018 Ray Jones <ray@mrjones.id.au>
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2019-01-18 07:09:40 +00:00
|
|
|
#include "PrimingScreen.h"
|
2018-12-16 07:34:39 +00:00
|
|
|
#include "KeyPad.h"
|
|
|
|
#include "../Protocol/helpers.h"
|
2019-02-06 20:24:22 +00:00
|
|
|
#include "../Utility/NVStorage.h"
|
2018-11-24 11:03:47 +00:00
|
|
|
|
2018-12-01 00:36:25 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
2019-01-18 07:09:40 +00:00
|
|
|
// CPrimingScreen
|
2018-12-01 00:36:25 +00:00
|
|
|
//
|
2018-12-20 06:29:00 +00:00
|
|
|
// This screen allows the temperature control mode to be selected and
|
2018-12-01 00:36:25 +00:00
|
|
|
// allows pump priming
|
|
|
|
//
|
|
|
|
///////////////////////////////////////////////////////////////////////////
|
2018-11-24 11:03:47 +00:00
|
|
|
|
|
|
|
|
2019-01-18 07:09:40 +00:00
|
|
|
CPrimingScreen::CPrimingScreen(C128x64_OLED& display, CScreenManager& mgr) : CScreenHeader(display, mgr)
|
2019-02-28 08:56:13 +00:00
|
|
|
{
|
|
|
|
_initUI();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CPrimingScreen::onSelect()
|
|
|
|
{
|
|
|
|
_stopPump();
|
|
|
|
_initUI();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CPrimingScreen::onExit()
|
|
|
|
{
|
|
|
|
_stopPump();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
CPrimingScreen::_initUI()
|
2018-11-25 04:45:17 +00:00
|
|
|
{
|
|
|
|
_PrimeStop = 0;
|
|
|
|
_PrimeCheck = 0;
|
|
|
|
_rowSel = 0;
|
|
|
|
_colSel = 0;
|
|
|
|
}
|
|
|
|
|
2019-01-18 23:06:12 +00:00
|
|
|
bool
|
2019-01-18 07:09:40 +00:00
|
|
|
CPrimingScreen::show()
|
2018-11-24 11:03:47 +00:00
|
|
|
{
|
2018-12-01 00:36:25 +00:00
|
|
|
CScreenHeader::show();
|
2018-11-25 04:45:17 +00:00
|
|
|
|
2018-11-24 11:03:47 +00:00
|
|
|
CRect extents;
|
2018-11-29 11:11:50 +00:00
|
|
|
|
2019-03-15 21:43:44 +00:00
|
|
|
int yPos = 53;
|
2019-03-15 23:54:50 +00:00
|
|
|
// show next/prev menu navigation line
|
2019-03-17 07:10:01 +00:00
|
|
|
switch(_rowSel) {
|
|
|
|
case 0:
|
|
|
|
_printMenuText(_display.xCentre(), yPos, " \021 \030Edit \020 ", _rowSel == 0, eCentreJustify);
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
case 2:
|
|
|
|
_display.drawFastHLine(0, 53, 128, WHITE);
|
|
|
|
_printMenuText(_display.xCentre(), 57, "\030\031 Sel \033\032 Adj", false, eCentreJustify);
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
_display.drawFastHLine(0, 53, 128, WHITE);
|
|
|
|
if(_colSel == 2) {
|
|
|
|
_printMenuText(_display.xCentre(), 57, "\033\030\031 Stop", false, eCentreJustify);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
_printMenuText(_display.xCentre(), 57, "\032 Start \031 Sel", false, eCentreJustify);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2018-11-24 11:03:47 +00:00
|
|
|
|
2018-12-01 00:36:25 +00:00
|
|
|
yPos = 40;
|
2018-11-25 04:45:17 +00:00
|
|
|
if(_rowSel == 1) {
|
2018-12-02 06:30:40 +00:00
|
|
|
// follow user desired setting, heater info is laggy
|
2018-12-07 04:18:24 +00:00
|
|
|
_printMenuText(border, yPos, "Thermostat", _colSel == 0);
|
|
|
|
_printMenuText(_display.width()-border, yPos, "Fixed Hz", _colSel == 1, eRightJustify);
|
2018-11-24 11:03:47 +00:00
|
|
|
}
|
|
|
|
else {
|
2018-12-02 06:30:40 +00:00
|
|
|
// follow actual heater settings
|
2019-03-24 05:48:03 +00:00
|
|
|
// int col = getHeaterInfo().isThermostat() ? 0 : 1;
|
|
|
|
int col = getThermostatModeActive() ? 0 : 1;
|
2018-12-01 00:36:25 +00:00
|
|
|
_printInverted(border, yPos, "Thermostat", col == 0);
|
|
|
|
_printInverted(_display.width()-border, yPos, "Fixed Hz", col == 1, eRightJustify);
|
2018-11-24 11:03:47 +00:00
|
|
|
}
|
2019-02-06 20:24:22 +00:00
|
|
|
yPos = 28;
|
|
|
|
if(_rowSel == 2) {
|
|
|
|
_printMenuText(border, yPos, "degC", _colSel == 0);
|
|
|
|
_printMenuText(_display.width()-border, yPos, "degF", _colSel == 1, eRightJustify);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
int col = NVstore.getDegFMode();
|
|
|
|
_printInverted(border, yPos, "degC", col == 0);
|
|
|
|
_printInverted(_display.width()-border, yPos, "degF", col == 1, eRightJustify);
|
|
|
|
}
|
2018-11-24 11:03:47 +00:00
|
|
|
|
|
|
|
// fuel pump priming menu
|
2019-02-06 20:24:22 +00:00
|
|
|
yPos = 16;
|
2019-03-17 07:10:01 +00:00
|
|
|
_printMenuText(border, yPos, "Pump");
|
2019-02-06 20:24:22 +00:00
|
|
|
if(_rowSel == 3) {
|
2019-03-17 07:10:01 +00:00
|
|
|
_printMenuText(40, yPos, "OFF", _colSel == 1);
|
2018-11-29 11:11:50 +00:00
|
|
|
if(_colSel != 2) {
|
2018-12-01 00:36:25 +00:00
|
|
|
if(!getHeaterInfo().getRunState()) { // prevent option if heater is running
|
2019-03-17 07:10:01 +00:00
|
|
|
_printMenuText(70, yPos, "ON"); // becomes Hz when actually priming
|
2018-11-29 11:11:50 +00:00
|
|
|
}
|
2018-11-24 11:03:47 +00:00
|
|
|
}
|
2018-11-29 11:11:50 +00:00
|
|
|
else {
|
2018-12-01 00:36:25 +00:00
|
|
|
float pumpHz = getHeaterInfo().getPump_Actual();
|
2018-11-29 11:11:50 +00:00
|
|
|
// recognise if heater has stopped pump, after an initial holdoff upon first starting
|
|
|
|
long tDelta = millis() - _PrimeCheck;
|
|
|
|
if(_PrimeCheck && tDelta > 0 && pumpHz < 0.1) {
|
2019-02-28 08:56:13 +00:00
|
|
|
_stopPump();
|
2018-11-29 11:11:50 +00:00
|
|
|
}
|
|
|
|
// test if time is up, stop priming if so
|
|
|
|
tDelta = millis() - _PrimeStop;
|
|
|
|
if(_PrimeStop && tDelta > 0) {
|
2019-02-28 08:56:13 +00:00
|
|
|
_stopPump();
|
2018-11-29 11:11:50 +00:00
|
|
|
}
|
2018-11-24 11:03:47 +00:00
|
|
|
|
2018-11-29 11:11:50 +00:00
|
|
|
if(_PrimeStop) {
|
|
|
|
char msg[16];
|
|
|
|
sprintf(msg, "%.1fHz", pumpHz);
|
2019-03-17 07:10:01 +00:00
|
|
|
_printMenuText(70, yPos, msg, true);
|
2018-11-29 11:11:50 +00:00
|
|
|
}
|
2018-11-24 11:03:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-18 23:06:12 +00:00
|
|
|
return true;
|
2018-11-24 11:03:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-01-18 23:06:12 +00:00
|
|
|
bool
|
2019-01-18 07:09:40 +00:00
|
|
|
CPrimingScreen::keyHandler(uint8_t event)
|
2018-11-24 11:03:47 +00:00
|
|
|
{
|
2018-12-01 00:36:25 +00:00
|
|
|
|
2018-11-24 11:03:47 +00:00
|
|
|
if(event & keyPressed) {
|
|
|
|
// press LEFT
|
|
|
|
if(event & key_Left) {
|
2018-11-25 04:45:17 +00:00
|
|
|
switch(_rowSel) {
|
2018-11-24 11:03:47 +00:00
|
|
|
case 0:
|
2019-03-15 21:43:44 +00:00
|
|
|
_ScreenManager.prevMenu();
|
2018-11-24 11:03:47 +00:00
|
|
|
break;
|
|
|
|
case 1:
|
2018-11-25 04:45:17 +00:00
|
|
|
_colSel = 0;
|
2018-11-24 11:03:47 +00:00
|
|
|
setThermostatMode(1);
|
2019-03-24 05:48:03 +00:00
|
|
|
saveNV();
|
2018-11-24 11:03:47 +00:00
|
|
|
break;
|
|
|
|
case 2:
|
2019-02-06 20:24:22 +00:00
|
|
|
_colSel = 0;
|
|
|
|
NVstore.setDegFMode(0);
|
|
|
|
break;
|
|
|
|
case 3:
|
2018-11-25 04:45:17 +00:00
|
|
|
_colSel = 1;
|
2018-11-24 11:03:47 +00:00
|
|
|
break;
|
2019-02-06 20:24:22 +00:00
|
|
|
case 4: break;
|
2018-11-24 11:03:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
// press RIGHT
|
|
|
|
if(event & key_Right) {
|
2018-11-25 04:45:17 +00:00
|
|
|
switch(_rowSel) {
|
2018-11-24 11:03:47 +00:00
|
|
|
case 0:
|
2019-03-15 21:43:44 +00:00
|
|
|
_ScreenManager.nextMenu();
|
2018-11-24 11:03:47 +00:00
|
|
|
break;
|
|
|
|
case 1:
|
2018-11-25 04:45:17 +00:00
|
|
|
_colSel = 1;
|
2018-11-24 11:03:47 +00:00
|
|
|
setThermostatMode(0);
|
2019-03-24 05:48:03 +00:00
|
|
|
saveNV();
|
2018-11-24 11:03:47 +00:00
|
|
|
break;
|
|
|
|
case 2:
|
2019-02-06 20:24:22 +00:00
|
|
|
_colSel = 1;
|
|
|
|
NVstore.setDegFMode(1);
|
|
|
|
break;
|
|
|
|
case 3:
|
2018-12-01 00:36:25 +00:00
|
|
|
if(!getHeaterInfo().getRunState())
|
2018-11-25 04:45:17 +00:00
|
|
|
_colSel = 2;
|
2018-11-24 11:03:47 +00:00
|
|
|
break;
|
2019-02-06 20:24:22 +00:00
|
|
|
case 4: break;
|
2018-11-24 11:03:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
// press UP
|
|
|
|
if(event & key_Up) {
|
2018-12-20 06:29:00 +00:00
|
|
|
if(hasOEMcontroller())
|
|
|
|
_reqOEMWarning();
|
|
|
|
else {
|
|
|
|
_rowSel++;
|
2019-02-06 20:24:22 +00:00
|
|
|
UPPERLIMIT(_rowSel, 3);
|
|
|
|
if(_rowSel == 3)
|
2018-12-20 06:29:00 +00:00
|
|
|
_colSel = 1; // select OFF upon entry to priming menu
|
2019-02-06 20:24:22 +00:00
|
|
|
if(_rowSel == 2)
|
|
|
|
_colSel = NVstore.getDegFMode();
|
2018-12-20 06:29:00 +00:00
|
|
|
if(_rowSel == 1)
|
2019-03-24 05:48:03 +00:00
|
|
|
// _colSel = getHeaterInfo().isThermostat() ? 0 : 1;
|
|
|
|
_colSel = getThermostatModeActive() ? 0 : 1;
|
2018-12-20 06:29:00 +00:00
|
|
|
}
|
2018-11-24 11:03:47 +00:00
|
|
|
}
|
|
|
|
// press DOWN
|
|
|
|
if(event & key_Down) {
|
2018-11-25 04:45:17 +00:00
|
|
|
_rowSel--;
|
|
|
|
LOWERLIMIT(_rowSel, 0);
|
|
|
|
_colSel = 0;
|
2018-12-02 06:30:40 +00:00
|
|
|
if(_rowSel == 1)
|
2019-03-24 05:48:03 +00:00
|
|
|
// _colSel = getHeaterInfo().isThermostat() ? 0 : 1;
|
|
|
|
_colSel = getThermostatModeActive() ? 0 : 1;
|
2019-02-06 20:24:22 +00:00
|
|
|
if(_rowSel == 2)
|
|
|
|
_colSel = NVstore.getDegFMode();
|
2018-11-24 11:03:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// check if fuel priming was selected
|
2019-02-06 20:24:22 +00:00
|
|
|
if(_rowSel == 3 && _colSel == 2) {
|
2018-11-24 11:03:47 +00:00
|
|
|
reqPumpPrime(true);
|
2018-11-25 04:45:17 +00:00
|
|
|
_PrimeStop = millis() + 150000; // allow 2.5 minutes - much the same as the heater itself cuts out at
|
|
|
|
_PrimeCheck = millis() + 3000; // holdoff upon start before testing for heater shutting off pump
|
2018-11-24 11:03:47 +00:00
|
|
|
}
|
|
|
|
else {
|
2019-02-28 08:56:13 +00:00
|
|
|
_stopPump();
|
2018-11-24 11:03:47 +00:00
|
|
|
}
|
|
|
|
|
2018-11-29 11:11:50 +00:00
|
|
|
_ScreenManager.reqUpdate();
|
2018-11-24 11:03:47 +00:00
|
|
|
}
|
2019-01-18 23:06:12 +00:00
|
|
|
return true;
|
2018-11-24 11:03:47 +00:00
|
|
|
}
|
|
|
|
|
2018-11-25 04:45:17 +00:00
|
|
|
void
|
2019-02-28 08:56:13 +00:00
|
|
|
CPrimingScreen::_stopPump()
|
2018-11-24 11:03:47 +00:00
|
|
|
{
|
|
|
|
reqPumpPrime(false);
|
2018-11-25 04:45:17 +00:00
|
|
|
_PrimeCheck = 0;
|
|
|
|
_PrimeStop = 0;
|
|
|
|
if(_colSel == 2)
|
|
|
|
_colSel = 1;
|
2018-11-24 11:03:47 +00:00
|
|
|
}
|