@leonardojc/capacitor-ioboard 2.0.1 → 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");
|
|
@@ -635,6 +648,80 @@ public class CapacitorIoboardPlugin extends Plugin implements SerialConnectionMa
|
|
|
635
648
|
}
|
|
636
649
|
}
|
|
637
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
|
+
|
|
638
725
|
// Create MTC3P08L protocol frame for unlock pallet command
|
|
639
726
|
private byte[] createUnlockPalletFrame(int address, int palletNumber, String ledColor) {
|
|
640
727
|
// MTC3P08L Protocol Frame Structure (según documentación):
|
|
@@ -654,33 +741,10 @@ public class CapacitorIoboardPlugin extends Plugin implements SerialConnectionMa
|
|
|
654
741
|
byte doorLock = 0x01; // LOCK: 1=unlock, 0=no action
|
|
655
742
|
|
|
656
743
|
// LED section (6 bytes): [RGB_R][RGB_G][RGB_B][Intensity][BlinkTimes][BlinkSpeed]
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
break;
|
|
662
|
-
case "green":
|
|
663
|
-
green = (byte) 255;
|
|
664
|
-
break;
|
|
665
|
-
case "blue":
|
|
666
|
-
blue = (byte) 255;
|
|
667
|
-
break;
|
|
668
|
-
case "white":
|
|
669
|
-
red = green = blue = (byte) 255;
|
|
670
|
-
break;
|
|
671
|
-
case "yellow":
|
|
672
|
-
red = green = (byte) 255;
|
|
673
|
-
break;
|
|
674
|
-
case "cyan":
|
|
675
|
-
green = blue = (byte) 255;
|
|
676
|
-
break;
|
|
677
|
-
case "magenta":
|
|
678
|
-
red = blue = (byte) 255;
|
|
679
|
-
break;
|
|
680
|
-
default:
|
|
681
|
-
green = (byte) 255; // Default to green
|
|
682
|
-
break;
|
|
683
|
-
}
|
|
744
|
+
int[] rgb = parseColorToRGB(ledColor);
|
|
745
|
+
byte red = (byte) rgb[0];
|
|
746
|
+
byte green = (byte) rgb[1];
|
|
747
|
+
byte blue = (byte) rgb[2];
|
|
684
748
|
|
|
685
749
|
byte intensity = (byte) 255; // Max intensity
|
|
686
750
|
byte blinkTimes = 16; // 16 veces como en el ejemplo
|
|
@@ -730,40 +794,11 @@ public class CapacitorIoboardPlugin extends Plugin implements SerialConnectionMa
|
|
|
730
794
|
|
|
731
795
|
byte extControl = (byte) 0x80; // Extended output control (fixed as per example)
|
|
732
796
|
|
|
733
|
-
// Convert color to RGB
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
break;
|
|
739
|
-
case "GREEN":
|
|
740
|
-
green = (byte) 0xFF;
|
|
741
|
-
break;
|
|
742
|
-
case "BLUE":
|
|
743
|
-
blue = (byte) 0xFF;
|
|
744
|
-
break;
|
|
745
|
-
case "YELLOW":
|
|
746
|
-
red = (byte) 0xFF;
|
|
747
|
-
green = (byte) 0xFF;
|
|
748
|
-
break;
|
|
749
|
-
case "PURPLE":
|
|
750
|
-
red = (byte) 0xFF;
|
|
751
|
-
blue = (byte) 0xFF;
|
|
752
|
-
break;
|
|
753
|
-
case "CYAN":
|
|
754
|
-
green = (byte) 0xFF;
|
|
755
|
-
blue = (byte) 0xFF;
|
|
756
|
-
break;
|
|
757
|
-
case "WHITE":
|
|
758
|
-
red = (byte) 0xFF;
|
|
759
|
-
green = (byte) 0xFF;
|
|
760
|
-
blue = (byte) 0xFF;
|
|
761
|
-
break;
|
|
762
|
-
default:
|
|
763
|
-
Log.w(TAG, "⚠️ Unknown color: " + color + ", using RED as default");
|
|
764
|
-
red = (byte) 0xFF;
|
|
765
|
-
break;
|
|
766
|
-
}
|
|
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];
|
|
767
802
|
|
|
768
803
|
// Build data array for CRC calculation
|
|
769
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",
|