Skip to content

Auto connect esp device to ESP-Decoder Terminal#25

Closed
Jason2866 wants to merge 7 commits into
mainfrom
auto_connect
Closed

Auto connect esp device to ESP-Decoder Terminal#25
Jason2866 wants to merge 7 commits into
mainfrom
auto_connect

Conversation

@Jason2866
Copy link
Copy Markdown
Owner

@Jason2866 Jason2866 commented Apr 9, 2026

Summary by CodeRabbit

  • New Features

    • Automatic ESP device detection and connection with a new configurable setting (ask/on/off) to control auto-connect behavior
    • Continuous USB port monitoring to detect when ESP devices are plugged in or removed
    • Prompting flow that can persist your choice for newly detected devices
  • Bug Fixes

    • Improved messages for serial port connection errors

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 9, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: f8144b2e-672f-423f-95b1-1dc8cd8420cf

📥 Commits

Reviewing files that changed from the base of the PR and between ce16aba and 4a94cb1.

📒 Files selected for processing (4)
  • package.json
  • src/extension.ts
  • src/serialPortManager.ts
  • src/webviewPanel.ts

📝 Walkthrough

Walkthrough

Adds a new esp-decoder.autoConnect configuration and implements USB-serial polling to detect ESP-like devices, optionally prompt or auto-connect on plug-in/startup, introduces port-setting helper and refined port-listing/connect error handling, and exposes webview state sync for external callers.

Changes

Cohort / File(s) Summary
Configuration
package.json
Added esp-decoder.autoConnect configuration property (type: string, default: "ask", enum: ask | on | off) with descriptions and enumDescriptions.
USB Polling & Auto-Connect
src/extension.ts
Added USB polling loop (2s), ESP vendor/manufacturer detection, startup scan, prompt-on-first-detection for ask, persisting user choice, auto-connect flow (set port, sync webview, connect), upload guard (isUploading), retry/reacquire handling, polling failure limit, and subscription cleanup.
Serial Port Management
src/serialPortManager.ts
Added listPortsSilent() (no UI handling) and setPort(portPath: string): void; refactored listPorts() to delegate to silent helper; improved connect() error messaging to surface “busy/locked/access denied” cases while preserving failure behavior.
Webview Synchronization
src/webviewPanel.ts
Changed EspDecoderWebviewPanel.syncState() visibility from private to public so external code (polling/activation) can push state updates to the webview.

Sequence Diagram

sequenceDiagram
    participant Ext as Extension (Polling)
    participant USB as USB Enumerator
    participant SPM as SerialPortManager
    participant WV as Webview Panel
    participant User as User

    Ext->>USB: listPorts() (startup)
    USB-->>Ext: ports[]
    Ext->>Ext: identify ESP-like ports
    alt autoConnect = "on" and ESP present
        Ext->>SPM: setPort(path)
        Ext->>SPM: connect()
        SPM-->>Ext: connect result
        Ext->>WV: syncState()
        Ext->>User: show success message
    end

    Note over Ext: Poll every 2s
    Ext->>USB: listPorts()
    USB-->>Ext: ports[]
    Ext->>Ext: diff knownPorts -> newPorts
    alt New ESP detected
        alt autoConnect = "ask"
            Ext->>User: prompt to connect
            User-->>Ext: choice (yes/no)
            Ext->>Ext: persist autoConnect = on/off (if chosen)
            alt yes
                Ext->>SPM: setPort(path)
                Ext->>SPM: connect()
                SPM-->>Ext: connect result
                Ext->>WV: syncState()
                Ext->>User: show success message
            end
        else autoConnect = "on"
            Ext->>SPM: setPort(path)
            Ext->>SPM: connect()
            SPM-->>Ext: connect result
            Ext->>WV: syncState()
            Ext->>User: show success message
        else autoConnect = "off"
            Note right of Ext: No action
        end
    end
Loading

