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"
|
2019-06-15 23:09:29 +00:00
|
|
|
#include "../Utility/helpers.h"
|
2019-07-02 08:27:20 +00:00
|
|
|
#include "../Utility/DebugPort.h"
|
2019-06-15 23:09:29 +00:00
|
|
|
#include "../Utility/macros.h"
|
2019-11-21 08:25:14 +00:00
|
|
|
#include "../Utility/NVStorage.h"
|
2019-06-15 23:09:29 +00:00
|
|
|
#include "../Protocol/Protocol.h"
|
2019-07-21 11:17:54 +00:00
|
|
|
#include "fonts/Icons.h"
|
2018-11-27 10:44:47 +00:00
|
|
|
|
|
|
|
|
2019-01-18 23:06:12 +00:00
|
|
|
CFuelMixtureScreen::CFuelMixtureScreen(C128x64_OLED& display, CScreenManager& mgr) : CPasswordScreen(display, mgr)
|
2018-11-27 10:44:47 +00:00
|
|
|
{
|
2019-02-28 08:56:13 +00:00
|
|
|
_initUI();
|
2018-11-27 10:44:47 +00:00
|
|
|
}
|
|
|
|
|
2019-01-19 11:05:14 +00:00
|
|
|
void
|
|
|
|
CFuelMixtureScreen::onSelect()
|
|
|
|
{
|
2019-02-28 08:56:13 +00:00
|
|
|
CPasswordScreen::onSelect();
|
2019-03-01 23:16:37 +00:00
|
|
|
|
2019-07-21 11:17:54 +00:00
|
|
|
_load();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CFuelMixtureScreen::_load()
|
|
|
|
{
|
2019-11-21 08:25:14 +00:00
|
|
|
adjPump[0] = NVstore.getHeaterTuning().getPmin();
|
|
|
|
adjPump[1] = NVstore.getHeaterTuning().getPmax();
|
|
|
|
adjFan[0] = NVstore.getHeaterTuning().Fmin;
|
|
|
|
adjFan[1] = NVstore.getHeaterTuning().Fmax;
|
2019-02-28 08:56:13 +00:00
|
|
|
}
|
|
|
|
|
2019-01-18 23:06:12 +00:00
|
|
|
bool
|
2019-01-18 07:09:40 +00:00
|
|
|
CFuelMixtureScreen::show()
|
2018-11-27 10:44:47 +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 col3 = _display.width() - border;
|
2018-11-27 10:44:47 +00:00
|
|
|
|
2019-07-21 11:17:54 +00:00
|
|
|
_display.fillRect(70, 0, 58, 64, BLACK); // scrub variables
|
|
|
|
_display.fillRect(0, 50, 128, 14, BLACK); // scrub footer
|
2018-11-28 11:15:23 +00:00
|
|
|
|
2019-11-21 08:25:14 +00:00
|
|
|
if(CPasswordScreen::show()) {
|
|
|
|
return true;
|
|
|
|
}
|
2018-11-28 11:15:23 +00:00
|
|
|
|
2019-11-21 08:25:14 +00:00
|
|
|
if(_animateCount == -1) {
|
|
|
|
_animateCount = 0;
|
|
|
|
_display.clearDisplay();
|
2018-11-27 10:44:47 +00:00
|
|
|
}
|
2019-11-21 08:25:14 +00:00
|
|
|
// Pump Minimum adjustment
|
|
|
|
yPos = border + 36;
|
|
|
|
_printMenuText(65, yPos, "Min", false, eRightJustify);
|
|
|
|
sprintf(str, "%.1f Hz", adjPump[0]);
|
|
|
|
_printMenuText(col3, yPos, str, _rowSel == 1, eRightJustify);
|
|
|
|
// Pump Maximum adjustment
|
|
|
|
yPos = border + 24;
|
|
|
|
_printMenuText(65, yPos, "Max", false, eRightJustify);
|
|
|
|
sprintf(str, "%.1f Hz", adjPump[1]);
|
|
|
|
_printMenuText(col3, yPos, str, _rowSel == 2, eRightJustify);
|
|
|
|
// Fan Minimum adjustment
|
|
|
|
yPos = border + 12;
|
|
|
|
_printMenuText(65, yPos, "Min", false, eRightJustify);
|
|
|
|
sprintf(str, "%d RPM", adjFan[0]);
|
|
|
|
_printMenuText(col3, yPos, str, _rowSel == 3, eRightJustify);
|
|
|
|
// Fan Maximum adjustment
|
|
|
|
yPos = border;
|
|
|
|
_printMenuText(65, yPos, "Max", false, eRightJustify);
|
|
|
|
sprintf(str, "%d RPM", adjFan[1]);
|
|
|
|
_printMenuText(col3, yPos, str, _rowSel == 4, eRightJustify);
|
|
|
|
// navigation line
|
|
|
|
yPos = 53;
|
|
|
|
xPos = _display.xCentre();
|
|
|
|
switch(_rowSel) {
|
|
|
|
case 0:
|
|
|
|
_printMenuText(xPos, yPos, " \021 Exit \020 ", _rowSel == 0, eCentreJustify); // " < Exit > "
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
case 2:
|
|
|
|
_display.drawFastHLine(0, 52, 128, WHITE);
|
|
|
|
_printMenuText(xPos, 56, "\030\031Sel Save \033\032 \3600.1", false, eCentreJustify); // "^vSel Save <> +-0.1"
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
case 4:
|
|
|
|
_display.drawFastHLine(0, 52, 128, WHITE);
|
|
|
|
_printMenuText(xPos, 56, "\030\031Sel Save \033\032 \36010", false, eCentreJustify); // "^vSel Save <> +-10"
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2018-11-27 10:44:47 +00:00
|
|
|
|
2019-01-18 23:06:12 +00:00
|
|
|
return true;
|
2018-11-27 10:44:47 +00:00
|
|
|
}
|
|
|
|
|
2019-07-21 11:17:54 +00:00
|
|
|
bool
|
|
|
|
CFuelMixtureScreen::animate()
|
|
|
|
{
|
2019-11-21 08:25:14 +00:00
|
|
|
if(_saveBusy())
|
|
|
|
return false;
|
|
|
|
|
2019-07-21 11:17:54 +00:00
|
|
|
if(_animateCount >= 0) {
|
|
|
|
|
|
|
|
int xPos = 20;
|
|
|
|
int yPos = 5;
|
|
|
|
int yFuel = 30;
|
|
|
|
_display.fillRect(xPos, yPos, FanIcon1Info.width, FanIcon1Info.height, BLACK);
|
|
|
|
_display.fillRect(xPos+5, yFuel, FuelIconInfo.width, FuelIconInfo.height + 4, BLACK);
|
|
|
|
_drawBitmap(xPos+5, yFuel+_animateCount, FuelIconInfo);
|
|
|
|
switch(_animateCount) {
|
|
|
|
case 0: _drawBitmap(xPos, yPos, FanIcon1Info); break;
|
|
|
|
case 1: _drawBitmap(xPos, yPos, FanIcon2Info); break;
|
|
|
|
case 2: _drawBitmap(xPos, yPos, FanIcon3Info); break;
|
|
|
|
case 3: _drawBitmap(xPos, yPos, FanIcon4Info); break;
|
|
|
|
}
|
|
|
|
|
|
|
|
_animateCount++;
|
|
|
|
WRAPUPPERLIMIT(_animateCount, 3, 0);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2018-11-27 10:44:47 +00:00
|
|
|
|
2019-01-18 23:06:12 +00:00
|
|
|
bool
|
2019-01-18 07:09:40 +00:00
|
|
|
CFuelMixtureScreen::keyHandler(uint8_t event)
|
2018-11-27 10:44:47 +00:00
|
|
|
{
|
2019-11-21 08:25:14 +00:00
|
|
|
if(CUIEditScreen::keyHandler(event)) { // handle save confirm
|
2019-11-10 04:44:54 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-01-19 11:05:14 +00:00
|
|
|
if(event & keyPressed) {
|
|
|
|
// press CENTRE
|
|
|
|
if(event & key_Centre) {
|
2019-11-21 08:25:14 +00:00
|
|
|
if(_rowSel) {
|
|
|
|
_animateCount = -1;
|
|
|
|
_display.clearDisplay();
|
|
|
|
_confirmSave(); // enter save confirm mode
|
|
|
|
_rowSel = 0;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
_ScreenManager.selectMenu(CScreenManager::RootMenuLoop);
|
2019-01-19 11:05:14 +00:00
|
|
|
}
|
2018-11-27 10:44:47 +00:00
|
|
|
}
|
2019-01-19 11:05:14 +00:00
|
|
|
// press LEFT
|
|
|
|
if(event & key_Left) {
|
2019-11-21 08:25:14 +00:00
|
|
|
if(_rowSel) {
|
|
|
|
_adjustSetting(-1);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
_ScreenManager.prevMenu();
|
2018-11-27 10:44:47 +00:00
|
|
|
}
|
2019-01-19 11:05:14 +00:00
|
|
|
}
|
|
|
|
// press RIGHT
|
|
|
|
if(event & key_Right) {
|
2019-11-21 08:25:14 +00:00
|
|
|
if(_rowSel) {
|
|
|
|
_adjustSetting(+1);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
_ScreenManager.nextMenu();
|
2018-11-27 10:44:47 +00:00
|
|
|
}
|
2019-01-19 11:05:14 +00:00
|
|
|
}
|
|
|
|
// press UP
|
|
|
|
if(event & key_Up) {
|
|
|
|
if(hasOEMcontroller())
|
|
|
|
_reqOEMWarning();
|
|
|
|
else {
|
2018-12-20 06:29:00 +00:00
|
|
|
switch(_rowSel) {
|
|
|
|
case 0:
|
2019-01-19 11:05:14 +00:00
|
|
|
// grab current settings upon entry to edit mode
|
2019-11-21 08:25:14 +00:00
|
|
|
_load();
|
|
|
|
// adjPump[0] = getHeaterInfo().getPump_Min();
|
|
|
|
// adjPump[1] = getHeaterInfo().getPump_Max();
|
|
|
|
// adjFan[0] = getHeaterInfo().getFan_Min();
|
|
|
|
// adjFan[1] = getHeaterInfo().getFan_Max();
|
2019-01-18 23:06:12 +00:00
|
|
|
case 1:
|
|
|
|
case 2:
|
|
|
|
case 3:
|
2019-01-19 11:05:14 +00:00
|
|
|
_rowSel++;
|
|
|
|
UPPERLIMIT(_rowSel, 4);
|
2019-01-18 23:06:12 +00:00
|
|
|
break;
|
2018-12-20 06:29:00 +00:00
|
|
|
}
|
2018-11-27 10:44:47 +00:00
|
|
|
}
|
|
|
|
}
|
2019-01-19 11:05:14 +00:00
|
|
|
// press DOWN
|
|
|
|
if(event & key_Down) {
|
2019-11-21 08:25:14 +00:00
|
|
|
if(_rowSel) {
|
|
|
|
_rowSel--;
|
|
|
|
if(_rowSel == 0) {
|
|
|
|
_load(); // dispose of any changes, re-obtain current settings
|
|
|
|
}
|
2018-11-27 10:44:47 +00:00
|
|
|
}
|
|
|
|
}
|
2019-01-19 11:05:14 +00:00
|
|
|
_ScreenManager.reqUpdate();
|
|
|
|
}
|
|
|
|
|
|
|
|
if(event & keyRepeat) {
|
2019-11-21 08:25:14 +00:00
|
|
|
if(_rowSel) {
|
|
|
|
int adj = 0;
|
|
|
|
if(event & key_Right) adj = +1;
|
|
|
|
if(event & key_Left) adj = -1;
|
|
|
|
if(adj) {
|
|
|
|
_adjustSetting(adj);
|
|
|
|
}
|
2019-01-19 11:05:14 +00:00
|
|
|
}
|
|
|
|
_ScreenManager.reqUpdate();
|
2018-11-27 10:44:47 +00:00
|
|
|
}
|
2019-01-18 23:06:12 +00:00
|
|
|
return true;
|
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) {
|
2019-01-18 23:06:12 +00:00
|
|
|
case 1:
|
2018-11-27 19:40:01 +00:00
|
|
|
adjPump[0] += (float(dir) * 0.1f);
|
|
|
|
break;
|
2019-01-18 23:06:12 +00:00
|
|
|
case 2:
|
2018-11-27 19:40:01 +00:00
|
|
|
adjPump[1] += (float(dir) * 0.1f);
|
|
|
|
break;
|
2019-01-18 23:06:12 +00:00
|
|
|
case 3:
|
2018-11-27 19:40:01 +00:00
|
|
|
adjFan[0] += dir * 10;
|
|
|
|
break;
|
2019-01-18 23:06:12 +00:00
|
|
|
case 4:
|
2018-11-27 19:40:01 +00:00
|
|
|
adjFan[1] += dir * 10;
|
|
|
|
break;
|
|
|
|
}
|
2019-11-21 08:25:14 +00:00
|
|
|
BOUNDSLIMIT(adjPump[0], 0.5f, 10.f);
|
|
|
|
BOUNDSLIMIT(adjPump[1], 0.5f, 10.f);
|
2020-01-13 08:48:32 +00:00
|
|
|
BOUNDSLIMIT(adjFan[0], 500, 5000);
|
2019-11-21 08:25:14 +00:00
|
|
|
BOUNDSLIMIT(adjFan[1], 1000, 5000);
|
2019-11-10 04:44:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CFuelMixtureScreen::_saveNV()
|
|
|
|
{
|
2020-04-11 08:49:52 +00:00
|
|
|
sHeaterTuning tuning = NVstore.getHeaterTuning();
|
|
|
|
tuning.setPmin(adjPump[0]);
|
|
|
|
tuning.setPmax(adjPump[1]);
|
|
|
|
tuning.setFmin(adjFan[0]);
|
|
|
|
tuning.setFmax(adjFan[1]);
|
|
|
|
NVstore.setHeaterTuning(tuning);
|
|
|
|
NVstore.save();
|
2019-11-10 04:44:54 +00:00
|
|
|
}
|