@leonardojc/capacitor-ioboard 2.0.3 → 2.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -19,6 +19,10 @@ public class CapacitorIoboardPlugin extends Plugin implements SerialConnectionMa
19
19
  private boolean isConnected = false;
20
20
  private String currentDeviceInfo = "";
21
21
  private String lastError = "";
22
+
23
+ // For response waiting in getStatus()
24
+ private volatile byte[] pendingResponse = null;
25
+ private final Object responseLock = new Object();
22
26
 
23
27
  // Helper method to convert bytes to hex string for debugging
24
28
  private String bytesToHex(byte[] bytes) {
@@ -134,6 +138,11 @@ public class CapacitorIoboardPlugin extends Plugin implements SerialConnectionMa
134
138
  int address = call.getInt("address", 1);
135
139
  int timeout = call.getInt("timeout", 1000); // 1 second default
136
140
 
141
+ // Clear previous response
142
+ synchronized (responseLock) {
143
+ pendingResponse = null;
144
+ }
145
+
137
146
  byte[] statusFrame = createStatusQueryFrame(address);
138
147
  boolean success = serialManager.writeData(statusFrame);
139
148
 
@@ -142,21 +151,20 @@ public class CapacitorIoboardPlugin extends Plugin implements SerialConnectionMa
142
151
  return;
143
152
  }
144
153
 
145
- // Wait for response
146
- long startTime = System.currentTimeMillis();
147
- byte[] response = null;
148
-
149
- while (System.currentTimeMillis() - startTime < timeout) {
150
- response = serialManager.readData(100); // Read with 100ms timeout
151
- if (response != null && response.length > 0) {
152
- break;
154
+ // Wait for response with timeout
155
+ byte[] response;
156
+ synchronized (responseLock) {
157
+ long startTime = System.currentTimeMillis();
158
+ while (pendingResponse == null) {
159
+ long elapsed = System.currentTimeMillis() - startTime;
160
+ if (elapsed >= timeout) {
161
+ call.reject("No response from IOBoard (timeout after " + timeout + "ms)");
162
+ return;
163
+ }
164
+ responseLock.wait(100); // Wait with 100ms intervals
153
165
  }
154
- Thread.sleep(50); // Small delay between attempts
155
- }
156
-
157
- if (response == null || response.length == 0) {
158
- call.reject("No response from IOBoard (timeout after " + timeout + "ms)");
159
- return;
166
+ response = pendingResponse;
167
+ pendingResponse = null; // Clear after reading
160
168
  }
161
169
 
162
170
  // Parse response
@@ -382,6 +390,12 @@ public class CapacitorIoboardPlugin extends Plugin implements SerialConnectionMa
382
390
  String dataString = new String(data);
383
391
  Log.d(TAG, "Data received: " + dataString);
384
392
 
393
+ // Store response for getStatus() waiting
394
+ synchronized (responseLock) {
395
+ pendingResponse = data;
396
+ responseLock.notifyAll();
397
+ }
398
+
385
399
  JSObject result = new JSObject();
386
400
  result.put("rawData", dataString);
387
401
  result.put("timestamp", System.currentTimeMillis());
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leonardojc/capacitor-ioboard",
3
- "version": "2.0.3",
3
+ "version": "2.0.4",
4
4
  "description": "A comprehensive Capacitor plugin for IOBoard devices with integrated serial communication and complete MTC3P08L protocol support including OTA updates",
5
5
  "main": "dist/plugin.cjs.js",
6
6
  "module": "dist/esm/index.js",