2019-04-19 11:38:39 +00:00
|
|
|
/*
|
|
|
|
* 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 "VersionInfoScreen.h"
|
|
|
|
#include "KeyPad.h"
|
2019-06-15 23:09:29 +00:00
|
|
|
#include "../Utility/helpers.h"
|
2019-04-19 11:38:39 +00:00
|
|
|
#include "../Utility/UtilClasses.h"
|
|
|
|
#include "../Utility/NVStorage.h"
|
2019-05-16 11:12:29 +00:00
|
|
|
#include "../WiFi/BTCWifi.h"
|
|
|
|
#include "../Utility/BoardDetect.h"
|
2019-04-19 11:38:39 +00:00
|
|
|
#include "fonts/Icons.h"
|
|
|
|
|
2019-05-21 08:29:16 +00:00
|
|
|
// nominally show the current version of firmware & hardware
|
|
|
|
// from here we can also update the firmware using web server update (requires internet STA connection)
|
|
|
|
// or factory default the stored non volatile memory contents
|
|
|
|
//
|
|
|
|
// progression is basically via the UP key:
|
|
|
|
|
|
|
|
// _rowSel=0 - standard view, may animate upload arrow if update is available, help prompt shows 'Exit':
|
|
|
|
// CENTRE > exit menu
|
|
|
|
//
|
|
|
|
// UP > _rowSel=1 - if update is available, help prompt shows 'Get Update', otherwise a silent step:
|
|
|
|
// CENTRE > _rowSel=20 - present firmware update confirmation (UP to perform)
|
|
|
|
// UP > update initated, reboot upon conclusion, % progress shown on display
|
|
|
|
//
|
|
|
|
// UP > _rowSel=2 - Factory default cancel selection, help prompt shows 'Exit':
|
|
|
|
// CENTRE > exit menu
|
|
|
|
//
|
|
|
|
// UP > _rowSel=3 - Factory default perform selection, help prompt shows 'Apply':
|
|
|
|
// CENTRE > _rowSel=10 - request factory default confirm
|
|
|
|
// UP > _rowSel=11 - defaults installed, present DONE screen, REBOOT after 5 seconds
|
2019-04-19 11:38:39 +00:00
|
|
|
|
|
|
|
|
2019-05-16 11:12:29 +00:00
|
|
|
CVersionInfoScreen::CVersionInfoScreen(C128x64_OLED& display, CScreenManager& mgr) : CPasswordScreen(display, mgr)
|
2019-04-19 11:38:39 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CVersionInfoScreen::onSelect()
|
|
|
|
{
|
|
|
|
CScreenHeader::onSelect();
|
2019-05-20 12:09:59 +00:00
|
|
|
_rowSel = 0;
|
|
|
|
_animateCount = 0;
|
|
|
|
checkFOTA();
|
2019-04-19 11:38:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CVersionInfoScreen::_initUI()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
CVersionInfoScreen::show()
|
|
|
|
{
|
|
|
|
char msg[16];
|
|
|
|
|
|
|
|
_display.clearDisplay();
|
|
|
|
|
2019-05-16 11:12:29 +00:00
|
|
|
if(!CPasswordScreen::show()) { // for showing "saving settings"
|
|
|
|
|
2019-05-21 08:29:16 +00:00
|
|
|
if(_rowSel < 2) {
|
|
|
|
// standard version information screens,
|
|
|
|
// animation of update available via animate() if firmware update is available on web server
|
2019-07-27 14:28:39 +00:00
|
|
|
_showTitle("Version Information");
|
2019-05-16 11:12:29 +00:00
|
|
|
|
2019-08-03 02:42:49 +00:00
|
|
|
_drawBitmap(8, 12, FirmwareIconInfo);
|
|
|
|
_printMenuText(41, 15, getVersionStr());
|
|
|
|
_printMenuText(41, 26, getVersionDate());
|
|
|
|
int newVer = isUpdateAvailable();
|
|
|
|
// if(newVer) {
|
|
|
|
// char msg[32];
|
|
|
|
// int major = (int)(newVer * 0.01);
|
|
|
|
// int minor = newVer - major*100;
|
|
|
|
// float prtMajor = major * 0.1;
|
|
|
|
// sprintf(msg, "V%.1f.%d", prtMajor, minor);
|
|
|
|
// _printMenuText(128, 15, msg, false, eRightJustify);
|
|
|
|
// }
|
|
|
|
_drawBitmap(18, 34, HardwareIconInfo);
|
2019-05-16 11:12:29 +00:00
|
|
|
int PCB = getBoardRevision();
|
|
|
|
sprintf(msg, "V%.1f", float(PCB)*0.1f);
|
2019-08-03 02:42:49 +00:00
|
|
|
_printMenuText(41, 38, msg);
|
2019-05-16 11:12:29 +00:00
|
|
|
if(PCB == 20) {
|
|
|
|
_printMenuText(108, 38, "Analog", false, eCentreJustify);
|
|
|
|
_display.drawLine(88, 42, 127, 42, WHITE);
|
|
|
|
}
|
2019-08-03 02:42:49 +00:00
|
|
|
if(PCB == 22) {
|
|
|
|
_printMenuText(114, 38, "GPIO", false, eCentreJustify);
|
|
|
|
_display.drawLine(94, 42, 121, 42, WHITE);
|
|
|
|
}
|
2019-05-20 12:09:59 +00:00
|
|
|
|
2019-08-03 02:42:49 +00:00
|
|
|
if(_rowSel == 1 && newVer) {
|
2019-05-21 08:29:16 +00:00
|
|
|
// prompt 'Get Update' for new firmware available and first UP press from home
|
2019-08-03 02:42:49 +00:00
|
|
|
char msg[32];
|
|
|
|
int major = (int)(newVer * 0.01);
|
|
|
|
int minor = newVer - major*100;
|
|
|
|
float prtMajor = major * 0.1;
|
|
|
|
sprintf(msg, "Get V%.1f.%d update", prtMajor, minor);
|
|
|
|
_printMenuText(_display.xCentre(), 53, " ", true, eCentreJustify);
|
|
|
|
_printMenuText(_display.xCentre(), 53, msg, false, eCentreJustify);
|
2019-05-20 12:09:59 +00:00
|
|
|
}
|
|
|
|
else {
|
2019-08-03 02:42:49 +00:00
|
|
|
_printMenuText(_display.xCentre(), 53, " \021 \020 ", true, eCentreJustify);
|
2019-07-27 14:28:39 +00:00
|
|
|
_printMenuText(_display.xCentre(), 53, "Exit", false, eCentreJustify);
|
2019-05-20 12:09:59 +00:00
|
|
|
}
|
2019-05-16 11:12:29 +00:00
|
|
|
}
|
|
|
|
else {
|
2019-05-20 12:09:59 +00:00
|
|
|
if(_rowSel == 11) { // after the saving popup has expired
|
2019-05-21 08:29:16 +00:00
|
|
|
// factory default completed screen, progress to REBOOT
|
2019-05-16 11:12:29 +00:00
|
|
|
const char* content[2];
|
|
|
|
content[0] = "Factory reset";
|
|
|
|
content[1] = "completed";
|
|
|
|
_ScreenManager.showRebootMsg(content, 5000);
|
|
|
|
}
|
2019-05-21 08:29:16 +00:00
|
|
|
else if(_rowSel == 20) {
|
|
|
|
// firmware update confirmation screen
|
2019-08-03 02:42:49 +00:00
|
|
|
_showTitle("Firmware update");
|
2019-05-21 08:29:16 +00:00
|
|
|
_printMenuText(_display.xCentre(), 35, "Press UP to", false, eCentreJustify);
|
|
|
|
_printMenuText(_display.xCentre(), 43, "confirm download", false, eCentreJustify);
|
|
|
|
}
|
2019-05-16 11:12:29 +00:00
|
|
|
else {
|
2019-08-03 02:42:49 +00:00
|
|
|
_showTitle("Factory Default");
|
2019-05-20 12:09:59 +00:00
|
|
|
if(_rowSel == 10) {
|
2019-05-21 08:29:16 +00:00
|
|
|
// factory default confirmation screen
|
2019-05-16 11:12:29 +00:00
|
|
|
_printMenuText(_display.xCentre(), 35, "Press UP to", false, eCentreJustify);
|
|
|
|
_printMenuText(_display.xCentre(), 43, "confirm save", false, eCentreJustify);
|
|
|
|
}
|
|
|
|
else {
|
2019-05-21 08:29:16 +00:00
|
|
|
// factory default apply/abort screens
|
2019-06-01 00:18:31 +00:00
|
|
|
_drawBitmap(10, 15, CautionIconInfo);
|
2019-05-16 11:12:29 +00:00
|
|
|
|
2019-05-20 12:09:59 +00:00
|
|
|
_printMenuText(50, 30, "Abort", _rowSel == 2);
|
|
|
|
_printMenuText(50, 16, "Apply", _rowSel == 3);
|
|
|
|
if(_rowSel == 3)
|
2019-05-16 11:12:29 +00:00
|
|
|
_printMenuText(_display.xCentre(), 53, " \021 Apply \020 ", true, eCentreJustify);
|
|
|
|
else
|
|
|
|
_printMenuText(_display.xCentre(), 53, " \021 Exit \020 ", true, eCentreJustify);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-04-19 11:38:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-05-20 12:09:59 +00:00
|
|
|
bool
|
|
|
|
CVersionInfoScreen::animate()
|
|
|
|
{
|
|
|
|
if(_rowSel <= 1 && isUpdateAvailable()) {
|
2019-05-21 08:29:16 +00:00
|
|
|
// show ascending up arrow if firmware update is available on web server
|
2019-05-20 12:09:59 +00:00
|
|
|
_animateCount++;
|
2019-08-03 02:42:49 +00:00
|
|
|
WRAPUPPERLIMIT(_animateCount, 3, 0);
|
|
|
|
/* int ypos = 11 + 16 - 7 - _animateCount;
|
2019-05-22 11:08:38 +00:00
|
|
|
_display.fillRect(0, 11, 10, 21, BLACK);
|
2019-06-01 00:18:31 +00:00
|
|
|
_display.drawBitmap(2, ypos, WifiOutIconInfo.pBitmap, WifiOutIconInfo.width, 7, WHITE); // upload arrow - from web to afterburner
|
2019-08-03 02:42:49 +00:00
|
|
|
_display.fillRect(1, 12, 7, 2, WHITE); // top bar
|
|
|
|
_drawBitmap(0, 11+17, WWWIconInfo); // www icon*/
|
|
|
|
|
|
|
|
int newVer = isUpdateAvailable();
|
|
|
|
if((_animateCount & 0x02) && newVer) {
|
|
|
|
char msg[32];
|
|
|
|
int major = (int)(newVer * 0.01);
|
|
|
|
int minor = newVer - major*100;
|
|
|
|
float prtMajor = major * 0.1;
|
|
|
|
sprintf(msg, "V%.1f.%d", prtMajor, minor);
|
|
|
|
_printMenuText(128, 15, msg, false, eRightJustify);
|
|
|
|
_drawBitmap(118, 24, UpdateIconInfo);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
_display.fillRect(82, 15, 46, 7, BLACK);
|
|
|
|
_display.fillRect(118, 24, 9, 10, BLACK);
|
|
|
|
}
|
2019-05-20 12:09:59 +00:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2019-04-19 11:38:39 +00:00
|
|
|
|
|
|
|
bool
|
|
|
|
CVersionInfoScreen::keyHandler(uint8_t event)
|
|
|
|
{
|
|
|
|
if(event & keyPressed) {
|
|
|
|
// UP press
|
|
|
|
if(event & key_Up) {
|
2019-05-20 12:09:59 +00:00
|
|
|
if(_rowSel == 20) {
|
|
|
|
isUpdateAvailable(false); // make firmware update happen
|
|
|
|
_rowSel = 0;
|
|
|
|
}
|
|
|
|
else if(_rowSel == 10) {
|
2019-05-16 11:12:29 +00:00
|
|
|
wifiFactoryDefault();
|
|
|
|
BoardRevisionReset();
|
|
|
|
NVstore.init();
|
|
|
|
NVstore.save();
|
2019-07-27 23:07:29 +00:00
|
|
|
_enableStoringMessage();
|
2019-05-20 12:09:59 +00:00
|
|
|
_rowSel = 11;
|
2019-05-16 11:12:29 +00:00
|
|
|
}
|
|
|
|
else {
|
2019-05-20 12:09:59 +00:00
|
|
|
_rowSel++;
|
|
|
|
UPPERLIMIT(_rowSel, 3);
|
2019-05-16 11:12:29 +00:00
|
|
|
}
|
2019-04-19 11:38:39 +00:00
|
|
|
}
|
2019-05-16 11:12:29 +00:00
|
|
|
// DOWN press
|
|
|
|
if(event & key_Down) {
|
2019-05-20 12:09:59 +00:00
|
|
|
if(_rowSel == 20) { // firmware update cancel
|
|
|
|
_rowSel = 0;
|
|
|
|
}
|
|
|
|
_rowSel--;
|
|
|
|
LOWERLIMIT(_rowSel, 0);
|
2019-04-19 11:38:39 +00:00
|
|
|
}
|
|
|
|
// LEFT press
|
|
|
|
if(event & key_Left) {
|
|
|
|
_ScreenManager.prevMenu();
|
|
|
|
}
|
|
|
|
// RIGHT press
|
|
|
|
if(event & key_Right) {
|
|
|
|
_ScreenManager.nextMenu();
|
|
|
|
}
|
2019-05-16 11:12:29 +00:00
|
|
|
// CENTRE press
|
2019-04-27 10:41:47 +00:00
|
|
|
if(event & key_Centre) {
|
2019-05-20 12:09:59 +00:00
|
|
|
if(_rowSel == 20) { // firmware update cancel
|
|
|
|
_rowSel = 0;
|
|
|
|
}
|
|
|
|
else if(_rowSel == 3) { // factory enable selection
|
|
|
|
_rowSel = 10;
|
|
|
|
}
|
|
|
|
else if(_rowSel == 1) { // firmware update selection
|
|
|
|
_rowSel = 20;
|
2019-05-16 11:12:29 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
_ScreenManager.selectMenu(CScreenManager::RootMenuLoop); // force return to main menu
|
|
|
|
}
|
2019-04-27 10:41:47 +00:00
|
|
|
}
|
2019-04-19 11:38:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
_ScreenManager.reqUpdate();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|