@leonardojc/capacitor-ioboard 2.0.0 → 2.0.2
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.
|
@@ -187,33 +187,46 @@ public class CapacitorIoboardPlugin extends Plugin implements SerialConnectionMa
|
|
|
187
187
|
}
|
|
188
188
|
|
|
189
189
|
try {
|
|
190
|
-
//
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
int
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
190
|
+
// Leer parámetros del call
|
|
191
|
+
int address = call.getInt("address", 1);
|
|
192
|
+
String color = call.getString("color", "RED");
|
|
193
|
+
int intensity = call.getInt("intensity", 255);
|
|
194
|
+
int blinkTimes = call.getInt("blinkTimes", 16);
|
|
195
|
+
int blinkSpeed = call.getInt("blinkSpeed", 1);
|
|
196
|
+
|
|
197
|
+
// Leer array de pallets
|
|
198
|
+
JSArray palletsArray = call.getArray("pallets");
|
|
199
|
+
List<Integer> pallets = new ArrayList<>();
|
|
200
|
+
if (palletsArray != null) {
|
|
201
|
+
for (int i = 0; i < palletsArray.length(); i++) {
|
|
202
|
+
try {
|
|
203
|
+
pallets.add(palletsArray.getInt(i));
|
|
204
|
+
} catch (Exception e) {
|
|
205
|
+
Log.w(TAG, "Error reading pallet at index " + i);
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
// Si no se especificaron pallets, usar todos (1-8)
|
|
211
|
+
if (pallets.isEmpty()) {
|
|
212
|
+
for (int i = 1; i <= 8; i++) {
|
|
213
|
+
pallets.add(i);
|
|
214
|
+
}
|
|
205
215
|
}
|
|
206
216
|
|
|
207
|
-
|
|
217
|
+
Log.d(TAG, String.format("Parameters - address: %d, color: %s, intensity: %d, blinkTimes: %d, blinkSpeed: %d, pallets: %s",
|
|
218
|
+
address, color, intensity, blinkTimes, blinkSpeed, pallets.toString()));
|
|
219
|
+
|
|
220
|
+
byte[] frame = createMultiplePalletsFrame(address, color, intensity, blinkTimes, blinkSpeed, pallets);
|
|
208
221
|
boolean success = serialManager.writeData(frame);
|
|
209
222
|
|
|
210
223
|
if (success) {
|
|
211
224
|
JSObject result = new JSObject();
|
|
212
225
|
result.put("success", true);
|
|
213
|
-
result.put("message", String.format("
|
|
214
|
-
|
|
226
|
+
result.put("message", String.format("Multiple pallets command sent - %d pallets with %s LEDs (intensity=%d, blink=%d)",
|
|
227
|
+
pallets.size(), color, intensity, blinkTimes));
|
|
215
228
|
result.put("address", address);
|
|
216
|
-
result.put("palletsCount",
|
|
229
|
+
result.put("palletsCount", pallets.size());
|
|
217
230
|
call.resolve(result);
|
|
218
231
|
} else {
|
|
219
232
|
call.reject("Failed to send multiple pallets command");
|
|
@@ -350,8 +363,10 @@ public class CapacitorIoboardPlugin extends Plugin implements SerialConnectionMa
|
|
|
350
363
|
Log.d(TAG, "🔓 unlockPallet called");
|
|
351
364
|
|
|
352
365
|
int address = call.getInt("address", 1);
|
|
353
|
-
|
|
354
|
-
|
|
366
|
+
// Soportar ambos nombres para compatibilidad
|
|
367
|
+
int pallet = call.hasOption("pallet") ? call.getInt("pallet", 0) : call.getInt("palletNumber", 0);
|
|
368
|
+
// Soportar ambos nombres para compatibilidad
|
|
369
|
+
String color = call.hasOption("ledColor") ? call.getString("ledColor", "green") : call.getString("color", "green");
|
|
355
370
|
|
|
356
371
|
Log.d(TAG, String.format("Parameters - address: %d, pallet: %d, color: %s", address, pallet, color));
|
|
357
372
|
|
|
@@ -633,6 +648,80 @@ public class CapacitorIoboardPlugin extends Plugin implements SerialConnectionMa
|
|
|
633
648
|
}
|
|
634
649
|
}
|
|
635
650
|
|
|
651
|
+
// Helper method to parse RGB color from string
|
|
652
|
+
// Accepts: "RED", "255,128,64", "#FF8040", or "rgb(255,128,64)"
|
|
653
|
+
private int[] parseColorToRGB(String color) {
|
|
654
|
+
int[] rgb = new int[3]; // [R, G, B]
|
|
655
|
+
|
|
656
|
+
// Check if it's RGB format: "255,128,64" or "rgb(255,128,64)"
|
|
657
|
+
if (color.contains(",")) {
|
|
658
|
+
String rgbString = color.replace("rgb(", "").replace(")", "").trim();
|
|
659
|
+
String[] parts = rgbString.split(",");
|
|
660
|
+
if (parts.length == 3) {
|
|
661
|
+
try {
|
|
662
|
+
rgb[0] = Integer.parseInt(parts[0].trim());
|
|
663
|
+
rgb[1] = Integer.parseInt(parts[1].trim());
|
|
664
|
+
rgb[2] = Integer.parseInt(parts[2].trim());
|
|
665
|
+
Log.d(TAG, String.format("🎨 Parsed RGB: (%d, %d, %d)", rgb[0], rgb[1], rgb[2]));
|
|
666
|
+
return rgb;
|
|
667
|
+
} catch (NumberFormatException e) {
|
|
668
|
+
Log.w(TAG, "⚠️ Invalid RGB format: " + color);
|
|
669
|
+
}
|
|
670
|
+
}
|
|
671
|
+
}
|
|
672
|
+
|
|
673
|
+
// Check if it's hex format: "#FF8040" or "FF8040"
|
|
674
|
+
if (color.startsWith("#") || (color.length() == 6 && color.matches("[0-9A-Fa-f]+"))) {
|
|
675
|
+
try {
|
|
676
|
+
String hex = color.replace("#", "");
|
|
677
|
+
rgb[0] = Integer.parseInt(hex.substring(0, 2), 16);
|
|
678
|
+
rgb[1] = Integer.parseInt(hex.substring(2, 4), 16);
|
|
679
|
+
rgb[2] = Integer.parseInt(hex.substring(4, 6), 16);
|
|
680
|
+
Log.d(TAG, String.format("🎨 Parsed HEX %s: RGB(%d, %d, %d)", color, rgb[0], rgb[1], rgb[2]));
|
|
681
|
+
return rgb;
|
|
682
|
+
} catch (Exception e) {
|
|
683
|
+
Log.w(TAG, "⚠️ Invalid HEX format: " + color);
|
|
684
|
+
}
|
|
685
|
+
}
|
|
686
|
+
|
|
687
|
+
// Named colors
|
|
688
|
+
switch (color.toUpperCase()) {
|
|
689
|
+
case "RED":
|
|
690
|
+
rgb[0] = 255; rgb[1] = 0; rgb[2] = 0;
|
|
691
|
+
break;
|
|
692
|
+
case "GREEN":
|
|
693
|
+
rgb[0] = 0; rgb[1] = 255; rgb[2] = 0;
|
|
694
|
+
break;
|
|
695
|
+
case "BLUE":
|
|
696
|
+
rgb[0] = 0; rgb[1] = 0; rgb[2] = 255;
|
|
697
|
+
break;
|
|
698
|
+
case "WHITE":
|
|
699
|
+
rgb[0] = 255; rgb[1] = 255; rgb[2] = 255;
|
|
700
|
+
break;
|
|
701
|
+
case "YELLOW":
|
|
702
|
+
rgb[0] = 255; rgb[1] = 255; rgb[2] = 0;
|
|
703
|
+
break;
|
|
704
|
+
case "CYAN":
|
|
705
|
+
rgb[0] = 0; rgb[1] = 255; rgb[2] = 255;
|
|
706
|
+
break;
|
|
707
|
+
case "MAGENTA":
|
|
708
|
+
case "PURPLE":
|
|
709
|
+
rgb[0] = 255; rgb[1] = 0; rgb[2] = 255;
|
|
710
|
+
break;
|
|
711
|
+
case "ORANGE":
|
|
712
|
+
rgb[0] = 255; rgb[1] = 165; rgb[2] = 0;
|
|
713
|
+
break;
|
|
714
|
+
case "PINK":
|
|
715
|
+
rgb[0] = 255; rgb[1] = 192; rgb[2] = 203;
|
|
716
|
+
break;
|
|
717
|
+
default:
|
|
718
|
+
Log.w(TAG, "⚠️ Unknown color: " + color + ", using GREEN as default");
|
|
719
|
+
rgb[0] = 0; rgb[1] = 255; rgb[2] = 0;
|
|
720
|
+
break;
|
|
721
|
+
}
|
|
722
|
+
return rgb;
|
|
723
|
+
}
|
|
724
|
+
|
|
636
725
|
// Create MTC3P08L protocol frame for unlock pallet command
|
|
637
726
|
private byte[] createUnlockPalletFrame(int address, int palletNumber, String ledColor) {
|
|
638
727
|
// MTC3P08L Protocol Frame Structure (según documentación):
|
|
@@ -652,33 +741,10 @@ public class CapacitorIoboardPlugin extends Plugin implements SerialConnectionMa
|
|
|
652
741
|
byte doorLock = 0x01; // LOCK: 1=unlock, 0=no action
|
|
653
742
|
|
|
654
743
|
// LED section (6 bytes): [RGB_R][RGB_G][RGB_B][Intensity][BlinkTimes][BlinkSpeed]
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
break;
|
|
660
|
-
case "green":
|
|
661
|
-
green = (byte) 255;
|
|
662
|
-
break;
|
|
663
|
-
case "blue":
|
|
664
|
-
blue = (byte) 255;
|
|
665
|
-
break;
|
|
666
|
-
case "white":
|
|
667
|
-
red = green = blue = (byte) 255;
|
|
668
|
-
break;
|
|
669
|
-
case "yellow":
|
|
670
|
-
red = green = (byte) 255;
|
|
671
|
-
break;
|
|
672
|
-
case "cyan":
|
|
673
|
-
green = blue = (byte) 255;
|
|
674
|
-
break;
|
|
675
|
-
case "magenta":
|
|
676
|
-
red = blue = (byte) 255;
|
|
677
|
-
break;
|
|
678
|
-
default:
|
|
679
|
-
green = (byte) 255; // Default to green
|
|
680
|
-
break;
|
|
681
|
-
}
|
|
744
|
+
int[] rgb = parseColorToRGB(ledColor);
|
|
745
|
+
byte red = (byte) rgb[0];
|
|
746
|
+
byte green = (byte) rgb[1];
|
|
747
|
+
byte blue = (byte) rgb[2];
|
|
682
748
|
|
|
683
749
|
byte intensity = (byte) 255; // Max intensity
|
|
684
750
|
byte blinkTimes = 16; // 16 veces como en el ejemplo
|
|
@@ -728,40 +794,11 @@ public class CapacitorIoboardPlugin extends Plugin implements SerialConnectionMa
|
|
|
728
794
|
|
|
729
795
|
byte extControl = (byte) 0x80; // Extended output control (fixed as per example)
|
|
730
796
|
|
|
731
|
-
// Convert color to RGB
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
break;
|
|
737
|
-
case "GREEN":
|
|
738
|
-
green = (byte) 0xFF;
|
|
739
|
-
break;
|
|
740
|
-
case "BLUE":
|
|
741
|
-
blue = (byte) 0xFF;
|
|
742
|
-
break;
|
|
743
|
-
case "YELLOW":
|
|
744
|
-
red = (byte) 0xFF;
|
|
745
|
-
green = (byte) 0xFF;
|
|
746
|
-
break;
|
|
747
|
-
case "PURPLE":
|
|
748
|
-
red = (byte) 0xFF;
|
|
749
|
-
blue = (byte) 0xFF;
|
|
750
|
-
break;
|
|
751
|
-
case "CYAN":
|
|
752
|
-
green = (byte) 0xFF;
|
|
753
|
-
blue = (byte) 0xFF;
|
|
754
|
-
break;
|
|
755
|
-
case "WHITE":
|
|
756
|
-
red = (byte) 0xFF;
|
|
757
|
-
green = (byte) 0xFF;
|
|
758
|
-
blue = (byte) 0xFF;
|
|
759
|
-
break;
|
|
760
|
-
default:
|
|
761
|
-
Log.w(TAG, "⚠️ Unknown color: " + color + ", using RED as default");
|
|
762
|
-
red = (byte) 0xFF;
|
|
763
|
-
break;
|
|
764
|
-
}
|
|
797
|
+
// Convert color to RGB using helper method
|
|
798
|
+
int[] rgb = parseColorToRGB(color);
|
|
799
|
+
byte red = (byte) rgb[0];
|
|
800
|
+
byte green = (byte) rgb[1];
|
|
801
|
+
byte blue = (byte) rgb[2];
|
|
765
802
|
|
|
766
803
|
// Build data array for CRC calculation
|
|
767
804
|
// CRC includes SOI + all data up to (but not including) the CRC field itself
|
|
@@ -103,13 +103,13 @@ export interface DeviceOptions {
|
|
|
103
103
|
}
|
|
104
104
|
export interface UnlockPalletOptions extends DeviceOptions {
|
|
105
105
|
palletNumber: number;
|
|
106
|
-
ledColor?:
|
|
106
|
+
ledColor?: string;
|
|
107
107
|
blinkTimes?: number;
|
|
108
108
|
blinkSpeed?: number;
|
|
109
109
|
}
|
|
110
110
|
export interface MultiplePalletOptions extends DeviceOptions {
|
|
111
111
|
doorLockMask: number;
|
|
112
|
-
ledColor?:
|
|
112
|
+
ledColor?: string;
|
|
113
113
|
ledControls?: LEDControlOptions[];
|
|
114
114
|
}
|
|
115
115
|
export interface ScanOptions {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@leonardojc/capacitor-ioboard",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.2",
|
|
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",
|