2018-11-23 10:34:37 +00:00
|
|
|
#include "128x64OLED.h"
|
|
|
|
#include "display.h"
|
|
|
|
#include "MiniFont.h"
|
|
|
|
#include "tahoma16.h"
|
|
|
|
#include "OLEDconsts.h"
|
|
|
|
#include "BluetoothAbstract.h"
|
|
|
|
#include "Screen2.h"
|
|
|
|
#include "BTCWifi.h"
|
|
|
|
#include "KeyPad.h"
|
|
|
|
#include "helpers.h"
|
|
|
|
#include "Protocol.h"
|
2018-11-24 00:51:09 +00:00
|
|
|
#include "UtilClasses.h"
|
2018-11-23 10:34:37 +00:00
|
|
|
|
|
|
|
|
|
|
|
#define MAXIFONT tahoma_16ptFontInfo
|
|
|
|
#define MINIFONT miniFontInfo
|
|
|
|
|
2018-11-25 04:45:17 +00:00
|
|
|
CScreen2::CScreen2(C128x64_OLED& display, CScreenManager& mgr) : CScreen(display, mgr)
|
|
|
|
{
|
|
|
|
_showSetMode = 0;
|
|
|
|
_showMode = 0;
|
|
|
|
_nModeSel = 0;
|
|
|
|
}
|
2018-11-24 00:51:09 +00:00
|
|
|
|
2018-11-25 04:45:17 +00:00
|
|
|
void
|
|
|
|
CScreen2::show(const CProtocol& CtlFrame, const CProtocol& HtrFrame)
|
2018-11-23 10:34:37 +00:00
|
|
|
{
|
2018-11-25 04:45:17 +00:00
|
|
|
CScreen::show(CtlFrame, HtrFrame);
|
|
|
|
|
2018-11-23 10:34:37 +00:00
|
|
|
char msg[20];
|
2018-11-24 00:51:09 +00:00
|
|
|
CRect textRect;
|
2018-11-23 10:34:37 +00:00
|
|
|
|
2018-11-25 04:45:17 +00:00
|
|
|
sprintf(msg, "%.1f`", getActualTemperature());
|
|
|
|
_display.setFontInfo(&MAXIFONT); // Dot Factory Font
|
|
|
|
_display.getTextExtents(msg, textRect);
|
|
|
|
textRect.xPos = (_display.width()- textRect.width) / 2;
|
2018-11-24 00:51:09 +00:00
|
|
|
textRect.yPos = 25;
|
2018-11-25 04:45:17 +00:00
|
|
|
_display.fillRect(textRect.xPos, textRect.yPos, textRect.width, textRect.height, BLACK);
|
|
|
|
_display.setCursor(textRect.xPos, textRect.yPos);
|
|
|
|
_display.print(msg);
|
|
|
|
_display.setFontInfo(NULL); // standard 5x7 font
|
2018-11-23 10:34:37 +00:00
|
|
|
|
2018-11-24 00:51:09 +00:00
|
|
|
|
|
|
|
// at bottom of screen show either:
|
|
|
|
// Selection between Fixed or Thermostat mode
|
|
|
|
// Current heat demand setting
|
|
|
|
// Run state of heater
|
|
|
|
|
2018-11-25 04:45:17 +00:00
|
|
|
if(_showMode) {
|
2018-11-24 00:51:09 +00:00
|
|
|
const int border = 3;
|
|
|
|
const int radius = 4;
|
|
|
|
// Show selection between Fixed or Thermostat mode
|
2018-11-25 04:45:17 +00:00
|
|
|
long tDelta = millis() - _showMode;
|
2018-11-24 11:03:47 +00:00
|
|
|
if(tDelta < 0) {
|
2018-11-24 00:51:09 +00:00
|
|
|
// display "Fixed Hz" at lower left, allowing space for a selection surrounding box
|
2018-11-23 10:34:37 +00:00
|
|
|
strcpy(msg, "Fixed Hz");
|
2018-11-25 04:45:17 +00:00
|
|
|
_display.getTextExtents(msg, textRect); // size of text to print
|
|
|
|
textRect.xPos = _display.width()- textRect.width - border; // set X position to finish short of RHS
|
|
|
|
textRect.yPos = _display.height() - textRect.height - border; // bottom of screen, with room for box
|
|
|
|
_display.setCursor(textRect.xPos, // centre text in potential box
|
2018-11-24 00:51:09 +00:00
|
|
|
textRect.yPos);
|
2018-11-25 04:45:17 +00:00
|
|
|
_display.print(msg); // show the text
|
|
|
|
if(_nModeSel == 1) { // add selection box if current selection
|
2018-11-24 00:51:09 +00:00
|
|
|
textRect.Expand(border); // expand about text position
|
2018-11-25 04:45:17 +00:00
|
|
|
_display.drawRoundRect(textRect.xPos, textRect.yPos, textRect.width, textRect.height, radius, WHITE);
|
2018-11-23 10:34:37 +00:00
|
|
|
}
|
2018-11-24 00:51:09 +00:00
|
|
|
// display "Thermostat" at lower right, allowing space for a selection surrounding box
|
2018-11-23 10:34:37 +00:00
|
|
|
strcpy(msg, "Thermostat");
|
2018-11-25 04:45:17 +00:00
|
|
|
_display.getTextExtents(msg, textRect);
|
2018-11-24 11:03:47 +00:00
|
|
|
textRect.xPos = border;
|
2018-11-25 04:45:17 +00:00
|
|
|
textRect.yPos = _display.height() - textRect.height - border; // bottom of screen, with room for box
|
|
|
|
_display.setCursor(textRect.xPos, // centre text in potential box
|
2018-11-24 00:51:09 +00:00
|
|
|
textRect.yPos);
|
2018-11-25 04:45:17 +00:00
|
|
|
_display.print(msg); // show the text
|
|
|
|
if(_nModeSel == 0) { // add selection box if current selection
|
2018-11-24 00:51:09 +00:00
|
|
|
textRect.Expand(border); // expand about text position
|
2018-11-25 04:45:17 +00:00
|
|
|
_display.drawRoundRect(textRect.xPos, textRect.yPos, textRect.width, textRect.height, radius, WHITE);
|
2018-11-23 10:34:37 +00:00
|
|
|
}
|
2018-11-25 04:45:17 +00:00
|
|
|
setThermostatMode(_nModeSel == 0 ? 1 : 0); // set the new mode
|
2018-11-23 10:34:37 +00:00
|
|
|
}
|
|
|
|
else {
|
2018-11-24 00:51:09 +00:00
|
|
|
// cancel selection mode, apply whatever is boxed
|
2018-11-25 04:45:17 +00:00
|
|
|
_showMode = 0;
|
|
|
|
_showSetMode = millis() + 5000; // then make the new mode setting be shown
|
2018-11-23 10:34:37 +00:00
|
|
|
}
|
|
|
|
}
|
2018-11-25 04:45:17 +00:00
|
|
|
if((_showMode == 0) && _showSetMode) {
|
|
|
|
long tDelta = millis() - _showSetMode;
|
2018-11-24 11:03:47 +00:00
|
|
|
if(tDelta < 0) {
|
2018-11-24 00:51:09 +00:00
|
|
|
// Show current heat demand setting
|
|
|
|
if(getThermostatMode()) {
|
|
|
|
sprintf(msg, "Setpoint = %d`C", getSetTemp());
|
2018-11-23 10:34:37 +00:00
|
|
|
}
|
|
|
|
else {
|
2018-11-24 00:51:09 +00:00
|
|
|
sprintf(msg, "Setpoint = %.1fHz", getFixedHz());
|
2018-11-23 10:34:37 +00:00
|
|
|
}
|
2018-11-24 00:51:09 +00:00
|
|
|
// centre message at bottom of screen
|
2018-11-25 04:45:17 +00:00
|
|
|
_display.getTextExtents(msg, textRect);
|
|
|
|
_display.setCursor(_display.xCentre(),
|
|
|
|
_display.height() - textRect.height);
|
|
|
|
_display.printCentreJustified(msg);
|
2018-11-24 00:51:09 +00:00
|
|
|
}
|
|
|
|
else {
|
2018-11-25 04:45:17 +00:00
|
|
|
_showSetMode = 0;
|
2018-11-23 10:34:37 +00:00
|
|
|
}
|
|
|
|
}
|
2018-11-25 04:45:17 +00:00
|
|
|
if((_showMode == 0) && (_showSetMode == 0)) {
|
|
|
|
showRunState();
|
2018-11-24 00:51:09 +00:00
|
|
|
}
|
2018-11-23 10:34:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-11-25 04:45:17 +00:00
|
|
|
void
|
|
|
|
CScreen2::keyHandler(uint8_t event)
|
2018-11-23 10:34:37 +00:00
|
|
|
{
|
|
|
|
static int repeatCount = -1;
|
|
|
|
if(event & keyPressed) {
|
|
|
|
repeatCount = 0; // unlock tracking of repeat events
|
|
|
|
// press LEFT to select previous screen, or Fixed Hz mode when in mode select
|
|
|
|
if(event & key_Left) {
|
2018-11-25 04:45:17 +00:00
|
|
|
if(!_showMode)
|
|
|
|
_Manager.prevScreen();
|
2018-11-23 10:34:37 +00:00
|
|
|
else {
|
2018-11-25 04:45:17 +00:00
|
|
|
_showMode = millis() + 5000;
|
|
|
|
_nModeSel = 0;
|
2018-11-23 10:34:37 +00:00
|
|
|
reqDisplayUpdate();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// press RIGHT to selecxt next screen, or Thermostat mode when in mode select
|
|
|
|
if(event & key_Right) {
|
2018-11-25 04:45:17 +00:00
|
|
|
if(!_showMode)
|
|
|
|
_Manager.nextScreen();
|
2018-11-23 10:34:37 +00:00
|
|
|
else {
|
2018-11-25 04:45:17 +00:00
|
|
|
_showMode = millis() + 5000;
|
|
|
|
_nModeSel = 1;
|
2018-11-23 10:34:37 +00:00
|
|
|
reqDisplayUpdate();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// press UP & DOWN to toggle thermostat / fixed Hz mode
|
2018-11-24 00:51:09 +00:00
|
|
|
// impossible with 5 way switch!
|
2018-11-23 10:34:37 +00:00
|
|
|
uint8_t doubleKey = key_Down | key_Up;
|
|
|
|
if((event & doubleKey) == doubleKey) {
|
|
|
|
reqThermoToggle();
|
2018-11-25 04:45:17 +00:00
|
|
|
_showSetMode = millis() + 2000;
|
2018-11-23 10:34:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
// use repeat function for key hold detection
|
|
|
|
if(event & keyRepeat) {
|
|
|
|
if(repeatCount >= 0) {
|
|
|
|
repeatCount++;
|
|
|
|
// hold DOWN to enter thermostat / fixed mode selection
|
|
|
|
if(event & key_Down) {
|
|
|
|
if(repeatCount > 2) {
|
|
|
|
repeatCount = -1; // prevent double handling
|
2018-11-25 04:45:17 +00:00
|
|
|
_showMode = millis() + 5000;
|
|
|
|
_nModeSel = getThermostatMode() ? 0 : 1;
|
2018-11-23 10:34:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
// hold CENTRE to turn ON or OFF
|
|
|
|
if(event & key_Centre) {
|
|
|
|
if(getRunState()) {
|
|
|
|
// running, request OFF
|
|
|
|
if(repeatCount > 5) {
|
2018-11-24 00:51:09 +00:00
|
|
|
repeatCount = -2; // prevent double handling
|
2018-11-23 10:34:37 +00:00
|
|
|
requestOff();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// standby, request ON
|
|
|
|
if(repeatCount > 3) {
|
|
|
|
repeatCount = -1;
|
|
|
|
requestOn();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(event & keyReleased) {
|
2018-11-25 04:45:17 +00:00
|
|
|
if(!_showMode) {
|
2018-11-23 10:34:37 +00:00
|
|
|
// release DOWN key to reduce set demand, provided we are not in mode select
|
|
|
|
if(event & key_Down) {
|
|
|
|
reqTempChange(-1);
|
2018-11-25 04:45:17 +00:00
|
|
|
_showSetMode = millis() + 2000;
|
2018-11-23 10:34:37 +00:00
|
|
|
}
|
|
|
|
// release UP key to increase set demand, provided we are not in mode select
|
|
|
|
if(event & key_Up) {
|
|
|
|
reqTempChange(+1);
|
2018-11-25 04:45:17 +00:00
|
|
|
_showSetMode = millis() + 2000;
|
2018-11-23 10:34:37 +00:00
|
|
|
}
|
|
|
|
}
|
2018-11-24 00:51:09 +00:00
|
|
|
// release CENTRE to accept new mode, and/or show current setting
|
|
|
|
if(event & key_Centre) {
|
|
|
|
if(repeatCount != -2) { // prevent after off commands
|
2018-11-25 04:45:17 +00:00
|
|
|
if(_showMode) {
|
|
|
|
_showMode = millis(); // force immediate cancellation of showmode (via screen update)
|
2018-11-24 00:51:09 +00:00
|
|
|
}
|
2018-11-25 04:45:17 +00:00
|
|
|
_showSetMode = millis() + 2000;
|
2018-11-24 00:51:09 +00:00
|
|
|
}
|
|
|
|
reqDisplayUpdate();
|
|
|
|
}
|
|
|
|
|
2018-11-23 10:34:37 +00:00
|
|
|
repeatCount = -1;
|
|
|
|
}
|
|
|
|
}
|
2018-11-24 00:51:09 +00:00
|
|
|
|
2018-11-25 04:45:17 +00:00
|
|
|
void
|
|
|
|
CScreen2::showRunState()
|
2018-11-24 00:51:09 +00:00
|
|
|
{
|
|
|
|
int runstate = getRunState();
|
|
|
|
int errstate = getErrState();
|
|
|
|
|
|
|
|
if(errstate) errstate--; // correct for +1 biased return value
|
|
|
|
|
|
|
|
static bool toggle = false;
|
|
|
|
const char* toPrint = NULL;
|
2018-11-25 04:45:17 +00:00
|
|
|
_display.setTextColor(WHITE, BLACK);
|
2018-11-24 00:51:09 +00:00
|
|
|
if(runstate >= 0 && runstate <= 8) {
|
|
|
|
if(((runstate == 0) || (runstate > 5)) && errstate) {
|
|
|
|
// create an "E-XX" message to display
|
|
|
|
char msg[16];
|
|
|
|
sprintf(msg, "E-%02d", errstate);
|
|
|
|
// determine height of font
|
|
|
|
CRect textRect;
|
2018-11-25 04:45:17 +00:00
|
|
|
_display.getTextExtents(msg, textRect);
|
|
|
|
_display.setCursor(_display.xCentre(), // locate at bottom centre, 1 line up
|
|
|
|
_display.height() - 2*textRect.height);
|
2018-11-24 00:51:09 +00:00
|
|
|
// flash error code
|
|
|
|
toggle = !toggle;
|
|
|
|
if(toggle)
|
2018-11-25 04:45:17 +00:00
|
|
|
_display.printCentreJustified(msg);
|
2018-11-24 00:51:09 +00:00
|
|
|
else {
|
2018-11-25 04:45:17 +00:00
|
|
|
_display.printCentreJustified(" ");
|
2018-11-24 00:51:09 +00:00
|
|
|
}
|
|
|
|
// bounds limit error and gather message
|
|
|
|
if(errstate > 10) errstate = 11;
|
|
|
|
toPrint = Errstates[errstate-1];
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if(runstate) {
|
|
|
|
if(runstate < 5) toPrint = "Starting";
|
|
|
|
else if(runstate == 5) toPrint = "Running";
|
|
|
|
else if(runstate == 8) toPrint = "Cooling";
|
|
|
|
else toPrint = "Shutting down";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(toPrint) {
|
|
|
|
// determine height of font
|
|
|
|
CRect textRect;
|
2018-11-25 04:45:17 +00:00
|
|
|
_display.getTextExtents(toPrint, textRect);
|
|
|
|
_display.setCursor(_display.xCentre(), // locate at bottom centre
|
|
|
|
_display.height() - textRect.height);
|
|
|
|
_display.printCentreJustified(toPrint);
|
2018-11-24 00:51:09 +00:00
|
|
|
}
|
2018-11-25 04:45:17 +00:00
|
|
|
}
|