Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions Firmware/GPAD_API/GPAD_API/GPAD_API.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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: ");
Expand Down Expand Up @@ -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
Expand All @@ -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();
Expand Down
19 changes: 15 additions & 4 deletions Firmware/GPAD_API/GPAD_API/GPAD_HAL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"));
Expand Down Expand Up @@ -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.
Expand All @@ -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);
Expand Down
5 changes: 3 additions & 2 deletions Firmware/GPAD_API/GPAD_API/GPAD_HAL.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
// #include <Arduino.h>
#include <PubSubClient.h>
#include <LiquidCrystal_I2C.h>
#include <WiFi.h>

// 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
Expand Down Expand Up @@ -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;
Expand Down
51 changes: 49 additions & 2 deletions Firmware/GPAD_API/GPAD_API/WiFiManagerOTA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 == "")
Expand All @@ -55,6 +67,29 @@ void Manager::setConnectedCallback(std::function<void()> callback)
this->connectedCallback = callback;
}

void Manager::setApStartedCallback(std::function<void()> 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: ");
Expand All @@ -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))
Expand Down
8 changes: 5 additions & 3 deletions Firmware/GPAD_API/GPAD_API/WiFiManagerOTA.h
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
#ifndef WIFI_MANAGER_H
#define WIFI_MANAGER_H

// #include <Arduino.h>
#include <WiFi.h>
#include <WiFiManager.h>
#include <FS.h>
#include <LittleFS.h>

extern const char *DEFAULT_SSID;
extern String ledState;
Expand All @@ -22,15 +19,20 @@ namespace WifiOTA
void initialize();
void connect(const char *const accessPointSsid);
void setConnectedCallback(std::function<void()> callBack);
void setApStartedCallback(std::function<void()> callback);
wifi_mode_t getMode();
IPAddress getAddress();

private:
WiFiClass &wifi;
Print &print;
WiFiManager wifiManager;
std::function<void()> connectedCallback;
std::function<void()> apStartedCallback;

void ssidSaved();
void ipSet();
void apStarted();
};

void initLittleFS();
Expand Down