Estimated Code Review Effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

  • Auto port switch #22 — Overlaps changes to serial-port handling and upload/port suspension logic in src/extension.ts and src/serialPortManager.ts.
  • make Terminal / Crash window moveable #12 — Related to webview integration and EspDecoderWebviewPanel refactor that may interact with making syncState() public.

Poem

🐰 I sniff the plugs and twitch my nose,

New ports arrive where circuitry grows.
Ask, on, or off — I hop to decide,
A tiny rabbit, connecting with pride.
Hooray — let devices join the code parade!

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 42.86% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly describes the main feature added: automatic connection of ESP devices to the ESP-Decoder Terminal, which aligns with the substantial changes across multiple files implementing USB polling, device detection, and auto-connect logic.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch auto_connect

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/extension.ts`:
- Around line 553-565: When auto-connecting, the code calls
serial.setPort(espPort.path) then awaits serial.connect() but only calls
viewProvider.syncState() on success, leaving the webview showing the old port
after a failed open; update the logic in the block around
serial.setPort/serial.connect (and the analogous block that also uses
setPort/connect later) to always call viewProvider.syncState() after setPort
regardless of connect() result (or call it in both success and failure
branches), so the webview reflects the newly selected port even if auto-connect
fails.
- Around line 507-528: The current isEspDevice() returns true for generic bridge
chips causing unintended auto-connections; change the logic so high-confidence
detection (used for autoConnect = "on") only returns true for Espressif-specific
matches (ESP_VENDOR_IDS membership or manufacturer includes 'espressif'), and
move CP210x/CH340/FTDI/WCH checks into a separate lower-confidence predicate
(e.g., isBridgeChip()) that callers can use only when autoConnect = "ask";
update callers that currently call isEspDevice() during the auto-connect flow to
use the stricter Espressif-only check for automatic connect and use
isBridgeChip() only for prompting/ask flows.
- Around line 579-584: The background poller should call a non-UI, log-only scan
instead of SerialPortManager.listPorts() which currently triggers
showErrorMessage(); modify the poller loop that currently invokes
serial.listPorts().then(...) to either call a new silent API (e.g.,
SerialPortManager.listPortsSilent()) or wrap serial.listPorts() in a try/catch
that only logs errors (using log.error) without calling showErrorMessage, and
implement simple throttling by counting consecutive failures and disabling the
poller (or backing off) after N failures; update references in the startup scan
and the poller code paths that call tryAutoConnectToExisting and update
knownPorts accordingly so the silent path mirrors the successful-port handling
but never surfaces repeated errors to the user.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: f6d30e40-9ed9-4648-9507-0c026ae01d1d

📥 Commits

Reviewing files that changed from the base of the PR and between ce16aba and fa97246.

📒 Files selected for processing (4)
  • package.json
  • src/extension.ts
  • src/serialPortManager.ts
  • src/webviewPanel.ts

Comment thread src/extension.ts
Comment thread src/extension.ts
Comment thread src/extension.ts Outdated
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/extension.ts`:
- Around line 589-655: The USB poller (usbPollingTimer) must be paused while a
platform upload is in progress to avoid auto-reconnecting after onWillUpload()
releases the monitor port; add a shared flag (e.g., isUploading) that
onWillUpload() sets true and the corresponding onDidUpload()/onDidFailUpload()
handlers set false, then early-return from the usbPollingTimer handler when
isUploading is true (and also have reacquireWithRetry() respect this flag before
attempting to re-open the port). Update references to serial.isConnected and
serial.setPort usage inside the poller to only run when not isUploading and
ensure viewProvider.syncState() behavior is unchanged.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 88839dcd-1b5a-462d-b2f4-3df91f04eac8

📥 Commits

Reviewing files that changed from the base of the PR and between fa97246 and 35573c9.

📒 Files selected for processing (1)
  • src/extension.ts

Comment thread src/extension.ts
@Jason2866
Copy link
Copy Markdown
Owner Author

@coderabbitai full review

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 9, 2026

✅ Actions performed

Full review triggered.

@Jason2866 Jason2866 closed this May 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant