Skip to content

Commit 03403b2

Browse files
(#226): The splash screen prints what the network mode is along with the IP
1 parent d6ec73d commit 03403b2

5 files changed

Lines changed: 48 additions & 12 deletions

File tree

Firmware/GPAD_API/GPAD_API/GPAD_API.ino

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -356,9 +356,8 @@ void setup()
356356
serialSplash();
357357
// We call this a second time to get the MAC on the screen
358358
clearLCD();
359-
splashLCD();
360359

361-
// Set LED pins as outputs
360+
// Set LED pins as outputs
362361
#if defined(LED_D9)
363362
pinMode(LED_D9, OUTPUT);
364363
#endif
@@ -382,7 +381,8 @@ void setup()
382381
// Setup and present LCD splash screen
383382
// Setup the SWITCH_MUTE
384383
// Setup the SWITCH_ENCODER
385-
GPAD_HAL_setup(&Serial);
384+
IPAddress deviceAddress = wifiManager.getAddress();
385+
GPAD_HAL_setup(&Serial, wifiManager.getMode(), deviceAddress);
386386

387387
#if (DEBUG > 0)
388388
Serial.println("MAC: ");
@@ -457,10 +457,22 @@ void setup()
457457
{
458458
reconnect();
459459
}
460+
461+
clearLCD();
462+
IPAddress currentAddress = wifiManager.getAddress();
463+
splashLCD(wifiManager.getMode(), currentAddress);
460464
};
461465
wifiManager.setConnectedCallback(connectedCallback);
462466
#endif
463467

468+
auto apStartedCallback = [&]()
469+
{
470+
clearLCD();
471+
IPAddress currentAddress = wifiManager.getAddress();
472+
splashLCD(wifiManager.getMode(), currentAddress);
473+
};
474+
wifiManager.setApStartedCallback(apStartedCallback);
475+
464476
wifiManager.connect(setupSsid);
465477
WifiOTA::initLittleFS();
466478
server.begin(); // Start server web socket to render pages
@@ -473,7 +485,7 @@ void setup()
473485
digitalWrite(LED_BUILTIN, LOW); // turn the LED off at end of setup
474486

475487
initRotator();
476-
splashLCD();
488+
splashLCD(wifiManager.getMode(), deviceAddress);
477489

478490
setupDFPlayer();
479491
setup_GPAD_menu();

Firmware/GPAD_API/GPAD_API/GPAD_HAL.cpp

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ void muteButtonCallback(byte buttonEvent)
325325
}
326326
}
327327

328-
void GPAD_HAL_setup(Stream *serialport)
328+
void GPAD_HAL_setup(Stream *serialport, wifi_mode_t wifiMode, IPAddress &deviceIp)
329329
{
330330
// Setup and present LCD splash screen
331331
// Setup the SWITCH_MUTE
@@ -344,7 +344,7 @@ void GPAD_HAL_setup(Stream *serialport)
344344
serialport->println(F("Start LCD splash"));
345345
#endif
346346

347-
splashLCD();
347+
splashLCD(wifiMode, deviceIp);
348348

349349
#if (DEBUG > 0)
350350
serialport->println(F("EndLCD splash"));
@@ -581,7 +581,7 @@ void clearLCD(void)
581581
}
582582

583583
// Splash a message so we can tell the LCD is working
584-
void splashLCD(void)
584+
void splashLCD(wifi_mode_t wifiMode, IPAddress &deviceIp)
585585
{
586586
lcd.init(); // initialize the lcd
587587
// Print a message to the LCD.
@@ -602,7 +602,18 @@ void splashLCD(void)
602602

603603
// Line 1
604604
lcd.setCursor(0, 1);
605-
lcd.print("IP: " + WiFi.localIP().toString());
605+
switch (wifiMode)
606+
{
607+
case wifi_mode_t::WIFI_MODE_AP:
608+
lcd.print("AP ");
609+
break;
610+
case wifi_mode_t::WIFI_MODE_STA:
611+
lcd.print("STA ");
612+
break;
613+
}
614+
615+
lcd.print("IP: ");
616+
deviceIp.printTo(lcd);
606617

607618
// Line 2
608619
lcd.setCursor(0, 2);

Firmware/GPAD_API/GPAD_API/GPAD_HAL.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
// #include <Arduino.h>
2525
#include <PubSubClient.h>
2626
#include <LiquidCrystal_I2C.h>
27+
#include <WiFi.h>
2728

2829
// On Nov. 5th, 2024, we image 3 different hardware platforms.
2930
// The GPAD exists, and is working: https://www.hardware-x.com/article/S2468-0672(24)00084-1/fulltext
@@ -185,12 +186,12 @@ void restoreAlarmLevel(Stream *serialport);
185186
void unchanged_anunicateAlarmLevel(Stream *serialport);
186187
void annunciateAlarmLevel(Stream *serialport);
187188
void clearLCD(void);
188-
void splashLCD(void);
189+
void splashLCD(wifi_mode_t wifiMode, IPAddress &deviceIp);
189190

190191
void interpretBuffer(char *buf, int rlen, Stream *serialport, PubSubClient *client);
191192

192193
// This module has to be initialized and called each time through the superloop
193-
void GPAD_HAL_setup(Stream *serialport);
194+
void GPAD_HAL_setup(Stream *serialport, wifi_mode_t wifiMode, IPAddress &deviceIp);
194195
void GPAD_HAL_loop();
195196

196197
extern LiquidCrystal_I2C lcd;

Firmware/GPAD_API/GPAD_API/WiFiManagerOTA.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,19 @@ wifi_mode_t Manager::getMode()
7777
return this->wifi.getMode();
7878
}
7979

80+
IPAddress Manager::getAddress()
81+
{
82+
switch (this->getMode())
83+
{
84+
case wifi_mode_t::WIFI_MODE_AP:
85+
return this->wifi.softAPIP();
86+
case wifi_mode_t::WIFI_MODE_STA:
87+
return this->wifi.localIP();
88+
default:
89+
return INADDR_NONE;
90+
}
91+
}
92+
8093
void Manager::ssidSaved()
8194
{
8295
this->print.print("Network Saved with SSID: ");

Firmware/GPAD_API/GPAD_API/WiFiManagerOTA.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@ namespace WifiOTA
2121
void setConnectedCallback(std::function<void()> callBack);
2222
void setApStartedCallback(std::function<void()> callback);
2323
wifi_mode_t getMode();
24-
// Include a "on wifi mode change" callback
25-
// The callback takes a single parameter, it's the WiFi's current mode
24+
IPAddress getAddress();
2625

2726
private:
2827
WiFiClass &wifi;

0 commit comments

Comments
 (0)