@leonardojc/capacitor-ioboard 2.0.3 → 2.0.5
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
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
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
|
-
|
|
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
|
|
@@ -174,29 +182,32 @@ public class CapacitorIoboardPlugin extends Plugin implements SerialConnectionMa
|
|
|
174
182
|
result.put("firmware", parsedResponse.firmware);
|
|
175
183
|
result.put("doorStatus", parsedResponse.doorStatus);
|
|
176
184
|
|
|
177
|
-
//
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
case 0x01:
|
|
190
|
-
doorStatusText = "moving";
|
|
191
|
-
break;
|
|
192
|
-
default:
|
|
193
|
-
doorStatusText = "custom";
|
|
194
|
-
break;
|
|
185
|
+
// Parse door status bitmask (each bit represents a door)
|
|
186
|
+
// Bit 0 = Door 1, Bit 1 = Door 2, etc.
|
|
187
|
+
// 0 = closed, 1 = open
|
|
188
|
+
// Example: 0xF8 (11111000) = doors 1,2,3 closed, rest open
|
|
189
|
+
JSArray doorsArray = new JSArray();
|
|
190
|
+
for (int i = 0; i < 8; i++) {
|
|
191
|
+
boolean isOpen = ((parsedResponse.doorStatus & (1 << i)) != 0);
|
|
192
|
+
JSObject doorInfo = new JSObject();
|
|
193
|
+
doorInfo.put("doorNumber", i + 1);
|
|
194
|
+
doorInfo.put("isOpen", isOpen);
|
|
195
|
+
doorInfo.put("status", isOpen ? "open" : "closed");
|
|
196
|
+
doorsArray.put(doorInfo);
|
|
195
197
|
}
|
|
196
|
-
result.put("
|
|
198
|
+
result.put("doors", doorsArray);
|
|
197
199
|
|
|
198
|
-
|
|
199
|
-
|
|
200
|
+
// Summary text
|
|
201
|
+
StringBuilder doorStatusText = new StringBuilder();
|
|
202
|
+
for (int i = 0; i < 8; i++) {
|
|
203
|
+
boolean isOpen = ((parsedResponse.doorStatus & (1 << i)) != 0);
|
|
204
|
+
if (i > 0) doorStatusText.append(", ");
|
|
205
|
+
doorStatusText.append("D").append(i + 1).append(":").append(isOpen ? "open" : "closed");
|
|
206
|
+
}
|
|
207
|
+
result.put("doorStatusText", doorStatusText.toString());
|
|
208
|
+
|
|
209
|
+
Log.i(TAG, String.format("✅ IOBoard Status - Firmware: %s, Door Status: 0x%02X (%s)",
|
|
210
|
+
parsedResponse.firmware, parsedResponse.doorStatus, doorStatusText.toString()));
|
|
200
211
|
|
|
201
212
|
call.resolve(result);
|
|
202
213
|
|
|
@@ -382,6 +393,12 @@ public class CapacitorIoboardPlugin extends Plugin implements SerialConnectionMa
|
|
|
382
393
|
String dataString = new String(data);
|
|
383
394
|
Log.d(TAG, "Data received: " + dataString);
|
|
384
395
|
|
|
396
|
+
// Store response for getStatus() waiting
|
|
397
|
+
synchronized (responseLock) {
|
|
398
|
+
pendingResponse = data;
|
|
399
|
+
responseLock.notifyAll();
|
|
400
|
+
}
|
|
401
|
+
|
|
385
402
|
JSObject result = new JSObject();
|
|
386
403
|
result.put("rawData", dataString);
|
|
387
404
|
result.put("timestamp", System.currentTimeMillis());
|
|
@@ -78,11 +78,17 @@ export interface IOBoardResponse {
|
|
|
78
78
|
message?: string;
|
|
79
79
|
data?: any;
|
|
80
80
|
}
|
|
81
|
+
export interface DoorInfo {
|
|
82
|
+
doorNumber: number;
|
|
83
|
+
isOpen: boolean;
|
|
84
|
+
status: 'open' | 'closed';
|
|
85
|
+
}
|
|
81
86
|
export interface IOBoardStatusResponse extends IOBoardResponse {
|
|
82
87
|
address?: number;
|
|
83
88
|
firmware?: string;
|
|
84
89
|
doorStatus?: number;
|
|
85
|
-
|
|
90
|
+
doors?: DoorInfo[];
|
|
91
|
+
doorStatusText?: string;
|
|
86
92
|
}
|
|
87
93
|
export interface SerialConnectionOptions {
|
|
88
94
|
portPath?: string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@leonardojc/capacitor-ioboard",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.5",
|
|
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",
|