@leonardojc/capacitor-ioboard 2.0.2 → 2.0.3

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.
@@ -132,19 +132,77 @@ public class CapacitorIoboardPlugin extends Plugin implements SerialConnectionMa
132
132
 
133
133
  try {
134
134
  int address = call.getInt("address", 1);
135
+ int timeout = call.getInt("timeout", 1000); // 1 second default
136
+
135
137
  byte[] statusFrame = createStatusQueryFrame(address);
136
138
  boolean success = serialManager.writeData(statusFrame);
137
139
 
138
- if (success) {
139
- JSObject result = new JSObject();
140
- result.put("success", true);
141
- result.put("message", "Status query sent successfully");
142
- result.put("address", address);
143
- call.resolve(result);
144
- } else {
140
+ if (!success) {
145
141
  call.reject("Failed to send status query");
142
+ return;
143
+ }
144
+
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;
153
+ }
154
+ Thread.sleep(50); // Small delay between attempts
146
155
  }
147
156
 
157
+ if (response == null || response.length == 0) {
158
+ call.reject("No response from IOBoard (timeout after " + timeout + "ms)");
159
+ return;
160
+ }
161
+
162
+ // Parse response
163
+ IOBoardResponse parsedResponse = parseIOBoardResponse(response);
164
+
165
+ if (!parsedResponse.isValid) {
166
+ call.reject("Invalid response from IOBoard");
167
+ return;
168
+ }
169
+
170
+ // Build result with door status
171
+ JSObject result = new JSObject();
172
+ result.put("success", true);
173
+ result.put("address", parsedResponse.address);
174
+ result.put("firmware", parsedResponse.firmware);
175
+ result.put("doorStatus", parsedResponse.doorStatus);
176
+
177
+ // Interpret door status for user
178
+ String doorStatusText;
179
+ switch (parsedResponse.doorStatus) {
180
+ case 0xFE:
181
+ doorStatusText = "closed";
182
+ break;
183
+ case 0xFF:
184
+ doorStatusText = "open";
185
+ break;
186
+ case 0x00:
187
+ doorStatusText = "unknown";
188
+ break;
189
+ case 0x01:
190
+ doorStatusText = "moving";
191
+ break;
192
+ default:
193
+ doorStatusText = "custom";
194
+ break;
195
+ }
196
+ result.put("doorStatusText", doorStatusText);
197
+
198
+ Log.i(TAG, String.format("✅ IOBoard Status - Firmware: %s, Door: 0x%02X (%s)",
199
+ parsedResponse.firmware, parsedResponse.doorStatus, doorStatusText));
200
+
201
+ call.resolve(result);
202
+
203
+ } catch (InterruptedException e) {
204
+ Log.e(TAG, "Thread interrupted while waiting for status: " + e.getMessage(), e);
205
+ call.reject("Status query interrupted: " + e.getMessage());
148
206
  } catch (Exception e) {
149
207
  Log.e(TAG, "Error in getStatus: " + e.getMessage(), e);
150
208
  call.reject("Error getting status: " + e.getMessage());
@@ -79,14 +79,10 @@ export interface IOBoardResponse {
79
79
  data?: any;
80
80
  }
81
81
  export interface IOBoardStatusResponse extends IOBoardResponse {
82
- data?: {
83
- doorLockStatus: number;
84
- softwareVersion: {
85
- major: number;
86
- minor: number;
87
- patch: number;
88
- };
89
- };
82
+ address?: number;
83
+ firmware?: string;
84
+ doorStatus?: number;
85
+ doorStatusText?: 'closed' | 'open' | 'unknown' | 'moving' | 'custom';
90
86
  }
91
87
  export interface SerialConnectionOptions {
92
88
  portPath?: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leonardojc/capacitor-ioboard",
3
- "version": "2.0.2",
3
+ "version": "2.0.3",
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",