Can now set/clear CFG mode with OLED. Can also clear credentials.
This commit is contained in:
parent
fa4c595efa
commit
af0980a72b
6 changed files with 83 additions and 29 deletions
|
@ -37,9 +37,11 @@
|
||||||
//
|
//
|
||||||
///////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
#define STA_HOLD_TIME 10
|
||||||
|
|
||||||
CScreen4::CScreen4(C128x64_OLED& display, CScreenManager& mgr) : CScreenHeader(display, mgr)
|
CScreen4::CScreen4(C128x64_OLED& display, CScreenManager& mgr) : CScreenHeader(display, mgr)
|
||||||
{
|
{
|
||||||
|
_rowSel = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -50,22 +52,29 @@ CScreen4::show()
|
||||||
|
|
||||||
int yPos = 16;
|
int yPos = 16;
|
||||||
if(isWifiConnected() || isWifiAP()) {
|
if(isWifiConnected() || isWifiAP()) {
|
||||||
if(isWifiAP()) {
|
|
||||||
_printInverted(0, yPos, " WiFi: AP only ", true);
|
const char* pTitle = NULL;
|
||||||
}
|
if(isWifiAP())
|
||||||
else {
|
pTitle = isWifiConfigPortal() ? " WiFi: CFG AP only " : " WiFi: AP only ";
|
||||||
_printInverted(0, yPos, " WiFi: STA+AP ", true);
|
else
|
||||||
}
|
pTitle = isWifiConfigPortal() ? " WiFi: CFG STA+AP " : " WiFi: STA+AP ";
|
||||||
// only show STA IP address if available!
|
|
||||||
if(isWifiSTA()) {
|
if(_rowSel == 1)
|
||||||
yPos += _display.textHeight() + 2;
|
_printMenuText(3, yPos, pTitle, true); // selection box
|
||||||
_printMenuText(0, yPos, "STA:");
|
else
|
||||||
_printMenuText(25, yPos, getWifiSTAAddrStr());
|
_printInverted(3, yPos, pTitle, true); // inverted title bar
|
||||||
}
|
yPos += 3;
|
||||||
|
|
||||||
// show AP IP address
|
// show AP IP address
|
||||||
yPos += _display.textHeight() + 2;
|
yPos += _display.textHeight() + 2;
|
||||||
_printMenuText(0, yPos, " AP:");
|
_printMenuText(0, yPos, " AP:");
|
||||||
_printMenuText(25, yPos, getWifiAPAddrStr());
|
_printMenuText(25, yPos, getWifiAPAddrStr());
|
||||||
|
// only show STA IP address if available!
|
||||||
|
if(isWifiSTA() && _repeatCount <= STA_HOLD_TIME) {
|
||||||
|
yPos += _display.textHeight() + 2;
|
||||||
|
_printMenuText(0, yPos, "STA:");
|
||||||
|
_printMenuText(25, yPos, getWifiSTAAddrStr());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
_printInverted(0, yPos, " WiFi Inactive ", true);
|
_printInverted(0, yPos, " WiFi Inactive ", true);
|
||||||
|
@ -82,6 +91,7 @@ void
|
||||||
CScreen4::keyHandler(uint8_t event)
|
CScreen4::keyHandler(uint8_t event)
|
||||||
{
|
{
|
||||||
if(event & keyPressed) {
|
if(event & keyPressed) {
|
||||||
|
_repeatCount = 0;
|
||||||
// press CENTRE
|
// press CENTRE
|
||||||
if(event & key_Centre) {
|
if(event & key_Centre) {
|
||||||
return;
|
return;
|
||||||
|
@ -94,6 +104,38 @@ CScreen4::keyHandler(uint8_t event)
|
||||||
if(event & key_Right) {
|
if(event & key_Right) {
|
||||||
_ScreenManager.nextScreen();
|
_ScreenManager.nextScreen();
|
||||||
}
|
}
|
||||||
|
// press UP
|
||||||
|
if(event & key_Up) {
|
||||||
|
_rowSel = 1;
|
||||||
|
// _rowSel++;
|
||||||
|
// UPPERLIMIT(_rowSel, (isWifiConfigPortal() ? 2 : 1));
|
||||||
|
}
|
||||||
|
// press DOWN
|
||||||
|
if(event & key_Down) {
|
||||||
|
_rowSel = 0;
|
||||||
|
// _rowSel--;
|
||||||
|
// UPPERLIMIT(_rowSel, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(event & keyRepeat) { // track key hold time
|
||||||
|
_repeatCount++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(event & keyReleased) {
|
||||||
|
if(event & key_Centre) {
|
||||||
|
if(_rowSel) {
|
||||||
|
if(isWifiConfigPortal())
|
||||||
|
wifiEnterConfigPortal(false); // stop config portal, reboot
|
||||||
|
else {
|
||||||
|
if(_rowSel==1)
|
||||||
|
wifiEnterConfigPortal(true, _repeatCount > STA_HOLD_TIME); // press - reboot into portal, long press - erase credentials
|
||||||
|
else
|
||||||
|
wifiEnterConfigPortal(false); // stop config portal, reboot
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_repeatCount = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -30,4 +30,7 @@ public:
|
||||||
CScreen4(C128x64_OLED& display, CScreenManager& mgr);
|
CScreen4(C128x64_OLED& display, CScreenManager& mgr);
|
||||||
void show();
|
void show();
|
||||||
void keyHandler(uint8_t event);
|
void keyHandler(uint8_t event);
|
||||||
|
private:
|
||||||
|
int _rowSel;
|
||||||
|
int _repeatCount;
|
||||||
};
|
};
|
||||||
|
|
|
@ -128,7 +128,7 @@ CScreenHeader::showWifiIcon()
|
||||||
{
|
{
|
||||||
if(isWifiConnected() || isWifiAP()) {
|
if(isWifiConnected() || isWifiAP()) {
|
||||||
_display.drawBitmap(X_WIFI_ICON, Y_WIFI_ICON, wifiIcon, W_WIFI_ICON, H_WIFI_ICON, WHITE);
|
_display.drawBitmap(X_WIFI_ICON, Y_WIFI_ICON, wifiIcon, W_WIFI_ICON, H_WIFI_ICON, WHITE);
|
||||||
if(isConfigPortal()) {
|
if(isWifiConfigPortal()) {
|
||||||
_display.fillRect(X_WIFI_ICON + 8, Y_WIFI_ICON + 5, 15, 7, BLACK);
|
_display.fillRect(X_WIFI_ICON + 8, Y_WIFI_ICON + 5, 15, 7, BLACK);
|
||||||
CTransientFont AF(_display, &MINIFONT); // temporarily use a mini font
|
CTransientFont AF(_display, &MINIFONT); // temporarily use a mini font
|
||||||
_display.setCursor(X_WIFI_ICON+9, Y_WIFI_ICON+6);
|
_display.setCursor(X_WIFI_ICON+9, Y_WIFI_ICON+6);
|
||||||
|
|
|
@ -166,31 +166,39 @@ void doWiFiManager()
|
||||||
DebugPort.print("Wifi config button tDelta = "); DebugPort.println(tDelta);
|
DebugPort.print("Wifi config button tDelta = "); DebugPort.println(tDelta);
|
||||||
// > 5 second press?
|
// > 5 second press?
|
||||||
if(tDelta > 5000) {
|
if(tDelta > 5000) {
|
||||||
prepBootIntoConfigPortal(true); // very long press - clear credentials, boot into portal
|
wifiEnterConfigPortal(true, true); // very long press - clear credentials, reboot into portal
|
||||||
wm.resetSettings();
|
|
||||||
DebugPort.println("*** Clearing credentials and rebooting into portal ***");
|
|
||||||
delay(1000);
|
|
||||||
ESP.restart();
|
|
||||||
}
|
}
|
||||||
// > 1 second press?
|
// > 1 second press?
|
||||||
else if(tDelta > 1000) {
|
else if(tDelta > 1000) {
|
||||||
prepBootIntoConfigPortal(false); // long press - boot into SoftAP
|
wifiEnterConfigPortal(false); // long press - reboot into web server
|
||||||
DebugPort.println("*** Rebooting into web server ***");
|
|
||||||
delay(1000);
|
|
||||||
ESP.restart();
|
|
||||||
}
|
}
|
||||||
// > 50ms press?
|
// > 50ms press?
|
||||||
else if(tDelta > 50) {
|
else if(tDelta > 50) {
|
||||||
prepBootIntoConfigPortal(true); // short press - boot into Portal
|
wifiEnterConfigPortal(true); // quick press - reboot into portal
|
||||||
DebugPort.println("*** Rebooting into config portal ***");
|
|
||||||
delay(1000);
|
|
||||||
ESP.restart();
|
|
||||||
}
|
}
|
||||||
// consider as contact bounce if < 50ms!
|
// consider as contact bounce if < 50ms!
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void wifiEnterConfigPortal(bool state, bool erase)
|
||||||
|
{
|
||||||
|
prepBootIntoConfigPortal(state);
|
||||||
|
|
||||||
|
if(erase) {
|
||||||
|
wm.resetSettings();
|
||||||
|
DebugPort.println("*** Erased wifi credentials ***");
|
||||||
|
}
|
||||||
|
|
||||||
|
if(state)
|
||||||
|
DebugPort.println("*** Rebooting into config portal ***");
|
||||||
|
else
|
||||||
|
DebugPort.println("*** Rebooting into web server ***");
|
||||||
|
|
||||||
|
delay(1000);
|
||||||
|
ESP.restart();
|
||||||
|
}
|
||||||
|
|
||||||
// callback is invoked by WiFiManager after new credentials are saved and verified
|
// callback is invoked by WiFiManager after new credentials are saved and verified
|
||||||
void saveParamsCallback()
|
void saveParamsCallback()
|
||||||
{
|
{
|
||||||
|
@ -238,7 +246,7 @@ bool isWifiSTA()
|
||||||
return isSTA; // true: STAtion mode link is active
|
return isSTA; // true: STAtion mode link is active
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isConfigPortal()
|
bool isWifiConfigPortal()
|
||||||
{
|
{
|
||||||
return isPortalAP; // true: config portal is running
|
return isPortalAP; // true: config portal is running
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,9 +33,10 @@
|
||||||
bool isWifiConnected();
|
bool isWifiConnected();
|
||||||
bool isWifiAP();
|
bool isWifiAP();
|
||||||
bool isWifiSTA();
|
bool isWifiSTA();
|
||||||
bool isConfigPortal();
|
bool isWifiConfigPortal();
|
||||||
bool isWebClientConnected();
|
bool isWebClientConnected();
|
||||||
bool hasWebClientSpoken(bool reset = false);
|
bool hasWebClientSpoken(bool reset = false);
|
||||||
bool hasWebServerSpoken(bool reset = false);
|
bool hasWebServerSpoken(bool reset = false);
|
||||||
|
void wifiEnterConfigPortal(bool state, bool erase = false);
|
||||||
|
|
||||||
#endif __BTCWIFI_H__
|
#endif __BTCWIFI_H__
|
||||||
|
|
|
@ -46,5 +46,5 @@ const uint8_t keyLeft_pin = 39; // input only, no chip pullup
|
||||||
|
|
||||||
const uint8_t ListenOnlyPin = 33;
|
const uint8_t ListenOnlyPin = 33;
|
||||||
//const uint8_t WiFi_TriggerPin = 25;
|
//const uint8_t WiFi_TriggerPin = 25;
|
||||||
const uint8_t WiFi_TriggerPin = 0;
|
const uint8_t WiFi_TriggerPin = 0; // BOOT switch!
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue