Skip to content

feat: reset_device() wait_for_output option — poll for boot output instead of returning immediately #68

Closed

Description

@zackees

Summary

SerialMonitor.reset_device() currently sends POST /api/reset and returns immediately. Add a wait_for_output option that watches for serial output after reset and returns as soon as the device starts producing data (= rebooted and running).

Current behavior

mon.reset_device(board="esp32s3")  # Returns True immediately after DTR toggle
time.sleep(3.0)  # Caller has to guess how long to wait

Proposed behavior

mon.reset_device(board="esp32s3", wait_for_output=True, timeout=5.0)
# Returns True as soon as any serial output is detected (device rebooted)
# Returns False if timeout expires with no output
# Typical ESP32-S3 USB-CDC: returns in <500ms instead of fixed 3s

Implementation

In crates/fbuild-python/src/lib.rs, after the HTTP reset call succeeds:

  1. If wait_for_output is false (default): return immediately (current behavior)
  2. If wait_for_output is true:
    • Attach a serial monitor to the port
    • Poll read_lines() in a tight loop (100ms intervals)
    • Return true as soon as any line is received
    • Return false if timeout expires

This is generic — no application-specific signatures needed. Any serial output = device booted.

API

#[pyo3(signature = (board=None, wait_for_output=false, timeout=5.0))]
fn reset_device(
    &self,
    board: Option<String>,
    wait_for_output: bool,
    timeout: f64,
) -> PyResult<bool>

Parent issue

FastLED/FastLED#2265 — replace sleep-based reset waits with spin-poll validation

Activity

  1. zackees commented on Apr 17, 2026

    @zackees
    MemberAuthor

    Looks like this is already implemented in the current tree. The SerialMonitor.reset_device method at crates/fbuild-python/src/lib.rs already carries the exact signature and semantics proposed:

    • #[pyo3(signature = (board=None, wait_for_output=false, timeout=5.0))]
    • WebSocket fast path: when __enter__ has been called, polls read_lines_inner(0.2s) in a tight loop (reset_device lines 524–535) and returns true on the first non-empty batch.
    • HTTP fallback: when no WebSocket session exists, polls /api/serial/output?port=...&limit=1 at 100ms intervals (reset_device lines 537–559).
    • Honors timeout as a deadline and returns false if no output arrives in time.
    • 300ms pause for USB re-enumeration after the DTR toggle (line 520), matching the proposed flow.

    Closing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions