From ca0e763da61b773512c4ab0fdb3bb80ff0c2e02d Mon Sep 17 00:00:00 2001 From: Ray Jones Date: Fri, 26 Jul 2019 23:12:00 +1000 Subject: [PATCH] Added Hour Meters screen --- README.md | 6 +- src/OLED/HourMeterScreen.cpp | 108 +++++++++++++++++++++++++++++++++++ src/OLED/HourMeterScreen.h | 40 +++++++++++++ src/OLED/ScreenManager.cpp | 4 +- src/Utility/BTC_JSON.cpp | 2 +- 5 files changed, 155 insertions(+), 5 deletions(-) create mode 100644 src/OLED/HourMeterScreen.cpp create mode 100644 src/OLED/HourMeterScreen.h diff --git a/README.md b/README.md index 690a7e8..ad22340 100644 --- a/README.md +++ b/README.md @@ -44,7 +44,7 @@ Working so far: * Two new experimental thermostat modes (No practical testing - presently too hot in .au!): Tighten or loosen the thermostat temperature range by specifying a hysteresis value. eg tell the heater it is 23 degrees when it really is only 22.25 degrees (only 0.25 above set point). Request a linear change in Hz according to the deviation from the setpoint -* 2 external digital inputs, 2 digital outputs, analogue input +* 2 external digital inputs, 2 digital outputs, analogue input .This would allow external timer units for example, or analogue temperature demand (which is still only 1 degree resolution with standard heater thermostat). * New Mk2 "Red PCB" that properly fits into an off the shelf case (requires machining) * Software updates over WiFi: Native OTA via espota.exe or espota.py (AP or STA mode) @@ -54,14 +54,14 @@ Working so far: * "Fuel gauge" - Integrates pump frequency, assumes a repeatable dose of fuel per pump stroke. * Low voltage cut out, definable threshold - auto adjusts for cable voltage drop during start * Temperature probe offset to correct adverse readings. +* Hour meter - run time, glow time To be implemented -------------------------- -* 433MHz Rx stream, 433MHz Tx stream connections. This would allow external timer units for example, or analogue temperature demand (which is still only 1 degree resolution with standard heater thermostat). +* 433MHz Rx stream, 433MHz Tx stream connections. * MQTT pub/sub * Regular Hot Burn cycle (DPF mode!) -* Hour meter - run time, glow time * list under construction..... Suggestions diff --git a/src/OLED/HourMeterScreen.cpp b/src/OLED/HourMeterScreen.cpp new file mode 100644 index 0000000..e5e56aa --- /dev/null +++ b/src/OLED/HourMeterScreen.cpp @@ -0,0 +1,108 @@ +/* + * This file is part of the "bluetoothheater" distribution + * (https://gitlab.com/mrjones.id.au/bluetoothheater) + * + * Copyright (C) 2019 Ray Jones + * + * 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 . + * + */ + +#include "128x64OLED.h" +#include "HourMeterScreen.h" +#include "KeyPad.h" +#include "../Utility/helpers.h" +#include "../Utility/HourMeter.h" + + +CHourMeterScreen::CHourMeterScreen(C128x64_OLED& display, CScreenManager& mgr) : CScreen(display, mgr) +{ +} + +void makeHourMeter(char* hrs, char* str, unsigned long seconds) +{ + unsigned long minutes = seconds / 60; + unsigned long hours = minutes / 60; + unsigned long days = hours / 24; + + unsigned long printMins = minutes - (hours * 60); + + sprintf(hrs, "%02ld:", hours); + + if(hours > 48) + sprintf(str, "%02ld (%ldd)", printMins, days); + else + sprintf(str, "%02ld", printMins); +} + +bool +CHourMeterScreen::show() +{ + char msg[32]; + char hrs[16]; + + int colon = 75; + + _display.clearDisplay(); + + // standard version information screens, + // animation of update available via animate() if firmware update is available on web server + _printInverted(_display.xCentre(), 0, " Hour Meters ", true, eCentreJustify); + + makeHourMeter(hrs, msg, pHourMeter->getRunTime()); + _printMenuText(38, 14, "Run", false, eRightJustify); + _printMenuText(colon, 14, hrs, false, eRightJustify); + _printMenuText(colon, 14, msg); + makeHourMeter(hrs, msg, pHourMeter->getGlowTime()); + _printMenuText(38, 26, "Glow", false, eRightJustify); + _printMenuText(colon, 26, hrs, false, eRightJustify); + _printMenuText(colon, 26, msg); + makeHourMeter(hrs, msg, sysUptime()); + _printMenuText(38, 38, "UpTime", false, eRightJustify); + _printMenuText(colon, 38, hrs, false, eRightJustify); + _printMenuText(colon, 38, msg); + + _printMenuText(_display.xCentre(), 53, " \021 Exit \020 ", true, eCentreJustify); // " < Exit > " + return true; +} + +bool +CHourMeterScreen::keyHandler(uint8_t event) +{ + if(event & keyPressed) { + // UP press + if(event & key_Up) { + } + // DOWN press + if(event & key_Down) { + } + // LEFT press + if(event & key_Left) { + _ScreenManager.prevMenu(); + } + // RIGHT press + if(event & key_Right) { + _ScreenManager.nextMenu(); + } + // CENTRE press + if(event & key_Centre) { + _ScreenManager.selectMenu(CScreenManager::RootMenuLoop); // force return to main menu + } + } + + _ScreenManager.reqUpdate(); + + return true; +} + diff --git a/src/OLED/HourMeterScreen.h b/src/OLED/HourMeterScreen.h new file mode 100644 index 0000000..9536a3a --- /dev/null +++ b/src/OLED/HourMeterScreen.h @@ -0,0 +1,40 @@ +/* + * This file is part of the "bluetoothheater" distribution + * (https://gitlab.com/mrjones.id.au/bluetoothheater) + * + * Copyright (C) 2018 Ray Jones + * + * 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 . + * + */ + +#ifndef __HOURMETERSCREEN_H__ +#define __HOURMETERSCREEN_H__ + +#include +#include "Screen.h" + +class C128x64_OLED; +class CScreenManager; + + +class CHourMeterScreen : public CScreen +{ +public: + CHourMeterScreen(C128x64_OLED& display, CScreenManager& mgr); + bool show(); + bool keyHandler(uint8_t event); +}; + +#endif diff --git a/src/OLED/ScreenManager.cpp b/src/OLED/ScreenManager.cpp index 15d2dc7..68b7e3f 100644 --- a/src/OLED/ScreenManager.cpp +++ b/src/OLED/ScreenManager.cpp @@ -40,6 +40,7 @@ #include "VersionInfoScreen.h" #include "HomeMenuSelScreen.h" #include "OtherOptionsScreen.h" +#include "HourMeterScreen.h" #include #include "../cfg/pins.h" #include "../cfg/BTCConfig.h" @@ -299,8 +300,9 @@ CScreenManager::begin(bool bNoClock) // create User Settings screens loop menuloop.clear(); menuloop.push_back(new CGPIOScreen(*_pDisplay, *this)); // GPIO settings screen - menuloop.push_back(new CThermostatModeScreen(*_pDisplay, *this)); // experimental settings screen + menuloop.push_back(new CThermostatModeScreen(*_pDisplay, *this)); // thermostat settings screen menuloop.push_back(new CVersionInfoScreen(*_pDisplay, *this)); // GPIO settings screen + menuloop.push_back(new CHourMeterScreen(*_pDisplay, *this)); // Hour Meter 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); diff --git a/src/Utility/BTC_JSON.cpp b/src/Utility/BTC_JSON.cpp index ff1701d..955a76e 100644 --- a/src/Utility/BTC_JSON.cpp +++ b/src/Utility/BTC_JSON.cpp @@ -476,7 +476,7 @@ bool makeJSONStringSysInfo(CModerator& moderator, char* opStr, int len) sprintf(str, "%d/%d/%d %02d:%02d:%02d", now.day(), now.month(), now.year(), now.hour(), now.minute(), now.second()); bSend |= moderator.addJson("DateTime", str, root); if(bTriggerSysParams) { - bSend |= moderator.addJson("UpTime", sysUptime(), root); + bSend |= moderator.addJson("SysUpTime", sysUptime(), root); bSend |= moderator.addJson("SysVer", getVersionStr(), root); bSend |= moderator.addJson("SysDate", getVersionDate(), root); bSend |= moderator.addJson("SysFreeMem", ESP.getFreeHeap(), root);