@leonardojc/capacitor-ioboard 1.2.7 → 2.0.0

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.
package/README.md CHANGED
@@ -1,292 +1,340 @@
1
- # @leonardojc/capacitor-ioboard
1
+ # 🚀 IOBoard Plugin v2.0 - Integrated Serial + Protocol
2
2
 
3
- Capacitor plugin for controlling IOBOARD devices via RS485 serial communication.
3
+ **@leonardojc/capacitor-ioboard v2.0.0** - Complete IOBoard control with integrated serial communication
4
4
 
5
- ## Install
5
+ ## ✨ What's New in v2.0
6
+
7
+ - **🔗 Integrated Serial Communication** - No need for separate serial plugin
8
+ - **🎯 Simplified API** - Single plugin handles everything
9
+ - **⚡ Real-time Events** - Connection state, data received, error handling
10
+ - **🎨 Enhanced Color Control** - Predefined colors and custom RGB support
11
+ - **🚀 Complete OTA Support** - Firmware updates with progress tracking
12
+ - **🌐 Web Compatible** - Works in browser with simulation mode
13
+
14
+ ## 📦 Installation
6
15
 
7
16
  ```bash
8
- npm install @leonardojc/capacitor-ioboard
17
+ npm install @leonardojc/capacitor-ioboard@2.0.0
9
18
  npx cap sync
10
19
  ```
11
20
 
