Skip to content

Feature/usb#252

Merged
zjs81 merged 56 commits into
zjs81:mainfrom
just-stuff-tm:feature/usb
Mar 7, 2026
Merged

Feature/usb#252
zjs81 merged 56 commits into
zjs81:mainfrom
just-stuff-tm:feature/usb

Conversation

@just-stuff-tm

@just-stuff-tm just-stuff-tm commented Mar 2, 2026

Copy link
Copy Markdown
Contributor

This pull request introduces support for USB serial transport alongside existing Bluetooth connectivity in the MeshCore connector. It refactors connection logic to accommodate multiple transport types, adds robust error handling especially for web platforms, and updates dependencies and Android configuration to enable USB features. The changes ensure the connector can list and connect to USB ports, manage transport state, and handle device communication via USB or Bluetooth seamlessly.

Transport Abstraction and USB Support

  • Added MeshCoreTransportType enum and refactored connection logic to support both Bluetooth and USB transports, including new properties and methods for transport state management (activeTransport, activeUsbPort, listUsbPorts, connectUsb, etc.) in MeshCoreConnector. [1] [2] [3] [4] [5]
  • Implemented USB transport connection and data handling via integration with UsbSerialService, including frame subscription and error handling. [1] [2] [3]

Platform-Specific Improvements and Error Handling

  • Enhanced error handling for Bluetooth operations (scanning, connecting, service discovery, notifications), with special consideration for web platform quirks and retries. [1] [2] [3] [4] [5] [6]
  • Added platform checks (via PlatformInfo) to gate certain operations and ensure proper behavior on web vs. native environments. [1] [2] [3] [4]

State Management Enhancements

  • Updated connection and handshake state management to handle transport switching, connection resets, and initial sync gating for both USB and Bluetooth. [1] [2] [3] [4]

Android Build and Dependency Updates

  • Added USB serial library dependency and enabled USB host feature in Android manifest; updated NDK version and repository sources for build compatibility. [1] [2] [3] [4]

Codebase Integration

  • Imported new services (usb_serial_service.dart, platform_info.dart) required for USB support and platform detection. [1] [2]

Platform status:

  • Android
  • Windows
  • Web Chrome
  • Linux
  • macOS

Feature Request #193

Copilot AI review requested due to automatic review settings March 2, 2026 06:02

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Adds USB serial transport support to the MeshCore Flutter app/connector, complementing the existing Bluetooth transport. This includes a new USB connection UI flow, platform-specific USB serial implementations (native + Web Serial), and Android USB-host bridging code.

Changes:

  • Introduce USB serial service + framing codec and integrate it into MeshCoreConnector with transport-aware send/connect/disconnect flows.
  • Add new UI entry point to choose USB vs Bluetooth and a dedicated USB port selection/connect screen.
  • Update platform build plumbing (Flutter desktop plugins, Android Gradle/Manifest) and add unit tests + localized strings for the new screens.

Reviewed changes

