Fix Companion pairing PIN display and truthful identity startup

This commit is contained in:
mikecarper committed 2026-10-02 12:42:26 -07:00
1 parent a2854f8f43
commit 202930de8f
31 files changed
+1915 -148

No files matched your search

+40 -22
View File
@@ -1,6 +1,8 @@
#include <Arduino.h> // needed for PlatformIO
#include <Mesh.h>
#include <helpers/IdentityGeneration.h>
#include <helpers/ui/StartupScreen.h>
#include <helpers/ui/DisplayPowerSettings.h>
#if MESH_PACKET_LOGGING
#include <helpers/SerialPacketLog.h>
#endif
@@ -57,34 +59,12 @@ void setup() {
#if MESH_PACKET_LOGGING
mesh::serialLogBegin();
#endif
delay(1000);
board.begin();
#ifdef HAS_EXTERNAL_WATCHDOG
external_watchdog.begin();
#endif
#ifdef DISPLAY_CLASS
display_ready = display.begin();
if (display_ready) {
display.turnOff(); // Stay dark until the saved display policy is loaded.
}
#endif
int radioinit_attempts = 0;
while (!radio_init()) {
++radioinit_attempts;
MESH_DEBUG_PRINTLN("Radio init failed! (attempt %d)", radioinit_attempts);
if (radioinit_attempts >= 3) {
MESH_DEBUG_PRINTLN("Radio init failed 3x - rebooting");
board.reboot();
}
delay(500);
}
fast_rng.begin(radio_driver.getRngSeed());
FILESYSTEM* fs;
#if defined(NRF52_PLATFORM)
bool volatile_primary_fs = false;
@@ -116,6 +96,32 @@ void setup() {
#else
#error "need to define filesystem"
#endif
#ifdef DISPLAY_CLASS
mesh::ui::loadDisplayPowerSettings(fs, false);
mesh::ui::StartupScreen startup_screen;
display_ready = display.begin();
if (display_ready) {
startup_screen.begin(&display,
board.isExternalPowered() || board.isUsbHostConnected());
}
#endif
// Let serial settle after the display is already showing startup.
delay(1000);
int radioinit_attempts = 0;
while (!radio_init()) {
++radioinit_attempts;
MESH_DEBUG_PRINTLN("Radio init failed! (attempt %d)", radioinit_attempts);
if (radioinit_attempts >= 3) {
MESH_DEBUG_PRINTLN("Radio init failed 3x - rebooting");
board.reboot();
}
delay(500);
}
fast_rng.begin(radio_driver.getRngSeed());
#if defined(NRF52_PLATFORM)
IdentityLoadResult identity_load = volatile_primary_fs
? store.loadResult("_main", the_mesh.self_id)
@@ -140,8 +146,20 @@ void setup() {
&& mesh::hasReservedIdentityPrefix(the_mesh.self_id));
bool identity_ready = identity_load != IdentityLoadResult::Unreadable;
if (needs_identity) {
#ifdef DISPLAY_CLASS
startup_screen.generatingKey();
mesh::ScopedIdentityGenerationProgress progress(
mesh::ui::StartupScreen::progress, &startup_screen);
#endif
identity_ready = mesh::generateUsableLocalIdentity(the_mesh.self_id, radio_new_identity);
#ifdef DISPLAY_CLASS
if (identity_ready) startup_screen.savingIdentity();
else startup_screen.starting();
#endif
if (identity_ready) identity_ready = store.saveWithRetry("_main", the_mesh.self_id);
#ifdef DISPLAY_CLASS
startup_screen.starting();
#endif
}
#if defined(ESP32_PLATFORM)