Add Indicator WiFi setup as eighth home page

This commit is contained in:
mikecarper committed 2026-08-31 17:31:48 -07:00
1 parent a38e0370f9
commit 42888e6e3a
20 files changed
+1660 -1311

No files matched your search

+9
View File
@@ -2,6 +2,15 @@
#include <stdint.h>
#ifndef UI_WIFI_SETUP_HOME_PAGE
#define UI_WIFI_SETUP_HOME_PAGE 0
#endif
#if UI_WIFI_SETUP_HOME_PAGE == 1 \
&& !(defined(ESP32) && defined(WIFI_SSID))
#error "UI_WIFI_SETUP_HOME_PAGE requires ESP32 infrastructure WiFi"
#endif
#if defined(COMPANION_EXCLUSIVE_WIFI_BLE) \
&& !(defined(ESP32) && defined(WIFI_SSID) && defined(BLE_PIN_CODE))
#error "COMPANION_EXCLUSIVE_WIFI_BLE requires ESP32, WIFI_SSID, and BLE_PIN_CODE"
+9 -102
View File
@@ -1173,7 +1173,8 @@ void halt() {
#endif
}
#if defined(WITH_WEBCONFIG) && defined(DISPLAY_CLASS)
#if defined(WITH_WEBCONFIG) && defined(DISPLAY_CLASS) \
&& UI_WIFI_SETUP_HOME_PAGE != 1
static DisplayDriver* companion_setup_display = nullptr;
static unsigned long companion_setup_display_refresh = 0;
@@ -1182,91 +1183,6 @@ void halt() {
&& companion_setup_display->height() >= 128;
}
static bool hasIndicatorSetupTypography() {
#if defined(INDICATOR_TRANSPORT_RENDER_PROFILE)
// This flag is emitted only for the two SenseCAP Indicator Full builds.
// Runtime canvas dimensions may differ after allocation fallback (and
// across historical UI macro ordering), but the physical panel remains
// 480x480. Never send this board through the generic size-1 setup page.
return true;
#else
return false;
#endif
}
static int drawIndicatorSetupValue(int y, const char* value) {
companion_setup_display->setTextSize(2);
// The setup AP has a stable prefix. Split on its semantic boundary so
// the two large centered rows read cleanly instead of wrapping midway
// through "Setup".
if (value != nullptr
&& strncmp(value, "MeshCore-Setup-", 15) == 0) {
companion_setup_display->drawTextCentered(
companion_setup_display->width() / 2, y, "MeshCore-");
companion_setup_display->drawTextCentered(
companion_setup_display->width() / 2, y + 17, value + 9);
return 2;
}
const int max_width = companion_setup_display->width() - 12;
int line_height = 17;
// A configured SSID can contain 32 bytes. Keep ordinary names at the
// large size, but let the longest legal value use two complete size-1
// rows instead of silently losing its tail.
if (value != nullptr
&& companion_setup_display->getTextWidth(value) > max_width * 2) {
companion_setup_display->setTextSize(1);
line_height = 9;
}
return mesh::ui::drawTextWrapped(
*companion_setup_display, 6, y,
max_width, line_height, 2,
value != nullptr && value[0] != 0 ? value : "(not set)");
}
static void drawIndicatorSetupAddress(int y, const char* address) {
const char* value = address != nullptr && address[0] != 0
? address : "(not set)";
companion_setup_display->setTextSize(2);
if (companion_setup_display->getTextWidth(value)
> companion_setup_display->width()) {
companion_setup_display->setTextSize(1);
}
companion_setup_display->drawTextCentered(
companion_setup_display->width() / 2, y, value);
}
static void renderIndicatorSetupDisplay(const char* title,
const char* wifi_name,
const char* address,
bool connecting) {
// Keep the requested sizes physically identical on a native canvas and
// the 320-to-480 emergency canvas. This page is sparse enough to use
// genuinely large type instead of relying on the global 480 boost.
companion_setup_display->setCompactText(true);
companion_setup_display->setTextSize(4);
companion_setup_display->drawTextCentered(
companion_setup_display->width() / 2, 0, title);
companion_setup_display->setTextSize(4);
companion_setup_display->drawTextCentered(
companion_setup_display->width() / 2, 35, "JOIN");
drawIndicatorSetupValue(70, wifi_name);
if (connecting) {
companion_setup_display->setTextSize(4);
companion_setup_display->drawTextCentered(
companion_setup_display->width() / 2, 108, "WAIT");
return;
}
companion_setup_display->setTextSize(4);
companion_setup_display->drawTextCentered(
companion_setup_display->width() / 2, 105, "OPEN");
// The scheme is implicit here so the address itself can remain nearly
// panel-wide at size 2. Long DHCP addresses fall back to size 1.
drawIndicatorSetupAddress(140, address);
}
static int drawCompanionSetupValue(int y, int max_lines,
const char* value) {
static constexpr int margin = 6;
@@ -1318,10 +1234,7 @@ void halt() {
char setup_ip[16] = {0};
if (WebConfigServer::getSetupInfo(setup_ssid, sizeof(setup_ssid),
setup_ip, sizeof(setup_ip))) {
if (hasIndicatorSetupTypography()) {
renderIndicatorSetupDisplay(
"SETUP", setup_ssid, setup_ip, false);
} else if (hasLargeCompanionSetupDisplay()) {
if (hasLargeCompanionSetupDisplay()) {
renderLargeCompanionSetupDisplay(
"WebUI setup", "Join open WiFi:", setup_ssid, setup_ip, false);
} else {
@@ -1338,10 +1251,7 @@ void halt() {
}
} else if (WiFi.status() == WL_CONNECTED) {
const String ip = WiFi.localIP().toString();
if (hasIndicatorSetupTypography()) {
renderIndicatorSetupDisplay(
"READY", configured_wifi_ssid, ip.c_str(), false);
} else if (hasLargeCompanionSetupDisplay()) {
if (hasLargeCompanionSetupDisplay()) {
renderLargeCompanionSetupDisplay(
"WebUI ready", "Join WiFi:", configured_wifi_ssid, ip.c_str(),
false);
@@ -1358,10 +1268,7 @@ void halt() {
companion_setup_display->width() / 2, 51, ip.c_str());
}
} else {
if (hasIndicatorSetupTypography()) {
renderIndicatorSetupDisplay(
"WIFI", configured_wifi_ssid, nullptr, true);
} else if (hasLargeCompanionSetupDisplay()) {
if (hasLargeCompanionSetupDisplay()) {
renderLargeCompanionSetupDisplay(
"WiFi connecting", "WiFi name:", configured_wifi_ssid, nullptr,
true);
@@ -1376,8 +1283,6 @@ void halt() {
companion_setup_display->width() / 2, 52, "Please wait...");
}
}
// Do not leak the setup page's fixed physical text scale into the normal
// UI after WebConfig exits.
companion_setup_display->setCompactText(false);
companion_setup_display->endFrame();
}
@@ -1779,7 +1684,8 @@ void setup() {
DisplayDriver* disp = NULL;
if (display.begin()) {
disp = &display;
#if defined(ESP32) && defined(WIFI_SSID) && defined(WITH_WEBCONFIG)
#if defined(ESP32) && defined(WIFI_SSID) && defined(WITH_WEBCONFIG) \
&& UI_WIFI_SETUP_HOME_PAGE != 1
companion_setup_display = disp;
#endif
disp->startFrame();
@@ -2133,7 +2039,8 @@ void loop() {
// main/UI task.
display.serviceFontRecovery();
#endif
#if defined(ESP32) && defined(WIFI_SSID) && defined(WITH_WEBCONFIG)
#if defined(ESP32) && defined(WIFI_SSID) && defined(WITH_WEBCONFIG) \
&& UI_WIFI_SETUP_HOME_PAGE != 1
if (isCompanionWiFiEnabled() && (the_mesh.isWebConfigSetupActive()
#ifdef WITH_MQTT_BRIDGE
|| !the_mesh.isMQTTConfigured()
+103 -2
View File
@@ -11,6 +11,10 @@
#ifdef WIFI_SSID
#include <WiFi.h>
#endif
#if UI_WIFI_SETUP_HOME_PAGE == 1
#include <helpers/esp32/WebConfigServer.h>
#include <helpers/ui/WiFiSetupQrPayload.h>
#endif
#if defined(ESP32)
#include <esp_timer.h>
#endif
@@ -113,6 +117,70 @@ static void drawCompanionTransportChoice(DisplayDriver& display,
}
#endif
#if UI_WIFI_SETUP_HOME_PAGE == 1
static void drawCompanionWiFiSetupPage(DisplayDriver& display) {
char setup_ssid[33] = {0};
char setup_ip[16] = {0};
const bool setup_active = WebConfigServer::getSetupInfo(
setup_ssid, sizeof(setup_ssid), setup_ip, sizeof(setup_ip));
// Keep the setup content below the shared title bar and page dots. Compact
// text makes its physical size identical on the 480 canvas and the
// 320-to-480 emergency canvas.
display.setCompactText(true);
display.setColor(UIColor::primary_txt);
if (setup_active) {
display.setTextSize(2);
display.drawTextCentered(display.width() / 2, 20, "WIFI SETUP");
display.drawTextCentered(display.width() / 2, 37, setup_ssid);
char payload[256];
const char* setup_password = nullptr;
#ifdef WEBCONFIG_AP_PASSWORD
setup_password = WEBCONFIG_AP_PASSWORD;
#endif
if (mesh::ui::buildWiFiSetupQrPayload(
payload, sizeof(payload), setup_ssid, setup_password)) {
static constexpr int qr_size = 105;
const int qr_x = (display.width() - qr_size) / 2;
if (display.drawQrCode(payload, qr_x, 55, qr_size)) {
display.setCompactText(false);
return;
}
}
display.setColor(UIColor::warning_txt);
display.setTextSize(2);
display.drawTextCentered(display.width() / 2, 70, "QR UNAVAILABLE");
display.setColor(UIColor::secondary_txt);
display.drawTextCentered(display.width() / 2, 100, setup_ip);
} else if (!isCompanionWiFiEnabled()) {
display.setTextSize(3);
display.drawTextCentered(display.width() / 2, 45, "WIFI OFF");
display.setTextSize(2);
display.setColor(UIColor::secondary_txt);
display.drawTextCentered(display.width() / 2, 90, "SELECT WIFI");
display.drawTextCentered(display.width() / 2, 112, "THEN REBOOT");
} else if (WiFi.status() == WL_CONNECTED) {
display.setTextSize(2);
display.drawTextCentered(display.width() / 2, 25, "WIFI READY");
const String ssid = WiFi.SSID();
display.drawTextEllipsized(4, 60, display.width() - 8, ssid.c_str());
const String ip = WiFi.localIP().toString();
display.drawTextCentered(display.width() / 2, 95, ip.c_str());
} else {
display.setTextSize(3);
display.drawTextCentered(display.width() / 2, 45, "WIFI");
display.setTextSize(2);
display.setColor(UIColor::secondary_txt);
display.drawTextCentered(display.width() / 2, 90, "CONNECTING");
}
display.setCompactText(false);
}
#endif
#include "icons.h"
class SplashScreen : public UIScreen {
@@ -190,6 +258,9 @@ class HomeScreen : public UIScreen {
#endif
#ifndef UI_NO_HIBERNATE
SHUTDOWN,
#endif
#if UI_WIFI_SETUP_HOME_PAGE == 1
WIFI_SETUP,
#endif
Count // keep as last
};
@@ -200,6 +271,9 @@ class HomeScreen : public UIScreen {
CompanionNodePrefs* _node_prefs;
uint8_t _page;
bool _shutdown_init;
#if UI_WIFI_SETUP_HOME_PAGE == 1
bool _wifi_setup_was_active;
#endif
uint32_t _uptime_last_millis;
uint64_t _uptime_millis;
AdvertPath recent[UI_RECENT_LIST_SIZE];
@@ -329,8 +403,17 @@ class HomeScreen : public UIScreen {
public:
HomeScreen(UITask* task, mesh::RTCClock* rtc, SensorManager* sensors, CompanionNodePrefs* node_prefs)
: _task(task), _rtc(rtc), _sensors(sensors), _node_prefs(node_prefs), _page(0),
_shutdown_init(false), _uptime_last_millis(millis()), _uptime_millis(0),
sensors_lpp(200) { }
_shutdown_init(false),
#if UI_WIFI_SETUP_HOME_PAGE == 1
_wifi_setup_was_active(false),
#endif
_uptime_last_millis(millis()), _uptime_millis(0), sensors_lpp(200) {
#if UI_WIFI_SETUP_HOME_PAGE == 1
_wifi_setup_was_active = WebConfigServer::getSetupInfo(
nullptr, 0, nullptr, 0);
if (_wifi_setup_was_active) _page = HomePage::WIFI_SETUP;
#endif
}
void showFirstPage() { _page = HomePage::FIRST; }
@@ -343,6 +426,17 @@ public:
}
void poll() override {
#if UI_WIFI_SETUP_HOME_PAGE == 1
const bool wifi_setup_active = WebConfigServer::getSetupInfo(
nullptr, 0, nullptr, 0);
if (wifi_setup_active && !_wifi_setup_was_active) {
// Focus a newly opened setup portal once. Keeping this edge-triggered
// lets the user swipe away while setup and LoRa continue running.
_page = HomePage::WIFI_SETUP;
_task->gotoHomeScreen();
}
_wifi_setup_was_active = wifi_setup_active;
#endif
if (_shutdown_init && !_task->isButtonPressed()) { // must wait for USR button to be released
_task->shutdown();
}
@@ -817,6 +911,10 @@ public:
if (sensors_scroll) sensors_scroll_offset = (sensors_scroll_offset+1)%sensors_nb;
else sensors_scroll_offset = 0;
#endif
#if UI_WIFI_SETUP_HOME_PAGE == 1
} else if (_page == HomePage::WIFI_SETUP) {
drawCompanionWiFiSetupPage(display);
#endif
#ifndef UI_NO_HIBERNATE
} else if (_page == HomePage::SHUTDOWN) {
display.setColor(UIColor::corp_blue);
@@ -834,6 +932,9 @@ public:
if (_page == HomePage::RADIO) return UI_RADIO_REFRESH_MILLIS;
#if UI_MESSAGES_HOME_PAGE == 1
if (_page == HomePage::MESSAGES) return 1000;
#endif
#if UI_WIFI_SETUP_HOME_PAGE == 1
if (_page == HomePage::WIFI_SETUP) return 1000;
#endif
return 5000;
}