Adding OnStart, OnStop and OnTimeout home screen actions
This commit is contained in:
parent
c1b1036ece
commit
480bd1b15c
|
@ -69,8 +69,8 @@ CBasicScreen::show()
|
|||
|
||||
{
|
||||
CTransientFont AF(_display, &MAXIFONT); // temporarily use a large font
|
||||
// _printMenuText(_display.xCentre(), 23, msg, false, eCentreJustify);
|
||||
_printMenuText(_display.xCentre(), 25, msg, false, eCentreJustify);
|
||||
_printMenuText(_display.xCentre(), 23, msg, false, eCentreJustify);
|
||||
// _printMenuText(_display.xCentre(), 25, msg, false, eCentreJustify);
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
|
|
@ -107,6 +107,23 @@ CClockScreen::keyHandler(uint8_t event)
|
|||
setGPIO(1, !getGPIO(1)); // toggle GPIO output #2
|
||||
}
|
||||
}
|
||||
// hold CENTRE to toggle On/Off state
|
||||
if(event & key_Centre) {
|
||||
int runstate = getHeaterInfo().getRunStateEx();
|
||||
if(runstate) { // running, including cyclic mode idle
|
||||
if(_keyRepeatCount > 5) {
|
||||
_keyRepeatCount = -1;
|
||||
requestOff();
|
||||
}
|
||||
}
|
||||
else { // standard idle state
|
||||
// standby, request ON
|
||||
if(_keyRepeatCount > 3) {
|
||||
_keyRepeatCount = -1;
|
||||
requestOn();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// release event
|
||||
|
|
173
Arduino/BTCDieselHeater/src/OLED/HomeMenuSelScreen.cpp
Normal file
173
Arduino/BTCDieselHeater/src/OLED/HomeMenuSelScreen.cpp
Normal file
|
@ -0,0 +1,173 @@
|
|||
/*
|
||||
* 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 "HomeMenuSelScreen.h"
|
||||
#include "KeyPad.h"
|
||||
#include "../Protocol/helpers.h"
|
||||
#include "../Utility/UtilClasses.h"
|
||||
#include "../Utility/NVStorage.h"
|
||||
#include "../Utility/GPIO.h"
|
||||
#include "fonts/Icons.h"
|
||||
|
||||
|
||||
|
||||
CHomeMenuSelScreen::CHomeMenuSelScreen(C128x64_OLED& display, CScreenManager& mgr) : CPasswordScreen(display, mgr)
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
CHomeMenuSelScreen::onSelect()
|
||||
{
|
||||
CScreenHeader::onSelect();
|
||||
_rowSel = 0;
|
||||
_action = NVstore.getHomeMenu();
|
||||
}
|
||||
|
||||
void
|
||||
CHomeMenuSelScreen::_initUI()
|
||||
{
|
||||
}
|
||||
|
||||
bool
|
||||
CHomeMenuSelScreen::show()
|
||||
{
|
||||
char msg[16];
|
||||
|
||||
_display.clearDisplay();
|
||||
|
||||
if(!CPasswordScreen::show()) { // for showing "saving settings"
|
||||
|
||||
if(_rowSel == 4) {
|
||||
_printInverted(_display.xCentre(), 0, " Saving Settings ", true, eCentreJustify);
|
||||
_printMenuText(_display.xCentre(), 35, "Press UP to", false, eCentreJustify);
|
||||
_printMenuText(_display.xCentre(), 43, "confirm save", false, eCentreJustify);
|
||||
}
|
||||
else {
|
||||
_printInverted(_display.xCentre(), 0, " Home Menu Actions ", true, eCentreJustify);
|
||||
|
||||
_printMenuText(66, 14, "On timeout:", false, eRightJustify);
|
||||
switch(_action.onTimeout) {
|
||||
case 0: strcpy(msg, "Default"); break;
|
||||
case 1: strcpy(msg, "Detailed"); break;
|
||||
case 2: strcpy(msg, "Basic"); break;
|
||||
case 3: strcpy(msg, "Clock"); break;
|
||||
}
|
||||
_printMenuText(70, 14, msg, _rowSel == 3);
|
||||
|
||||
_printMenuText(66, 26, "On Start:", false, eRightJustify);
|
||||
switch(_action.onStart) {
|
||||
case 0: strcpy(msg, "Default"); break;
|
||||
case 1: strcpy(msg, "Detailed"); break;
|
||||
case 2: strcpy(msg, "Basic"); break;
|
||||
case 3: strcpy(msg, "Clock"); break;
|
||||
}
|
||||
_printMenuText(70, 26, msg, _rowSel == 2);
|
||||
|
||||
_printMenuText(66, 38, "On Stop:", false, eRightJustify);
|
||||
switch(_action.onStop) {
|
||||
case 0: strcpy(msg, "Default"); break;
|
||||
case 1: strcpy(msg, "Detailed"); break;
|
||||
case 2: strcpy(msg, "Basic"); break;
|
||||
case 3: strcpy(msg, "Clock"); break;
|
||||
}
|
||||
_printMenuText(70, 38, msg, _rowSel == 1);
|
||||
|
||||
_printMenuText(_display.xCentre(), 53, " \021 Exit \020 ", _rowSel == 0, eCentreJustify);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
CHomeMenuSelScreen::keyHandler(uint8_t event)
|
||||
{
|
||||
if(event & keyPressed) {
|
||||
// UP press
|
||||
if(event & key_Up) {
|
||||
if(_rowSel == 4) {
|
||||
_showStoringMessage();
|
||||
NVstore.setHomeMenu(_action);
|
||||
saveNV();
|
||||
_rowSel = 0;
|
||||
}
|
||||
else {
|
||||
_rowSel++;
|
||||
UPPERLIMIT(_rowSel, 3);
|
||||
}
|
||||
}
|
||||
// UP press
|
||||
if(event & key_Down) {
|
||||
_rowSel--;
|
||||
LOWERLIMIT(_rowSel, 0);
|
||||
}
|
||||
// CENTRE press
|
||||
if(event & key_Centre) {
|
||||
if(_rowSel == 0) {
|
||||
_ScreenManager.selectMenu(CScreenManager::RootMenuLoop); // force return to main menu
|
||||
}
|
||||
else {
|
||||
_rowSel = 4;
|
||||
}
|
||||
}
|
||||
// LEFT press
|
||||
if(event & key_Left) {
|
||||
if(_rowSel == 0)
|
||||
_ScreenManager.prevMenu();
|
||||
else
|
||||
adjust(-1);
|
||||
}
|
||||
// RIGHT press
|
||||
if(event & key_Right) {
|
||||
if(_rowSel == 0)
|
||||
_ScreenManager.nextMenu();
|
||||
else
|
||||
adjust(+1);
|
||||
}
|
||||
}
|
||||
|
||||
_ScreenManager.reqUpdate();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void
|
||||
CHomeMenuSelScreen::adjust(int dir)
|
||||
{
|
||||
switch(_rowSel) {
|
||||
case 1:
|
||||
_action.onStop += dir;
|
||||
ROLLLOWERLIMIT(_action.onStop, 0, 3);
|
||||
ROLLUPPERLIMIT(_action.onStop, 3, 0);
|
||||
break;
|
||||
case 2:
|
||||
_action.onStart += dir;
|
||||
ROLLLOWERLIMIT(_action.onStart, 0, 3);
|
||||
ROLLUPPERLIMIT(_action.onStart, 3, 0);
|
||||
break;
|
||||
case 3:
|
||||
_action.onTimeout += dir;
|
||||
ROLLLOWERLIMIT(_action.onTimeout, 0, 3);
|
||||
ROLLUPPERLIMIT(_action.onTimeout, 3, 0);
|
||||
break;
|
||||
}
|
||||
}
|
46
Arduino/BTCDieselHeater/src/OLED/HomeMenuSelScreen.h
Normal file
46
Arduino/BTCDieselHeater/src/OLED/HomeMenuSelScreen.h
Normal file
|
@ -0,0 +1,46 @@
|
|||
/*
|
||||
* 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/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef __HOMEMENUSELSCREEN_H__
|
||||
#define __HOMEMENUSELSCREEN_H__
|
||||
|
||||
#include <stdint.h>
|
||||
#include "PasswordScreen.h"
|
||||
#include "../Utility/NVStorage.h"
|
||||
|
||||
class C128x64_OLED;
|
||||
class CScreenManager;
|
||||
|
||||
|
||||
class CHomeMenuSelScreen : public CPasswordScreen
|
||||
{
|
||||
int _rowSel;
|
||||
sHomeMenuActions _action;
|
||||
void _initUI();
|
||||
public:
|
||||
CHomeMenuSelScreen(C128x64_OLED& display, CScreenManager& mgr);
|
||||
bool show();
|
||||
bool keyHandler(uint8_t event);
|
||||
void onSelect();
|
||||
void adjust(int dir);
|
||||
};
|
||||
|
||||
#endif
|
|
@ -40,7 +40,7 @@ COtherOptionsScreen::onSelect()
|
|||
CScreenHeader::onSelect();
|
||||
_rowSel = 0;
|
||||
_frameRate = NVstore.getFrameRate();
|
||||
_homeMenu = NVstore.getHomeMenu();
|
||||
// _homeMenu = NVstore.getHomeMenu();
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -69,14 +69,14 @@ COtherOptionsScreen::show()
|
|||
sprintf(msg, "%dms", _frameRate);
|
||||
_printMenuText(70, 14, msg, _rowSel == 2);
|
||||
|
||||
_printMenuText(66, 25, "Home menu:", false, eRightJustify);
|
||||
/* _printMenuText(66, 25, "Home menu:", false, eRightJustify);
|
||||
switch(_homeMenu) {
|
||||
case 0: strcpy(msg, "Default"); break;
|
||||
case 1: strcpy(msg, "Detailed"); break;
|
||||
case 2: strcpy(msg, "Basic"); break;
|
||||
case 3: strcpy(msg, "Clock"); break;
|
||||
}
|
||||
_printMenuText(70, 25, msg, _rowSel == 1);
|
||||
_printMenuText(70, 25, msg, _rowSel == 1);*/
|
||||
|
||||
_printMenuText(_display.xCentre(), 53, " \021 Exit \020 ", _rowSel == 0, eCentreJustify);
|
||||
}
|
||||
|
@ -94,18 +94,20 @@ COtherOptionsScreen::keyHandler(uint8_t event)
|
|||
if(_rowSel == 4) {
|
||||
_showStoringMessage();
|
||||
NVstore.setFrameRate(_frameRate);
|
||||
NVstore.setHomeMenu(_homeMenu);
|
||||
// NVstore.setHomeMenu(_homeMenu);
|
||||
saveNV();
|
||||
_rowSel = 0;
|
||||
}
|
||||
else {
|
||||
_rowSel++;
|
||||
// _rowSel++;
|
||||
_rowSel = 2;
|
||||
UPPERLIMIT(_rowSel, 2);
|
||||
}
|
||||
}
|
||||
// UP press
|
||||
if(event & key_Down) {
|
||||
_rowSel--;
|
||||
// _rowSel--;
|
||||
_rowSel = 0;
|
||||
LOWERLIMIT(_rowSel, 0);
|
||||
}
|
||||
// CENTRE press
|
||||
|
@ -143,9 +145,9 @@ COtherOptionsScreen::adjust(int dir)
|
|||
{
|
||||
switch(_rowSel) {
|
||||
case 1:
|
||||
_homeMenu += dir;
|
||||
ROLLLOWERLIMIT(_homeMenu, 0, 3);
|
||||
ROLLUPPERLIMIT(_homeMenu, 3, 0);
|
||||
// _homeMenu += dir;
|
||||
// ROLLLOWERLIMIT(_homeMenu, 0, 3);
|
||||
// ROLLUPPERLIMIT(_homeMenu, 3, 0);
|
||||
break;
|
||||
case 2:
|
||||
_frameRate += dir * 50;
|
||||
|
|
|
@ -33,7 +33,7 @@ class COtherOptionsScreen : public CPasswordScreen
|
|||
{
|
||||
int _rowSel;
|
||||
uint16_t _frameRate;
|
||||
uint8_t _homeMenu;
|
||||
// uint8_t _homeMenu;
|
||||
void _initUI();
|
||||
public:
|
||||
COtherOptionsScreen(C128x64_OLED& display, CScreenManager& mgr);
|
||||
|
|
|
@ -37,6 +37,7 @@
|
|||
#include "InheritSettingsScreen.h"
|
||||
#include "GPIOScreen.h"
|
||||
#include "VersionInfoScreen.h"
|
||||
#include "HomeMenuSelScreen.h"
|
||||
#include "OtherOptionsScreen.h"
|
||||
#include <Wire.h>
|
||||
#include "../cfg/pins.h"
|
||||
|
@ -216,6 +217,7 @@ CScreenManager::begin(bool bNoClock)
|
|||
menuloop.push_back(new CThermostatModeScreen(*_pDisplay, *this)); // experimental settings screen
|
||||
menuloop.push_back(new CGPIOScreen(*_pDisplay, *this)); // GPIO settings screen
|
||||
menuloop.push_back(new CVersionInfoScreen(*_pDisplay, *this)); // GPIO settings screen
|
||||
menuloop.push_back(new CHomeMenuSelScreen(*_pDisplay, *this)); // Home menu settings screen
|
||||
menuloop.push_back(new COtherOptionsScreen(*_pDisplay, *this)); // Other options screen
|
||||
_Screens.push_back(menuloop);
|
||||
|
||||
|
@ -259,9 +261,11 @@ CScreenManager::checkUpdate()
|
|||
// return to those upon timeout, otherwise return to Basic Control screen
|
||||
if(_rootMenu > 2) {
|
||||
_rootMenu = _subMenu = 1;
|
||||
if(NVstore.getHomeMenu()) { // allow user to override defualt screen
|
||||
DebugPort.print("Falling back to user home screen #"); DebugPort.println(NVstore.getHomeMenu()-1);
|
||||
_rootMenu = _subMenu = NVstore.getHomeMenu()-1;
|
||||
uint8_t userHomeMenu = NVstore.getHomeMenu().onTimeout;
|
||||
if(userHomeMenu) { // allow user to override defualt screen
|
||||
userHomeMenu--;
|
||||
DebugPort.print("Falling back to user home screen #"); DebugPort.println(userHomeMenu);
|
||||
_rootMenu = _subMenu = userHomeMenu;
|
||||
}
|
||||
}
|
||||
_enterScreen();
|
||||
|
|
|
@ -351,14 +351,14 @@ CHeaterStorage::setFrameRate(uint16_t val)
|
|||
_calValues.Options.FrameRate = val;
|
||||
}
|
||||
|
||||
uint8_t
|
||||
CHeaterStorage::getHomeMenu()
|
||||
const sHomeMenuActions&
|
||||
CHeaterStorage::getHomeMenu() const
|
||||
{
|
||||
return _calValues.Options.HomeMenu;
|
||||
}
|
||||
|
||||
void
|
||||
CHeaterStorage::setHomeMenu(uint8_t val)
|
||||
CHeaterStorage::setHomeMenu(sHomeMenuActions val)
|
||||
{
|
||||
_calValues.Options.HomeMenu = val;
|
||||
}
|
||||
|
@ -485,7 +485,9 @@ CESP32HeaterStorage::loadUI()
|
|||
validatedLoad("GPIOinMode", _calValues.Options.GPIOinMode, 0, u8inBounds, 0, 3);
|
||||
validatedLoad("GPIOoutMode", _calValues.Options.GPIOoutMode, 0, u8inBounds, 0, 2);
|
||||
validatedLoad("GPIOalgMode", _calValues.Options.GPIOalgMode, 0, u8inBounds, 0, 2);
|
||||
validatedLoad("HomeMenu", _calValues.Options.HomeMenu, 0, u8inBounds, 0, 3);
|
||||
validatedLoad("HomeMenuonTimeout", _calValues.Options.HomeMenu.onTimeout, 0, u8inBounds, 0, 3);
|
||||
validatedLoad("HomeMenuonStart", _calValues.Options.HomeMenu.onStart, 0, u8inBounds, 0, 3);
|
||||
validatedLoad("HomeMenuonStop", _calValues.Options.HomeMenu.onStop, 0, u8inBounds, 0, 3);
|
||||
validatedLoad("FrameRate", _calValues.Options.FrameRate, 1000, u16inBounds, 300, 1500);
|
||||
preferences.end();
|
||||
}
|
||||
|
@ -503,7 +505,9 @@ CESP32HeaterStorage::saveUI()
|
|||
preferences.putUChar("GPIOinMode", _calValues.Options.GPIOinMode);
|
||||
preferences.putUChar("GPIOoutMode", _calValues.Options.GPIOoutMode);
|
||||
preferences.putUChar("GPIOalgMode", _calValues.Options.GPIOalgMode);
|
||||
preferences.putUChar("HomeMenu", _calValues.Options.HomeMenu);
|
||||
preferences.putUChar("HomeMenuonTimeout", _calValues.Options.HomeMenu.onTimeout);
|
||||
preferences.putUChar("HomeMenuonStart", _calValues.Options.HomeMenu.onStart);
|
||||
preferences.putUChar("HomeMenuonStop", _calValues.Options.HomeMenu.onStop);
|
||||
preferences.putUShort("FrameRate", _calValues.Options.FrameRate);
|
||||
preferences.end();
|
||||
}
|
||||
|
|
|
@ -62,6 +62,24 @@ struct sHeater {
|
|||
};
|
||||
};
|
||||
|
||||
struct sHomeMenuActions {
|
||||
uint8_t onTimeout;
|
||||
uint8_t onStart;
|
||||
uint8_t onStop;
|
||||
bool valid() {
|
||||
bool retval = true;
|
||||
retval &= onTimeout < 4;
|
||||
retval &= onStart < 4;
|
||||
retval &= onStop < 4;
|
||||
return retval;
|
||||
}
|
||||
void init() {
|
||||
onTimeout = 0;
|
||||
onStart = 0;
|
||||
onStop = 0;
|
||||
}
|
||||
};
|
||||
|
||||
struct sBTCoptions {
|
||||
long DimTime;
|
||||
uint8_t degF;
|
||||
|
@ -73,7 +91,7 @@ struct sBTCoptions {
|
|||
uint8_t GPIOoutMode;
|
||||
uint8_t GPIOalgMode;
|
||||
uint16_t FrameRate;
|
||||
uint8_t HomeMenu;
|
||||
sHomeMenuActions HomeMenu;
|
||||
|
||||
bool valid() {
|
||||
bool retval = true;
|
||||
|
@ -86,7 +104,7 @@ struct sBTCoptions {
|
|||
retval &= GPIOinMode < 4;
|
||||
retval &= GPIOoutMode < 3;
|
||||
retval &= (FrameRate >= 300) && (FrameRate <= 1500);
|
||||
retval &= HomeMenu < 4;
|
||||
retval &= HomeMenu.valid();
|
||||
return retval;
|
||||
}
|
||||
void init() {
|
||||
|
@ -100,7 +118,7 @@ struct sBTCoptions {
|
|||
GPIOoutMode = 0;
|
||||
GPIOalgMode = 0;
|
||||
FrameRate = 1000;
|
||||
HomeMenu = 0;
|
||||
HomeMenu.init();
|
||||
};
|
||||
};
|
||||
|
||||
|
@ -159,7 +177,7 @@ public:
|
|||
GPIOoutModes getGPIOoutMode();
|
||||
GPIOalgModes getGPIOalgMode();
|
||||
uint16_t getFrameRate();
|
||||
uint8_t getHomeMenu();
|
||||
const sHomeMenuActions& getHomeMenu() const;
|
||||
|
||||
void setPmin(float);
|
||||
void setPmax(float);
|
||||
|
@ -181,7 +199,7 @@ public:
|
|||
void setGPIOoutMode(unsigned char val);
|
||||
void setGPIOalgMode(unsigned char val);
|
||||
void setFrameRate(uint16_t val);
|
||||
void setHomeMenu(uint8_t val);
|
||||
void setHomeMenu(sHomeMenuActions val);
|
||||
|
||||
void getTimerInfo(int idx, sTimer& timerInfo);
|
||||
void setTimerInfo(int idx, const sTimer& timerInfo);
|
||||
|
|
Loading…
Reference in a new issue