Copilot reviewed 51 out of 51 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
windows/flutter/generated_plugins.cmake Registers flserial as an FFI plugin for Windows builds.
windows/CMakeLists.txt Guards native-asset install step to avoid failing when assets dir is absent.
linux/flutter/generated_plugins.cmake Registers flserial as an FFI plugin for Linux builds.
pubspec.yaml Adds flserial dependency for native serial transport.
lib/utils/usb_port_labels.dart Adds utilities for normalizing/friendly USB port labels across platforms.
lib/services/usb_serial_frame_codec.dart Defines USB serial frame wrapper and a streaming frame decoder.
lib/services/usb_serial_service.dart Provides conditional export for native vs web USB serial implementations.
lib/services/usb_serial_service_native.dart Implements USB serial transport using flserial + Android USB-host bridge channels.
lib/services/usb_serial_service_web.dart Implements USB serial transport using the browser Web Serial API via JS interop.
lib/connector/meshcore_connector.dart Refactors connector to support both Bluetooth and USB transport, including USB connect and write paths.
lib/screens/connection_choice_screen.dart Adds new home screen letting users choose USB vs Bluetooth connection.
lib/screens/usb_screen.dart Adds USB port listing/selection UI and triggers USB connect flow.
lib/screens/scanner_screen.dart Refactors connector reference + adds conditional back button handling.
lib/main.dart Switches app home from ScannerScreen to ConnectionChoiceScreen.
test/utils/usb_port_labels_test.dart Unit tests for USB port label normalization/description helpers.
test/services/usb_serial_frame_codec_test.dart Unit tests for USB serial frame wrapping/decoding behavior.
android/build.gradle.kts Adds JitPack repository for Android USB serial dependency resolution.
android/app/build.gradle.kts Pins NDK version and adds usb-serial-for-android dependency.
android/app/src/main/AndroidManifest.xml Declares optional USB host feature support.
android/app/src/main/kotlin/com/meshcore/meshcore_open/MainActivity.kt Implements Android USB-host serial bridge (port listing, permissions, connect/read/write).
lib/l10n/app_en.arb Adds new strings for connection choice + USB screen.
lib/l10n/app_bg.arb Adds localized strings for connection choice + USB screen.
lib/l10n/app_de.arb Adds localized strings for connection choice + USB screen.
lib/l10n/app_es.arb Adds localized strings for connection choice + USB screen.
lib/l10n/app_fr.arb Adds localized strings for connection choice + USB screen.
lib/l10n/app_it.arb Adds localized strings for connection choice + USB screen.
lib/l10n/app_nl.arb Adds localized strings for connection choice + USB screen.
lib/l10n/app_pl.arb Adds localized strings for connection choice + USB screen.
lib/l10n/app_pt.arb Adds localized strings for connection choice + USB screen.
lib/l10n/app_ru.arb Adds localized strings for connection choice + USB screen.
lib/l10n/app_sk.arb Adds localized strings for connection choice + USB screen.
lib/l10n/app_sl.arb Adds localized strings for connection choice + USB screen.
lib/l10n/app_sv.arb Adds localized strings for connection choice + USB screen.
lib/l10n/app_uk.arb Adds localized strings for connection choice + USB screen.
lib/l10n/app_zh.arb Adds localized strings for connection choice + USB screen.
lib/l10n/app_localizations.dart Adds new localization getters for the connection choice + USB screen strings.
lib/l10n/app_localizations_bg.dart Generated localization updates for new strings (Bulgarian).
lib/l10n/app_localizations_de.dart Generated localization updates for new strings (German).
lib/l10n/app_localizations_en.dart Generated localization updates for new strings (English).
lib/l10n/app_localizations_es.dart Generated localization updates for new strings (Spanish).
lib/l10n/app_localizations_fr.dart Generated localization updates for new strings (French).
lib/l10n/app_localizations_it.dart Generated localization updates for new strings (Italian).
lib/l10n/app_localizations_nl.dart Generated localization updates for new strings (Dutch).
lib/l10n/app_localizations_pl.dart Generated localization updates for new strings (Polish).
lib/l10n/app_localizations_pt.dart Generated localization updates for new strings (Portuguese).
lib/l10n/app_localizations_ru.dart Generated localization updates for new strings (Russian).
lib/l10n/app_localizations_sk.dart Generated localization updates for new strings (Slovak).
lib/l10n/app_localizations_sl.dart Generated localization updates for new strings (Slovenian).
lib/l10n/app_localizations_sv.dart Generated localization updates for new strings (Swedish).
lib/l10n/app_localizations_uk.dart Generated localization updates for new strings (Ukrainian).
lib/l10n/app_localizations_zh.dart Generated localization updates for new strings (Chinese).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread lib/services/usb_serial_service_web.dart Outdated
Comment thread lib/connector/meshcore_connector.dart Outdated
Comment thread lib/services/usb_serial_frame_codec.dart Outdated
Comment thread android/app/src/main/kotlin/com/meshcore/meshcore_open/MainActivity.kt Outdated
Copilot AI review requested due to automatic review settings March 2, 2026 06:50

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 51 out of 51 changed files in this pull request and generated 5 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread lib/services/usb_serial_service_web.dart
Comment thread lib/services/usb_serial_service_native.dart
Comment thread lib/services/usb_serial_frame_codec.dart
Comment thread lib/connector/meshcore_connector.dart
Comment thread lib/l10n/app_de.arb Outdated
Copilot AI review requested due to automatic review settings March 2, 2026 07:46
@just-stuff-tm

