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-23 10:34:37 +00:00
|
|
|
#include "128x64OLED.h"
|
2018-12-16 07:34:39 +00:00
|
|
|
#include "fonts/tahoma16.h"
|
|
|
|
#include "fonts/Icons.h"
|
2019-01-18 07:09:40 +00:00
|
|
|
#include "BasicScreen.h"
|
2018-11-23 10:34:37 +00:00
|
|
|
#include "KeyPad.h"
|
2018-12-16 07:34:39 +00:00
|
|
|
#include "../Protocol/helpers.h"
|
|
|
|
#include "../Utility/UtilClasses.h"
|
2019-02-06 20:24:22 +00:00
|
|
|
#include "../Utility/NVStorage.h"
|
2018-11-23 10:34:37 +00:00
|
|
|
|
|
|
|
|
|
|
|
#define MAXIFONT tahoma_16ptFontInfo
|
|
|
|
|
2018-12-01 00:36:25 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
2019-01-18 07:09:40 +00:00
|
|
|
// CBasicScreen
|
2018-12-01 00:36:25 +00:00
|
|
|
//
|
|
|
|
// This screen provides a basic control function
|
|
|
|
//
|
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2019-01-18 07:09:40 +00:00
|
|
|
CBasicScreen::CBasicScreen(C128x64_OLED& display, CScreenManager& mgr) : CScreenHeader(display, mgr)
|
2018-11-25 04:45:17 +00:00
|
|
|
{
|
|
|
|
_showSetMode = 0;
|
|
|
|
_showMode = 0;
|
|
|
|
_nModeSel = 0;
|
|
|
|
}
|
2018-11-24 00:51:09 +00:00
|
|
|
|
2019-01-18 23:06:12 +00:00
|
|
|
bool
|
2019-01-18 07:09:40 +00:00
|
|
|
CBasicScreen::show()
|
2018-11-23 10:34:37 +00:00
|
|
|
{
|
2018-12-01 00:36:25 +00:00
|
|
|
CScreenHeader::show();
|
|
|
|
|
2018-11-23 10:34:37 +00:00
|
|
|
char msg[20];
|
2018-11-29 11:11:50 +00:00
|
|
|
int xPos, yPos;
|
2018-11-23 10:34:37 +00:00
|
|
|
|
2019-03-14 10:52:59 +00:00
|
|
|
float fTemp = getTemperatureSensor();
|
2019-01-11 05:40:25 +00:00
|
|
|
if(fTemp > -80) {
|
2019-02-06 20:24:22 +00:00
|
|
|
if(NVstore.getDegFMode()) {
|
|
|
|
fTemp = fTemp * 9 / 5 + 32;
|
|
|
|
sprintf(msg, "%.1f`F", fTemp);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
sprintf(msg, "%.1f`C", fTemp);
|
|
|
|
}
|
|
|
|
|
2019-01-11 05:40:25 +00:00
|
|
|
{
|
|
|
|
CTransientFont AF(_display, &MAXIFONT); // temporarily use a large font
|
|
|
|
_printMenuText(_display.xCentre(), 25, msg, false, eCentreJustify);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
_printMenuText(_display.xCentre(), 25, "No Temperature Sensor", false, eCentreJustify);
|
2018-11-29 11:11:50 +00:00
|
|
|
}
|
2018-11-23 10:34:37 +00:00
|
|
|
|
2018-11-24 00:51:09 +00:00
|
|
|
|
|
|
|
// at bottom of screen show either:
|
|
|
|
// Selection between Fixed or Thermostat mode
|
|
|
|
// Current heat demand setting
|
|
|
|
// Run state of heater
|
|
|
|
|
2018-11-25 04:45:17 +00:00
|
|
|
if(_showMode) {
|
2018-11-24 00:51:09 +00:00
|
|
|
const int border = 3;
|
|
|
|
const int radius = 4;
|
|
|
|
// Show selection between Fixed or Thermostat mode
|
2018-11-25 04:45:17 +00:00
|
|
|
long tDelta = millis() - _showMode;
|
2018-11-24 11:03:47 +00:00
|
|
|
if(tDelta < 0) {
|
2018-11-29 11:11:50 +00:00
|
|
|
|
2018-12-01 18:25:10 +00:00
|
|
|
yPos = _display.height() - _display.textHeight() - border; // bottom of screen, with room for box
|
2018-11-29 11:11:50 +00:00
|
|
|
|
2018-11-30 13:33:49 +00:00
|
|
|
// display "Fixed Hz" at lower right, allowing space for a selection surrounding box
|
2018-11-23 10:34:37 +00:00
|
|
|
strcpy(msg, "Fixed Hz");
|
2018-11-29 11:11:50 +00:00
|
|
|
xPos = _display.width() - border; // set X position to finish short of RHS
|
2018-12-07 04:18:24 +00:00
|
|
|
_printMenuText(xPos, yPos, msg, _nModeSel == 1, eRightJustify);
|
2018-11-29 11:11:50 +00:00
|
|
|
|
2018-11-30 13:33:49 +00:00
|
|
|
// display "Thermostat" at lower left, allowing space for a selection surrounding box
|
2018-11-23 10:34:37 +00:00
|
|
|
strcpy(msg, "Thermostat");
|
2018-11-29 11:11:50 +00:00
|
|
|
xPos = border;
|
2018-12-07 04:18:24 +00:00
|
|
|
_printMenuText(xPos, yPos, msg, _nModeSel == 0);
|
2018-11-29 11:11:50 +00:00
|
|
|
|
2018-11-25 04:45:17 +00:00
|
|
|
setThermostatMode(_nModeSel == 0 ? 1 : 0); // set the new mode
|
2018-11-23 10:34:37 +00:00
|
|
|
}
|
|
|
|
else {
|
2018-11-24 00:51:09 +00:00
|
|
|
// cancel selection mode, apply whatever is boxed
|
2018-11-25 04:45:17 +00:00
|
|
|
_showMode = 0;
|
|
|
|
_showSetMode = millis() + 5000; // then make the new mode setting be shown
|
2018-11-23 10:34:37 +00:00
|
|
|
}
|
|
|
|
}
|
2018-11-25 04:45:17 +00:00
|
|
|
if((_showMode == 0) && _showSetMode) {
|
|
|
|
long tDelta = millis() - _showSetMode;
|
2018-11-24 11:03:47 +00:00
|
|
|
if(tDelta < 0) {
|
2018-11-24 00:51:09 +00:00
|
|
|
// Show current heat demand setting
|
2019-03-14 10:52:59 +00:00
|
|
|
if(getThermostatModeActive()) {
|
|
|
|
float fTemp = getTemperatureDesired();
|
2019-02-06 20:24:22 +00:00
|
|
|
if(NVstore.getDegFMode()) {
|
|
|
|
fTemp = fTemp * 9 / 5 + 32;
|
|
|
|
sprintf(msg, "Setpoint = %.0f`F", fTemp);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
sprintf(msg, "Setpoint = %.0f`C", fTemp);
|
|
|
|
}
|
2018-11-23 10:34:37 +00:00
|
|
|
}
|
|
|
|
else {
|
2018-12-01 00:36:25 +00:00
|
|
|
sprintf(msg, "Setpoint = %.1fHz", getHeaterInfo().getPump_Fixed());
|
2018-11-23 10:34:37 +00:00
|
|
|
}
|
2018-11-24 00:51:09 +00:00
|
|
|
// centre message at bottom of screen
|
2018-12-07 04:18:24 +00:00
|
|
|
_printMenuText(_display.xCentre(), _display.height() - _display.textHeight(), msg, false, eCentreJustify);
|
2018-11-24 00:51:09 +00:00
|
|
|
}
|
|
|
|
else {
|
2018-11-25 04:45:17 +00:00
|
|
|
_showSetMode = 0;
|
2018-11-23 10:34:37 +00:00
|
|
|
}
|
|
|
|
}
|
2018-11-25 04:45:17 +00:00
|
|
|
if((_showMode == 0) && (_showSetMode == 0)) {
|
|
|
|
showRunState();
|
2018-11-24 00:51:09 +00:00
|
|
|
}
|
2019-01-18 23:06:12 +00:00
|
|
|
return true;
|
2018-11-23 10:34:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-01-18 23:06:12 +00:00
|
|
|
bool
|
2019-01-18 07:09:40 +00:00
|
|
|
CBasicScreen::keyHandler(uint8_t event)
|
2018-11-23 10:34:37 +00:00
|
|
|
{
|
|
|
|
static int repeatCount = -1;
|
2018-12-01 00:36:25 +00:00
|
|
|
|
2018-11-23 10:34:37 +00:00
|
|
|
if(event & keyPressed) {
|
|
|
|
repeatCount = 0; // unlock tracking of repeat events
|
|
|
|
// press LEFT to select previous screen, or Fixed Hz mode when in mode select
|
|
|
|
if(event & key_Left) {
|
2018-11-25 04:45:17 +00:00
|
|
|
if(!_showMode)
|
2018-11-29 11:11:50 +00:00
|
|
|
_ScreenManager.prevScreen();
|
2018-11-23 10:34:37 +00:00
|
|
|
else {
|
2018-12-20 06:29:00 +00:00
|
|
|
if(hasOEMcontroller())
|
|
|
|
_reqOEMWarning();
|
|
|
|
else {
|
|
|
|
_showMode = millis() + 5000;
|
|
|
|
_nModeSel = 0;
|
|
|
|
}
|
2018-11-29 11:11:50 +00:00
|
|
|
_ScreenManager.reqUpdate();
|
2018-11-23 10:34:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
// press RIGHT to selecxt next screen, or Thermostat mode when in mode select
|
|
|
|
if(event & key_Right) {
|
2018-11-25 04:45:17 +00:00
|
|
|
if(!_showMode)
|
2018-11-29 11:11:50 +00:00
|
|
|
_ScreenManager.nextScreen();
|
2018-11-23 10:34:37 +00:00
|
|
|
else {
|
2018-12-20 06:29:00 +00:00
|
|
|
if(hasOEMcontroller())
|
|
|
|
_reqOEMWarning();
|
|
|
|
else {
|
|
|
|
_showMode = millis() + 5000;
|
|
|
|
_nModeSel = 1;
|
|
|
|
}
|
2018-11-29 11:11:50 +00:00
|
|
|
_ScreenManager.reqUpdate();
|
2018-11-23 10:34:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
// press UP & DOWN to toggle thermostat / fixed Hz mode
|
2018-11-24 00:51:09 +00:00
|
|
|
// impossible with 5 way switch!
|
2018-11-23 10:34:37 +00:00
|
|
|
uint8_t doubleKey = key_Down | key_Up;
|
|
|
|
if((event & doubleKey) == doubleKey) {
|
2018-12-20 06:29:00 +00:00
|
|
|
if(reqThermoToggle())
|
|
|
|
_showSetMode = millis() + 2000;
|
|
|
|
else
|
|
|
|
_reqOEMWarning();
|
2018-11-23 10:34:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
// use repeat function for key hold detection
|
|
|
|
if(event & keyRepeat) {
|
|
|
|
if(repeatCount >= 0) {
|
|
|
|
repeatCount++;
|
|
|
|
// hold DOWN to enter thermostat / fixed mode selection
|
|
|
|
if(event & key_Down) {
|
|
|
|
if(repeatCount > 2) {
|
|
|
|
repeatCount = -1; // prevent double handling
|
2018-11-25 04:45:17 +00:00
|
|
|
_showMode = millis() + 5000;
|
2019-03-14 10:52:59 +00:00
|
|
|
_nModeSel = getThermostatModeActive() ? 0 : 1;
|
2018-11-23 10:34:37 +00:00
|
|
|
}
|
|
|
|
}
|
2019-02-06 20:24:22 +00:00
|
|
|
// hold UP to toggle degC/degF mode selection
|
|
|
|
if(event & key_Up) {
|
|
|
|
if(repeatCount > 2) {
|
|
|
|
repeatCount = -1; // prevent double handling
|
|
|
|
_showMode = millis() + 5000;
|
|
|
|
NVstore.setDegFMode(NVstore.getDegFMode() ? 0 : 1);
|
|
|
|
}
|
|
|
|
}
|
2018-11-23 10:34:37 +00:00
|
|
|
// hold CENTRE to turn ON or OFF
|
|
|
|
if(event & key_Centre) {
|
2018-12-01 00:36:25 +00:00
|
|
|
if(getHeaterInfo().getRunState()) {
|
2018-11-23 10:34:37 +00:00
|
|
|
// running, request OFF
|
|
|
|
if(repeatCount > 5) {
|
2018-11-24 00:51:09 +00:00
|
|
|
repeatCount = -2; // prevent double handling
|
2018-11-23 10:34:37 +00:00
|
|
|
requestOff();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// standby, request ON
|
|
|
|
if(repeatCount > 3) {
|
|
|
|
repeatCount = -1;
|
|
|
|
requestOn();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(event & keyReleased) {
|
2018-11-25 04:45:17 +00:00
|
|
|
if(!_showMode) {
|
2018-11-23 10:34:37 +00:00
|
|
|
// release DOWN key to reduce set demand, provided we are not in mode select
|
|
|
|
if(event & key_Down) {
|
2018-12-20 06:29:00 +00:00
|
|
|
if(reqTempDelta(-1))
|
|
|
|
_showSetMode = millis() + 2000;
|
|
|
|
else
|
|
|
|
_reqOEMWarning();
|
2018-11-23 10:34:37 +00:00
|
|
|
}
|
|
|
|
// release UP key to increase set demand, provided we are not in mode select
|
|
|
|
if(event & key_Up) {
|
2018-12-20 06:29:00 +00:00
|
|
|
if(reqTempDelta(+1))
|
|
|
|
_showSetMode = millis() + 2000;
|
|
|
|
else
|
|
|
|
_reqOEMWarning();
|
2018-11-23 10:34:37 +00:00
|
|
|
}
|
|
|
|
}
|
2018-11-24 00:51:09 +00:00
|
|
|
// release CENTRE to accept new mode, and/or show current setting
|
|
|
|
if(event & key_Centre) {
|
|
|
|
if(repeatCount != -2) { // prevent after off commands
|
2018-11-25 04:45:17 +00:00
|
|
|
if(_showMode) {
|
|
|
|
_showMode = millis(); // force immediate cancellation of showmode (via screen update)
|
2018-11-24 00:51:09 +00:00
|
|
|
}
|
2018-11-25 04:45:17 +00:00
|
|
|
_showSetMode = millis() + 2000;
|
2018-11-24 00:51:09 +00:00
|
|
|
}
|
2018-11-29 11:11:50 +00:00
|
|
|
_ScreenManager.reqUpdate();
|
2018-11-24 00:51:09 +00:00
|
|
|
}
|
|
|
|
|
2018-11-23 10:34:37 +00:00
|
|
|
repeatCount = -1;
|
|
|
|
}
|
2019-01-18 23:06:12 +00:00
|
|
|
return true;
|
2018-11-23 10:34:37 +00:00
|
|
|
}
|
2018-11-24 00:51:09 +00:00
|
|
|
|
2018-11-25 04:45:17 +00:00
|
|
|
void
|
2019-01-18 07:09:40 +00:00
|
|
|
CBasicScreen::showRunState()
|
2018-11-24 00:51:09 +00:00
|
|
|
{
|
2018-12-01 00:36:25 +00:00
|
|
|
int runstate = getHeaterInfo().getRunState();
|
|
|
|
int errstate = getHeaterInfo().getErrState();
|
2018-11-24 00:51:09 +00:00
|
|
|
|
|
|
|
if(errstate) errstate--; // correct for +1 biased return value
|
|
|
|
|
|
|
|
static bool toggle = false;
|
|
|
|
const char* toPrint = NULL;
|
2018-11-25 04:45:17 +00:00
|
|
|
_display.setTextColor(WHITE, BLACK);
|
2018-11-24 00:51:09 +00:00
|
|
|
if(runstate >= 0 && runstate <= 8) {
|
|
|
|
if(((runstate == 0) || (runstate > 5)) && errstate) {
|
2018-12-01 18:25:10 +00:00
|
|
|
|
2018-11-24 00:51:09 +00:00
|
|
|
// flash error code
|
2018-12-01 18:25:10 +00:00
|
|
|
char msg[16];
|
2018-11-24 00:51:09 +00:00
|
|
|
toggle = !toggle;
|
2018-12-01 18:25:10 +00:00
|
|
|
if(toggle) {
|
|
|
|
// create an "E-XX" message to display
|
|
|
|
sprintf(msg, "E-%02d", errstate);
|
|
|
|
}
|
2018-11-24 00:51:09 +00:00
|
|
|
else {
|
2018-12-01 18:25:10 +00:00
|
|
|
strcpy(msg, " ");
|
2018-11-24 00:51:09 +00:00
|
|
|
}
|
2018-12-01 18:25:10 +00:00
|
|
|
int xPos = _display.xCentre();
|
|
|
|
int yPos = _display.height() - 2*_display.textHeight();
|
2018-12-07 04:18:24 +00:00
|
|
|
_printMenuText(xPos, yPos, msg, false, eCentreJustify);
|
2018-12-01 18:25:10 +00:00
|
|
|
|
|
|
|
toPrint = getHeaterInfo().getErrStateStr();
|
2018-11-24 00:51:09 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
if(runstate) {
|
|
|
|
if(runstate < 5) toPrint = "Starting";
|
|
|
|
else if(runstate == 5) toPrint = "Running";
|
|
|
|
else if(runstate == 8) toPrint = "Cooling";
|
|
|
|
else toPrint = "Shutting down";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(toPrint) {
|
2018-12-01 18:25:10 +00:00
|
|
|
// locate at bottom centre
|
2018-12-07 04:18:24 +00:00
|
|
|
_printMenuText(_display.xCentre(), _display.height() - _display.textHeight(), toPrint, false, eCentreJustify);
|
2018-11-24 00:51:09 +00:00
|
|
|
}
|
2018-11-25 04:45:17 +00:00
|
|
|
}
|