12
- ## Prerequisites
13
-
14
- This plugin requires the [@leonardojc/capacitor-serial-port](https://www.npmjs.com/package/@leonardojc/capacitor-serial-port) plugin for serial communication.
21
+ ## 🚀 Quick Start
15
22
 
16
- ```bash
17
- npm install @leonardojc/capacitor-serial-port
18
- ```
23
+ ```typescript
24
+ import { ioboard } from '@leonardojc/capacitor-ioboard';
19
25
 
20
- ## Hardware Requirements
26
+ // Connect to device
27
+ const result = await ioboard.connect('/dev/ttyS2', 115200);
21
28
 
22
- - IOBOARD MTC3P08L device
23
- - Serial to RS485 adapter (transparent to the application)
24
- - Android device with USB OTG support or USB-to-serial adapter
29
+ // Unlock pallet with green color
30
+ await ioboard.unlockPallet(1, 3, 'GREEN', {
31
+ intensity: 100,
32
+ blinkTimes: 3,
33
+ blinkSpeed: 2
34
+ });
25
35
 
26
- ## API
36
+ // Set all pallets to red
37
+ await ioboard.setAllPalletsColor(1, 'RED');
27
38
 
28
- ### Connection Management
39
+ // Get device status
40
+ const status = await ioboard.getStatus(1);
41
+ console.log(\`Firmware: \${status.status.firmwareVersion}\`);
42
+ ```
29
43
 
30
- #### `openConnection(options)`
44
+ ## 📚 Complete API Reference
31
45
 
32
- Opens a serial connection with the specified parameters.
46
+ ### 🔌 Connection Methods
33
47
 
48
+ #### `connect(portPath?, baudRate?)`
49
+ Connect to IOBoard device
34
50
  ```typescript
35
- import { CapacitorIoboard } from '@leonardojc/capacitor-ioboard';
36
-
37
- const result = await CapacitorIoboard.openConnection({
38
- baudRate: 115200,
39
- dataBits: 8,
40
- stopBits: 1,
41
- parity: 'none',
42
- timeout: 5000
43
- });
51
+ await ioboard.connect('/dev/ttyS2', 115200);
44
52
  ```
45
53
 
46
- **Parameters:**
54
+ #### `disconnect()`
55
+ Disconnect from device
56
+ ```typescript
57
+ await ioboard.disconnect();
58
+ ```
47
59
 
48
- | Name | Type | Default | Description |
49
- |--------------|-------------------------------|-----------|--------------------------------|
50
- | baudRate | number | 115200 | Baud rate for communication |
51
- | dataBits | number | 8 | Number of data bits |
52
- | stopBits | number | 1 | Number of stop bits |
53
- | parity | 'none' \| 'even' \| 'odd' | 'none' | Parity checking |
54
- | flowControl | 'none' \| 'hardware' \| 'software' | 'none' | Flow control method |
55
- | timeout | number | 5000 | Response timeout (ms) |
60
+ #### `isDeviceConnected()`
61
+ Check connection status
62
+ ```typescript
63
+ const status = await ioboard.isDeviceConnected();
64
+ console.log(status.connected); // true/false
65
+ ```
56
66
 
57
- #### `closeConnection()`
67
+ #### `listPorts()`
68
+ List available serial ports
69
+ ```typescript
70
+ const result = await ioboard.listPorts();
71
+ console.log(result.ports); // ['/dev/ttyS0', '/dev/ttyS1', ...]
72
+ ```
58
73
 
59
- Closes the serial connection.
74
+ ### 🎮 IOBoard Device Methods
60
75
 
76
+ #### `getStatus(address)`
77
+ Get device status and information
61
78
  ```typescript
62
- const result = await CapacitorIoboard.closeConnection();
79
+ const result = await ioboard.getStatus(1);
80
+ console.log(result.status);
81
+ // {
82
+ // address: 1,
83
+ // connected: true,
84
+ // firmwareVersion: "2.1.0",
85
+ // palletStates: [false, false, ...], // 8 pallets
86
+ // temperature: 25.5,
87
+ // voltage: 12.0,
88
+ // uptime: 86400
89
+ // }
63
90
  ```
64
91
 
65
- #### `isConnected()`
92
+ #### `unlockPallet(address, palletNumber, color, options?)`
93
+ Unlock specific pallet with color and effects
94
+ ```typescript
95
+ await ioboard.unlockPallet(1, 3, 'GREEN', {
96
+ intensity: 100, // 0-100
97
+ blinkTimes: 3, // Number of blinks (0 = solid)
98
+ blinkSpeed: 2 // Blink speed (1-5)
99
+ });
66
100
 
67
- Checks if a serial connection is active.
101
+ // Using custom RGB color
102
+ await ioboard.unlockPallet(1, 5, { red: 255, green: 128, blue: 0 });
103
+ ```
68
104
 
105
+ #### `setAllPalletsColor(address, color, options?)`
106
+ Set color for all 8 pallets
69
107
  ```typescript
70
- const status = await CapacitorIoboard.isConnected();
71
- console.log('Connected:', status.connected);
108
+ await ioboard.setAllPalletsColor(1, 'BLUE', {
109
+ intensity: 80,
110
+ blinkTimes: 0 // Solid color
111
+ });
72
112
  ```
73
113
 
74
- ### Device Control
114
+ #### `controlMultipleLEDs(address, ledConfigs)`
115
+ Control each pallet individually
116
+ ```typescript
117
+ const configs = [
118
+ { color: 'RED', intensity: 100 },
119
+ { color: 'GREEN', intensity: 90 },
120
+ { color: 'BLUE', intensity: 80 },
121
+ { color: { red: 255, green: 128, blue: 0 }, intensity: 70 },
122
+ // ... up to 8 configurations
123
+ ];
124
+
125
+ await ioboard.controlMultipleLEDs(1, configs);
126
+ ```
75
127
 
76
- #### `queryStatus(options)`
128
+ ### 🎨 Predefined Colors
77
129
 
78
- Queries the status of an IOBOARD device.
130
+ Available color presets:
131
+ - `RED`, `GREEN`, `BLUE`
132
+ - `YELLOW`, `MAGENTA`, `CYAN`
133
+ - `WHITE`, `OFF`
134
+ - `ORANGE`, `PURPLE`, `PINK`, `LIME`
79
135
 
80
136
  ```typescript
81
- const response = await CapacitorIoboard.queryStatus({ address: 1 });
137
+ // Using predefined colors
138
+ await ioboard.unlockPallet(1, 0, 'PURPLE');
82
139
 
83
- if (response.success && response.data) {
84
- console.log('Door Lock Status:', response.data.doorLockStatus);
85
- console.log('Software Version:', response.data.softwareVersion);
86
- }
87
- ```
88
-
89
- **Parameters:**
140
+ // Using custom RGB
141
+ await ioboard.unlockPallet(1, 1, { red: 128, green: 64, blue: 192 });
90
142
 
91
- | Name | Type | Description |
92
- |---------|--------|------------------------------------|
93
- | address | number | IOBOARD address (1-63) |
143
+ // Get available colors
144
+ const colors = ioboard.getColorPresets();
145
+ ```
94
146
 
95
- **Response:**
147
+ ### 🚀 OTA Firmware Update
96
148
 
149
+ #### `startOTAUpdate(address, fileName, fileSize)`
150
+ Initialize OTA update process
97
151
  ```typescript
98
- {
99
- success: boolean;
100
- message?: string;
101
- data?: {
102
- doorLockStatus: number; // 8-bit status (each bit represents a lock)
103
- softwareVersion: {
104
- major: number;
105
- minor: number;
106
- patch: number;
107
- };
108
- };
109
- }
152
+ await ioboard.startOTAUpdate(1, 'firmware.bin', 32768);
110
153
  ```
111
154
 
112
- #### `controlSinglePallet(options)`
113
-
114
- Controls a single pallet on the IOBOARD.
115
-
155
+ #### `sendOTAData(address, packetNumber, data)`
156
+ Send OTA data packet
116
157
  ```typescript
117
- const response = await CapacitorIoboard.controlSinglePallet({
118
- address: 1,
119
- palletNumber: 0,
120
- doorLock: true, // true = unlock, false = no action
121
- ledControl: {
122
- red: 255,
123
- green: 0,
124
- blue: 0,
125
- intensity: 100,
126
- blinkTimes: 5,
127
- blinkSpeed: 2
128
- }
129
- });
158
+ await ioboard.sendOTAData(1, 0, [0x48, 0x65, 0x6C, 0x6C, 0x6F]); // "Hello"
130
159
  ```
131
160
 
132
- **Parameters:**
161
+ #### `performOTAUpdate(address, file, onProgress?)`
162
+ Complete OTA update with progress callback
163
+ ```typescript
164
+ const file = new File([firmwareData], 'firmware.bin');
133
165
 
134
- | Name | Type | Description |
135
- |--------------|-------------------|-----------------------------------|
136
- | address | number | IOBOARD address (1-63) |
137
- | palletNumber | number | Pallet number (0-7) |
138
- | doorLock | boolean | true = unlock, false = no action |
139
- | ledControl | LEDControlOptions | LED control parameters |
166
+ await ioboard.performOTAUpdate(1, file, (progress, packet, total) => {
167
+ console.log(\`Progress: \${progress.toFixed(1)}% (\${packet}/\${total})\`);
168
+ });
169
+ ```
140
170
 
141
- #### `controlFullPallet(options)`
171
+ ### 📡 Event Handling
142
172
 
143
- Controls all pallets on the IOBOARD.
173
+ #### `addDataReceivedListener(callback)`
174
+ Listen for data received from device
175
+ ```typescript
176
+ await ioboard.addDataReceivedListener((event) => {
177
+ console.log('Data received:', event);
178
+ });
179
+ ```
144
180
 
181
+ #### `addConnectionStateListener(callback)`
182
+ Listen for connection state changes
145
183
  ```typescript
146
- const ledControls = Array(8).fill({
147
- red: 0, green: 255, blue: 0,
148
- intensity: 50, blinkTimes: 0, blinkSpeed: 0
184
+ await ioboard.addConnectionStateListener((event) => {
185
+ console.log(\`Connection: \${event.connected}\`);
149
186
  });
187
+ ```
150
188
 
151
- const response = await CapacitorIoboard.controlFullPallet({
152
- address: 1,
153
- doorLockControl: 0xFF, // 8-bit mask (unlock all)
154
- extendedControl: 0x00,
155
- ledControls: ledControls
189
+ #### `addSerialErrorListener(callback)`
190
+ Listen for serial communication errors
191
+ ```typescript
192
+ await ioboard.addSerialErrorListener((event) => {
193
+ console.error('Serial error:', event.error);
156
194
  });
157
195
  ```
158
196
 
159
- **Parameters:**
197
+ #### `removeAllListeners()`
198
+ Remove all event listeners
199
+ ```typescript
200
+ await ioboard.removeAllListeners();
201
+ ```
160
202
 
161
- | Name | Type | Description |
162
- |-----------------|---------------------|--------------------------------|
163
- | address | number | IOBOARD address (1-63) |
164
- | doorLockControl | number | 8-bit mask for door control |
165
- | extendedControl | number | Extended control byte |
166
- | ledControls | LEDControlOptions[] | Array of 8 LED control configs |
203
+ ## 🛠️ Utility Methods
167
204
 
168
- ### LED Control Options
205
+ #### `getConnectionInfo()`
206
+ Get current connection information
207
+ ```typescript
208
+ const info = ioboard.getConnectionInfo();
209
+ console.log(info.isConnected, info.currentPort);
210
+ ```
169
211
 
212
+ #### `createColor(red, green, blue)`
213
+ Create RGB color object
170
214
  ```typescript
171
- interface LEDControlOptions {
172
- red: number; // 0-255
173
- green: number; // 0-255
174
- blue: number; // 0-255
175
- intensity: number; // 0-255 (0=off, 1-100=percentage, 101-255=max)
176
- blinkTimes: number; // 0-255 (0=no blink, 255=infinite)
177
- blinkSpeed: number; // 1-30 seconds interval
178
- }
215
+ const orange = ioboard.createColor(255, 165, 0);
216
+ await ioboard.unlockPallet(1, 0, orange);
179
217
  ```
180
218
 
181
- ### OTA (Over-The-Air) Updates
219
+ ## 🌟 React Component Example
182
220
 
183
- #### `otaNotification(options)`
221
+ ```jsx
222
+ import React, { useState, useEffect } from 'react';
223
+ import { ioboard } from '@leonardojc/capacitor-ioboard';
184
224
 
185
- Sends an OTA update notification to the IOBOARD.
225
+ const IOBoardController = () => {
226
+ const [isConnected, setIsConnected] = useState(false);
186
227
 
187
- ```typescript
188
- const response = await CapacitorIoboard.otaNotification({
189
- address: 1,
190
- majorVersion: 1,
191
- minorVersion: 1,
192
- patchVersion: 0,
193
- firmwareSize: 65536 // Size in bytes
194
- });
195
- ```
228
+ useEffect(() => {
229
+ // Setup event listeners
230
+ ioboard.addConnectionStateListener((event) => {
231
+ setIsConnected(event.connected);
232
+ });
196
233
 
197
- #### `otaData(options)`
234
+ return () => {
235
+ ioboard.removeAllListeners();
236
+ };
237
+ }, []);
198
238
 
199
- Sends an OTA data packet to the IOBOARD.
239
+ const handleConnect = async () => {
240
+ const result = await ioboard.connect('/dev/ttyS2');
241
+ if (result.success) {
242
+ console.log('Connected successfully!');
243
+ }
244
+ };
200
245
 
201
- ```typescript
202
- const response = await CapacitorIoboard.otaData({
203
- address: 1,
204
- packetNumber: 0,
205
- data: 'base64EncodedFirmwareData...' // Base64 encoded, max 128 bytes
206
- });
246
+ const handleUnlockPallet = async (pallet) => {
247
+ await ioboard.unlockPallet(1, pallet, 'GREEN', {
248
+ intensity: 100,
249
+ blinkTimes: 3
250
+ });
251
+ };
252
+
253
+ return (
254
+ <div>
255
+ <button onClick={handleConnect} disabled={isConnected}>
256
+ {isConnected ? 'Connected' : 'Connect'}
257
+ </button>
258
+
259
+ {isConnected && (
260
+ <div>
261
+ {[0,1,2,3,4,5,6,7].map(pallet => (
262
+ <button
263
+ key={pallet}
264
+ onClick={() => handleUnlockPallet(pallet)}
265
+ >
266
+ Unlock Pallet {pallet}
267
+ </button>
268
+ ))}
269
+ </div>
270
+ )}
271
+ </div>
272
+ );
273
+ };
207
274
  ```
208
275
 
209
- ## Protocol Details
276
+ ## 📋 MTC3P08L Protocol
210
277
 
211
- The plugin implements the IOBOARD MTC3P08L communication protocol:
278
+ The plugin implements the complete MTC3P08L protocol:
212
279
 
213
- - **Baud Rate:** 115200 bps
214
- - **Data Format:** 8N1 (8 data bits, no parity, 1 stop bit)
215
- - **Frame Structure:** SOI (0x0D) + Address + FrameType + Data + CRC16 + EOI (0x0A)
216
- - **CRC:** CRC-16 CCITT checksum
217
- - **Address Range:** 1-63
218
- - **Response Timeout:** Configurable (default 5000ms)
280
+ - **Device Status** - Get firmware version, temperature, voltage
281
+ - **Pallet Control** - Individual pallet unlock with RGB LEDs
282
+ - **Multiple Control** - Control all 8 pallets simultaneously
283
+ - **OTA Updates** - Complete firmware update support
284
+ - **Error Handling** - Comprehensive error reporting
219
285
 
220
- ## Error Handling
286
+ ## 🔧 Configuration
221
287
 
222
- All methods return a response object with a `success` boolean field:
288
+ Default connection settings:
289
+ - **Baud Rate**: 115200
290
+ - **Data Bits**: 8
291
+ - **Stop Bits**: 1
292
+ - **Parity**: None
293
+ - **Default Port**: '/dev/ttyS2'
223
294
 
224
- ```typescript
225
- const response = await CapacitorIoboard.queryStatus({ address: 1 });
226
-
227
- if (response.success) {
228
- console.log('Operation successful:', response.message);
229
- // Use response.data if available
230
- } else {
231
- console.error('Operation failed:', response.message);
232
- }
233
- ```
295
+ ## 🌐 Platform Support
296
+
297
+ - ✅ **Android** - Full native support
298
+ - **iOS** - Full native support
299
+ - **Web** - Simulation mode for testing
234
300
 
235
- ## Example Usage
301
+ ## 🆚 Migration from v1.x
236
302
 
303
+ Version 2.0 is a complete rewrite with breaking changes:
304
+
305
+ ### Before (v1.x - Two plugins)
237
306
  ```typescript
307
+ // Required two separate plugins
308
+ import { CapacitorSerialPort } from '@leonardojc/capacitor-serial-port';
238
309
  import { CapacitorIoboard } from '@leonardojc/capacitor-ioboard';
239
310
 
240
- class IOBoardController {
241
- async initialize() {
242
- // Open serial connection
243
- const connection = await CapacitorIoboard.openConnection({
244
- baudRate: 115200,
245
- timeout: 5000
246
- });
247
-
248
- if (!connection.success) {
249
- throw new Error('Failed to open connection');
250
- }
251
-
252
- console.log('Connection established');
253
- }
254
-
255
- async unlockPallet(address: number, palletNumber: number) {
256
- const response = await CapacitorIoboard.controlSinglePallet({
257
- address,
258
- palletNumber,
259
- doorLock: true,
260
- ledControl: {
261
- red: 0, green: 255, blue: 0, // Green light
262
- intensity: 100,
263
- blinkTimes: 3,
264
- blinkSpeed: 1
265
- }
266
- });
267
-
268
- return response.success;
269
- }
270
-
271
- async getDeviceStatus(address: number) {
272
- const response = await CapacitorIoboard.queryStatus({ address });
273
-
274
- if (response.success && response.data) {
275
- return {
276
- doorStatus: response.data.doorLockStatus,
277
- version: response.data.softwareVersion
278
- };
279
- }
280
-
281
- return null;
282
- }
283
- }
311
+ // Complex coordination required
312
+ await CapacitorSerialPort.connect({...});
313
+ await CapacitorIoboard.unlockPallet({...});
314
+ ```
315
+
316
+ ### After (v2.0 - Single plugin)
317
+ ```typescript
318
+ // Single integrated plugin
319
+ import { ioboard } from '@leonardojc/capacitor-ioboard';
320
+
321
+ // Simple, unified API
322
+ await ioboard.connect('/dev/ttyS2');
323
+ await ioboard.unlockPallet(1, 3, 'GREEN');
284
324
  ```
285
325
 
286
- ## License
326
+ ## 🔗 Links
327
+
328
+ - **NPM Package**: [@leonardojc/capacitor-ioboard](https://www.npmjs.com/package/@leonardojc/capacitor-ioboard)
329
+ - **GitHub**: [IOBoard Plugin Repository](#)
330
+ - **Documentation**: [Complete API Docs](#)
331
+
332
+ ## 📄 License
333
+
334
+ MIT License - see LICENSE file for details.
287
335
 
288
- MIT
336
+ ---
289
337
 
290
- ## Author
338
+ ### 🎉 IOBoard v2.0 - Simplified, Powerful, Complete!
291
339
 
292
- Leonardo JC - [@leonardojc](https://github.com/leonardojc)
340
+ Single plugin, comprehensive control, zero hassle. Everything you need for IOBoard device integration.
@@ -33,7 +33,6 @@ repositories {
33
33
  dependencies {
34
34
  implementation fileTree(dir: 'libs', include: ['*.jar'])
35
35
  implementation project(':capacitor-android')
36
- implementation project(':leonardojc-capacitor-serial-port') // SerialPort plugin dependency
37
36
  testImplementation 'junit:junit:4.13.2'
38
37
  androidTestImplementation 'androidx.test.ext:junit:1.1.5'
39
38
  androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'