Copy link
Copy Markdown
Contributor Author

Can anyone test on linux and MacOS. Then leave a review here. Or fork and submit a PR to this branch

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 52 out of 52 changed files in this pull request and generated 5 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread lib/connector/meshcore_connector.dart Outdated
Comment thread android/app/src/main/kotlin/com/meshcore/meshcore_open/MainActivity.kt Outdated
Comment thread lib/utils/usb_port_labels.dart
Comment thread lib/l10n/app_sv.arb Outdated
Comment thread lib/screens/usb_screen.dart Outdated
Copilot AI review requested due to automatic review settings March 2, 2026 08:13
@just-stuff-tm just-stuff-tm marked this pull request as ready for review March 2, 2026 08:15

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 52 out of 52 changed files in this pull request and generated 3 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread lib/services/usb_serial_frame_codec.dart
Comment thread android/app/src/main/kotlin/com/meshcore/meshcore_open/MainActivity.kt Outdated
Comment thread lib/l10n/app_fr.arb Outdated
Copilot AI review requested due to automatic review settings March 2, 2026 08:24

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 52 out of 52 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread lib/services/usb_serial_service_web.dart
Comment thread android/app/src/main/kotlin/com/meshcore/meshcore_open/MainActivity.kt Outdated
Copilot AI review requested due to automatic review settings March 2, 2026 08:47

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 52 out of 52 changed files in this pull request and generated 6 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread lib/connector/meshcore_connector.dart Outdated
Comment thread lib/services/usb_serial_service_native.dart
Comment thread lib/services/usb_serial_service_web.dart Outdated
Comment thread android/app/src/main/kotlin/com/meshcore/meshcore_open/MainActivity.kt Outdated
Comment thread android/build.gradle.kts Outdated
Comment thread android/app/build.gradle.kts Outdated
@just-stuff-tm

just-stuff-tm commented Mar 2, 2026

Copy link
Copy Markdown
Contributor Author

@wel97459 @zjs81 @446564 @benallfree @ericszimmermann can i get a non AI review.

Copilot AI review requested due to automatic review settings March 2, 2026 09:55

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 52 out of 52 changed files in this pull request and generated 3 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread lib/services/usb_serial_service_native.dart
Comment thread lib/utils/usb_port_labels.dart Outdated
Comment thread lib/screens/connection_choice_screen.dart Outdated
@just-stuff-tm

just-stuff-tm commented Mar 2, 2026

Copy link
Copy Markdown
Contributor Author

I pushed updates to address the review threads and wanted to summarize what I changed, what remains open, and a few questions to help move this forward.

Summary of changes (in response to review)

  • Implemented USB transport support and the MeshCoreTransportType abstraction; connection flow now supports switching between Bluetooth and USB.
  • Added UsbSerialService integration and wired USB frame subscription with safer cancellation and error handling.
  • Improved platform gating (PlatformInfo) and added web-specific workarounds / retries for flaky Bluetooth operations.
  • Hardened connection/handshake state handling to better cope with transport switching and resets.
  • Updated Android build files (USB host feature, USB serial dependency, NDK/repo updates).
  • Cleaned up a few helper methods and added inline comments where behavior is subtle.

Files/areas I’d particularly like a re-check

  • MeshCoreConnector (transport switching, activeTransport/activeUsbPort management)
  • usb_serial_service.dart (connection lifecycle and frame handling)
  • platform_info.dart (platform gating logic used across codepaths)
  • Android manifest / build.gradle / pubspec changes

Remaining items / questions

  • Linux & macOS support are not tested here — should we open a follow-up issue/PR to track those platforms separately?
  • There are a few places where I added extra logging for debugging. If you prefer different log levels or a more structured logging approach, I can adjust.

Next steps I propose

  • If everything looks good, please re-run CI and, if green, consider approving/merging.
  • If you want further changes here, tell me which threads/files to focus on and I’ll update the branch.

If I missed any review comments or misinterpreted a request, please point me to the specific thread and I’ll address it right away. Thanks again for the review — looking forward to your guidance on the remaining items.

