Skip to content

Commit 72f6b60

Browse files
committed
Remove unused import
1 parent f3f0436 commit 72f6b60

File tree

4 files changed

+102
-184
lines changed

4 files changed

+102
-184
lines changed
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
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
2+
index a366b4a..c094c1e 100644
3+
--- a/node_modules/capacitor-plugin-usb-serial/android/src/main/java/com/viewtrak/plugins/usbserial/UsbSerial.java
4+
+++ b/node_modules/capacitor-plugin-usb-serial/android/src/main/java/com/viewtrak/plugins/usbserial/UsbSerial.java
5+
@@ -105,6 +105,7 @@ public class UsbSerial implements SerialInputOutputManager.Listener {
6+
7+
@Override
8+
public void onNewData(byte[] data) {
9+
+ android.util.Log.d("UsbSerial", "onNewData called with " + data.length + " bytes");
10+
mainLooper.post(() -> updateReceivedData(data));
11+
}
12+
13+
@@ -195,11 +196,15 @@ public class UsbSerial implements SerialInputOutputManager.Listener {
14+
}
15+
}
16+
usbSerialPort.open(usbConnection);
17+
+ android.util.Log.d("UsbSerial", "Serial port opened successfully");
18+
usbSerialPort.setParameters(settings.baudRate, settings.dataBits, settings.stopBits, settings.parity);
19+
+ android.util.Log.d("UsbSerial", "Serial parameters set: baudRate=" + settings.baudRate);
20+
if (settings.dtr) usbSerialPort.setDTR(true);
21+
if (settings.rts) usbSerialPort.setRTS(true);
22+
usbIoManager = new SerialInputOutputManager(usbSerialPort, this);
23+
+ android.util.Log.d("UsbSerial", "SerialInputOutputManager created");
24+
usbIoManager.start();
25+
+ android.util.Log.d("UsbSerial", "SerialInputOutputManager started - should now receive data");
26+
// connected = true;
27+
setConnectedDevice(device);
28+
} catch (Exception exception) {
29+
@@ -233,8 +238,12 @@ public class UsbSerial implements SerialInputOutputManager.Listener {
30+
throw new Error("can't send empty string to device", new Throwable("EMPTY_STRING"));
31+
}
32+
try {
33+
- byte[] data = (str + "\r\n").getBytes();
34+
+ // Convert hex string to bytes (for binary protocols like MSP)
35+
+ android.util.Log.d("UsbSerial", "writeSerial: converting hex string (" + str.length() + " chars) to bytes");
36+
+ byte[] data = HexDump.hexStringToByteArray(str);
37+
+ android.util.Log.d("UsbSerial", "writeSerial: writing " + data.length + " bytes");
38+
usbSerialPort.write(data, WRITE_WAIT_MILLIS);
39+
+ android.util.Log.d("UsbSerial", "writeSerial: write successful");
40+
} catch (Exception e) {
41+
closeSerial();
42+
throw new Error("connection lost: " + e.getMessage(), e.getCause());
43+
@@ -260,25 +269,13 @@ public class UsbSerial implements SerialInputOutputManager.Listener {
44+
45+
private void updateReceivedData(byte[] data) {
46+
try {
47+
- messageNMEA += new String(data);
48+
-
49+
- while (messageNMEA.indexOf(0x0a) != -1) {
50+
-
51+
- int eol = messageNMEA.indexOf(0x0a);
52+
- if (-1 != eol) {
53+
- String sentence = messageNMEA.substring(0, eol + 1);
54+
- messageNMEA = messageNMEA.substring(eol + 1);
55+
-
56+
- // Boolean allowed = throttle.tryAcquire();
57+
- // if (!allowed) {
58+
- // return;
59+
- // }
60+
-
61+
- callback.receivedData(sentence);
62+
- } else if (messageNMEA.length() > 128) {
63+
- throw new Exception("invalid NMEA string");
64+
- }
65+
- }
66+
+ // FIXED: Send all data immediately as hex string (for binary protocols like MSP)
67+
+ // Original code waited for newline characters (NMEA protocol), which never comes with binary data
68+
+ android.util.Log.d("UsbSerial", "updateReceivedData: sending " + data.length + " bytes as hex");
69+
+ String hexData = HexDump.toHexString(data);
70+
+ android.util.Log.d("UsbSerial", "updateReceivedData: hex string length = " + hexData.length());
71+
+ callback.receivedData(hexData);
72+
+ android.util.Log.d("UsbSerial", "updateReceivedData: callback.receivedData called successfully");
73+
} catch (Exception exception) {
74+
updateReadDataError(exception);
75+
}
76+
diff --git a/node_modules/capacitor-plugin-usb-serial/android/src/main/java/com/viewtrak/plugins/usbserial/UsbSerialPlugin.java b/node_modules/capacitor-plugin-usb-serial/android/src/main/java/com/viewtrak/plugins/usbserial/UsbSerialPlugin.java
77+
index 2d2edd1..ec097e8 100644
78+
--- a/node_modules/capacitor-plugin-usb-serial/android/src/main/java/com/viewtrak/plugins/usbserial/UsbSerialPlugin.java
79+
+++ b/node_modules/capacitor-plugin-usb-serial/android/src/main/java/com/viewtrak/plugins/usbserial/UsbSerialPlugin.java
80+
@@ -156,9 +156,12 @@ public class UsbSerialPlugin extends Plugin implements Callback {
81+
82+
@Override
83+
public void receivedData(String Data) {
84+
+ android.util.Log.d("UsbSerialPlugin", "receivedData callback: " + Data.length() + " chars");
85+
JSObject ret = new JSObject();
86+
ret.put("data", Data);
87+
+ android.util.Log.d("UsbSerialPlugin", "Calling notifyListeners with data event");
88+
notifyListeners("data", ret);
89+
+ android.util.Log.d("UsbSerialPlugin", "notifyListeners completed");
90+
}
91+
92+
@Override

src/js/port_handler.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ const PortHandler = new (function () {
5050
})();
5151

5252
PortHandler.initialize = function () {
53-
EventBus.$on("ports-input:request-permission-bluetooth", () => this.requestDevicePermission("webbluetooth"));
53+
EventBus.$on("ports-input:request-permission-bluetooth", () => this.requestDevicePermission("bluetooth"));
5454
EventBus.$on("ports-input:request-permission-serial", () => this.requestDevicePermission("serial"));
5555
EventBus.$on("ports-input:request-permission-usb", () => this.requestDevicePermission("usb"));
5656
EventBus.$on("ports-input:change", this.onChangeSelectedPort.bind(this));
@@ -60,7 +60,7 @@ PortHandler.initialize = function () {
6060
const detail = event.detail;
6161

6262
if (detail?.path?.startsWith("bluetooth")) {
63-
this.handleDeviceAdded(detail, "webbluetooth");
63+
this.handleDeviceAdded(detail, "bluetooth");
6464
} else {
6565
this.handleDeviceAdded(detail, "serial");
6666
}
@@ -82,7 +82,7 @@ PortHandler.refreshAllDeviceLists = async function () {
8282
// Update all device lists in parallel
8383
return Promise.all([
8484
this.updateDeviceList("serial"),
85-
this.updateDeviceList("webbluetooth"),
85+
this.updateDeviceList("bluetooth"),
8686
this.updateDeviceList("usb"),
8787
]).then(() => {
8888
this.selectActivePort();
@@ -120,7 +120,7 @@ PortHandler.removedSerialDevice = function (device) {
120120

121121
// Update the appropriate ports list based on the device type
122122
const updatePromise = devicePath.startsWith("bluetooth")
123-
? this.updateDeviceList("webbluetooth")
123+
? this.updateDeviceList("bluetooth")
124124
: this.updateDeviceList("serial");
125125

126126
const wasSelectedPort = this.portPicker.selectedPort === devicePath;
@@ -274,7 +274,7 @@ PortHandler.handleDeviceAdded = function (device, deviceType) {
274274

275275
// Update the appropriate device list
276276
const updatePromise =
277-
deviceType === "webbluetooth" ? this.updateDeviceList("webbluetooth") : this.updateDeviceList("serial");
277+
deviceType === "bluetooth" ? this.updateDeviceList("bluetooth") : this.updateDeviceList("serial");
278278

279279
updatePromise.then(() => {
280280
const selectedPort = this.selectActivePort(device);
@@ -295,9 +295,9 @@ PortHandler.updateDeviceList = async function (deviceType) {
295295

296296
try {
297297
switch (deviceType) {
298-
case "webbluetooth":
298+
case "bluetooth":
299299
if (this.showBluetoothOption) {
300-
ports = await serial.getDevices("webbluetooth");
300+
ports = await serial.getDevices("bluetooth");
301301
}
302302
break;
303303
case "usb":
@@ -320,7 +320,7 @@ PortHandler.updateDeviceList = async function (deviceType) {
320320

321321
// Update the appropriate properties based on device type
322322
switch (deviceType) {
323-
case "webbluetooth":
323+
case "bluetooth":
324324
this.bluetoothAvailable = orderedPorts.length > 0;
325325
this.currentBluetoothPorts = [...orderedPorts];
326326
console.log(`${this.logHead} Found bluetooth port(s)`, orderedPorts);

src/js/serial.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class Serial extends EventTarget {
2424
} else {
2525
this._protocols = [
2626
{ name: "serial", instance: new WebSerial() },
27-
{ name: "webbluetooth", instance: new WebBluetooth() },
27+
{ name: "bluetooth", instance: new WebBluetooth() },
2828
{ name: "websocket", instance: new Websocket() },
2929
{ name: "virtual", instance: new VirtualSerial() },
3030
];
@@ -88,7 +88,7 @@ class Serial extends EventTarget {
8888
return this._protocols.find((p) => p.name === "websocket")?.instance;
8989
}
9090
if (s.startsWith("bluetooth")) {
91-
return this._protocols.find((p) => p.name === "webbluetooth")?.instance;
91+
return this._protocols.find((p) => p.name === "bluetooth")?.instance;
9292
}
9393
return this._protocols.find((p) => p.name === "serial")?.instance;
9494
}

src/js/utils/checkBrowserCompatibility.js

Lines changed: 0 additions & 174 deletions
This file was deleted.

0 commit comments

Comments
 (0)