diff --git a/src/Afterburner.cpp b/src/Afterburner.cpp index 6c07788..a615552 100644 --- a/src/Afterburner.cpp +++ b/src/Afterburner.cpp @@ -1753,6 +1753,11 @@ int sysUptime() return Clock.get().secondstime() - BootTime; } +void resetFuelGauge() +{ + FuelGauge.reset(); +} + void setSSID(const char* name) { sCredentials creds = NVstore.getCredentials(); diff --git a/src/OLED/MQTTScreen.cpp b/src/OLED/MQTTScreen.cpp new file mode 100644 index 0000000..72a6868 --- /dev/null +++ b/src/OLED/MQTTScreen.cpp @@ -0,0 +1,163 @@ +/* + * 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 . + * + */ + +#include "MQTTScreen.h" +#include "KeyPad.h" +#include "../Utility/helpers.h" +#include "../WiFi/ABMqtt.h" +#include "../WiFi/BTCWifi.h" +#include "../Utility/NVStorage.h" +#include "fonts/Arial.h" + +/////////////////////////////////////////////////////////////////////////// +// +// CMQTTScreen +// +// This screen presents sundry information +// eg WiFi status +// +/////////////////////////////////////////////////////////////////////////// + +#define STA_HOLD_TIME 10 + +static const int LIMIT_AWAY = 0; +static const int LIMIT_LEFT = 1; +static const int LIMIT_RIGHT = 2; + +CMQTTScreen::CMQTTScreen(C128x64_OLED& display, CScreenManager& mgr) : CScreen(display, mgr) +{ + _initUI(); +} + +void +CMQTTScreen::onSelect() +{ + CScreen::onSelect(); + _initUI(); +} + +void +CMQTTScreen::_initUI() +{ + _rowSel = 0; + _colSel = 0; +} + + +bool +CMQTTScreen::show() +{ + CScreen::show(); + + _display.clearDisplay(); + _showTitle("MQTT status"); + + int yPos = 18; + + if(NVstore.getMQTTinfo().enabled) { + if(isWifiConnected()) { + if(isMQTTconnected()) + _printMenuText(border, yPos, "CONNECTED"); + else + _printInverted(border, yPos, " DISCONNECTED ", true); + } + else { + _printInverted(border, yPos, " NO STA NETWORK ", true); + } + } + else { + _printMenuText(border, yPos, "DISABLED"); + } + char msg[40]; + sprintf(msg, "QoS:%d", NVstore.getMQTTinfo().qos); + _printMenuText(_display.width(), yPos, msg, false, eRightJustify); + yPos += _display.textHeight() + 2; + sprintf(msg, "%s:%d", NVstore.getMQTTinfo().host, NVstore.getMQTTinfo().port); + _printMenuText(border, yPos, msg); + yPos += _display.textHeight() + 2; + sprintf(msg, "%s/%s", NVstore.getMQTTinfo().username, NVstore.getMQTTinfo().password); + _printMenuText(border, yPos, msg); + + return true; +} + +bool +CMQTTScreen::animate() +{ + return false; +} + +bool +CMQTTScreen::keyHandler(uint8_t event) +{ + if(event & keyPressed) { + _repeatCount = 0; + // press LEFT + if(event & key_Left) { + switch(_rowSel) { + case 0: + _ScreenManager.prevMenu(); + break; + } + } + // press RIGHT + if(event & key_Right) { + switch(_rowSel) { + case 0: + _ScreenManager.nextMenu(); + break; + } + } + // press UP + if(event & key_Up) { +// _rowSel++; + UPPERLIMIT(_rowSel, 2); + } + // press DOWN + if(event & key_Down) { +// _rowSel--; + LOWERLIMIT(_rowSel, 0); + } + _ScreenManager.reqUpdate(); + } + + if(event & keyRepeat) { // track key hold time + if(event & key_Centre) { + _repeatCount++; + } + } + + if(event & keyReleased) { + if(event & key_Centre) { + if(_rowSel == 0) { + _ScreenManager.selectMenu(CScreenManager::RootMenuLoop); // force return to main menu + } + if(_rowSel == 1) { + + } + if(_rowSel == 2) { + } + } + _repeatCount = 0; + } + return true; +} + diff --git a/src/OLED/MQTTScreen.h b/src/OLED/MQTTScreen.h new file mode 100644 index 0000000..a663126 --- /dev/null +++ b/src/OLED/MQTTScreen.h @@ -0,0 +1,44 @@ +/* + * 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 __MQTTSCREEN_H__ +#define __MQTTSCREEN_H__ + +#include +#include "ScreenHeader.h" + +class C128x64_OLED; +class CScreenManager; + +class CMQTTScreen : public CScreen { +public: + CMQTTScreen(C128x64_OLED& display, CScreenManager& mgr); + void onSelect(); + bool show(); + bool animate(); + bool keyHandler(uint8_t event); +private: + int _rowSel, _colSel; + int _repeatCount; + void _initUI(); +}; + +#endif diff --git a/src/OLED/ScreenManager.cpp b/src/OLED/ScreenManager.cpp index 6043269..644fc3e 100644 --- a/src/OLED/ScreenManager.cpp +++ b/src/OLED/ScreenManager.cpp @@ -44,6 +44,7 @@ #include "HourMeterScreen.h" #include "BTScreen.h" #include "MenuTrunkScreen.h" +#include "MQTTScreen.h" #include #include "../cfg/pins.h" #include "../cfg/BTCConfig.h" @@ -442,6 +443,7 @@ CScreenManager::begin(bool bNoClock) menuloop.push_back(new CVersionInfoScreen(*_pDisplay, *this)); // GPIO settings screen menuloop.push_back(new CHourMeterScreen(*_pDisplay, *this)); // Hour Meter screen menuloop.push_back(new CWiFiScreen(*_pDisplay, *this)); + menuloop.push_back(new CMQTTScreen(*_pDisplay, *this)); menuloop.push_back(new CBTScreen(*_pDisplay, *this)); _Screens.push_back(menuloop); diff --git a/src/Utility/BTC_JSON.cpp b/src/Utility/BTC_JSON.cpp index 453aafe..3896b39 100644 --- a/src/Utility/BTC_JSON.cpp +++ b/src/Utility/BTC_JSON.cpp @@ -275,7 +275,7 @@ void interpretJsonCommand(char* pLine) else if(strcmp("PumpCount", it->key) == 0) { // reset fuel gauge int Count = it->value.as(); if(Count == 0) { - RTC_Store.setFuelGauge(0); + resetFuelGauge(); } } else if(strcmp("PumpCal", it->key) == 0) { diff --git a/src/Utility/helpers.h b/src/Utility/helpers.h index 4cab4c0..70be4de 100644 --- a/src/Utility/helpers.h +++ b/src/Utility/helpers.h @@ -60,6 +60,7 @@ extern void setSystemVoltage(float val); extern void interpretJsonCommand(char* pLine); extern void resetWebModerator(); extern void resetJSONmoderator(); +extern void resetFuelGauge(); extern const char* getBlueWireStatStr(); extern bool hasOEMcontroller(); extern bool hasOEMLCDcontroller(); diff --git a/src/WiFi/ABMqtt.cpp b/src/WiFi/ABMqtt.cpp index d6cd704..aed6bcd 100644 --- a/src/WiFi/ABMqtt.cpp +++ b/src/WiFi/ABMqtt.cpp @@ -244,4 +244,8 @@ void doMQTT() } +bool isMQTTconnected() { + return MQTTclient.connected(); +} + #endif \ No newline at end of file diff --git a/src/WiFi/ABmqtt.h b/src/WiFi/ABmqtt.h index 9ecfafc..5fa6c48 100644 --- a/src/WiFi/ABmqtt.h +++ b/src/WiFi/ABmqtt.h @@ -9,6 +9,7 @@ void doMQTT(); bool mqttPublishJSON(const char* str); void connectToMqtt(); void kickMQTT(); +bool isMQTTconnected(); #endif