@just-stuff-tm

Copy link
Copy Markdown
Contributor Author

@codex
REVIEW

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 99967d3799

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread lib/screens/usb_screen.dart
Copilot AI review requested due to automatic review settings March 2, 2026 20:30

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 54 out of 54 changed files in this pull request and generated 4 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread lib/screens/usb_screen.dart Outdated
Comment thread lib/connector/meshcore_connector.dart Outdated
Comment thread lib/services/usb_serial_service_native.dart
Comment thread android/app/src/main/kotlin/com/meshcore/meshcore_open/MainActivity.kt Outdated
@just-stuff-tm

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: f584c4fba0

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread lib/screens/scanner_screen.dart
Comment thread lib/services/usb_serial_service_native.dart Outdated
@just-stuff-tm just-stuff-tm marked this pull request as ready for review March 5, 2026 07:52
@zjs81

zjs81 commented Mar 6, 2026

Copy link
Copy Markdown
Owner

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: fb58a3262c

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread lib/connector/meshcore_connector.dart Outdated
Comment thread lib/services/usb_serial_service_web.dart Outdated
just-stuff-tm and others added 5 commits March 6, 2026 20:31
- Rewrite UsbScreen to mirror ScannerScreen patterns (status bar,
  tap-to-connect port list, bottom FABs, SnackBar errors)
- Extract MeshCoreUsbManager from MeshCoreConnector for cleaner
  USB transport ownership
- Add debug logging throughout USB connection flow (connector,
  manager, web/native services)
- Print debug logs to console in debug mode even when app debug
  log setting is disabled
- Localize remaining hardcoded strings (Web Serial Device fallback
  label, USB status bar keys, companion firmware timeout hint)
- Fix Swedish misspelling in translations (stöderliga → stödda)
- Guard Linux notification init against missing D-Bus session bus
- Fix SNRIndicator hit-test error by adding minimum size constraints
- Update USB flow tests for new UI patterns

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: fef73b7b62

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +2498 to +2500
if (PlatformInfo.isWeb &&
_activeTransport == MeshCoreTransportType.bluetooth) {
_pendingInitialContactsSync = true;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Trigger contact sync even when channel 0 is unavailable

On web BLE, this path defers getContacts() and only sets _pendingInitialContactsSync, which means contact sync is later triggered only by the channel.index == 0 branch in _handleChannelInfo. If channel 0 never arrives (for example, channel requests time out or firmware doesn't respond to cmdGetChannel), there is no fallback path that starts contact sync, so the app can remain connected with an empty contacts list indefinitely.

Useful? React with 👍 / 👎.

Comment thread macos/Flutter/GeneratedPluginRegistrant.swift
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, you can upgrade your account or add credits to your account and enable them for code reviews in your settings.

@just-stuff-tm

Copy link
Copy Markdown
Contributor Author

@codex review

zjs81 added 2 commits March 7, 2026 13:00
On web BLE, contact sync is deferred until channel 0 arrives via
_handleChannelInfo. If channel 0 times out or channel sync completes
without it, _pendingInitialContactsSync stays true and contacts never
load. Add fallback in _cleanupChannelSync to trigger getContacts() if
the flag is still set when channel sync ends.
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, you can upgrade your account or add credits to your account and enable them for code reviews in your settings.

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, you can upgrade your account or add credits to your account and enable them for code reviews in your settings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: e1327a93c7

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread macos/Flutter/GeneratedPluginRegistrant.swift
The /dev/ prefix granted read/write to all device nodes. The app only
needs access to serial port devices (/dev/cu.* and /dev/tty.*) for USB
LoRa communication.
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, you can upgrade your account or add credits to your account and enable them for code reviews in your settings.

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, you can upgrade your account or add credits to your account and enable them for code reviews in your settings.

@zjs81 zjs81 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Good to merge

Comment thread macos/Flutter/GeneratedPluginRegistrant.swift
@zjs81 zjs81 merged commit 4eecfc9 into zjs81:main Mar 7, 2026
6 checks passed
@just-stuff-tm just-stuff-tm deleted the feature/usb branch March 7, 2026 20:25
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.

4 participants