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/>.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2018-11-24 11:03:47 +00:00
|
|
|
#include "128x64OLED.h"
|
|
|
|
#include "display.h"
|
|
|
|
#include "KeyPad.h"
|
|
|
|
#include "helpers.h"
|
|
|
|
#include "Screen3.h"
|
|
|
|
|
|
|
|
const int border = 3;
|
|
|
|
const int radius = 4;
|
|
|
|
const int Row[] = { 52, 40, 28, 16 } ;
|
|
|
|
const int Col[] = { border, 70, 100};
|
2018-11-27 10:44:47 +00:00
|
|
|
const char* Label0 = "<- ->";
|
2018-11-24 11:03:47 +00:00
|
|
|
const char* Label1[] = { "Thermostat",
|
|
|
|
"Fixed Hz" };
|
|
|
|
const char* Label2[] = { "Prime pump",
|
|
|
|
"OFF",
|
|
|
|
"ON" };
|
|
|
|
|
|
|
|
|
2018-11-25 04:45:17 +00:00
|
|
|
CScreen3::CScreen3(C128x64_OLED& display, CScreenManager& mgr) : CScreen(display, mgr)
|
|
|
|
{
|
|
|
|
_PrimeStop = 0;
|
|
|
|
_PrimeCheck = 0;
|
|
|
|
_rowSel = 0;
|
|
|
|
_colSel = 0;
|
|
|
|
}
|
|
|
|
|
2018-11-24 11:03:47 +00:00
|
|
|
|
2018-11-25 04:45:17 +00:00
|
|
|
void
|
|
|
|
CScreen3::show(const CProtocol& CtlFrame, const CProtocol& HtrFrame)
|
2018-11-24 11:03:47 +00:00
|
|
|
{
|
2018-11-25 04:45:17 +00:00
|
|
|
CScreen::show(CtlFrame, HtrFrame);
|
|
|
|
|
2018-11-24 11:03:47 +00:00
|
|
|
CRect extents;
|
2018-11-29 11:11:50 +00:00
|
|
|
|
|
|
|
// show next/prev screen navigation line
|
2018-11-30 13:33:49 +00:00
|
|
|
_drawMenuText(_display.xCentre(), Row[0], Label0, _rowSel == 0, eCentreJustify);
|
2018-11-24 11:03:47 +00:00
|
|
|
|
|
|
|
int col = getThermostatMode() ? 0 : 1; // follow actual heater settings
|
2018-11-25 04:45:17 +00:00
|
|
|
if(_rowSel == 1) {
|
2018-11-30 13:33:49 +00:00
|
|
|
_drawMenuText(border, Row[1], Label1[0], col == 0);
|
|
|
|
_drawMenuText(_display.width()-border, Row[1], Label1[1], col == 1, eRightJustify);
|
2018-11-24 11:03:47 +00:00
|
|
|
}
|
|
|
|
else {
|
2018-11-30 13:33:49 +00:00
|
|
|
_printInverted(border, Row[1], Label1[0], col == 0);
|
|
|
|
_printInverted(_display.width()-border, Row[1], Label1[1], col == 1, eRightJustify);
|
2018-11-24 11:03:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// fuel pump priming menu
|
2018-11-29 11:11:50 +00:00
|
|
|
_drawMenuText(Col[0], Row[2], "Prime pump");
|
2018-11-25 04:45:17 +00:00
|
|
|
if(_rowSel == 2) {
|
2018-11-30 13:33:49 +00:00
|
|
|
_drawMenuText(Col[1], Row[2], "OFF", _colSel == 1);
|
2018-11-29 11:11:50 +00:00
|
|
|
if(_colSel != 2) {
|
|
|
|
if(!getRunState()) { // prevent option if heater is running
|
|
|
|
_drawMenuText(Col[2], Row[2], "ON"); // becomes Hz when actually priming
|
|
|
|
}
|
2018-11-24 11:03:47 +00:00
|
|
|
}
|
2018-11-29 11:11:50 +00:00
|
|
|
else {
|
|
|
|
float pumpHz = getPumpHz();
|
|
|
|
// recognise if heater has stopped pump, after an initial holdoff upon first starting
|
|
|
|
long tDelta = millis() - _PrimeCheck;
|
|
|
|
if(_PrimeCheck && tDelta > 0 && pumpHz < 0.1) {
|
|
|
|
stopPump();
|
|
|
|
}
|
|
|
|
// test if time is up, stop priming if so
|
|
|
|
tDelta = millis() - _PrimeStop;
|
|
|
|
if(_PrimeStop && tDelta > 0) {
|
|
|
|
stopPump();
|
|
|
|
}
|
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);
|
2018-11-30 13:33:49 +00:00
|
|
|
_drawMenuText(_display.width()-border, Row[2], msg, true, eRightJustify);
|
2018-11-29 11:11:50 +00:00
|
|
|
}
|
2018-11-24 11:03:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-26 10:26:38 +00:00
|
|
|
_display.display();
|
|
|
|
|
2018-11-24 11:03:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-11-27 10:44:47 +00:00
|
|
|
void
|
|
|
|
CScreen3::animate()
|
|
|
|
{
|
|
|
|
// do nothing!!
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2018-11-25 04:45:17 +00:00
|
|
|
void
|
|
|
|
CScreen3::keyHandler(uint8_t event)
|
2018-11-24 11:03:47 +00:00
|
|
|
{
|
|
|
|
if(event & keyPressed) {
|
|
|
|
// press CENTRE
|
|
|
|
if(event & key_Centre) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// 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:
|
2018-11-29 11:11:50 +00:00
|
|
|
_ScreenManager.prevScreen();
|
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);
|
|
|
|
break;
|
|
|
|
case 2:
|
2018-11-25 04:45:17 +00:00
|
|
|
_colSel = 1;
|
2018-11-24 11:03:47 +00:00
|
|
|
break;
|
|
|
|
case 3: break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// 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:
|
2018-11-29 11:11:50 +00:00
|
|
|
_ScreenManager.nextScreen();
|
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);
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
if(!getRunState())
|
2018-11-25 04:45:17 +00:00
|
|
|
_colSel = 2;
|
2018-11-24 11:03:47 +00:00
|
|
|
break;
|
|
|
|
case 3: break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// press UP
|
|
|
|
if(event & key_Up) {
|
2018-11-25 04:45:17 +00:00
|
|
|
_rowSel++;
|
|
|
|
UPPERLIMIT(_rowSel, 2);
|
|
|
|
if(_rowSel == 2)
|
|
|
|
_colSel = 1; // select OFF upon entry to priming menu
|
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-11-24 11:03:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// check if fuel priming was selected
|
2018-11-25 04:45:17 +00:00
|
|
|
if(_rowSel == 2 && _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 {
|
|
|
|
stopPump();
|
|
|
|
}
|
|
|
|
|
2018-11-29 11:11:50 +00:00
|
|
|
_ScreenManager.reqUpdate();
|
2018-11-24 11:03:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-25 04:45:17 +00:00
|
|
|
void
|
|
|
|
CScreen3::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
|
|
|
}
|