BUG FIX: Fuel gauge reset via web page

NEW FEATURE: MQTT status screen
This commit is contained in:
Ray Jones 2019-09-04 20:59:01 +10:00
parent 13fb3f715a
commit 77dada9d6b
8 changed files with 221 additions and 1 deletions

View File

@ -1753,6 +1753,11 @@ int sysUptime()
return Clock.get().secondstime() - BootTime;
}
void resetFuelGauge()
{
FuelGauge.reset();
}
void setSSID(const char* name)
{
sCredentials creds = NVstore.getCredentials();

163
src/OLED/MQTTScreen.cpp Normal file
View File

@ -0,0 +1,163 @@
/*
* 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 "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;
}

44
src/OLED/MQTTScreen.h Normal file
View File

@ -0,0 +1,44 @@
/*
* 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 __MQTTSCREEN_H__
#define __MQTTSCREEN_H__
#include <stdint.h>
#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

View File

@ -44,6 +44,7 @@
#include "HourMeterScreen.h"
#include "BTScreen.h"
#include "MenuTrunkScreen.h"
#include "MQTTScreen.h"
#include <Wire.h>
#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);

View File

@ -275,7 +275,7 @@ void interpretJsonCommand(char* pLine)
else if(strcmp("PumpCount", it->key) == 0) { // reset fuel gauge
int Count = it->value.as<int>();
if(Count == 0) {
RTC_Store.setFuelGauge(0);
resetFuelGauge();
}
}
else if(strcmp("PumpCal", it->key) == 0) {

View File

@ -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();

View File

@ -244,4 +244,8 @@ void doMQTT()
}
bool isMQTTconnected() {
return MQTTclient.connected();
}
#endif

View File

@ -9,6 +9,7 @@ void doMQTT();
bool mqttPublishJSON(const char* str);
void connectToMqtt();
void kickMQTT();
bool isMQTTconnected();
#endif