diff --git a/Firmware/GPAD_API/GPAD_API/GPAD_API.ino b/Firmware/GPAD_API/GPAD_API/GPAD_API.ino index 5ca68a6..df9160a 100644 --- a/Firmware/GPAD_API/GPAD_API/GPAD_API.ino +++ b/Firmware/GPAD_API/GPAD_API/GPAD_API.ino @@ -356,9 +356,8 @@ void setup() serialSplash(); // We call this a second time to get the MAC on the screen clearLCD(); - splashLCD(); - // Set LED pins as outputs +// Set LED pins as outputs #if defined(LED_D9) pinMode(LED_D9, OUTPUT); #endif @@ -382,7 +381,8 @@ void setup() // Setup and present LCD splash screen // Setup the SWITCH_MUTE // Setup the SWITCH_ENCODER - GPAD_HAL_setup(&Serial); + IPAddress deviceAddress = wifiManager.getAddress(); + GPAD_HAL_setup(&Serial, wifiManager.getMode(), deviceAddress); #if (DEBUG > 0) Serial.println("MAC: "); @@ -457,10 +457,22 @@ void setup() { reconnect(); } + + clearLCD(); + IPAddress currentAddress = wifiManager.getAddress(); + splashLCD(wifiManager.getMode(), currentAddress); }; wifiManager.setConnectedCallback(connectedCallback); #endif + auto apStartedCallback = [&]() + { + clearLCD(); + IPAddress currentAddress = wifiManager.getAddress(); + splashLCD(wifiManager.getMode(), currentAddress); + }; + wifiManager.setApStartedCallback(apStartedCallback); + wifiManager.connect(setupSsid); WifiOTA::initLittleFS(); server.begin(); // Start server web socket to render pages @@ -473,7 +485,7 @@ void setup() digitalWrite(LED_BUILTIN, LOW); // turn the LED off at end of setup initRotator(); - splashLCD(); + splashLCD(wifiManager.getMode(), deviceAddress); setupDFPlayer(); setup_GPAD_menu(); diff --git a/Firmware/GPAD_API/GPAD_API/GPAD_HAL.cpp b/Firmware/GPAD_API/GPAD_API/GPAD_HAL.cpp index c318953..1a8dffe 100644 --- a/Firmware/GPAD_API/GPAD_API/GPAD_HAL.cpp +++ b/Firmware/GPAD_API/GPAD_API/GPAD_HAL.cpp @@ -325,7 +325,7 @@ void muteButtonCallback(byte buttonEvent) } } -void GPAD_HAL_setup(Stream *serialport) +void GPAD_HAL_setup(Stream *serialport, wifi_mode_t wifiMode, IPAddress &deviceIp) { // Setup and present LCD splash screen // Setup the SWITCH_MUTE @@ -344,7 +344,7 @@ void GPAD_HAL_setup(Stream *serialport) serialport->println(F("Start LCD splash")); #endif - splashLCD(); + splashLCD(wifiMode, deviceIp); #if (DEBUG > 0) serialport->println(F("EndLCD splash")); @@ -581,7 +581,7 @@ void clearLCD(void) } // Splash a message so we can tell the LCD is working -void splashLCD(void) +void splashLCD(wifi_mode_t wifiMode, IPAddress &deviceIp) { lcd.init(); // initialize the lcd // Print a message to the LCD. @@ -602,7 +602,18 @@ void splashLCD(void) // Line 1 lcd.setCursor(0, 1); - lcd.print("IP: " + WiFi.localIP().toString()); + switch (wifiMode) + { + case wifi_mode_t::WIFI_MODE_AP: + lcd.print("AP "); + break; + case wifi_mode_t::WIFI_MODE_STA: + lcd.print("STA "); + break; + } + + lcd.print("IP: "); + deviceIp.printTo(lcd); // Line 2 lcd.setCursor(0, 2); @@ -612,6 +623,7 @@ void splashLCD(void) lcd.setCursor(0, 3); lcd.print("MAC: "); lcd.print(macAddressString); + lcd.scrollDisplayRight(); } bool printable(char c) { diff --git a/Firmware/GPAD_API/GPAD_API/GPAD_HAL.h b/Firmware/GPAD_API/GPAD_API/GPAD_HAL.h index aba0f8e..e2e62bb 100644 --- a/Firmware/GPAD_API/GPAD_API/GPAD_HAL.h +++ b/Firmware/GPAD_API/GPAD_API/GPAD_HAL.h @@ -24,6 +24,7 @@ // #include #include #include +#include // On Nov. 5th, 2024, we image 3 different hardware platforms. // 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); void unchanged_anunicateAlarmLevel(Stream *serialport); void annunciateAlarmLevel(Stream *serialport); void clearLCD(void); -void splashLCD(void); +void splashLCD(wifi_mode_t wifiMode, IPAddress &deviceIp); void interpretBuffer(char *buf, int rlen, Stream *serialport, PubSubClient *client); // This module has to be initialized and called each time through the superloop -void GPAD_HAL_setup(Stream *serialport); +void GPAD_HAL_setup(Stream *serialport, wifi_mode_t wifiMode, IPAddress &deviceIp); void GPAD_HAL_loop(); extern LiquidCrystal_I2C lcd; diff --git a/Firmware/GPAD_API/GPAD_API/WiFiManagerOTA.cpp b/Firmware/GPAD_API/GPAD_API/WiFiManagerOTA.cpp index 6b3c52a..f8c99aa 100644 --- a/Firmware/GPAD_API/GPAD_API/WiFiManagerOTA.cpp +++ b/Firmware/GPAD_API/GPAD_API/WiFiManagerOTA.cpp @@ -33,11 +33,23 @@ void Manager::connect(const char *const accessPointSsid) this->wifiManager.setSaveConfigCallback(saveConfigCallback); - auto apStaConnectedCallback = [this](arduino_event_id_t event, arduino_event_info_t info) + auto apStartedCallback = [this](WiFiManager *wifiManager) { + this->apStarted(); + }; + + this->wifiManager.setAPCallback(apStartedCallback); + + auto staGotIpCallback = [this](arduino_event_id_t event, arduino_event_info_t info) + { + if ((this->wifi.localIP() == INADDR_NONE) && (this->getMode() == wifi_mode_t::WIFI_MODE_STA)) + { + return; + } + this->ipSet(); }; - this->wifi.onEvent(apStaConnectedCallback, arduino_event_id_t::ARDUINO_EVENT_WIFI_STA_GOT_IP); + this->wifi.onEvent(staGotIpCallback, arduino_event_id_t::ARDUINO_EVENT_WIFI_STA_GOT_IP); bool connectSuccess = false; if (accessPointSsid == "") @@ -55,6 +67,29 @@ void Manager::setConnectedCallback(std::function callback) this->connectedCallback = callback; } +void Manager::setApStartedCallback(std::function callback) +{ + this->apStartedCallback = callback; +} + +wifi_mode_t Manager::getMode() +{ + return this->wifi.getMode(); +} + +IPAddress Manager::getAddress() +{ + switch (this->getMode()) + { + case wifi_mode_t::WIFI_MODE_AP: + return this->wifi.softAPIP(); + case wifi_mode_t::WIFI_MODE_STA: + return this->wifi.localIP(); + default: + return INADDR_NONE; + } +} + void Manager::ssidSaved() { this->print.print("Network Saved with SSID: "); @@ -78,6 +113,18 @@ void Manager::ipSet() } } +void Manager::apStarted() +{ + this->print.print("AP Has Started: "); + this->wifi.softAPIP().printTo(this->print); + this->print.print("\n"); + + if (this->apStartedCallback) + { + this->apStartedCallback(); + } +} + void WifiOTA::initLittleFS() { if (!LittleFS.begin(true)) diff --git a/Firmware/GPAD_API/GPAD_API/WiFiManagerOTA.h b/Firmware/GPAD_API/GPAD_API/WiFiManagerOTA.h index b2af372..f6e9355 100644 --- a/Firmware/GPAD_API/GPAD_API/WiFiManagerOTA.h +++ b/Firmware/GPAD_API/GPAD_API/WiFiManagerOTA.h @@ -1,11 +1,8 @@ #ifndef WIFI_MANAGER_H #define WIFI_MANAGER_H -// #include #include #include -#include -#include extern const char *DEFAULT_SSID; extern String ledState; @@ -22,15 +19,20 @@ namespace WifiOTA void initialize(); void connect(const char *const accessPointSsid); void setConnectedCallback(std::function callBack); + void setApStartedCallback(std::function callback); + wifi_mode_t getMode(); + IPAddress getAddress(); private: WiFiClass &wifi; Print &print; WiFiManager wifiManager; std::function connectedCallback; + std::function apStartedCallback; void ssidSaved(); void ipSet(); + void apStarted(); }; void initLittleFS();