Skip to content

Commit 3f6f2aa

Browse files
committed
fix(cli): don't report a false join failure after configure-wifi
After REBOOT_TO_RUN the pre-reboot setup-mode COM port lingers in the OS for a second or two before the board re-enumerates as the XInput controller. The join-watch loop read that stale port as the Pico bouncing back to setup and printed 'came back in setup-mode USB before joining Wi-Fi' even when the board went on to join normally. Flag a setup port as a real bounce only after it has first disappeared.
1 parent 900d862 commit 3f6f2aa

1 file changed

Lines changed: 21 additions & 7 deletions

File tree

bridge/src/cmd_configure_wifi.rs

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,13 @@ async fn print_discovered_pico_ips(before: BTreeSet<u32>) -> Result<()> {
149149
let started = Instant::now();
150150
let deadline = started + Duration::from_secs(60);
151151
let mut next_beat = started + Duration::from_secs(10);
152+
// The setup-mode COM port we just rebooted lingers in the OS for a
153+
// second or two after REBOOT_TO_RUN, before the board re-enumerates as
154+
// the XInput controller. Only treat a setup port as a genuine bounce
155+
// back to setup once it has first disappeared -- otherwise the stale
156+
// pre-reboot port reads as an instant "didn't join" even when the board
157+
// went on to join Wi-Fi normally.
158+
let mut setup_port_gone = false;
152159
loop {
153160
let picos = cmd_run::discover_picos(Duration::from_secs(2)).await?;
154161
let current: BTreeSet<u32> = picos.iter().map(|pico| pico.info.unique_id_short).collect();
@@ -157,13 +164,20 @@ async fn print_discovered_pico_ips(before: BTreeSet<u32>) -> Result<()> {
157164
return Ok(());
158165
}
159166

160-
if let Ok(port) = cdc::find_setup_port() {
161-
println!();
162-
println!("The Pico came back in setup-mode USB before joining Wi-Fi.");
163-
println!("That usually means the SSID was not found, the password was rejected, or DHCP never completed.");
164-
print_setup_mode_diag(&port).await;
165-
println!("Fix the Wi-Fi details, then run `couchlink configure-wifi` again.");
166-
return Ok(());
167+
match cdc::find_setup_port() {
168+
// No setup port right now: the reboot took effect. A setup port
169+
// that appears *after* this point is a real bounce-back.
170+
Err(_) => setup_port_gone = true,
171+
Ok(port) if setup_port_gone => {
172+
println!();
173+
println!("The Pico came back in setup-mode USB before joining Wi-Fi.");
174+
println!("That usually means the SSID was not found, the password was rejected, or DHCP never completed.");
175+
print_setup_mode_diag(&port).await;
176+
println!("Fix the Wi-Fi details, then run `couchlink configure-wifi` again.");
177+
return Ok(());
178+
}
179+
// Pre-reboot setup port still lingering; ignore and keep waiting.
180+
Ok(_) => {}
167181
}
168182

169183
let now = Instant::now();

0 commit comments

Comments
 (0)