2019-07-24 09:25:07 +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 "128x64OLED.h"
|
|
|
|
#include "FuelCalScreen.h"
|
|
|
|
#include "KeyPad.h"
|
|
|
|
#include "../Utility/helpers.h"
|
|
|
|
#include "../Utility/macros.h"
|
|
|
|
#include "../Utility/NVStorage.h"
|
|
|
|
#include "../Protocol/Protocol.h"
|
|
|
|
#include "fonts/Icons.h"
|
|
|
|
|
|
|
|
static const int Line3 = 14;
|
2020-03-30 05:17:54 +00:00
|
|
|
static const int Line2 = 26;
|
|
|
|
static const int Line1 = 38;
|
2019-07-24 09:25:07 +00:00
|
|
|
|
|
|
|
|
|
|
|
CFuelCalScreen::CFuelCalScreen(C128x64_OLED& display, CScreenManager& mgr) : CPasswordScreen(display, mgr)
|
|
|
|
{
|
|
|
|
_initUI();
|
|
|
|
_mlPerStroke = 0.02;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CFuelCalScreen::onSelect()
|
|
|
|
{
|
|
|
|
CPasswordScreen::onSelect();
|
|
|
|
_initUI();
|
|
|
|
_mlPerStroke = NVstore.getHeaterTuning().pumpCal;
|
2020-03-30 05:17:54 +00:00
|
|
|
_maxUsage = NVstore.getHeaterTuning().maxFuelUsage;
|
|
|
|
_warnUsage = NVstore.getHeaterTuning().warnFuelUsage;
|
2019-07-24 09:25:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
CFuelCalScreen::show()
|
|
|
|
{
|
|
|
|
char msg[20];
|
2020-03-30 05:17:54 +00:00
|
|
|
const int col = 86;
|
2019-07-24 09:25:07 +00:00
|
|
|
|
|
|
|
_display.fillRect(0, 50, 128, 14, BLACK);
|
|
|
|
_display.fillRect(col-border, Line3-border, 128-(col-1), 64-Line3-border, BLACK);
|
|
|
|
|
|
|
|
if(!CPasswordScreen::show()) { // for showing "saving settings"
|
|
|
|
|
2019-11-10 04:44:54 +00:00
|
|
|
if(_animateCount < 0) {
|
|
|
|
_display.clearDisplay();
|
|
|
|
_animateCount = 0;
|
2019-07-24 09:25:07 +00:00
|
|
|
}
|
|
|
|
|
2020-03-30 05:17:54 +00:00
|
|
|
_showTitle("Fuel usage");
|
2019-11-10 04:44:54 +00:00
|
|
|
// fuel calibration
|
|
|
|
int yPos = Line1;
|
2020-03-30 05:17:54 +00:00
|
|
|
_printMenuText(col, yPos, ":", false, eRightJustify);
|
|
|
|
_printMenuText(col-7, yPos, "mL/stroke", false, eRightJustify);
|
2019-11-10 04:44:54 +00:00
|
|
|
sprintf(msg, "%.03f", _mlPerStroke);
|
2020-03-30 05:17:54 +00:00
|
|
|
_printMenuText(col+2, yPos, msg, _rowSel == 1);
|
|
|
|
|
|
|
|
// tank calibration
|
|
|
|
_drawBitmap(6, Line3+3, BowserIconInfo);
|
|
|
|
yPos = Line3;
|
|
|
|
_printMenuText(col, yPos, ":", false, eRightJustify);
|
|
|
|
_printMenuText(col-7, yPos, "Maximum", false, eRightJustify);
|
|
|
|
if(_maxUsage != 0)
|
|
|
|
sprintf(msg, "%.1fL", float(_maxUsage) * 0.1f);
|
2019-11-10 04:44:54 +00:00
|
|
|
else
|
2020-03-30 05:17:54 +00:00
|
|
|
strcpy(msg, "Off");
|
|
|
|
_printMenuText(col+2, yPos, msg, _rowSel == 3);
|
|
|
|
|
|
|
|
yPos = Line2;
|
|
|
|
_printMenuText(col, yPos, ":", false, eRightJustify);
|
|
|
|
_printMenuText(col-7, yPos, "Warning", false, eRightJustify);
|
|
|
|
if(_maxUsage != 0)
|
|
|
|
sprintf(msg, "%.1fL", float(_warnUsage) * 0.1f);
|
|
|
|
else
|
|
|
|
strcpy(msg, "n/a");
|
|
|
|
_printMenuText(col+2, yPos, msg, _rowSel == 2);
|
2019-11-10 04:44:54 +00:00
|
|
|
// navigation line
|
|
|
|
yPos = 53;
|
|
|
|
int xPos = _display.xCentre();
|
|
|
|
|
|
|
|
switch(_rowSel) {
|
|
|
|
case 0:
|
|
|
|
_printMenuText(xPos, yPos, " \021 Exit \020 ", true, eCentreJustify);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
_display.drawFastHLine(0, 52, 128, WHITE);
|
|
|
|
_printMenuText(xPos, 56, "\030\031Sel \033\032 Adj", false, eCentreJustify);
|
|
|
|
_printMenuText(xPos, 56, "Save", false, eCentreJustify);
|
|
|
|
break;
|
2019-07-24 09:25:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
CFuelCalScreen::animate()
|
|
|
|
{
|
2019-11-21 08:25:14 +00:00
|
|
|
if(_saveBusy()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-07-24 09:25:07 +00:00
|
|
|
if(_animateCount >= 0) {
|
|
|
|
switch(_animateCount) {
|
|
|
|
case 0:
|
2020-03-30 05:17:54 +00:00
|
|
|
_display.fillRect(6, Line1-3, FuelIconSmallInfo.width, FuelIconSmallInfo.height+4, BLACK); // scrub prior drip
|
2019-07-24 09:25:07 +00:00
|
|
|
_drawBitmap(6, Line1-3, FuelIconSmallInfo);
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
_display.fillRect(6, Line1-3, FuelIconSmallInfo.width, FuelIconSmallInfo.height, BLACK); // scrub prior drip
|
|
|
|
_drawBitmap(6, Line1-2, FuelIconSmallInfo); // drip fuel
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
_display.fillRect(6, Line1-2, FuelIconSmallInfo.width, FuelIconSmallInfo.height, BLACK); // scrub prior drip
|
|
|
|
_drawBitmap(6, Line1-1, FuelIconSmallInfo); // drip fuel
|
|
|
|
break;
|
|
|
|
case 6:
|
|
|
|
_display.fillRect(6, Line1-1, FuelIconSmallInfo.width, FuelIconSmallInfo.height, BLACK); // scrub prior drip
|
|
|
|
_drawBitmap(6, Line1, FuelIconSmallInfo); // drip fuel
|
|
|
|
break;
|
|
|
|
case 8:
|
|
|
|
_display.fillRect(6, Line1, FuelIconSmallInfo.width, FuelIconSmallInfo.height, BLACK); // scrub prior drip
|
|
|
|
_drawBitmap(6, Line1+1, FuelIconSmallInfo); // drip fuel
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
_animateCount++;
|
|
|
|
WRAPUPPERLIMIT(_animateCount, 9, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
CFuelCalScreen::keyHandler(uint8_t event)
|
|
|
|
{
|
2019-11-21 08:25:14 +00:00
|
|
|
if(CUIEditScreen::keyHandler(event)) { // handles save confirm
|
2019-11-10 04:44:54 +00:00
|
|
|
return true;
|
|
|
|
}
|
2019-07-24 09:25:07 +00:00
|
|
|
|
|
|
|
if(event & keyRepeat) {
|
|
|
|
if(event & key_Left) {
|
|
|
|
_adjust(-1);
|
|
|
|
}
|
|
|
|
if(event & key_Right) {
|
|
|
|
_adjust(+1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(event & keyPressed) {
|
|
|
|
// press LEFT to select previous screen
|
|
|
|
if(event & key_Left) {
|
|
|
|
switch(_rowSel) {
|
|
|
|
case 0:
|
|
|
|
_ScreenManager.prevMenu();
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
case 2:
|
|
|
|
case 3:
|
|
|
|
_adjust(-1);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// press RIGHT to select next screen
|
|
|
|
if(event & key_Right) {
|
|
|
|
switch(_rowSel) {
|
|
|
|
case 0:
|
|
|
|
_ScreenManager.nextMenu();
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
case 2:
|
|
|
|
case 3:
|
|
|
|
_adjust(+1);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(event & key_Down) {
|
|
|
|
_rowSel--;
|
|
|
|
LOWERLIMIT(_rowSel, 0);
|
|
|
|
}
|
|
|
|
// UP press
|
|
|
|
if(event & key_Up) {
|
|
|
|
switch(_rowSel) {
|
|
|
|
case 0:
|
|
|
|
case 1:
|
|
|
|
case 2:
|
|
|
|
case 3:
|
|
|
|
_rowSel++;
|
2020-03-30 05:17:54 +00:00
|
|
|
UPPERLIMIT(_rowSel, 3);
|
2019-07-24 09:25:07 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// CENTRE press
|
|
|
|
if(event & key_Centre) {
|
|
|
|
switch(_rowSel) {
|
|
|
|
case 0:
|
|
|
|
_ScreenManager.selectMenu(CScreenManager::RootMenuLoop);
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
case 2:
|
|
|
|
case 3:
|
|
|
|
_animateCount = -1;
|
|
|
|
_display.clearDisplay();
|
2019-11-21 08:25:14 +00:00
|
|
|
_confirmSave();
|
|
|
|
_rowSel = 0;
|
2019-07-24 09:25:07 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
_ScreenManager.reqUpdate();
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CFuelCalScreen::_adjust(int dir)
|
|
|
|
{
|
|
|
|
switch(_rowSel) {
|
|
|
|
case 1:
|
|
|
|
_mlPerStroke += dir * 0.001;
|
|
|
|
BOUNDSLIMIT(_mlPerStroke, 0.001, 1);
|
|
|
|
break;
|
|
|
|
case 2:
|
2020-03-30 05:17:54 +00:00
|
|
|
_warnUsage += dir;
|
|
|
|
BOUNDSLIMIT(_warnUsage, 0, 100);
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
_maxUsage += dir;
|
|
|
|
BOUNDSLIMIT(_maxUsage, 0, 10000);
|
2019-07-24 09:25:07 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2019-11-10 04:44:54 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
CFuelCalScreen::_saveNV()
|
|
|
|
{
|
|
|
|
sHeaterTuning tuning = NVstore.getHeaterTuning();
|
|
|
|
tuning.pumpCal = _mlPerStroke;
|
2020-03-30 05:17:54 +00:00
|
|
|
tuning.maxFuelUsage = _maxUsage;
|
|
|
|
tuning.warnFuelUsage = _warnUsage;
|
2019-11-10 04:44:54 +00:00
|
|
|
NVstore.setHeaterTuning(tuning);
|
|
|
|
NVstore.save();
|
|
|
|
}
|