2018-11-27 10:44:47 +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-12-01 00:36:25 +00:00
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
2019-01-18 07:09:40 +00:00
|
|
|
// CFuelMixtureScreen
|
2018-12-01 00:36:25 +00:00
|
|
|
//
|
|
|
|
// This screen allows the fuel mixture endpoints to be adjusted
|
|
|
|
//
|
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2019-01-18 07:09:40 +00:00
|
|
|
#include "FuelMixtureScreen.h"
|
2018-12-16 07:34:39 +00:00
|
|
|
#include "KeyPad.h"
|
|
|
|
#include "../Protocol/helpers.h"
|
|
|
|
#include "../Wifi/BTCWifi.h"
|
|
|
|
#include "fonts/Arial.h"
|
2018-11-27 10:44:47 +00:00
|
|
|
|
|
|
|
|
2019-01-18 07:09:40 +00:00
|
|
|
CFuelMixtureScreen::CFuelMixtureScreen(C128x64_OLED& display, CScreenManager& mgr) : CScreenHeader(display, mgr)
|
2018-11-27 10:44:47 +00:00
|
|
|
{
|
|
|
|
_rowSel = 0;
|
|
|
|
_colSel = 0;
|
|
|
|
for(int i= 0; i < 4; i++)
|
|
|
|
_PWdig[i] = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
2019-01-18 07:09:40 +00:00
|
|
|
CFuelMixtureScreen::show()
|
2018-11-27 10:44:47 +00:00
|
|
|
{
|
2018-12-01 00:36:25 +00:00
|
|
|
CScreenHeader::show();
|
2018-12-02 06:30:40 +00:00
|
|
|
|
2018-11-27 19:40:01 +00:00
|
|
|
char str[16];
|
2018-11-28 11:15:23 +00:00
|
|
|
int xPos, yPos;
|
2018-11-27 19:40:01 +00:00
|
|
|
const int col2 = 90;
|
|
|
|
const int col3 = _display.width() - border;
|
2018-11-27 10:44:47 +00:00
|
|
|
|
2018-12-02 06:30:40 +00:00
|
|
|
_printInverted(0, 16, " Fuel Settings ", true);
|
2018-11-27 10:44:47 +00:00
|
|
|
|
2018-11-27 19:40:01 +00:00
|
|
|
switch(_rowSel) {
|
|
|
|
case 0:
|
2018-11-28 19:32:26 +00:00
|
|
|
// show settings overview (initial screen entry)
|
|
|
|
// pump max/min
|
2018-11-27 19:40:01 +00:00
|
|
|
yPos = 28;
|
2018-12-07 04:18:24 +00:00
|
|
|
_printMenuText(0, yPos, "Pump (Hz)");
|
2018-12-01 00:36:25 +00:00
|
|
|
sprintf(str, "%.1f", getHeaterInfo().getPump_Min());
|
2018-12-07 04:18:24 +00:00
|
|
|
_printMenuText(col2, yPos, str, false, eRightJustify);
|
2018-12-01 00:36:25 +00:00
|
|
|
sprintf(str, "%.1f", getHeaterInfo().getPump_Max());
|
2018-12-07 04:18:24 +00:00
|
|
|
_printMenuText(col3, yPos, str, false, eRightJustify);
|
2018-11-28 19:32:26 +00:00
|
|
|
// fan max/min
|
2018-11-27 19:40:01 +00:00
|
|
|
yPos = 40;
|
2018-12-07 04:18:24 +00:00
|
|
|
_printMenuText(0, yPos, "Fan (RPM)");
|
2018-12-01 00:36:25 +00:00
|
|
|
sprintf(str, "%d", getHeaterInfo().getFan_Min());
|
2018-12-07 04:18:24 +00:00
|
|
|
_printMenuText(col2, yPos, str, false, eRightJustify);
|
2018-12-01 00:36:25 +00:00
|
|
|
sprintf(str, "%d", getHeaterInfo().getFan_Max());
|
2018-12-07 04:18:24 +00:00
|
|
|
_printMenuText(col3, yPos, str, false, eRightJustify);
|
2018-11-28 19:32:26 +00:00
|
|
|
// navigation line
|
2018-11-28 11:15:23 +00:00
|
|
|
yPos = 53;
|
|
|
|
xPos = _display.xCentre();
|
2018-12-07 04:18:24 +00:00
|
|
|
_printMenuText(xPos, yPos, "<- ->", true, eCentreJustify);
|
2018-11-27 19:40:01 +00:00
|
|
|
break;
|
2018-11-28 11:15:23 +00:00
|
|
|
|
2018-11-27 19:40:01 +00:00
|
|
|
case 1:
|
2018-12-07 04:18:24 +00:00
|
|
|
_printMenuText(_display.xCentre(), 34, "Enter password...", false, eCentreJustify);
|
2018-11-27 19:40:01 +00:00
|
|
|
_showPassword();
|
|
|
|
break;
|
2018-11-28 11:15:23 +00:00
|
|
|
|
2018-11-27 19:40:01 +00:00
|
|
|
case 2:
|
|
|
|
case 3:
|
|
|
|
case 4:
|
|
|
|
case 5:
|
|
|
|
_display.clearDisplay();
|
|
|
|
// Pump Minimum adjustment
|
2018-11-28 19:32:26 +00:00
|
|
|
yPos = border + 36;
|
2018-12-07 04:18:24 +00:00
|
|
|
_printMenuText(80, yPos, "Min", false, eRightJustify);
|
2018-11-27 19:40:01 +00:00
|
|
|
sprintf(str, "%.1f", adjPump[0]);
|
2018-12-07 04:18:24 +00:00
|
|
|
_printMenuText(col3, yPos, str, _rowSel == 2, eRightJustify);
|
2018-11-27 19:40:01 +00:00
|
|
|
// Pump Maximum adjustment
|
|
|
|
yPos = border + 24;
|
2018-12-07 04:18:24 +00:00
|
|
|
_printMenuText(80, yPos, "Pump Hz Max", false, eRightJustify);
|
2018-11-27 19:40:01 +00:00
|
|
|
sprintf(str, "%.1f", adjPump[1]);
|
2018-12-07 04:18:24 +00:00
|
|
|
_printMenuText(col3, yPos, str, _rowSel == 3, eRightJustify);
|
2018-11-27 19:40:01 +00:00
|
|
|
// Fan Minimum adjustment
|
|
|
|
yPos = border + 12;
|
2018-12-07 04:18:24 +00:00
|
|
|
_printMenuText(80, yPos, "Min", false, eRightJustify);
|
2018-11-27 19:40:01 +00:00
|
|
|
sprintf(str, "%d", adjFan[0]);
|
2018-12-07 04:18:24 +00:00
|
|
|
_printMenuText(col3, yPos, str, _rowSel == 4, eRightJustify);
|
2018-11-27 19:40:01 +00:00
|
|
|
// Fan Maximum adjustment
|
|
|
|
yPos = border;
|
2018-12-07 04:18:24 +00:00
|
|
|
_printMenuText(80, yPos, "Fan RPM Max", false, eRightJustify);
|
2018-11-27 19:40:01 +00:00
|
|
|
sprintf(str, "%d", adjFan[1]);
|
2018-12-07 04:18:24 +00:00
|
|
|
_printMenuText(col3, yPos, str, _rowSel == 5, eRightJustify);
|
2018-11-28 19:32:26 +00:00
|
|
|
// navigation line
|
2018-11-27 19:40:01 +00:00
|
|
|
yPos = 53;
|
2018-12-07 04:18:24 +00:00
|
|
|
_printMenuText(_display.xCentre(), yPos, "<- ->", false, eCentreJustify);
|
2018-11-27 19:40:01 +00:00
|
|
|
break;
|
2018-11-28 11:15:23 +00:00
|
|
|
|
|
|
|
case 6:
|
2018-12-07 04:18:24 +00:00
|
|
|
_printMenuText(_display.xCentre(), 35, "Press UP to", false, eCentreJustify);
|
|
|
|
_printMenuText(_display.xCentre(), 43, "confirm save", false, eCentreJustify);
|
2018-11-28 11:15:23 +00:00
|
|
|
break;
|
2018-11-27 10:44:47 +00:00
|
|
|
}
|
|
|
|
|
2018-12-01 18:25:10 +00:00
|
|
|
// _display.display();
|
2018-11-27 10:44:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
2019-01-18 07:09:40 +00:00
|
|
|
CFuelMixtureScreen::keyHandler(uint8_t event)
|
2018-11-27 10:44:47 +00:00
|
|
|
{
|
2018-12-01 00:36:25 +00:00
|
|
|
|
2018-11-27 10:44:47 +00:00
|
|
|
if(event & keyPressed) {
|
|
|
|
// press CENTRE
|
|
|
|
if(event & key_Centre) {
|
2018-11-28 11:15:23 +00:00
|
|
|
switch(_rowSel) {
|
|
|
|
case 1:
|
|
|
|
// match "1688"
|
|
|
|
if((_PWdig[0] == 1) &&
|
|
|
|
(_PWdig[1] == 6) &&
|
|
|
|
(_PWdig[2] == 8) &&
|
|
|
|
(_PWdig[3] == 8)) {
|
|
|
|
_rowSel = 2;
|
|
|
|
_colSel = 0;
|
|
|
|
// grab current settings upon entry to edit mode
|
2018-12-01 00:36:25 +00:00
|
|
|
adjPump[0] = getHeaterInfo().getPump_Min();
|
|
|
|
adjPump[1] = getHeaterInfo().getPump_Max();
|
|
|
|
adjFan[0] = getHeaterInfo().getFan_Min();
|
|
|
|
adjFan[1] = getHeaterInfo().getFan_Max();
|
2018-11-28 11:15:23 +00:00
|
|
|
}
|
|
|
|
// reset PW digits
|
2018-11-27 10:44:47 +00:00
|
|
|
for(int i= 0; i < 4; i++)
|
|
|
|
_PWdig[i] = -1;
|
2018-11-28 11:15:23 +00:00
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
case 3:
|
|
|
|
case 4:
|
|
|
|
case 5:
|
|
|
|
_rowSel = 6; // enter save confirm mode
|
|
|
|
break;
|
|
|
|
case 6:
|
|
|
|
_rowSel = 0;
|
|
|
|
break;
|
2018-11-27 10:44:47 +00:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// press LEFT
|
|
|
|
if(event & key_Left) {
|
|
|
|
switch(_rowSel) {
|
|
|
|
case 0:
|
2018-11-29 11:11:50 +00:00
|
|
|
_ScreenManager.prevScreen();
|
2018-11-27 10:44:47 +00:00
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
_colSel--;
|
|
|
|
LOWERLIMIT(_colSel, 0);
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
case 3:
|
2018-11-27 19:40:01 +00:00
|
|
|
case 4:
|
|
|
|
case 5:
|
|
|
|
_adjustSetting(-1);
|
2018-11-27 10:44:47 +00:00
|
|
|
break;
|
2018-11-28 11:15:23 +00:00
|
|
|
case 6:
|
|
|
|
_rowSel = 0;
|
|
|
|
break;
|
2018-11-27 10:44:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
// press RIGHT
|
|
|
|
if(event & key_Right) {
|
|
|
|
switch(_rowSel) {
|
|
|
|
case 0:
|
2018-11-29 11:11:50 +00:00
|
|
|
_ScreenManager.nextScreen();
|
2018-11-27 10:44:47 +00:00
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
_colSel++;
|
2018-11-27 19:40:01 +00:00
|
|
|
UPPERLIMIT(_colSel, 5);
|
2018-11-27 10:44:47 +00:00
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
case 3:
|
2018-11-27 19:40:01 +00:00
|
|
|
case 4:
|
|
|
|
case 5:
|
|
|
|
_adjustSetting(+1);
|
2018-11-27 10:44:47 +00:00
|
|
|
break;
|
2018-11-28 11:15:23 +00:00
|
|
|
case 6:
|
|
|
|
_rowSel = 0;
|
|
|
|
break;
|
2018-11-27 10:44:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
// press UP
|
|
|
|
if(event & key_Up) {
|
2018-12-20 06:29:00 +00:00
|
|
|
if(hasOEMcontroller())
|
|
|
|
_reqOEMWarning();
|
|
|
|
else {
|
|
|
|
switch(_rowSel) {
|
|
|
|
case 0:
|
|
|
|
case 2:
|
|
|
|
case 3:
|
|
|
|
case 4:
|
|
|
|
_rowSel++;
|
|
|
|
_colSel = 0;
|
|
|
|
UPPERLIMIT(_rowSel, 5);
|
|
|
|
break;
|
|
|
|
case 1: // password entry
|
|
|
|
_PWdig[_colSel]++;
|
|
|
|
ROLLUPPERLIMIT(_PWdig[_colSel], 9, 0);
|
|
|
|
break;
|
|
|
|
case 6:
|
|
|
|
setPumpMin(adjPump[0]);
|
|
|
|
setPumpMax(adjPump[1]);
|
|
|
|
setFanMin(adjFan[0]);
|
|
|
|
setFanMax(adjFan[1]);
|
|
|
|
saveNV();
|
|
|
|
_rowSel = 0;
|
|
|
|
break;
|
|
|
|
}
|
2018-11-27 10:44:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
// press DOWN
|
|
|
|
if(event & key_Down) {
|
|
|
|
switch(_rowSel) {
|
2018-11-28 11:15:23 +00:00
|
|
|
case 1: // password entry
|
2018-11-27 10:44:47 +00:00
|
|
|
_PWdig[_colSel]--;
|
|
|
|
ROLLLOWERLIMIT(_PWdig[_colSel], 0, 9);
|
|
|
|
break;
|
|
|
|
case 2:
|
2018-11-27 19:40:01 +00:00
|
|
|
_rowSel = 0;
|
|
|
|
break;
|
2018-11-27 10:44:47 +00:00
|
|
|
case 3:
|
2018-11-27 19:40:01 +00:00
|
|
|
case 4:
|
|
|
|
case 5:
|
2018-11-27 10:44:47 +00:00
|
|
|
_rowSel--;
|
2018-11-27 19:40:01 +00:00
|
|
|
_colSel = 0;
|
2018-11-27 10:44:47 +00:00
|
|
|
break;
|
2018-11-28 11:15:23 +00:00
|
|
|
case 6:
|
|
|
|
_rowSel = 0;
|
|
|
|
break;
|
2018-11-27 10:44:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-28 11:15:23 +00:00
|
|
|
|
2018-11-27 10:44:47 +00:00
|
|
|
if(event & keyRepeat) {
|
2018-11-28 11:15:23 +00:00
|
|
|
switch(_rowSel) {
|
|
|
|
case 1:
|
|
|
|
if(event & key_Centre)
|
|
|
|
_rowSel = 0; // escape PW entry by holding centre button
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
case 3:
|
|
|
|
case 4:
|
|
|
|
case 5:
|
|
|
|
int adj = 0;
|
|
|
|
if(event & key_Right) adj = +1;
|
|
|
|
if(event & key_Left) adj = -1;
|
|
|
|
if(adj) {
|
|
|
|
_adjustSetting(adj);
|
|
|
|
}
|
|
|
|
break;
|
2018-11-27 10:44:47 +00:00
|
|
|
}
|
|
|
|
}
|
2018-11-29 11:11:50 +00:00
|
|
|
_ScreenManager.reqUpdate();
|
2018-11-27 10:44:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2019-01-18 07:09:40 +00:00
|
|
|
CFuelMixtureScreen::_showPassword()
|
2018-11-27 10:44:47 +00:00
|
|
|
{
|
|
|
|
// determine metrics of character sizing
|
|
|
|
CRect extents;
|
|
|
|
_display.getTextExtents("X", extents);
|
|
|
|
int charWidth = extents.width;
|
|
|
|
_display.getTextExtents(" ", extents);
|
|
|
|
int spaceWidth = extents.width;
|
|
|
|
|
2018-11-30 13:33:49 +00:00
|
|
|
for(int idx =0 ; idx < 4; idx++) {
|
2018-11-27 10:44:47 +00:00
|
|
|
|
2018-11-30 13:33:49 +00:00
|
|
|
extents.xPos = _display.xCentre() - (2 - idx) * (charWidth * 1.5);
|
2018-11-28 11:15:23 +00:00
|
|
|
extents.yPos = 50;
|
|
|
|
|
2018-11-27 10:44:47 +00:00
|
|
|
char str[8];
|
|
|
|
|
2018-11-30 13:33:49 +00:00
|
|
|
if(_PWdig[idx] < 0) {
|
2018-11-27 10:44:47 +00:00
|
|
|
strcpy(str, "-");
|
|
|
|
}
|
|
|
|
else {
|
2018-11-30 13:33:49 +00:00
|
|
|
sprintf(str, "%d", _PWdig[idx]);
|
2018-11-27 10:44:47 +00:00
|
|
|
}
|
2018-12-07 04:18:24 +00:00
|
|
|
_printMenuText(extents.xPos, extents.yPos, str, _colSel == idx);
|
2018-11-27 10:44:47 +00:00
|
|
|
}
|
|
|
|
}
|
2018-11-27 19:40:01 +00:00
|
|
|
|
|
|
|
void
|
2019-01-18 07:09:40 +00:00
|
|
|
CFuelMixtureScreen::_adjustSetting(int dir)
|
2018-11-27 19:40:01 +00:00
|
|
|
{
|
|
|
|
switch(_rowSel) {
|
|
|
|
case 2:
|
|
|
|
adjPump[0] += (float(dir) * 0.1f);
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
adjPump[1] += (float(dir) * 0.1f);
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
adjFan[0] += dir * 10;
|
|
|
|
break;
|
|
|
|
case 5:
|
|
|
|
adjFan[1] += dir * 10;
|
|
|
|
break;
|
|
|
|
}
|
2018-11-28 11:15:23 +00:00
|
|
|
LOWERLIMIT(adjPump[0], 0.5f);
|
|
|
|
UPPERLIMIT(adjPump[0], 10.f);
|
|
|
|
LOWERLIMIT(adjFan[1], 1000);
|
|
|
|
UPPERLIMIT(adjFan[1], 5000);
|
2018-11-27 19:40:01 +00:00
|
|
|
}
|