-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Add USB serial support for Android (Capacitor) #4698
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
haslinghuis
wants to merge
68
commits into
betaflight:master
Choose a base branch
from
haslinghuis:capacitor-usb-serial
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+594
−124
Open
Changes from all commits
Commits
Show all changes
68 commits
Select commit
Hold shift + click to select a range
3433452
Add initial Tauri v2 support
haslinghuis 8f14ff4
Add native tauri check
haslinghuis ede1c21
Add Tauri v2 shell:allow-open capability
haslinghuis 1ca8699
Update
haslinghuis f8dab3c
Add DockerFile (needs testing)
haslinghuis 1da5d9f
Update edition
haslinghuis 617ff0a
Update DOCKER.MD
haslinghuis f84571d
Fix app security capabilities
haslinghuis 80ac855
Fix outdated versions
haslinghuis 5e028da
Fix shell open
haslinghuis eb42e49
Add android commands
haslinghuis 68701cf
Use yarn for docker
haslinghuis bdf976e
Use cargo
haslinghuis 166339d
Fix yarn tauri:android:dev
haslinghuis a076fa6
isTauri does not work with Android
haslinghuis e39b6a8
Update path for ADB
haslinghuis f3584f2
Use run-script-os
haslinghuis 4684bd9
Fix HMR on android
haslinghuis cc1fc43
Remove redundant alias
haslinghuis 544a4cb
Avoid device offline races
haslinghuis a9626ea
👾
haslinghuis 6303719
add equivalent boot completion check to Windows version
haslinghuis cada7cc
Fix sonar
haslinghuis d472ec7
Nitpicks
haslinghuis a007672
Added support for tauriserial
haslinghuis c1e2b06
Added support for tauriserial II
haslinghuis 6dafd31
Update DOCKER.md
haslinghuis 48b74e2
Update
haslinghuis 25962ab
Fix broken pipe, reconnect, unplug
haslinghuis abc5631
Fix some sonar issues
haslinghuis a988841
Coderabbit refactoring
haslinghuis ef2294b
Use function not object
haslinghuis 734a3fc
Fix race condition
haslinghuis 8e85239
Remove deadcode after refactoring
haslinghuis 8ba48f9
Fix some more sonar issues but not all
haslinghuis a1d67e2
cargo update
haslinghuis cb7b589
ci: simplify to node-only, add workflow_dispatch test wrapper
haslinghuis 01cc1be
release: add Tauri desktop builds (dmg/nsis/deb/appimage) and optiona…
haslinghuis 452ef67
release: always build Android APK; setup Android SDK and cache Gradle…
haslinghuis 73a9e76
ci: run on pull_request and push; upload web-dist artifact to PR; gua…
haslinghuis b03b13e
ci: add Tauri Linux preview job to build and upload .deb/.AppImage on…
haslinghuis d8c3480
ci: fix Tauri Linux preview by installing required Linux deps (webkit…
haslinghuis 244c915
CI: fix Tauri Linux preview by building web assets and set correct CW…
haslinghuis 79a182e
Fix tauri.conf.json schema error: remove unsupported *Cwd keys; run w…
haslinghuis 36e6ea3
CI: run Tauri before* commands at repo root (remove `cd ..`) to fix p…
haslinghuis 01b2bce
Rust
haslinghuis 45cdf14
CI+Tauri: point frontendDist to ../src/dist and upload correct web ar…
haslinghuis c1bf16e
CI: fix Tauri action invocation (use `yarn tauri` so action appends `…
haslinghuis 7d74b82
CI(Linux): install pkg-config, libudev-dev, and libssl-dev to satisfy…
haslinghuis 8289a55
Publish
haslinghuis 0e15d1b
Remove fallback
haslinghuis 596b2d5
Fix artifact-links workflow: trigger on "CI" workflow instead of non-…
haslinghuis 3ebf95e
Fix artifact-links: only run when CI was triggered by pull_request (s…
haslinghuis a598391
Add permissions to artifact-links workflow (pull-requests: write, act…
haslinghuis 42d8784
Rewrite artifact-links workflow with github-script for better reliabi…
haslinghuis caad22d
Revert "Switch to Tauri branch for configurator builds"
haslinghuis 4c0399f
Add Android USB support
haslinghuis 188a51b
Initial cleanup
haslinghuis f3f0436
CR review
haslinghuis 72f6b60
Remove unused import
haslinghuis 6aba010
Missed one
haslinghuis 4ec261e
Always add virtual protocol
haslinghuis 3782d33
Some sonar
haslinghuis 5dd2a2e
Remove logging
haslinghuis 1848e79
Good nitpick
haslinghuis e3c6152
Address (re)connection issues
haslinghuis c8d2d3d
Remove Java logging & update patch
haslinghuis 1341146
Fix the patch
haslinghuis File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <resources> | ||
| <!-- USB device filters for Betaflight-compatible devices --> | ||
|
|
||
| <!-- FT232R USB UART --> | ||
| <usb-device vendor-id="1027" product-id="24577" /> | ||
|
|
||
| <!-- STM32 devices --> | ||
| <usb-device vendor-id="1155" product-id="12886" /> <!-- STM32 in HID mode --> | ||
| <usb-device vendor-id="1155" product-id="14158" /> <!-- STLink Virtual COM Port (NUCLEO boards) --> | ||
| <usb-device vendor-id="1155" product-id="22336" /> <!-- STM Electronics Virtual COM Port --> | ||
| <usb-device vendor-id="1155" product-id="57105" /> <!-- STM Device in DFU Mode --> | ||
|
|
||
| <!-- CP210x devices --> | ||
| <usb-device vendor-id="4292" product-id="60000" /> | ||
| <usb-device vendor-id="4292" product-id="60001" /> | ||
| <usb-device vendor-id="4292" product-id="60002" /> | ||
|
|
||
| <!-- GD32 devices --> | ||
| <usb-device vendor-id="10473" product-id="394" /> <!-- GD32 VCP --> | ||
| <usb-device vendor-id="10473" product-id="393" /> <!-- GD32 DFU Bootloader --> | ||
|
|
||
| <!-- AT32 devices --> | ||
| <usb-device vendor-id="11836" product-id="22336" /> <!-- AT32 VCP --> | ||
| <usb-device vendor-id="11836" product-id="57105" /> <!-- AT32F435 DFU Bootloader --> | ||
|
|
||
| <!-- APM32 devices --> | ||
| <usb-device vendor-id="12619" product-id="22336" /> <!-- APM32 VCP --> | ||
| <usb-device vendor-id="12619" product-id="262" /> <!-- APM32 DFU Bootloader --> | ||
|
|
||
| <!-- Raspberry Pi Pico devices --> | ||
| <usb-device vendor-id="11914" product-id="9" /> <!-- Raspberry Pi Pico VCP --> | ||
| <usb-device vendor-id="11914" product-id="15" /> <!-- Raspberry Pi Pico in Bootloader mode --> | ||
| </resources> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,6 @@ | ||
| // DO NOT EDIT THIS FILE! IT IS GENERATED EACH TIME "capacitor update" IS RUN | ||
| include ':capacitor-android' | ||
| project(':capacitor-android').projectDir = new File('../node_modules/@capacitor/android/capacitor') | ||
|
|
||
| include ':capacitor-plugin-usb-serial' | ||
| project(':capacitor-plugin-usb-serial').projectDir = new File('../node_modules/capacitor-plugin-usb-serial/android') |
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| diff --git a/node_modules/capacitor-plugin-usb-serial/android/src/main/java/com/viewtrak/plugins/usbserial/UsbSerial.java b/node_modules/capacitor-plugin-usb-serial/android/src/main/java/com/viewtrak/plugins/usbserial/UsbSerial.java | ||
| index a366b4a..c80e172 100644 | ||
| --- a/node_modules/capacitor-plugin-usb-serial/android/src/main/java/com/viewtrak/plugins/usbserial/UsbSerial.java | ||
| +++ b/node_modules/capacitor-plugin-usb-serial/android/src/main/java/com/viewtrak/plugins/usbserial/UsbSerial.java | ||
| @@ -233,7 +233,8 @@ public class UsbSerial implements SerialInputOutputManager.Listener { | ||
| throw new Error("can't send empty string to device", new Throwable("EMPTY_STRING")); | ||
| } | ||
| try { | ||
| - byte[] data = (str + "\r\n").getBytes(); | ||
| + // Convert hex string to bytes (for binary protocols like MSP) | ||
| + byte[] data = HexDump.hexStringToByteArray(str); | ||
| usbSerialPort.write(data, WRITE_WAIT_MILLIS); | ||
| } catch (Exception e) { | ||
| closeSerial(); | ||
| @@ -260,25 +261,10 @@ public class UsbSerial implements SerialInputOutputManager.Listener { | ||
|
|
||
| private void updateReceivedData(byte[] data) { | ||
| try { | ||
| - messageNMEA += new String(data); | ||
| - | ||
| - while (messageNMEA.indexOf(0x0a) != -1) { | ||
| - | ||
| - int eol = messageNMEA.indexOf(0x0a); | ||
| - if (-1 != eol) { | ||
| - String sentence = messageNMEA.substring(0, eol + 1); | ||
| - messageNMEA = messageNMEA.substring(eol + 1); | ||
| - | ||
| - // Boolean allowed = throttle.tryAcquire(); | ||
| - // if (!allowed) { | ||
| - // return; | ||
| - // } | ||
| - | ||
| - callback.receivedData(sentence); | ||
| - } else if (messageNMEA.length() > 128) { | ||
| - throw new Exception("invalid NMEA string"); | ||
| - } | ||
| - } | ||
| + // FIXED: Send all data immediately as hex string (for binary protocols like MSP) | ||
| + // Original code waited for newline characters (NMEA protocol), which never comes with binary data | ||
| + String hexData = HexDump.toHexString(data); | ||
| + callback.receivedData(hexData); | ||
| } catch (Exception exception) { | ||
| updateReadDataError(exception); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.