2018-11-26 11:58:15 +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/>.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2019-01-18 07:09:40 +00:00
|
|
|
#include "WiFiScreen.h"
|
2018-12-16 07:34:39 +00:00
|
|
|
#include "KeyPad.h"
|
2019-06-15 23:09:29 +00:00
|
|
|
#include "../Utility/helpers.h"
|
2019-06-30 12:39:40 +00:00
|
|
|
#include "../WiFi/BTCWifi.h"
|
2019-07-02 10:22:14 +00:00
|
|
|
#include "../Utility/NVStorage.h"
|
2019-07-27 14:28:39 +00:00
|
|
|
#include "fonts/Arial.h"
|
2018-11-24 11:03:47 +00:00
|
|
|
|
2018-12-01 00:36:25 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
2019-01-18 07:09:40 +00:00
|
|
|
// CWiFiScreen
|
2018-12-01 00:36:25 +00:00
|
|
|
//
|
|
|
|
// This screen presents sundry information
|
|
|
|
// eg WiFi status
|
|
|
|
//
|
|
|
|
///////////////////////////////////////////////////////////////////////////
|
2018-11-24 11:03:47 +00:00
|
|
|
|
2019-01-14 21:41:54 +00:00
|
|
|
#define STA_HOLD_TIME 10
|
2018-12-01 00:36:25 +00:00
|
|
|
|
2019-03-17 07:10:01 +00:00
|
|
|
static const int LIMIT_AWAY = 0;
|
|
|
|
static const int LIMIT_LEFT = 1;
|
|
|
|
static const int LIMIT_RIGHT = 2;
|
|
|
|
|
2019-07-27 14:28:39 +00:00
|
|
|
CWiFiScreen::CWiFiScreen(C128x64_OLED& display, CScreenManager& mgr) : CScreen(display, mgr)
|
2019-02-28 08:56:13 +00:00
|
|
|
{
|
|
|
|
_initUI();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CWiFiScreen::onSelect()
|
|
|
|
{
|
2019-07-27 14:28:39 +00:00
|
|
|
CScreen::onSelect();
|
2019-02-28 08:56:13 +00:00
|
|
|
_initUI();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CWiFiScreen::_initUI()
|
2018-11-24 11:03:47 +00:00
|
|
|
{
|
2019-01-14 21:41:54 +00:00
|
|
|
_rowSel = 0;
|
2019-03-24 05:48:03 +00:00
|
|
|
_colSel = 0;
|
2019-06-06 01:32:43 +00:00
|
|
|
_OTAsel = NVstore.getUserSettings().enableOTA;
|
2019-01-18 03:34:32 +00:00
|
|
|
_bShowMAC = false;
|
2019-03-17 07:10:01 +00:00
|
|
|
|
2019-06-06 01:32:43 +00:00
|
|
|
if(NVstore.getUserSettings().enableWifi) {
|
2019-03-24 05:48:03 +00:00
|
|
|
if(isWifiAP()) {
|
|
|
|
if(isWifiConfigPortal()) {
|
2019-03-24 06:38:48 +00:00
|
|
|
_colSel = 1; // " WiFi: CFG AP only "
|
2019-03-24 05:48:03 +00:00
|
|
|
}
|
|
|
|
else {
|
2019-03-24 06:38:48 +00:00
|
|
|
_colSel = 2; // " WiFi: AP only ";
|
2019-03-24 05:48:03 +00:00
|
|
|
}
|
2019-03-17 07:10:01 +00:00
|
|
|
}
|
|
|
|
else {
|
2019-03-24 05:48:03 +00:00
|
|
|
if(isWifiConfigPortal()) {
|
2019-03-24 06:38:48 +00:00
|
|
|
_colSel = 3; // " WiFi: CFG STA+AP "
|
2019-03-24 05:48:03 +00:00
|
|
|
}
|
|
|
|
else {
|
2019-03-24 06:38:48 +00:00
|
|
|
_colSel = 4; // " WiFi: STA+AP ";
|
2019-03-24 05:48:03 +00:00
|
|
|
}
|
2019-03-17 07:10:01 +00:00
|
|
|
}
|
|
|
|
}
|
2018-11-25 04:45:17 +00:00
|
|
|
}
|
|
|
|
|
2019-01-18 23:06:12 +00:00
|
|
|
bool
|
2019-01-18 07:09:40 +00:00
|
|
|
CWiFiScreen::show()
|
2018-11-25 04:45:17 +00:00
|
|
|
{
|
2019-07-27 14:28:39 +00:00
|
|
|
// CScreenHeader::show(false);
|
|
|
|
CScreen::show();
|
2018-11-25 04:45:17 +00:00
|
|
|
|
2019-07-27 14:28:39 +00:00
|
|
|
_display.clearDisplay();
|
|
|
|
_showTitle("WiFi settings");
|
|
|
|
|
2019-01-18 03:34:32 +00:00
|
|
|
int yPos = 18;
|
2019-01-14 21:41:54 +00:00
|
|
|
|
2019-03-24 05:48:03 +00:00
|
|
|
const char* pTitle = NULL;
|
|
|
|
switch(_colSel) {
|
|
|
|
case 0:
|
2019-07-27 14:28:39 +00:00
|
|
|
pTitle = "DISABLED";
|
2019-03-24 05:48:03 +00:00
|
|
|
break;
|
|
|
|
case 1:
|
2019-07-27 14:28:39 +00:00
|
|
|
pTitle = "CFG AP only";
|
2019-03-24 05:48:03 +00:00
|
|
|
break;
|
|
|
|
case 2:
|
2019-07-27 14:28:39 +00:00
|
|
|
pTitle = "AP only";
|
2019-03-24 05:48:03 +00:00
|
|
|
break;
|
|
|
|
case 3:
|
2019-07-27 14:28:39 +00:00
|
|
|
pTitle = "CFG STA+AP";
|
2019-03-24 05:48:03 +00:00
|
|
|
break;
|
|
|
|
case 4:
|
2019-07-27 14:28:39 +00:00
|
|
|
pTitle = "STA+AP";
|
2019-03-24 05:48:03 +00:00
|
|
|
break;
|
|
|
|
}
|
2019-01-14 21:41:54 +00:00
|
|
|
|
2019-07-27 14:28:39 +00:00
|
|
|
_printMenuText(border, yPos, pTitle, _rowSel==1); // selection box
|
|
|
|
if(_OTAsel == 0)
|
|
|
|
_printMenuText(128-border, yPos, "OTA: OFF", _rowSel==2, eRightJustify); // selection box
|
|
|
|
else
|
|
|
|
_printMenuText(128-border, yPos, "OTA: ON ", _rowSel==2, eRightJustify); // selection box
|
2019-03-24 05:48:03 +00:00
|
|
|
yPos += 3;
|
2019-01-14 21:41:54 +00:00
|
|
|
|
2019-03-24 05:48:03 +00:00
|
|
|
if(_colSel) {
|
2019-01-14 09:54:31 +00:00
|
|
|
// only show STA IP address if available!
|
2019-01-14 21:41:54 +00:00
|
|
|
if(isWifiSTA() && _repeatCount <= STA_HOLD_TIME) {
|
2019-01-14 09:54:31 +00:00
|
|
|
yPos += _display.textHeight() + 2;
|
|
|
|
_printMenuText(0, yPos, "STA:");
|
2019-01-18 03:34:32 +00:00
|
|
|
if(_bShowMAC)
|
|
|
|
_printMenuText(25, yPos, getWifiSTAMACStr());
|
|
|
|
else
|
|
|
|
_printMenuText(25, yPos, getWifiSTAAddrStr());
|
2019-01-14 09:54:31 +00:00
|
|
|
}
|
2019-01-18 03:34:32 +00:00
|
|
|
// show AP IP address
|
|
|
|
yPos += _display.textHeight() + 2;
|
|
|
|
_printMenuText(0, yPos, " AP:");
|
|
|
|
if(_bShowMAC)
|
|
|
|
_printMenuText(25, yPos, getWifiAPMACStr());
|
|
|
|
else
|
|
|
|
_printMenuText(25, yPos, getWifiAPAddrStr());
|
2018-11-24 11:03:47 +00:00
|
|
|
}
|
2019-01-16 09:22:17 +00:00
|
|
|
|
2019-01-18 23:06:12 +00:00
|
|
|
return true;
|
2018-11-24 11:03:47 +00:00
|
|
|
}
|
|
|
|
|
2019-03-17 07:10:01 +00:00
|
|
|
bool
|
|
|
|
CWiFiScreen::animate()
|
|
|
|
{
|
|
|
|
// show next/prev menu navigation line
|
|
|
|
if(_rowSel == 0) {
|
2019-07-27 14:28:39 +00:00
|
|
|
// _printMenuText(_display.xCentre(), 53, " ", true, eCentreJustify);
|
|
|
|
_printMenuText(_display.xCentre(), 53, "\021 \020", true, eCentreJustify);
|
|
|
|
if(_bShowMAC) {
|
|
|
|
_printMenuText(_display.xCentre(), 53, "\030Mode \031IP", false, eCentreJustify);
|
|
|
|
_printMenuText(_display.xCentre(), 53, " Exit", false, eCentreJustify);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
_printMenuText(_display.xCentre(), 53, "\030Mode \031MAC", false, eCentreJustify);
|
|
|
|
_printMenuText(_display.xCentre(), 53, " Exit", false, eCentreJustify);
|
|
|
|
}
|
2019-03-17 07:10:01 +00:00
|
|
|
}
|
|
|
|
if(_rowSel == 1) {
|
|
|
|
_display.drawFastHLine(0, 52, 128, WHITE);
|
|
|
|
const char* pMsg = NULL;
|
2019-07-27 14:28:39 +00:00
|
|
|
pMsg = "\031ESC \030OTA Set \033\032Adj"; // both Sel arrows
|
|
|
|
_printMenuText(_display.xCentre(), 56, pMsg, false, eCentreJustify);
|
2019-03-17 07:10:01 +00:00
|
|
|
}
|
2019-03-24 05:48:03 +00:00
|
|
|
if(_rowSel == 2) {
|
|
|
|
_display.drawFastHLine(0, 52, 128, WHITE);
|
|
|
|
const char* pMsg = NULL;
|
2019-07-27 14:28:39 +00:00
|
|
|
pMsg = "\031Mode Set \033\032Adj";
|
|
|
|
_printMenuText(_display.xCentre(), 56, pMsg, false, eCentreJustify);
|
2019-03-24 05:48:03 +00:00
|
|
|
}
|
2019-07-27 14:28:39 +00:00
|
|
|
CScreen::animate();
|
2019-03-17 07:10:01 +00:00
|
|
|
return true;
|
|
|
|
}
|
2018-11-24 11:03:47 +00:00
|
|
|
|
2019-01-18 23:06:12 +00:00
|
|
|
bool
|
2019-01-18 07:09:40 +00:00
|
|
|
CWiFiScreen::keyHandler(uint8_t event)
|
2018-11-24 11:03:47 +00:00
|
|
|
{
|
|
|
|
if(event & keyPressed) {
|
2019-01-14 21:41:54 +00:00
|
|
|
_repeatCount = 0;
|
2018-11-24 11:03:47 +00:00
|
|
|
// press LEFT
|
|
|
|
if(event & key_Left) {
|
2019-03-24 05:48:03 +00:00
|
|
|
switch(_rowSel) {
|
|
|
|
case 0:
|
|
|
|
_ScreenManager.prevMenu();
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
if(isWifiAP()) {
|
|
|
|
_colSel--;
|
2019-07-27 14:28:39 +00:00
|
|
|
WRAPLOWERLIMIT(_colSel, 0, 2);
|
2019-03-24 05:48:03 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
_colSel--;
|
2019-07-27 14:28:39 +00:00
|
|
|
WRAPLOWERLIMIT(_colSel, 0, 4);
|
2019-03-24 05:48:03 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 2:
|
2019-07-27 14:28:39 +00:00
|
|
|
_OTAsel--;
|
|
|
|
WRAPLOWERLIMIT(_OTAsel, 0, 1);
|
2019-03-24 05:48:03 +00:00
|
|
|
break;
|
2019-03-17 07:10:01 +00:00
|
|
|
}
|
2018-11-24 11:03:47 +00:00
|
|
|
}
|
|
|
|
// press RIGHT
|
|
|
|
if(event & key_Right) {
|
2019-03-24 05:48:03 +00:00
|
|
|
switch(_rowSel) {
|
|
|
|
case 0:
|
|
|
|
_ScreenManager.nextMenu();
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
if(isWifiAP()) {
|
|
|
|
_colSel++;
|
2019-07-27 14:28:39 +00:00
|
|
|
WRAPUPPERLIMIT(_colSel, 2, 0);
|
2019-03-24 05:48:03 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
_colSel++;
|
2019-07-27 14:28:39 +00:00
|
|
|
WRAPUPPERLIMIT(_colSel, 4, 0);
|
2019-03-24 05:48:03 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 2:
|
2019-07-27 14:28:39 +00:00
|
|
|
_OTAsel++;
|
|
|
|
WRAPUPPERLIMIT(_OTAsel, 1, 0);
|
2019-03-24 05:48:03 +00:00
|
|
|
break;
|
2019-03-17 07:10:01 +00:00
|
|
|
}
|
2018-11-24 11:03:47 +00:00
|
|
|
}
|
2019-01-14 21:41:54 +00:00
|
|
|
// press UP
|
|
|
|
if(event & key_Up) {
|
2019-03-24 05:48:03 +00:00
|
|
|
_rowSel++;
|
|
|
|
UPPERLIMIT(_rowSel, 2);
|
2019-01-14 21:41:54 +00:00
|
|
|
}
|
|
|
|
// press DOWN
|
|
|
|
if(event & key_Down) {
|
2019-01-18 03:34:32 +00:00
|
|
|
if(_rowSel == 0) {
|
|
|
|
_bShowMAC = !_bShowMAC; // toogle MAC/IP address if on navigation row
|
|
|
|
}
|
2019-03-24 05:48:03 +00:00
|
|
|
_rowSel--;
|
|
|
|
LOWERLIMIT(_rowSel, 0);
|
2019-01-14 21:41:54 +00:00
|
|
|
}
|
2019-01-16 09:22:17 +00:00
|
|
|
_ScreenManager.reqUpdate();
|
2019-01-14 21:41:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if(event & keyRepeat) { // track key hold time
|
2019-03-17 07:10:01 +00:00
|
|
|
if(event & key_Centre) {
|
|
|
|
_repeatCount++;
|
|
|
|
}
|
2019-01-14 21:41:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if(event & keyReleased) {
|
|
|
|
if(event & key_Centre) {
|
2019-07-27 14:28:39 +00:00
|
|
|
if(_rowSel == 0) {
|
|
|
|
_ScreenManager.selectMenu(CScreenManager::RootMenuLoop); // force return to main menu
|
|
|
|
}
|
2019-03-24 05:48:03 +00:00
|
|
|
if(_rowSel == 1) {
|
2019-01-16 09:22:17 +00:00
|
|
|
|
2019-03-17 07:10:01 +00:00
|
|
|
switch(_colSel) {
|
|
|
|
case 0:
|
2019-03-24 05:48:03 +00:00
|
|
|
wifiDisable(5000);
|
2019-03-17 07:10:01 +00:00
|
|
|
break;
|
|
|
|
case 1:
|
2019-03-24 05:48:03 +00:00
|
|
|
wifiEnterConfigPortal(true, true, 5000); // CFG AP: erase credentials, reboot into portal
|
2019-03-17 07:10:01 +00:00
|
|
|
break;
|
|
|
|
case 2:
|
2019-03-24 05:48:03 +00:00
|
|
|
wifiEnterConfigPortal(false, true, 5000); // AP Only: erase credentials, reboot into webserver
|
2019-03-17 07:10:01 +00:00
|
|
|
break;
|
|
|
|
case 3:
|
2019-03-24 05:48:03 +00:00
|
|
|
wifiEnterConfigPortal(true, false, 5000); // CFG STA+AP: keep credentials, reboot into portal
|
|
|
|
break;
|
|
|
|
case 4:
|
2019-03-17 07:10:01 +00:00
|
|
|
wifiEnterConfigPortal(false, false, 5000); // STA+AP: keep credentials, reboot into webserver
|
|
|
|
break;
|
2019-01-14 21:41:54 +00:00
|
|
|
}
|
2019-03-24 05:48:03 +00:00
|
|
|
_rowSel = 3; // stop ticker display
|
|
|
|
}
|
|
|
|
if(_rowSel == 2) {
|
2019-06-06 01:32:43 +00:00
|
|
|
sUserSettings settings = NVstore.getUserSettings();
|
|
|
|
settings.enableOTA = _OTAsel;
|
|
|
|
NVstore.setUserSettings(settings);
|
2019-03-24 05:48:03 +00:00
|
|
|
NVstore.save();
|
|
|
|
const char* content[2];
|
|
|
|
if(_OTAsel)
|
|
|
|
content[0] = "Enabling OTA";
|
|
|
|
else
|
|
|
|
content[0] = "Disabling OTA";
|
|
|
|
content[1] = "";
|
|
|
|
|
|
|
|
_ScreenManager.showRebootMsg(content, 5000);
|
2019-01-14 21:41:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
_repeatCount = 0;
|
2018-11-24 11:03:47 +00:00
|
|
|
}
|
2019-01-18 23:06:12 +00:00
|
|
|
return true;
|
2018-11-24 11:03:47 +00:00
|
|
|
}
|
|
|
|
|