2019-04-09 23:30:27 +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/>.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "ThermostatModeScreen.h"
|
|
|
|
#include "KeyPad.h"
|
2019-06-15 23:09:29 +00:00
|
|
|
#include "../Utility/helpers.h"
|
2019-04-09 23:30:27 +00:00
|
|
|
#include "../Utility/UtilClasses.h"
|
2019-04-27 10:41:47 +00:00
|
|
|
#include "fonts/Icons.h"
|
2019-10-18 01:55:16 +00:00
|
|
|
#include "../Utility/BTC_GPIO.h"
|
2019-04-09 23:30:27 +00:00
|
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// CThermostatModeScreen
|
|
|
|
//
|
|
|
|
// This screen provides control over experimental features
|
|
|
|
//
|
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
static const int Line3 = 14;
|
|
|
|
static const int Line2 = 27;
|
|
|
|
static const int Line1 = 40;
|
2019-05-11 02:18:06 +00:00
|
|
|
static const int Column = 40;
|
2019-04-09 23:30:27 +00:00
|
|
|
|
2019-11-21 08:25:14 +00:00
|
|
|
CThermostatModeScreen::CThermostatModeScreen(C128x64_OLED& display, CScreenManager& mgr) : CUIEditScreen(display, mgr)
|
2019-04-09 23:30:27 +00:00
|
|
|
{
|
|
|
|
_initUI();
|
|
|
|
_window = 10;
|
|
|
|
_thermoMode = 0;
|
2019-04-27 10:41:47 +00:00
|
|
|
_cyclicMode.init();
|
2019-04-09 23:30:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CThermostatModeScreen::onSelect()
|
|
|
|
{
|
2019-11-21 08:25:14 +00:00
|
|
|
CUIEditScreen::onSelect();
|
2019-04-09 23:30:27 +00:00
|
|
|
_initUI();
|
2019-06-06 01:32:43 +00:00
|
|
|
_window = NVstore.getUserSettings().ThermostatWindow;
|
|
|
|
_thermoMode = NVstore.getUserSettings().ThermostatMethod;
|
2019-07-03 13:01:36 +00:00
|
|
|
_cyclicMode = NVstore.getUserSettings().cyclic;
|
2019-04-09 23:30:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CThermostatModeScreen::_initUI()
|
|
|
|
{
|
2019-11-21 08:25:14 +00:00
|
|
|
CUIEditScreen::_initUI();
|
2019-04-18 11:02:39 +00:00
|
|
|
_keyRepeat = -1;
|
2019-04-09 23:30:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
CThermostatModeScreen::show()
|
|
|
|
{
|
|
|
|
char msg[20];
|
|
|
|
_display.clearDisplay();
|
|
|
|
|
2019-11-21 08:25:14 +00:00
|
|
|
if(!CUIEditScreen::show()) { // for showing "saving settings"
|
2019-04-09 23:30:27 +00:00
|
|
|
|
2019-11-10 04:44:54 +00:00
|
|
|
_showTitle("Thermostat Mode");
|
|
|
|
_drawBitmap(3, 14, ThermostatIconInfo);
|
|
|
|
float fTemp = _window;
|
|
|
|
if(NVstore.getUserSettings().degF) {
|
|
|
|
fTemp = fTemp * 9 / 5;
|
|
|
|
sprintf(msg, "%.1f`F", fTemp);
|
2019-04-09 23:30:27 +00:00
|
|
|
}
|
|
|
|
else {
|
2019-11-10 04:44:54 +00:00
|
|
|
sprintf(msg, "%.1f`C", fTemp);
|
|
|
|
}
|
|
|
|
_printMenuText(Column, Line2, msg, _rowSel == 3);
|
|
|
|
const char* modeStr = NULL;
|
|
|
|
switch(_thermoMode) {
|
|
|
|
case 0: modeStr = "Standard"; break;
|
|
|
|
case 1: modeStr = "Deadband"; break;
|
|
|
|
case 2: modeStr = "Linear Hz"; break;
|
|
|
|
case 3: modeStr = "Ext thermostat"; break;
|
2020-05-13 00:37:31 +00:00
|
|
|
case 4: modeStr = "Stop Start"; break;
|
2019-11-10 04:44:54 +00:00
|
|
|
}
|
|
|
|
if(modeStr)
|
|
|
|
_printMenuText(Column, Line3, modeStr, _rowSel == 4);
|
|
|
|
if(_cyclicMode.isEnabled()) {
|
|
|
|
float fTemp = _cyclicMode.Stop+1;
|
2019-06-06 01:32:43 +00:00
|
|
|
if(NVstore.getUserSettings().degF) {
|
2019-05-11 02:18:06 +00:00
|
|
|
fTemp = fTemp * 9 / 5;
|
2019-11-10 04:44:54 +00:00
|
|
|
sprintf(msg, "\352>%.0f`F", fTemp);
|
2019-04-09 23:30:27 +00:00
|
|
|
}
|
|
|
|
else {
|
2019-11-10 04:44:54 +00:00
|
|
|
sprintf(msg, "\352>%.0f`C", fTemp);
|
2019-04-09 23:30:27 +00:00
|
|
|
}
|
2019-11-10 04:44:54 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
strcpy(msg, "OFF");
|
|
|
|
}
|
|
|
|
_printMenuText(Column, Line1, msg, _rowSel == 1);
|
|
|
|
if(_cyclicMode.isEnabled()) {
|
|
|
|
float fTemp = _cyclicMode.Start;
|
|
|
|
if(NVstore.getUserSettings().degF) {
|
|
|
|
fTemp = fTemp * 9 / 5;
|
|
|
|
sprintf(msg, "\352<%.0f`F", fTemp);
|
2019-04-27 10:41:47 +00:00
|
|
|
}
|
|
|
|
else {
|
2019-11-10 04:44:54 +00:00
|
|
|
sprintf(msg, "\352<%.0f`C", fTemp);
|
2019-04-27 10:41:47 +00:00
|
|
|
}
|
2019-04-09 23:30:27 +00:00
|
|
|
}
|
2019-11-10 04:44:54 +00:00
|
|
|
else {
|
|
|
|
strcpy(msg, "");
|
|
|
|
}
|
|
|
|
_printMenuText(Column + 42, Line1, msg, _rowSel == 2);
|
2019-04-09 23:30:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
CThermostatModeScreen::animate()
|
|
|
|
{
|
2019-11-21 08:25:14 +00:00
|
|
|
if(_saveBusy()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
int yPos = 53;
|
|
|
|
int xPos = _display.xCentre();
|
|
|
|
const char* pMsg = NULL;
|
|
|
|
switch(_rowSel) {
|
|
|
|
case 0:
|
|
|
|
_printMenuText(xPos, yPos, " \021 \030Edit Exit \020 ", true, eCentreJustify);
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
_display.drawFastHLine(0, 52, 128, WHITE);
|
|
|
|
pMsg = " Heater shuts down over set point. ";
|
|
|
|
_scrollMessage(56, pMsg, _scrollChar);
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
_display.drawFastHLine(0, 52, 128, WHITE);
|
|
|
|
pMsg = " Heater restarts below setpoint. ";
|
|
|
|
_scrollMessage(56, pMsg, _scrollChar);
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
_display.drawFastHLine(0, 52, 128, WHITE);
|
|
|
|
pMsg = " User defined window for custom thermostat modes. ";
|
|
|
|
_scrollMessage(56, pMsg, _scrollChar);
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
_display.drawFastHLine(0, 52, 128, WHITE);
|
|
|
|
switch(_thermoMode) {
|
2019-07-27 14:28:39 +00:00
|
|
|
case 0:
|
2019-11-21 08:25:14 +00:00
|
|
|
pMsg = " Use heater's standard thermostat control. ";
|
2019-07-27 14:28:39 +00:00
|
|
|
break;
|
|
|
|
case 1:
|
2019-11-21 08:25:14 +00:00
|
|
|
pMsg = " The user defined window sets the thermostat's hysteresis. ";
|
2019-07-27 14:28:39 +00:00
|
|
|
break;
|
|
|
|
case 2:
|
2019-11-21 08:25:14 +00:00
|
|
|
pMsg = " The pump rate is adjusted linearly across the set point window. ";
|
2019-07-27 14:28:39 +00:00
|
|
|
break;
|
|
|
|
case 3:
|
2019-11-21 08:25:14 +00:00
|
|
|
pMsg = " The heater runs according to GPIO input #2: Open:minimum, Closed:maximum. ";
|
2019-07-27 14:28:39 +00:00
|
|
|
break;
|
2020-05-13 00:37:31 +00:00
|
|
|
case 4:
|
|
|
|
pMsg = " The heater is stopped then started according to the defined window. ";
|
|
|
|
break;
|
2019-07-27 14:28:39 +00:00
|
|
|
}
|
2019-11-21 08:25:14 +00:00
|
|
|
if(pMsg)
|
|
|
|
_scrollMessage(56, pMsg, _scrollChar);
|
|
|
|
break;
|
2019-04-09 23:30:27 +00:00
|
|
|
}
|
2019-11-21 08:25:14 +00:00
|
|
|
return true;
|
2019-04-09 23:30:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
CThermostatModeScreen::keyHandler(uint8_t event)
|
|
|
|
{
|
2019-11-21 08:25:14 +00:00
|
|
|
if(CUIEditScreen::keyHandler(event)) { // potentially handles save confirm stage
|
2019-11-10 04:44:54 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-04-09 23:30:27 +00:00
|
|
|
if(event & keyPressed) {
|
2019-04-18 11:02:39 +00:00
|
|
|
_keyRepeat = 0; // unlock hold function
|
2019-04-09 23:30:27 +00:00
|
|
|
// press LEFT to select previous screen
|
|
|
|
if(event & key_Left) {
|
|
|
|
switch(_rowSel) {
|
|
|
|
case 0:
|
|
|
|
_ScreenManager.prevMenu();
|
|
|
|
break;
|
2019-04-27 10:41:47 +00:00
|
|
|
case 4:
|
|
|
|
_scrollChar = 0;
|
2019-08-25 22:41:44 +00:00
|
|
|
// deliberate fall through here
|
2019-04-09 23:30:27 +00:00
|
|
|
case 1:
|
2019-04-27 10:41:47 +00:00
|
|
|
case 2:
|
2019-04-09 23:30:27 +00:00
|
|
|
case 3:
|
|
|
|
_adjust(-1);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// press RIGHT to select next screen
|
|
|
|
if(event & key_Right) {
|
|
|
|
switch(_rowSel) {
|
|
|
|
case 0:
|
|
|
|
_ScreenManager.nextMenu();
|
|
|
|
break;
|
2019-04-27 10:41:47 +00:00
|
|
|
case 4:
|
|
|
|
_scrollChar = 0;
|
2019-08-25 22:41:44 +00:00
|
|
|
// deliberate fall through here
|
2019-04-09 23:30:27 +00:00
|
|
|
case 1:
|
2019-04-27 10:41:47 +00:00
|
|
|
case 2:
|
2019-04-09 23:30:27 +00:00
|
|
|
case 3:
|
|
|
|
_adjust(+1);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(event & key_Down) {
|
2019-04-27 10:41:47 +00:00
|
|
|
if(_rowSel != 0) {
|
|
|
|
_scrollChar = 0;
|
2019-04-09 23:30:27 +00:00
|
|
|
_rowSel--;
|
2019-04-27 10:41:47 +00:00
|
|
|
if(_rowSel == 2 && !_cyclicMode.isEnabled())
|
|
|
|
_rowSel--;
|
2019-04-09 23:30:27 +00:00
|
|
|
LOWERLIMIT(_rowSel, 0);
|
|
|
|
}
|
2019-07-27 14:28:39 +00:00
|
|
|
else {
|
|
|
|
_ScreenManager.selectMenu(CScreenManager::SystemSettingsLoop, CScreenManager::SysVerUI);
|
|
|
|
}
|
2019-04-09 23:30:27 +00:00
|
|
|
}
|
|
|
|
// UP press
|
|
|
|
if(event & key_Up) {
|
|
|
|
switch(_rowSel) {
|
|
|
|
case 0:
|
|
|
|
case 1:
|
|
|
|
case 2:
|
|
|
|
case 3:
|
2019-04-27 10:41:47 +00:00
|
|
|
_scrollChar = 0;
|
2019-04-09 23:30:27 +00:00
|
|
|
_rowSel++;
|
2019-04-27 10:41:47 +00:00
|
|
|
if(_rowSel == 2 && !_cyclicMode.isEnabled())
|
|
|
|
_rowSel++;
|
|
|
|
UPPERLIMIT(_rowSel, 4);
|
2019-04-09 23:30:27 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// CENTRE press
|
|
|
|
if(event & key_Centre) {
|
|
|
|
switch(_rowSel) {
|
|
|
|
case 0:
|
2019-07-27 14:28:39 +00:00
|
|
|
// _ScreenManager.selectMenu(CScreenManager::RootMenuLoop, CScreenManager::SettingsUI); // force return to main menu
|
|
|
|
_ScreenManager.selectMenu(CScreenManager::RootMenuLoop); // force return to main menu
|
2019-04-09 23:30:27 +00:00
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
case 2:
|
|
|
|
case 3:
|
2019-04-27 10:41:47 +00:00
|
|
|
case 4:
|
2019-11-21 08:25:14 +00:00
|
|
|
_confirmSave(); // enter save confirm mode
|
|
|
|
_rowSel = 0;
|
2019-04-09 23:30:27 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2019-11-10 04:44:54 +00:00
|
|
|
if(event & keyRepeat) {
|
|
|
|
_keyRepeat++;
|
|
|
|
if(_rowSel == 3) {
|
|
|
|
if(event & key_Right) {
|
|
|
|
_adjust(+1);
|
|
|
|
_ScreenManager.reqUpdate();
|
|
|
|
}
|
|
|
|
if(event & key_Left) {
|
|
|
|
_adjust(-1);
|
|
|
|
_ScreenManager.reqUpdate();
|
|
|
|
}
|
2019-06-06 01:32:43 +00:00
|
|
|
}
|
|
|
|
}
|
2019-11-10 04:44:54 +00:00
|
|
|
if(event & keyReleased) {
|
|
|
|
_keyRepeat = -1;
|
|
|
|
}
|
|
|
|
_ScreenManager.reqUpdate();
|
2019-04-18 11:02:39 +00:00
|
|
|
}
|
2019-04-09 23:30:27 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CThermostatModeScreen::_adjust(int dir)
|
|
|
|
{
|
|
|
|
switch(_rowSel) {
|
2019-04-27 10:41:47 +00:00
|
|
|
case 1:
|
|
|
|
_cyclicMode.Stop += dir;
|
2019-07-03 13:01:36 +00:00
|
|
|
BOUNDSLIMIT(_cyclicMode.Stop, 0, 9);
|
2019-04-27 10:41:47 +00:00
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
_cyclicMode.Start += dir;
|
2019-07-03 13:01:36 +00:00
|
|
|
BOUNDSLIMIT(_cyclicMode.Start, -20, 0);
|
2019-04-27 10:41:47 +00:00
|
|
|
break;
|
|
|
|
case 3: // window
|
2019-04-09 23:30:27 +00:00
|
|
|
_window += (dir * 0.1);
|
2019-07-03 13:01:36 +00:00
|
|
|
BOUNDSLIMIT(_window, 0.2, 10.0);
|
2019-04-09 23:30:27 +00:00
|
|
|
break;
|
2019-04-27 10:41:47 +00:00
|
|
|
case 4: // thermostat mode
|
2019-04-09 23:30:27 +00:00
|
|
|
_thermoMode += dir;
|
2019-10-27 00:02:49 +00:00
|
|
|
#if USE_JTAG == 0
|
2020-05-13 00:37:31 +00:00
|
|
|
if(_thermoMode == 3 && !GPIOin.usesExternalThermostat())
|
|
|
|
_thermoMode += dir;
|
2019-10-27 00:02:49 +00:00
|
|
|
#else
|
2020-05-13 00:37:31 +00:00
|
|
|
// CANNOT USE GPIO WITH JTAG DEBUG
|
|
|
|
if(_thermoMode == 3
|
|
|
|
_thermoMode += dir;
|
2019-10-27 00:02:49 +00:00
|
|
|
#endif
|
2020-05-13 00:37:31 +00:00
|
|
|
WRAPLIMITS(_thermoMode, 0, 4);
|
2019-04-09 23:30:27 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2019-11-10 04:44:54 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
CThermostatModeScreen::_saveNV()
|
|
|
|
{
|
|
|
|
sUserSettings settings = NVstore.getUserSettings();
|
|
|
|
settings.ThermostatMethod = _thermoMode;
|
|
|
|
settings.ThermostatWindow = _window;
|
|
|
|
settings.cyclic = _cyclicMode;
|
|
|
|
NVstore.setUserSettings(settings);
|
|
|
|
NVstore.save();
|
|
|
|
}
|