@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 +257 -209
- package/android/build.gradle +0 -1
- package/android/src/main/java/com/leonardojc/capacitor/ioboard/CapacitorIoboardPlugin.java +926 -381
- package/android/src/main/java/com/leonardojc/capacitor/ioboard/CapacitorIoboardPlugin.java.backup +777 -0
- package/android/src/main/java/com/leonardojc/capacitor/ioboard/SerialConnectionManager.java +446 -0
- package/dist/esm/definitions-v2.d.ts +228 -0
- package/dist/esm/definitions-v2.js +11 -0
- package/dist/esm/definitions.d.ts +28 -0
- package/dist/esm/index-v2.d.ts +266 -0
- package/dist/esm/index-v2.js +295 -0
- package/dist/esm/web.d.ts +13 -16
- package/dist/esm/web.js +51 -135
- package/dist/plugin.cjs.js +50 -134
- package/dist/plugin.cjs.js.map +1 -1
- package/dist/plugin.js +50 -134
- package/dist/plugin.js.map +1 -1
- package/package.json +3 -4
|
@@ -1,4 +1,12 @@
|
|
|
1
1
|
export interface CapacitorIoboardPlugin {
|
|
2
|
+
/**
|
|
3
|
+
* List available serial ports
|
|
4
|
+
*/
|
|
5
|
+
listPorts(): Promise<{
|
|
6
|
+
success: boolean;
|
|
7
|
+
ports: string[];
|
|
8
|
+
error?: string;
|
|
9
|
+
}>;
|
|
2
10
|
/**
|
|
3
11
|
* Open serial connection to IOBOARD device
|
|
4
12
|
* @param options Serial connection parameters
|
|
@@ -14,6 +22,26 @@ export interface CapacitorIoboardPlugin {
|
|
|
14
22
|
isConnected(): Promise<{
|
|
15
23
|
connected: boolean;
|
|
16
24
|
}>;
|
|
25
|
+
/**
|
|
26
|
+
* Get connection status and device info
|
|
27
|
+
*/
|
|
28
|
+
getConnectionStatus(): Promise<{
|
|
29
|
+
success: boolean;
|
|
30
|
+
isConnected: boolean;
|
|
31
|
+
deviceInfo?: string;
|
|
32
|
+
lastError?: string;
|
|
33
|
+
}>;
|
|
34
|
+
/**
|
|
35
|
+
* Send raw command to serial port
|
|
36
|
+
*/
|
|
37
|
+
sendRawCommand(options: {
|
|
38
|
+
command: string;
|
|
39
|
+
}): Promise<{
|
|
40
|
+
success: boolean;
|
|
41
|
+
command: string;
|
|
42
|
+
hexSent?: string;
|
|
43
|
+
error?: string;
|
|
44
|
+
}>;
|
|
17
45
|
/**
|
|
18
46
|
* Query the status of an IOBOARD device
|
|
19
47
|
* @param options Device address and timeout
|
|
@@ -0,0 +1,266 @@
|
|
|
1
|
+
import type { CapacitorIoboardPlugin, RGBColor } from './definitions-v2';
|
|
2
|
+
declare const COLOR_PRESETS: {
|
|
3
|
+
readonly RED: {
|
|
4
|
+
readonly red: 255;
|
|
5
|
+
readonly green: 0;
|
|
6
|
+
readonly blue: 0;
|
|
7
|
+
};
|
|
8
|
+
readonly GREEN: {
|
|
9
|
+
readonly red: 0;
|
|
10
|
+
readonly green: 255;
|
|
11
|
+
readonly blue: 0;
|
|
12
|
+
};
|
|
13
|
+
readonly BLUE: {
|
|
14
|
+
readonly red: 0;
|
|
15
|
+
readonly green: 0;
|
|
16
|
+
readonly blue: 255;
|
|
17
|
+
};
|
|
18
|
+
readonly YELLOW: {
|
|
19
|
+
readonly red: 255;
|
|
20
|
+
readonly green: 255;
|
|
21
|
+
readonly blue: 0;
|
|
22
|
+
};
|
|
23
|
+
readonly MAGENTA: {
|
|
24
|
+
readonly red: 255;
|
|
25
|
+
readonly green: 0;
|
|
26
|
+
readonly blue: 255;
|
|
27
|
+
};
|
|
28
|
+
readonly CYAN: {
|
|
29
|
+
readonly red: 0;
|
|
30
|
+
readonly green: 255;
|
|
31
|
+
readonly blue: 255;
|
|
32
|
+
};
|
|
33
|
+
readonly WHITE: {
|
|
34
|
+
readonly red: 255;
|
|
35
|
+
readonly green: 255;
|
|
36
|
+
readonly blue: 255;
|
|
37
|
+
};
|
|
38
|
+
readonly OFF: {
|
|
39
|
+
readonly red: 0;
|
|
40
|
+
readonly green: 0;
|
|
41
|
+
readonly blue: 0;
|
|
42
|
+
};
|
|
43
|
+
readonly ORANGE: {
|
|
44
|
+
readonly red: 255;
|
|
45
|
+
readonly green: 165;
|
|
46
|
+
readonly blue: 0;
|
|
47
|
+
};
|
|
48
|
+
readonly PURPLE: {
|
|
49
|
+
readonly red: 128;
|
|
50
|
+
readonly green: 0;
|
|
51
|
+
readonly blue: 128;
|
|
52
|
+
};
|
|
53
|
+
readonly PINK: {
|
|
54
|
+
readonly red: 255;
|
|
55
|
+
readonly green: 192;
|
|
56
|
+
readonly blue: 203;
|
|
57
|
+
};
|
|
58
|
+
readonly LIME: {
|
|
59
|
+
readonly red: 50;
|
|
60
|
+
readonly green: 205;
|
|
61
|
+
readonly blue: 50;
|
|
62
|
+
};
|
|
63
|
+
};
|
|
64
|
+
declare const CapacitorIoboard: CapacitorIoboardPlugin;
|
|
65
|
+
/**
|
|
66
|
+
* IOBoard v2.0 - Integrated Serial + Protocol Plugin
|
|
67
|
+
*
|
|
68
|
+
* This plugin provides a unified interface for IOBoard devices with integrated
|
|
69
|
+
* serial communication and complete MTC3P08L protocol support.
|
|
70
|
+
*
|
|
71
|
+
* Key Features:
|
|
72
|
+
* - Direct serial port management
|
|
73
|
+
* - Complete MTC3P08L protocol implementation
|
|
74
|
+
* - OTA firmware update support
|
|
75
|
+
* - RGB LED control for 8 pallets
|
|
76
|
+
* - Event-driven architecture
|
|
77
|
+
* - No external dependencies
|
|
78
|
+
*/
|
|
79
|
+
declare class IOBoard {
|
|
80
|
+
private plugin;
|
|
81
|
+
private isConnected;
|
|
82
|
+
private currentPort;
|
|
83
|
+
/**
|
|
84
|
+
* Connect to IOBoard device
|
|
85
|
+
* @param portPath Serial port path (default: '/dev/ttyS2')
|
|
86
|
+
* @param baudRate Baud rate (default: 115200)
|
|
87
|
+
*/
|
|
88
|
+
connect(portPath?: string, baudRate?: number): Promise<import("./definitions-v2").ConnectionResponse>;
|
|
89
|
+
/**
|
|
90
|
+
* Disconnect from IOBoard device
|
|
91
|
+
*/
|
|
92
|
+
disconnect(): Promise<import("./definitions-v2").BasicResponse>;
|
|
93
|
+
/**
|
|
94
|
+
* Check connection status
|
|
95
|
+
*/
|
|
96
|
+
isDeviceConnected(): Promise<import("./definitions-v2").ConnectionStatusResponse>;
|
|
97
|
+
/**
|
|
98
|
+
* List available serial ports
|
|
99
|
+
*/
|
|
100
|
+
listPorts(): Promise<import("./definitions-v2").PortListResponse>;
|
|
101
|
+
/**
|
|
102
|
+
* Get device status
|
|
103
|
+
* @param address Device address (1-255)
|
|
104
|
+
*/
|
|
105
|
+
getStatus(address?: number): Promise<import("./definitions-v2").StatusResponse>;
|
|
106
|
+
/**
|
|
107
|
+
* Unlock specific pallet with color
|
|
108
|
+
* @param address Device address
|
|
109
|
+
* @param palletNumber Pallet number (0-7)
|
|
110
|
+
* @param color RGB color or color name
|
|
111
|
+
* @param options Additional LED options
|
|
112
|
+
*/
|
|
113
|
+
unlockPallet(address: number, palletNumber: number, color?: RGBColor | keyof typeof COLOR_PRESETS, options?: {
|
|
114
|
+
intensity?: number;
|
|
115
|
+
blinkTimes?: number;
|
|
116
|
+
blinkSpeed?: number;
|
|
117
|
+
}): Promise<import("./definitions-v2").BasicResponse>;
|
|
118
|
+
/**
|
|
119
|
+
* Set color for all pallets
|
|
120
|
+
* @param address Device address
|
|
121
|
+
* @param color RGB color or color name
|
|
122
|
+
* @param options Additional LED options
|
|
123
|
+
*/
|
|
124
|
+
setAllPalletsColor(address: number, color: RGBColor | keyof typeof COLOR_PRESETS, options?: {
|
|
125
|
+
intensity?: number;
|
|
126
|
+
blinkTimes?: number;
|
|
127
|
+
blinkSpeed?: number;
|
|
128
|
+
}): Promise<import("./definitions-v2").BasicResponse>;
|
|
129
|
+
/**
|
|
130
|
+
* Control multiple LEDs individually
|
|
131
|
+
* @param address Device address
|
|
132
|
+
* @param ledConfigs Array of LED configurations for 8 pallets
|
|
133
|
+
*/
|
|
134
|
+
controlMultipleLEDs(address: number, ledConfigs: Array<{
|
|
135
|
+
color: RGBColor | keyof typeof COLOR_PRESETS;
|
|
136
|
+
intensity?: number;
|
|
137
|
+
blinkTimes?: number;
|
|
138
|
+
blinkSpeed?: number;
|
|
139
|
+
}>): Promise<import("./definitions-v2").BasicResponse>;
|
|
140
|
+
/**
|
|
141
|
+
* Start OTA firmware update
|
|
142
|
+
* @param address Device address
|
|
143
|
+
* @param fileName Firmware file name
|
|
144
|
+
* @param fileSize File size in bytes
|
|
145
|
+
*/
|
|
146
|
+
startOTAUpdate(address: number, fileName: string, fileSize: number): Promise<import("./definitions-v2").BasicResponse>;
|
|
147
|
+
/**
|
|
148
|
+
* Send OTA data packet
|
|
149
|
+
* @param address Device address
|
|
150
|
+
* @param packetNumber Packet sequence number
|
|
151
|
+
* @param data Data payload (up to 128 bytes)
|
|
152
|
+
*/
|
|
153
|
+
sendOTAData(address: number, packetNumber: number, data: number[]): Promise<import("./definitions-v2").BasicResponse>;
|
|
154
|
+
/**
|
|
155
|
+
* Perform complete OTA update with progress callback
|
|
156
|
+
* @param address Device address
|
|
157
|
+
* @param file File to upload
|
|
158
|
+
* @param onProgress Progress callback
|
|
159
|
+
*/
|
|
160
|
+
performOTAUpdate(address: number, file: File, onProgress?: (progress: number, packet: number, total: number) => void): Promise<{
|
|
161
|
+
success: boolean;
|
|
162
|
+
message: string;
|
|
163
|
+
error?: undefined;
|
|
164
|
+
} | {
|
|
165
|
+
success: boolean;
|
|
166
|
+
error: string;
|
|
167
|
+
message?: undefined;
|
|
168
|
+
}>;
|
|
169
|
+
/**
|
|
170
|
+
* Add data received event listener
|
|
171
|
+
*/
|
|
172
|
+
addDataReceivedListener(callback: (event: any) => void): Promise<import("./definitions-v2").PluginListenerHandle>;
|
|
173
|
+
/**
|
|
174
|
+
* Add connection state changed event listener
|
|
175
|
+
*/
|
|
176
|
+
addConnectionStateListener(callback: (event: any) => void): Promise<import("./definitions-v2").PluginListenerHandle>;
|
|
177
|
+
/**
|
|
178
|
+
* Add serial error event listener
|
|
179
|
+
*/
|
|
180
|
+
addSerialErrorListener(callback: (event: any) => void): Promise<import("./definitions-v2").PluginListenerHandle>;
|
|
181
|
+
/**
|
|
182
|
+
* Remove all event listeners
|
|
183
|
+
*/
|
|
184
|
+
removeAllListeners(): Promise<void>;
|
|
185
|
+
/**
|
|
186
|
+
* Get current connection info
|
|
187
|
+
*/
|
|
188
|
+
getConnectionInfo(): {
|
|
189
|
+
isConnected: boolean;
|
|
190
|
+
currentPort: string | null;
|
|
191
|
+
};
|
|
192
|
+
/**
|
|
193
|
+
* Create RGB color object
|
|
194
|
+
*/
|
|
195
|
+
static createColor(red: number, green: number, blue: number): RGBColor;
|
|
196
|
+
/**
|
|
197
|
+
* Get predefined colors
|
|
198
|
+
*/
|
|
199
|
+
static getColorPresets(): {
|
|
200
|
+
readonly RED: {
|
|
201
|
+
readonly red: 255;
|
|
202
|
+
readonly green: 0;
|
|
203
|
+
readonly blue: 0;
|
|
204
|
+
};
|
|
205
|
+
readonly GREEN: {
|
|
206
|
+
readonly red: 0;
|
|
207
|
+
readonly green: 255;
|
|
208
|
+
readonly blue: 0;
|
|
209
|
+
};
|
|
210
|
+
readonly BLUE: {
|
|
211
|
+
readonly red: 0;
|
|
212
|
+
readonly green: 0;
|
|
213
|
+
readonly blue: 255;
|
|
214
|
+
};
|
|
215
|
+
readonly YELLOW: {
|
|
216
|
+
readonly red: 255;
|
|
217
|
+
readonly green: 255;
|
|
218
|
+
readonly blue: 0;
|
|
219
|
+
};
|
|
220
|
+
readonly MAGENTA: {
|
|
221
|
+
readonly red: 255;
|
|
222
|
+
readonly green: 0;
|
|
223
|
+
readonly blue: 255;
|
|
224
|
+
};
|
|
225
|
+
readonly CYAN: {
|
|
226
|
+
readonly red: 0;
|
|
227
|
+
readonly green: 255;
|
|
228
|
+
readonly blue: 255;
|
|
229
|
+
};
|
|
230
|
+
readonly WHITE: {
|
|
231
|
+
readonly red: 255;
|
|
232
|
+
readonly green: 255;
|
|
233
|
+
readonly blue: 255;
|
|
234
|
+
};
|
|
235
|
+
readonly OFF: {
|
|
236
|
+
readonly red: 0;
|
|
237
|
+
readonly green: 0;
|
|
238
|
+
readonly blue: 0;
|
|
239
|
+
};
|
|
240
|
+
readonly ORANGE: {
|
|
241
|
+
readonly red: 255;
|
|
242
|
+
readonly green: 165;
|
|
243
|
+
readonly blue: 0;
|
|
244
|
+
};
|
|
245
|
+
readonly PURPLE: {
|
|
246
|
+
readonly red: 128;
|
|
247
|
+
readonly green: 0;
|
|
248
|
+
readonly blue: 128;
|
|
249
|
+
};
|
|
250
|
+
readonly PINK: {
|
|
251
|
+
readonly red: 255;
|
|
252
|
+
readonly green: 192;
|
|
253
|
+
readonly blue: 203;
|
|
254
|
+
};
|
|
255
|
+
readonly LIME: {
|
|
256
|
+
readonly red: 50;
|
|
257
|
+
readonly green: 205;
|
|
258
|
+
readonly blue: 50;
|
|
259
|
+
};
|
|
260
|
+
};
|
|
261
|
+
private checkConnection;
|
|
262
|
+
}
|
|
263
|
+
export declare const ioboard: IOBoard;
|
|
264
|
+
export { CapacitorIoboard };
|
|
265
|
+
export * from './definitions-v2';
|
|
266
|
+
export default ioboard;
|
|
@@ -0,0 +1,295 @@
|
|
|
1
|
+
import { registerPlugin } from '@capacitor/core';
|
|
2
|
+
// Define color presets as constant object
|
|
3
|
+
const COLOR_PRESETS = {
|
|
4
|
+
RED: { red: 255, green: 0, blue: 0 },
|
|
5
|
+
GREEN: { red: 0, green: 255, blue: 0 },
|
|
6
|
+
BLUE: { red: 0, green: 0, blue: 255 },
|
|
7
|
+
YELLOW: { red: 255, green: 255, blue: 0 },
|
|
8
|
+
MAGENTA: { red: 255, green: 0, blue: 255 },
|
|
9
|
+
CYAN: { red: 0, green: 255, blue: 255 },
|
|
10
|
+
WHITE: { red: 255, green: 255, blue: 255 },
|
|
11
|
+
OFF: { red: 0, green: 0, blue: 0 },
|
|
12
|
+
ORANGE: { red: 255, green: 165, blue: 0 },
|
|
13
|
+
PURPLE: { red: 128, green: 0, blue: 128 },
|
|
14
|
+
PINK: { red: 255, green: 192, blue: 203 },
|
|
15
|
+
LIME: { red: 50, green: 205, blue: 50 }
|
|
16
|
+
};
|
|
17
|
+
const CapacitorIoboard = registerPlugin('CapacitorIoboard', {
|
|
18
|
+
web: () => import('./web').then(m => new m.CapacitorIoboardWeb()),
|
|
19
|
+
});
|
|
20
|
+
/**
|
|
21
|
+
* IOBoard v2.0 - Integrated Serial + Protocol Plugin
|
|
22
|
+
*
|
|
23
|
+
* This plugin provides a unified interface for IOBoard devices with integrated
|
|
24
|
+
* serial communication and complete MTC3P08L protocol support.
|
|
25
|
+
*
|
|
26
|
+
* Key Features:
|
|
27
|
+
* - Direct serial port management
|
|
28
|
+
* - Complete MTC3P08L protocol implementation
|
|
29
|
+
* - OTA firmware update support
|
|
30
|
+
* - RGB LED control for 8 pallets
|
|
31
|
+
* - Event-driven architecture
|
|
32
|
+
* - No external dependencies
|
|
33
|
+
*/
|
|
34
|
+
class IOBoard {
|
|
35
|
+
constructor() {
|
|
36
|
+
this.plugin = CapacitorIoboard;
|
|
37
|
+
this.isConnected = false;
|
|
38
|
+
this.currentPort = null;
|
|
39
|
+
}
|
|
40
|
+
// ================== CONNECTION METHODS ==================
|
|
41
|
+
/**
|
|
42
|
+
* Connect to IOBoard device
|
|
43
|
+
* @param portPath Serial port path (default: '/dev/ttyS2')
|
|
44
|
+
* @param baudRate Baud rate (default: 115200)
|
|
45
|
+
*/
|
|
46
|
+
async connect(portPath = '/dev/ttyS2', baudRate = 115200) {
|
|
47
|
+
const result = await this.plugin.connect({
|
|
48
|
+
portPath,
|
|
49
|
+
baudRate,
|
|
50
|
+
dataBits: 8,
|
|
51
|
+
stopBits: 1,
|
|
52
|
+
parity: 'none'
|
|
53
|
+
});
|
|
54
|
+
if (result.success) {
|
|
55
|
+
this.isConnected = true;
|
|
56
|
+
this.currentPort = portPath;
|
|
57
|
+
}
|
|
58
|
+
return result;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Disconnect from IOBoard device
|
|
62
|
+
*/
|
|
63
|
+
async disconnect() {
|
|
64
|
+
const result = await this.plugin.disconnect();
|
|
65
|
+
if (result.success) {
|
|
66
|
+
this.isConnected = false;
|
|
67
|
+
this.currentPort = null;
|
|
68
|
+
}
|
|
69
|
+
return result;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Check connection status
|
|
73
|
+
*/
|
|
74
|
+
async isDeviceConnected() {
|
|
75
|
+
const status = await this.plugin.isConnected();
|
|
76
|
+
this.isConnected = status.connected;
|
|
77
|
+
return status;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* List available serial ports
|
|
81
|
+
*/
|
|
82
|
+
async listPorts() {
|
|
83
|
+
return await this.plugin.listPorts();
|
|
84
|
+
}
|
|
85
|
+
// ================== IOBoard DEVICE METHODS ==================
|
|
86
|
+
/**
|
|
87
|
+
* Get device status
|
|
88
|
+
* @param address Device address (1-255)
|
|
89
|
+
*/
|
|
90
|
+
async getStatus(address = 1) {
|
|
91
|
+
this.checkConnection();
|
|
92
|
+
return await this.plugin.getStatus({ address });
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Unlock specific pallet with color
|
|
96
|
+
* @param address Device address
|
|
97
|
+
* @param palletNumber Pallet number (0-7)
|
|
98
|
+
* @param color RGB color or color name
|
|
99
|
+
* @param options Additional LED options
|
|
100
|
+
*/
|
|
101
|
+
async unlockPallet(address, palletNumber, color = 'GREEN', options = {}) {
|
|
102
|
+
var _a, _b, _c;
|
|
103
|
+
this.checkConnection();
|
|
104
|
+
const rgbColor = typeof color === 'string' ? COLOR_PRESETS[color] : color;
|
|
105
|
+
return await this.plugin.unlockPallet({
|
|
106
|
+
address,
|
|
107
|
+
palletNumber,
|
|
108
|
+
red: rgbColor.red,
|
|
109
|
+
green: rgbColor.green,
|
|
110
|
+
blue: rgbColor.blue,
|
|
111
|
+
intensity: (_a = options.intensity) !== null && _a !== void 0 ? _a : 100,
|
|
112
|
+
blinkTimes: (_b = options.blinkTimes) !== null && _b !== void 0 ? _b : 0,
|
|
113
|
+
blinkSpeed: (_c = options.blinkSpeed) !== null && _c !== void 0 ? _c : 1
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Set color for all pallets
|
|
118
|
+
* @param address Device address
|
|
119
|
+
* @param color RGB color or color name
|
|
120
|
+
* @param options Additional LED options
|
|
121
|
+
*/
|
|
122
|
+
async setAllPalletsColor(address, color, options = {}) {
|
|
123
|
+
this.checkConnection();
|
|
124
|
+
const rgbColor = typeof color === 'string' ? COLOR_PRESETS[color] : color;
|
|
125
|
+
// Create LED configuration for all 8 pallets
|
|
126
|
+
const leds = Array(8).fill(null).map(() => {
|
|
127
|
+
var _a, _b, _c;
|
|
128
|
+
return ({
|
|
129
|
+
red: rgbColor.red,
|
|
130
|
+
green: rgbColor.green,
|
|
131
|
+
blue: rgbColor.blue,
|
|
132
|
+
intensity: (_a = options.intensity) !== null && _a !== void 0 ? _a : 100,
|
|
133
|
+
blinkTimes: (_b = options.blinkTimes) !== null && _b !== void 0 ? _b : 0,
|
|
134
|
+
blinkSpeed: (_c = options.blinkSpeed) !== null && _c !== void 0 ? _c : 1
|
|
135
|
+
});
|
|
136
|
+
});
|
|
137
|
+
return await this.plugin.controlMultiple({ address, leds });
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Control multiple LEDs individually
|
|
141
|
+
* @param address Device address
|
|
142
|
+
* @param ledConfigs Array of LED configurations for 8 pallets
|
|
143
|
+
*/
|
|
144
|
+
async controlMultipleLEDs(address, ledConfigs) {
|
|
145
|
+
this.checkConnection();
|
|
146
|
+
const leds = ledConfigs.map(config => {
|
|
147
|
+
var _a, _b, _c;
|
|
148
|
+
const rgbColor = typeof config.color === 'string' ? COLOR_PRESETS[config.color] : config.color;
|
|
149
|
+
return {
|
|
150
|
+
red: rgbColor.red,
|
|
151
|
+
green: rgbColor.green,
|
|
152
|
+
blue: rgbColor.blue,
|
|
153
|
+
intensity: (_a = config.intensity) !== null && _a !== void 0 ? _a : 100,
|
|
154
|
+
blinkTimes: (_b = config.blinkTimes) !== null && _b !== void 0 ? _b : 0,
|
|
155
|
+
blinkSpeed: (_c = config.blinkSpeed) !== null && _c !== void 0 ? _c : 1
|
|
156
|
+
};
|
|
157
|
+
});
|
|
158
|
+
return await this.plugin.controlMultiple({ address, leds });
|
|
159
|
+
}
|
|
160
|
+
// ================== OTA UPDATE METHODS ==================
|
|
161
|
+
/**
|
|
162
|
+
* Start OTA firmware update
|
|
163
|
+
* @param address Device address
|
|
164
|
+
* @param fileName Firmware file name
|
|
165
|
+
* @param fileSize File size in bytes
|
|
166
|
+
*/
|
|
167
|
+
async startOTAUpdate(address, fileName, fileSize) {
|
|
168
|
+
this.checkConnection();
|
|
169
|
+
const totalPackets = Math.ceil(fileSize / 128);
|
|
170
|
+
return await this.plugin.startOTAUpdate({
|
|
171
|
+
address,
|
|
172
|
+
fileName,
|
|
173
|
+
fileSize,
|
|
174
|
+
totalPackets
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* Send OTA data packet
|
|
179
|
+
* @param address Device address
|
|
180
|
+
* @param packetNumber Packet sequence number
|
|
181
|
+
* @param data Data payload (up to 128 bytes)
|
|
182
|
+
*/
|
|
183
|
+
async sendOTAData(address, packetNumber, data) {
|
|
184
|
+
this.checkConnection();
|
|
185
|
+
// Ensure data is exactly 128 bytes
|
|
186
|
+
const paddedData = [...data];
|
|
187
|
+
while (paddedData.length < 128) {
|
|
188
|
+
paddedData.push(0);
|
|
189
|
+
}
|
|
190
|
+
return await this.plugin.sendOTAData({
|
|
191
|
+
address,
|
|
192
|
+
packetNumber,
|
|
193
|
+
data: paddedData.slice(0, 128)
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* Perform complete OTA update with progress callback
|
|
198
|
+
* @param address Device address
|
|
199
|
+
* @param file File to upload
|
|
200
|
+
* @param onProgress Progress callback
|
|
201
|
+
*/
|
|
202
|
+
async performOTAUpdate(address, file, onProgress) {
|
|
203
|
+
this.checkConnection();
|
|
204
|
+
try {
|
|
205
|
+
// Start OTA update
|
|
206
|
+
const startResult = await this.startOTAUpdate(address, file.name, file.size);
|
|
207
|
+
if (!startResult.success) {
|
|
208
|
+
throw new Error(`Failed to start OTA: ${startResult.error}`);
|
|
209
|
+
}
|
|
210
|
+
// Read file data
|
|
211
|
+
const arrayBuffer = await file.arrayBuffer();
|
|
212
|
+
const fileData = new Uint8Array(arrayBuffer);
|
|
213
|
+
const totalPackets = Math.ceil(file.size / 128);
|
|
214
|
+
// Send data packets
|
|
215
|
+
for (let packetNumber = 0; packetNumber < totalPackets; packetNumber++) {
|
|
216
|
+
const start = packetNumber * 128;
|
|
217
|
+
const end = Math.min(start + 128, fileData.length);
|
|
218
|
+
const chunk = Array.from(fileData.slice(start, end));
|
|
219
|
+
const result = await this.sendOTAData(address, packetNumber, chunk);
|
|
220
|
+
if (!result.success) {
|
|
221
|
+
throw new Error(`Failed to send packet ${packetNumber}: ${result.error}`);
|
|
222
|
+
}
|
|
223
|
+
// Report progress
|
|
224
|
+
const progress = ((packetNumber + 1) / totalPackets) * 100;
|
|
225
|
+
onProgress === null || onProgress === void 0 ? void 0 : onProgress(progress, packetNumber + 1, totalPackets);
|
|
226
|
+
// Small delay to prevent overwhelming device
|
|
227
|
+
await new Promise(resolve => setTimeout(resolve, 10));
|
|
228
|
+
}
|
|
229
|
+
return { success: true, message: 'OTA update completed successfully' };
|
|
230
|
+
}
|
|
231
|
+
catch (error) {
|
|
232
|
+
return {
|
|
233
|
+
success: false,
|
|
234
|
+
error: error instanceof Error ? error.message : 'Unknown error during OTA update'
|
|
235
|
+
};
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
// ================== EVENT METHODS ==================
|
|
239
|
+
/**
|
|
240
|
+
* Add data received event listener
|
|
241
|
+
*/
|
|
242
|
+
async addDataReceivedListener(callback) {
|
|
243
|
+
return await this.plugin.addListener('dataReceived', callback);
|
|
244
|
+
}
|
|
245
|
+
/**
|
|
246
|
+
* Add connection state changed event listener
|
|
247
|
+
*/
|
|
248
|
+
async addConnectionStateListener(callback) {
|
|
249
|
+
return await this.plugin.addListener('connectionStateChanged', callback);
|
|
250
|
+
}
|
|
251
|
+
/**
|
|
252
|
+
* Add serial error event listener
|
|
253
|
+
*/
|
|
254
|
+
async addSerialErrorListener(callback) {
|
|
255
|
+
return await this.plugin.addListener('serialError', callback);
|
|
256
|
+
}
|
|
257
|
+
/**
|
|
258
|
+
* Remove all event listeners
|
|
259
|
+
*/
|
|
260
|
+
async removeAllListeners() {
|
|
261
|
+
return await this.plugin.removeAllListeners();
|
|
262
|
+
}
|
|
263
|
+
// ================== UTILITY METHODS ==================
|
|
264
|
+
/**
|
|
265
|
+
* Get current connection info
|
|
266
|
+
*/
|
|
267
|
+
getConnectionInfo() {
|
|
268
|
+
return {
|
|
269
|
+
isConnected: this.isConnected,
|
|
270
|
+
currentPort: this.currentPort
|
|
271
|
+
};
|
|
272
|
+
}
|
|
273
|
+
/**
|
|
274
|
+
* Create RGB color object
|
|
275
|
+
*/
|
|
276
|
+
static createColor(red, green, blue) {
|
|
277
|
+
return { red, green, blue };
|
|
278
|
+
}
|
|
279
|
+
/**
|
|
280
|
+
* Get predefined colors
|
|
281
|
+
*/
|
|
282
|
+
static getColorPresets() {
|
|
283
|
+
return COLOR_PRESETS;
|
|
284
|
+
}
|
|
285
|
+
checkConnection() {
|
|
286
|
+
if (!this.isConnected) {
|
|
287
|
+
throw new Error('Not connected to IOBoard device. Call connect() first.');
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
// Export singleton instance and types
|
|
292
|
+
export const ioboard = new IOBoard();
|
|
293
|
+
export { CapacitorIoboard };
|
|
294
|
+
export * from './definitions-v2';
|
|
295
|
+
export default ioboard;
|
package/dist/esm/web.d.ts
CHANGED
|
@@ -1,17 +1,14 @@
|
|
|
1
|
-
import { WebPlugin } from
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
sendOTANotification(options: OTANotificationOptions): Promise<IOBoardResponse>;
|
|
15
|
-
sendOTAData(options: OTADataOptions): Promise<IOBoardResponse>;
|
|
16
|
-
private getMaskBits;
|
|
1
|
+
import { WebPlugin } from "@capacitor/core";
|
|
2
|
+
export declare class CapacitorIoboardWeb extends WebPlugin {
|
|
3
|
+
constructor();
|
|
4
|
+
connect(options: any): Promise<any>;
|
|
5
|
+
disconnect(): Promise<any>;
|
|
6
|
+
isConnected(): Promise<any>;
|
|
7
|
+
listPorts(): Promise<any>;
|
|
8
|
+
getStatus(options: any): Promise<any>;
|
|
9
|
+
unlockPallet(options: any): Promise<any>;
|
|
10
|
+
controlMultiplePallets(options: any): Promise<any>;
|
|
11
|
+
controlMultiple(options: any): Promise<any>;
|
|
12
|
+
startOTAUpdate(options: any): Promise<any>;
|
|
13
|
+
sendOTAData(options: any): Promise<any>;
|
|
17
14
|
}
|