@hangtime/grip-connect 0.12.0 → 0.13.1
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 +20 -9
- package/dist/cjs/index.d.ts +2 -2
- package/dist/cjs/index.d.ts.map +1 -1
- package/dist/cjs/index.js +3 -3
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/interfaces/command.interface.d.ts +110 -21
- package/dist/cjs/interfaces/command.interface.d.ts.map +1 -1
- package/dist/cjs/interfaces/device/aurora.interface.d.ts +17 -0
- package/dist/cjs/interfaces/device/aurora.interface.d.ts.map +1 -0
- package/dist/cjs/interfaces/device/{kilterboard.interface.js → aurora.interface.js} +1 -1
- package/dist/cjs/interfaces/device/aurora.interface.js.map +1 -0
- package/dist/cjs/interfaces/device/cts500.interface.d.ts +96 -0
- package/dist/cjs/interfaces/device/cts500.interface.d.ts.map +1 -0
- package/dist/cjs/interfaces/device/cts500.interface.js +3 -0
- package/dist/cjs/interfaces/device/cts500.interface.js.map +1 -0
- package/dist/cjs/interfaces/device/forceboard.interface.d.ts +2 -2
- package/dist/cjs/interfaces/device/forceboard.interface.d.ts.map +1 -1
- package/dist/cjs/interfaces/device/motherboard.interface.d.ts +1 -1
- package/dist/cjs/interfaces/device/pb-700bt.interface.d.ts +53 -0
- package/dist/cjs/interfaces/device/pb-700bt.interface.d.ts.map +1 -0
- package/dist/cjs/interfaces/device/pb-700bt.interface.js +3 -0
- package/dist/cjs/interfaces/device/pb-700bt.interface.js.map +1 -0
- package/dist/cjs/interfaces/device/progressor.interface.d.ts +2 -2
- package/dist/cjs/interfaces/device/progressor.interface.d.ts.map +1 -1
- package/dist/cjs/interfaces/index.d.ts +4 -1
- package/dist/cjs/interfaces/index.d.ts.map +1 -1
- package/dist/cjs/interfaces/nordic.interface.d.ts +47 -0
- package/dist/cjs/interfaces/nordic.interface.d.ts.map +1 -0
- package/dist/cjs/interfaces/nordic.interface.js +3 -0
- package/dist/cjs/interfaces/nordic.interface.js.map +1 -0
- package/dist/cjs/models/device/{kilterboard.model.d.ts → aurora.model.d.ts} +82 -40
- package/dist/cjs/models/device/aurora.model.d.ts.map +1 -0
- package/dist/cjs/models/device/aurora.model.js +407 -0
- package/dist/cjs/models/device/aurora.model.js.map +1 -0
- package/dist/cjs/models/device/climbro.model.js +1 -1
- package/dist/cjs/models/device/climbro.model.js.map +1 -1
- package/dist/cjs/models/device/cts500.model.d.ts +173 -0
- package/dist/cjs/models/device/cts500.model.d.ts.map +1 -0
- package/dist/cjs/models/device/cts500.model.js +596 -0
- package/dist/cjs/models/device/cts500.model.js.map +1 -0
- package/dist/cjs/models/device/forceboard.model.d.ts +2 -2
- package/dist/cjs/models/device/forceboard.model.d.ts.map +1 -1
- package/dist/cjs/models/device/forceboard.model.js +9 -16
- package/dist/cjs/models/device/forceboard.model.js.map +1 -1
- package/dist/cjs/models/device/motherboard.model.d.ts +4 -1
- package/dist/cjs/models/device/motherboard.model.d.ts.map +1 -1
- package/dist/cjs/models/device/motherboard.model.js +26 -10
- package/dist/cjs/models/device/motherboard.model.js.map +1 -1
- package/dist/cjs/models/device/pb-700bt.model.d.ts +2 -1
- package/dist/cjs/models/device/pb-700bt.model.d.ts.map +1 -1
- package/dist/cjs/models/device/pb-700bt.model.js.map +1 -1
- package/dist/cjs/models/device/progressor.model.d.ts +2 -2
- package/dist/cjs/models/device/progressor.model.d.ts.map +1 -1
- package/dist/cjs/models/device/progressor.model.js +4 -20
- package/dist/cjs/models/device/progressor.model.js.map +1 -1
- package/dist/cjs/models/device/wh-c06.model.d.ts +2 -0
- package/dist/cjs/models/device/wh-c06.model.d.ts.map +1 -1
- package/dist/cjs/models/device/wh-c06.model.js +45 -34
- package/dist/cjs/models/device/wh-c06.model.js.map +1 -1
- package/dist/cjs/models/device.model.d.ts +25 -5
- package/dist/cjs/models/device.model.d.ts.map +1 -1
- package/dist/cjs/models/device.model.js +94 -24
- package/dist/cjs/models/device.model.js.map +1 -1
- package/dist/cjs/models/index.d.ts +3 -1
- package/dist/cjs/models/index.d.ts.map +1 -1
- package/dist/cjs/models/index.js +8 -4
- package/dist/cjs/models/index.js.map +1 -1
- package/dist/cjs/models/nordic.model.d.ts +128 -0
- package/dist/cjs/models/nordic.model.d.ts.map +1 -0
- package/dist/cjs/models/nordic.model.js +405 -0
- package/dist/cjs/models/nordic.model.js.map +1 -0
- package/dist/cjs/package.json +3 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/interfaces/command.interface.d.ts +110 -21
- package/dist/interfaces/command.interface.d.ts.map +1 -1
- package/dist/interfaces/device/aurora.interface.d.ts +17 -0
- package/dist/interfaces/device/aurora.interface.d.ts.map +1 -0
- package/dist/interfaces/device/aurora.interface.js +2 -0
- package/dist/interfaces/device/aurora.interface.js.map +1 -0
- package/dist/interfaces/device/cts500.interface.d.ts +96 -0
- package/dist/interfaces/device/cts500.interface.d.ts.map +1 -0
- package/dist/interfaces/device/cts500.interface.js +2 -0
- package/dist/interfaces/device/cts500.interface.js.map +1 -0
- package/dist/interfaces/device/forceboard.interface.d.ts +2 -2
- package/dist/interfaces/device/forceboard.interface.d.ts.map +1 -1
- package/dist/interfaces/device/motherboard.interface.d.ts +1 -1
- package/dist/interfaces/device/pb-700bt.interface.d.ts +53 -0
- package/dist/interfaces/device/pb-700bt.interface.d.ts.map +1 -0
- package/dist/interfaces/device/pb-700bt.interface.js +2 -0
- package/dist/interfaces/device/pb-700bt.interface.js.map +1 -0
- package/dist/interfaces/device/progressor.interface.d.ts +2 -2
- package/dist/interfaces/device/progressor.interface.d.ts.map +1 -1
- package/dist/interfaces/index.d.ts +4 -1
- package/dist/interfaces/index.d.ts.map +1 -1
- package/dist/interfaces/nordic.interface.d.ts +47 -0
- package/dist/interfaces/nordic.interface.d.ts.map +1 -0
- package/dist/interfaces/nordic.interface.js +2 -0
- package/dist/interfaces/nordic.interface.js.map +1 -0
- package/dist/models/device/{kilterboard.model.d.ts → aurora.model.d.ts} +82 -40
- package/dist/models/device/aurora.model.d.ts.map +1 -0
- package/dist/models/device/aurora.model.js +401 -0
- package/dist/models/device/aurora.model.js.map +1 -0
- package/dist/models/device/climbro.model.js +1 -1
- package/dist/models/device/climbro.model.js.map +1 -1
- package/dist/models/device/cts500.model.d.ts +173 -0
- package/dist/models/device/cts500.model.d.ts.map +1 -0
- package/dist/models/device/cts500.model.js +592 -0
- package/dist/models/device/cts500.model.js.map +1 -0
- package/dist/models/device/forceboard.model.d.ts +2 -2
- package/dist/models/device/forceboard.model.d.ts.map +1 -1
- package/dist/models/device/forceboard.model.js +9 -16
- package/dist/models/device/forceboard.model.js.map +1 -1
- package/dist/models/device/motherboard.model.d.ts +4 -1
- package/dist/models/device/motherboard.model.d.ts.map +1 -1
- package/dist/models/device/motherboard.model.js +26 -10
- package/dist/models/device/motherboard.model.js.map +1 -1
- package/dist/models/device/pb-700bt.model.d.ts +2 -1
- package/dist/models/device/pb-700bt.model.d.ts.map +1 -1
- package/dist/models/device/pb-700bt.model.js.map +1 -1
- package/dist/models/device/progressor.model.d.ts +2 -2
- package/dist/models/device/progressor.model.d.ts.map +1 -1
- package/dist/models/device/progressor.model.js +4 -20
- package/dist/models/device/progressor.model.js.map +1 -1
- package/dist/models/device/wh-c06.model.d.ts +2 -0
- package/dist/models/device/wh-c06.model.d.ts.map +1 -1
- package/dist/models/device/wh-c06.model.js +44 -34
- package/dist/models/device/wh-c06.model.js.map +1 -1
- package/dist/models/device.model.d.ts +25 -5
- package/dist/models/device.model.d.ts.map +1 -1
- package/dist/models/device.model.js +93 -24
- package/dist/models/device.model.js.map +1 -1
- package/dist/models/index.d.ts +3 -1
- package/dist/models/index.d.ts.map +1 -1
- package/dist/models/index.js +3 -1
- package/dist/models/index.js.map +1 -1
- package/dist/models/nordic.model.d.ts +128 -0
- package/dist/models/nordic.model.d.ts.map +1 -0
- package/dist/models/nordic.model.js +393 -0
- package/dist/models/nordic.model.js.map +1 -0
- package/package.json +47 -43
- package/src/index.ts +6 -3
- package/src/interfaces/command.interface.ts +131 -21
- package/src/interfaces/device/aurora.interface.ts +18 -0
- package/src/interfaces/device/cts500.interface.ts +113 -0
- package/src/interfaces/device/forceboard.interface.ts +2 -2
- package/src/interfaces/device/motherboard.interface.ts +1 -1
- package/src/interfaces/device/pb-700bt.interface.ts +61 -0
- package/src/interfaces/device/progressor.interface.ts +2 -2
- package/src/interfaces/index.ts +8 -2
- package/src/interfaces/nordic.interface.ts +47 -0
- package/src/models/device/aurora.model.ts +497 -0
- package/src/models/device/climbro.model.ts +1 -1
- package/src/models/device/cts500.model.ts +709 -0
- package/src/models/device/forceboard.model.ts +9 -16
- package/src/models/device/motherboard.model.ts +51 -9
- package/src/models/device/pb-700bt.model.ts +2 -1
- package/src/models/device/progressor.model.ts +4 -20
- package/src/models/device/wh-c06.model.ts +54 -42
- package/src/models/device.model.ts +104 -24
- package/src/models/index.ts +5 -1
- package/src/models/nordic.model.ts +468 -0
- package/dist/cjs/interfaces/device/kilterboard.interface.d.ts +0 -17
- package/dist/cjs/interfaces/device/kilterboard.interface.d.ts.map +0 -1
- package/dist/cjs/interfaces/device/kilterboard.interface.js.map +0 -1
- package/dist/cjs/models/device/kilterboard.model.d.ts.map +0 -1
- package/dist/cjs/models/device/kilterboard.model.js +0 -327
- package/dist/cjs/models/device/kilterboard.model.js.map +0 -1
- package/dist/interfaces/device/kilterboard.interface.d.ts +0 -17
- package/dist/interfaces/device/kilterboard.interface.d.ts.map +0 -1
- package/dist/interfaces/device/kilterboard.interface.js +0 -2
- package/dist/interfaces/device/kilterboard.interface.js.map +0 -1
- package/dist/models/device/kilterboard.model.d.ts.map +0 -1
- package/dist/models/device/kilterboard.model.js +0 -323
- package/dist/models/device/kilterboard.model.js.map +0 -1
- package/dist/tsconfig.cjs.tsbuildinfo +0 -1
- package/src/interfaces/device/kilterboard.interface.ts +0 -12
- package/src/models/device/kilterboard.model.ts +0 -347
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { IDevice } from "./device.interface.js";
|
|
2
|
+
/**
|
|
3
|
+
* Shared Nordic Secure DFU functionality for devices that expose the FE59 DFU service.
|
|
4
|
+
*/
|
|
5
|
+
export interface INordicDfuDevice extends IDevice {
|
|
6
|
+
/**
|
|
7
|
+
* Switches the device from application mode into the Nordic DFU bootloader.
|
|
8
|
+
*/
|
|
9
|
+
dfuSwitch(): Promise<void>;
|
|
10
|
+
/**
|
|
11
|
+
* Sends a raw Nordic Secure DFU control operation and resolves with the response payload bytes.
|
|
12
|
+
* Call after dfuSwitch() has reconnected to the DFU bootloader.
|
|
13
|
+
*/
|
|
14
|
+
dfuControl(operation: Uint8Array, payload?: ArrayBuffer): Promise<Uint8Array>;
|
|
15
|
+
/**
|
|
16
|
+
* Sends Nordic Secure DFU SELECT for command or data objects and returns the bootloader state.
|
|
17
|
+
*/
|
|
18
|
+
dfuSelect(objectType: "command" | "data"): Promise<{
|
|
19
|
+
maxSize: number;
|
|
20
|
+
offset: number;
|
|
21
|
+
crc: number;
|
|
22
|
+
}>;
|
|
23
|
+
/**
|
|
24
|
+
* Sends Nordic Secure DFU CREATE for command or data objects.
|
|
25
|
+
*/
|
|
26
|
+
dfuCreate(objectType: "command" | "data", size: number): Promise<void>;
|
|
27
|
+
/**
|
|
28
|
+
* Writes raw bytes to the Nordic Secure DFU packet characteristic.
|
|
29
|
+
*/
|
|
30
|
+
dfuWritePacket(data: Uint8Array | ArrayBuffer): Promise<void>;
|
|
31
|
+
/**
|
|
32
|
+
* Sends Nordic Secure DFU CALCULATE_CHECKSUM and returns the bootloader state.
|
|
33
|
+
*/
|
|
34
|
+
dfuChecksum(): Promise<{
|
|
35
|
+
offset: number;
|
|
36
|
+
crc: number;
|
|
37
|
+
}>;
|
|
38
|
+
/**
|
|
39
|
+
* Sends Nordic Secure DFU EXECUTE for the currently created object.
|
|
40
|
+
*/
|
|
41
|
+
dfuExecute(): Promise<void>;
|
|
42
|
+
/**
|
|
43
|
+
* Runs a complete Nordic Secure DFU upload: switch to bootloader, send init packet, then send firmware.
|
|
44
|
+
*/
|
|
45
|
+
dfuUpload(initPacket: Uint8Array | ArrayBuffer, firmware: Uint8Array | ArrayBuffer): Promise<void>;
|
|
46
|
+
}
|
|
47
|
+
//# sourceMappingURL=nordic.interface.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nordic.interface.d.ts","sourceRoot":"","sources":["../../../src/interfaces/nordic.interface.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAA;AAEpD;;GAEG;AACH,MAAM,WAAW,gBAAiB,SAAQ,OAAO;IAC/C;;OAEG;IACH,SAAS,IAAI,OAAO,CAAC,IAAI,CAAC,CAAA;IAE1B;;;OAGG;IACH,UAAU,CAAC,SAAS,EAAE,UAAU,EAAE,OAAO,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,UAAU,CAAC,CAAA;IAE7E;;OAEG;IACH,SAAS,CAAC,UAAU,EAAE,SAAS,GAAG,MAAM,GAAG,OAAO,CAAC;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,MAAM,CAAA;KAAE,CAAC,CAAA;IAEpG;;OAEG;IACH,SAAS,CAAC,UAAU,EAAE,SAAS,GAAG,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;IAEtE;;OAEG;IACH,cAAc,CAAC,IAAI,EAAE,UAAU,GAAG,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;IAE7D;;OAEG;IACH,WAAW,IAAI,OAAO,CAAC;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,MAAM,CAAA;KAAE,CAAC,CAAA;IAEvD;;OAEG;IACH,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC,CAAA;IAE3B;;OAEG;IACH,SAAS,CAAC,UAAU,EAAE,UAAU,GAAG,WAAW,EAAE,QAAQ,EAAE,UAAU,GAAG,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;CACnG"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nordic.interface.js","sourceRoot":"","sources":["../../../src/interfaces/nordic.interface.ts"],"names":[],"mappings":""}
|
|
@@ -1,16 +1,15 @@
|
|
|
1
1
|
import { Device } from "../device.model.js";
|
|
2
|
-
import type {
|
|
2
|
+
import type { AuroraLedPlacement, IAurora } from "../../interfaces/device/aurora.interface.js";
|
|
3
3
|
/**
|
|
4
4
|
* For API level 2 and API level 3.
|
|
5
5
|
* The first byte in the data is dependent on where the packet is in the message as a whole.
|
|
6
|
-
* More details: https://github.com/1-max-1/fake_kilter_board
|
|
7
6
|
*/
|
|
8
|
-
export declare enum
|
|
7
|
+
export declare enum AuroraPacket {
|
|
9
8
|
/** If this packet is in the middle, the byte gets set to 77 (M). */
|
|
10
9
|
V2_MIDDLE = 77,
|
|
11
10
|
/** If this packet is the first packet in the message, then this byte gets set to 78 (N). */
|
|
12
11
|
V2_FIRST = 78,
|
|
13
|
-
/** If this is the last packet in the message, this byte gets set to 79 (
|
|
12
|
+
/** If this is the last packet in the message, this byte gets set to 79 (O). */
|
|
14
13
|
V2_LAST = 79,
|
|
15
14
|
/** If this packet is the only packet in the message, the byte gets set to 80 (P). Note that this takes priority over the other conditions. */
|
|
16
15
|
V2_ONLY = 80,
|
|
@@ -23,27 +22,15 @@ export declare enum KilterBoardPacket {
|
|
|
23
22
|
/** If this packet is the only packet in the message, the byte gets set to 84 (T). Note that this takes priority over the other conditions. */
|
|
24
23
|
V3_ONLY = 84
|
|
25
24
|
}
|
|
26
|
-
/**
|
|
27
|
-
* Extracted from placement_roles database table.
|
|
28
|
-
*/
|
|
29
|
-
export declare const KilterBoardPlacementRoles: {
|
|
30
|
-
id: number;
|
|
31
|
-
product_id: number;
|
|
32
|
-
position: number;
|
|
33
|
-
name: string;
|
|
34
|
-
full_name: string;
|
|
35
|
-
led_color: string;
|
|
36
|
-
screen_color: string;
|
|
37
|
-
}[];
|
|
38
25
|
/**
|
|
39
26
|
* Represents a Aurora Climbing device.
|
|
40
|
-
*
|
|
27
|
+
* Aurora Board
|
|
41
28
|
* {@link https://auroraclimbing.com}
|
|
42
29
|
*/
|
|
43
|
-
export declare class
|
|
30
|
+
export declare class Aurora extends Device implements IAurora {
|
|
44
31
|
/**
|
|
45
32
|
* UUID for the Aurora Climbing Advertising service.
|
|
46
|
-
* This constant is used to identify the specific Bluetooth service for
|
|
33
|
+
* This constant is used to identify the specific Bluetooth service for Aurora LED boards.
|
|
47
34
|
* @type {string}
|
|
48
35
|
* @static
|
|
49
36
|
* @readonly
|
|
@@ -70,9 +57,20 @@ export declare class KilterBoard extends Device implements IKilterBoard {
|
|
|
70
57
|
* @constant
|
|
71
58
|
*/
|
|
72
59
|
private static readonly maxBluetoothMessageSize;
|
|
60
|
+
private apiLevel;
|
|
61
|
+
private writeQueue;
|
|
73
62
|
constructor();
|
|
74
63
|
/**
|
|
75
|
-
*
|
|
64
|
+
* Sets the API level from the Aurora board name format:
|
|
65
|
+
* display name, optional #serial, optional trailing @apiLevel. Missing @apiLevel defaults to API level 2.
|
|
66
|
+
* @param name - The name of the device.
|
|
67
|
+
*/
|
|
68
|
+
protected setApiLevelFromDeviceName(name?: string | null): void;
|
|
69
|
+
protected onBluetoothDeviceSelected(device: BluetoothDevice): void;
|
|
70
|
+
private getApiLevelFromDeviceName;
|
|
71
|
+
private normalizeApiLevel;
|
|
72
|
+
/**
|
|
73
|
+
* Calculates the checksum for a byte array by summing up all packet-data bytes in a single-byte variable.
|
|
76
74
|
* @param data - The array of bytes to calculate the checksum for.
|
|
77
75
|
* @returns {number} The calculated checksum value.
|
|
78
76
|
*/
|
|
@@ -84,13 +82,20 @@ export declare class KilterBoard extends Device implements IKilterBoard {
|
|
|
84
82
|
*/
|
|
85
83
|
private wrapBytes;
|
|
86
84
|
/**
|
|
87
|
-
* Encodes
|
|
88
|
-
* The lowest 8 bits
|
|
89
|
-
* The highest 8 bits of the position get put in the second byte of the group.
|
|
85
|
+
* Encodes an API level 2 position into two bytes.
|
|
86
|
+
* The lowest 8 bits go in the first byte; the highest 2 bits are reserved for the second byte.
|
|
90
87
|
* @param position - The position to encode.
|
|
91
88
|
* @returns {number[]} The encoded byte array representing the position.
|
|
92
89
|
*/
|
|
93
|
-
private
|
|
90
|
+
private validatePosition;
|
|
91
|
+
private encodePositionV2;
|
|
92
|
+
/**
|
|
93
|
+
* Encodes an API level 3 position into two bytes.
|
|
94
|
+
* The lowest 8 bits go in the first byte; the highest 8 bits go in the second byte.
|
|
95
|
+
* @param position - The position to encode.
|
|
96
|
+
* @returns {number[]} The encoded byte array representing the position.
|
|
97
|
+
*/
|
|
98
|
+
private encodePositionV3;
|
|
94
99
|
/**
|
|
95
100
|
* Encodes a color string into a numeric representation.
|
|
96
101
|
* The rgb color, 3 bits for the R and G components, 2 bits for the B component, with the 3 R bits occupying the high end of the byte and the 2 B bits in the low end (hence 3 G bits in the middle).
|
|
@@ -98,20 +103,51 @@ export declare class KilterBoard extends Device implements IKilterBoard {
|
|
|
98
103
|
* @param color - The color string in hexadecimal format (e.g., 'FFFFFF').
|
|
99
104
|
* @returns The encoded /compressed color value.
|
|
100
105
|
*/
|
|
101
|
-
private
|
|
106
|
+
private encodeColorV3;
|
|
107
|
+
/**
|
|
108
|
+
* Encodes a color string using API level 2's 2-bit RGB format.
|
|
109
|
+
* Format: 0bRRGGBB00. The lowest two bits are reserved for the high bits of the LED position.
|
|
110
|
+
* @param color - The color string in hexadecimal format (e.g., 'FFFFFF').
|
|
111
|
+
* @returns The encoded /compressed color value.
|
|
112
|
+
*/
|
|
113
|
+
private encodeColorV2;
|
|
114
|
+
private normalizeColor;
|
|
102
115
|
/**
|
|
103
|
-
* Encodes
|
|
116
|
+
* Encodes an API level 2 placement into two bytes.
|
|
117
|
+
* API level 2 stores a 10-bit position and a 2-bit-per-channel RGB color.
|
|
104
118
|
* @param position - The position to encode.
|
|
105
119
|
* @param ledColor - The color of the LED in hexadecimal format (e.g., 'FFFFFF').
|
|
106
120
|
* @returns The encoded byte array representing the placement.
|
|
107
121
|
*/
|
|
108
|
-
private
|
|
122
|
+
private encodePlacementV2;
|
|
109
123
|
/**
|
|
110
|
-
*
|
|
111
|
-
*
|
|
112
|
-
* @
|
|
124
|
+
* Encodes an API level 3 placement into three bytes.
|
|
125
|
+
* API level 3 stores a 16-bit position and a 3/3/2-bit RGB color.
|
|
126
|
+
* @param position - The position to encode.
|
|
127
|
+
* @param ledColor - The color of the LED in hexadecimal format (e.g., 'FFFFFF').
|
|
128
|
+
* @returns The encoded byte array representing the placement.
|
|
129
|
+
*/
|
|
130
|
+
private encodePlacementV3;
|
|
131
|
+
/**
|
|
132
|
+
* Resolves placements into LED positions and concrete hex colors.
|
|
133
|
+
* @param climbPlacementList - The list of climb placements containing position and color.
|
|
134
|
+
* @returns The resolved placements ready for API-level encoding.
|
|
135
|
+
*/
|
|
136
|
+
private resolvePlacements;
|
|
137
|
+
private buildPayload;
|
|
138
|
+
/**
|
|
139
|
+
* Prepares API level 2 byte arrays for transmission based on a list of climb placements.
|
|
140
|
+
* @param climbPlacementList - The list of climb placements containing position and color.
|
|
141
|
+
* @returns The final byte array ready for transmission.
|
|
142
|
+
*/
|
|
143
|
+
private prepBytesV2;
|
|
144
|
+
/**
|
|
145
|
+
* Prepares API level 3 byte arrays for transmission based on a list of climb placements.
|
|
146
|
+
* @param climbPlacementList - The list of climb placements containing position and color.
|
|
147
|
+
* @returns The final byte array ready for transmission.
|
|
113
148
|
*/
|
|
114
149
|
private prepBytesV3;
|
|
150
|
+
private prepBytes;
|
|
115
151
|
/**
|
|
116
152
|
* Splits a collection into slices of the specified length.
|
|
117
153
|
* https://github.com/ramda/ramda/blob/master/source/splitEvery
|
|
@@ -121,26 +157,32 @@ export declare class KilterBoard extends Device implements IKilterBoard {
|
|
|
121
157
|
*/
|
|
122
158
|
private splitEvery;
|
|
123
159
|
/**
|
|
124
|
-
*
|
|
160
|
+
* Aurora boards only support messages of 20 bytes
|
|
125
161
|
* at a time. This method splits a full message into parts
|
|
126
162
|
* of 20 bytes
|
|
127
163
|
*
|
|
128
164
|
* @param buffer
|
|
129
165
|
*/
|
|
130
166
|
private splitMessages;
|
|
167
|
+
private getWriteCharacteristic;
|
|
131
168
|
/**
|
|
132
169
|
* Sends a series of messages to a device.
|
|
133
170
|
*/
|
|
134
171
|
private writeMessageSeries;
|
|
172
|
+
private queueWrite;
|
|
173
|
+
private writeMessageChunk;
|
|
174
|
+
private canWriteWithoutResponse;
|
|
135
175
|
/**
|
|
136
176
|
* Configures the LEDs based on an array of climb placements.
|
|
137
|
-
* @param
|
|
138
|
-
* @returns {Promise<number[] | undefined>} A promise that resolves with the payload array for the
|
|
139
|
-
*/
|
|
140
|
-
led: (config
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
177
|
+
* @param config - Array of climb placements for the LEDs. Each placement must include a color hex string.
|
|
178
|
+
* @returns {Promise<number[] | undefined>} A promise that resolves with the payload array for the Aurora board if LED settings were applied, or `undefined` if no action was taken.
|
|
179
|
+
*/
|
|
180
|
+
led: (config?: AuroraLedPlacement[]) => Promise<number[] | undefined>;
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Aurora Board
|
|
184
|
+
* {@link https://auroraboardapp.com}
|
|
185
|
+
*/
|
|
186
|
+
export declare class AuroraBoard extends Aurora implements IAurora {
|
|
145
187
|
}
|
|
146
|
-
//# sourceMappingURL=
|
|
188
|
+
//# sourceMappingURL=aurora.model.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"aurora.model.d.ts","sourceRoot":"","sources":["../../../../src/models/device/aurora.model.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAA;AAC3C,OAAO,KAAK,EAAE,kBAAkB,EAAE,OAAO,EAAE,MAAM,6CAA6C,CAAA;AAgB9F;;;GAGG;AACH,oBAAY,YAAY;IACtB,oEAAoE;IACpE,SAAS,KAAK;IACd,4FAA4F;IAC5F,QAAQ,KAAA;IACR,+EAA+E;IAC/E,OAAO,KAAA;IACP,8IAA8I;IAC9I,OAAO,KAAA;IACP,oEAAoE;IACpE,SAAS,KAAA;IACT,4FAA4F;IAC5F,QAAQ,KAAA;IACR,+EAA+E;IAC/E,OAAO,KAAA;IACP,8IAA8I;IAC9I,OAAO,KAAA;CACR;AAED;;;;GAIG;AACH,qBAAa,MAAO,SAAQ,MAAO,YAAW,OAAO;IACnD;;;;;;;OAOG;IACH,MAAM,CAAC,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAyC;IAE3E;;;;;;;;OAQG;IACH,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,oBAAoB,CAAc;IAE1D;;;;;;;;OAQG;IACH,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,uBAAuB,CAAa;IAE5D,OAAO,CAAC,QAAQ,CAAgB;IAEhC,OAAO,CAAC,UAAU,CAAmC;;IAiCrD;;;;OAIG;IACH,SAAS,CAAC,yBAAyB,CAAC,IAAI,CAAC,EAAE,MAAM,GAAG,IAAI,GAAG,IAAI;cAM5C,yBAAyB,CAAC,MAAM,EAAE,eAAe,GAAG,IAAI;IAI3E,OAAO,CAAC,yBAAyB;IAUjC,OAAO,CAAC,iBAAiB;IAQzB;;;;OAIG;IACH,OAAO,CAAC,QAAQ;IAQhB;;;;OAIG;IACH,OAAO,CAAC,SAAS;IAiBjB;;;;;OAKG;IACH,OAAO,CAAC,gBAAgB;IAQxB,OAAO,CAAC,gBAAgB;IASxB;;;;;OAKG;IACH,OAAO,CAAC,gBAAgB;IASxB;;;;;;OAMG;IACH,OAAO,CAAC,aAAa;IAerB;;;;;OAKG;IACH,OAAO,CAAC,aAAa;IAYrB,OAAO,CAAC,cAAc;IAUtB;;;;;;OAMG;IACH,OAAO,CAAC,iBAAiB;IAMzB;;;;;;OAMG;IACH,OAAO,CAAC,iBAAiB;IAIzB;;;;OAIG;IACH,OAAO,CAAC,iBAAiB;IAiBzB,OAAO,CAAC,YAAY;IAoCpB;;;;OAIG;IACH,OAAO,CAAC,WAAW;IAcnB;;;;OAIG;IACH,OAAO,CAAC,WAAW;IAcnB,OAAO,CAAC,SAAS;IAIjB;;;;;;OAMG;IACH,OAAO,CAAC,UAAU;IAYlB;;;;;;OAMG;IACH,OAAO,CAAC,aAAa,CACsE;IAE3F,OAAO,CAAC,sBAAsB;IAK9B;;OAEG;YACW,kBAAkB;YAUlB,UAAU;YAOV,iBAAiB;IAgB/B,OAAO,CAAC,uBAAuB;IAO/B;;;;OAIG;IACH,GAAG,GAAU,SAAQ,kBAAkB,EAAO,KAAG,OAAO,CAAC,MAAM,EAAE,GAAG,SAAS,CAAC,CAc7E;CACF;AAED;;;GAGG;AACH,qBAAa,WAAY,SAAQ,MAAO,YAAW,OAAO;CAAG"}
|
|
@@ -0,0 +1,407 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AuroraBoard = exports.Aurora = exports.AuroraPacket = void 0;
|
|
4
|
+
const device_model_js_1 = require("../device.model.js");
|
|
5
|
+
/**
|
|
6
|
+
* For API level 2 and API level 3.
|
|
7
|
+
* The first byte in the data is dependent on where the packet is in the message as a whole.
|
|
8
|
+
*/
|
|
9
|
+
var AuroraPacket;
|
|
10
|
+
(function (AuroraPacket) {
|
|
11
|
+
/** If this packet is in the middle, the byte gets set to 77 (M). */
|
|
12
|
+
AuroraPacket[AuroraPacket["V2_MIDDLE"] = 77] = "V2_MIDDLE";
|
|
13
|
+
/** If this packet is the first packet in the message, then this byte gets set to 78 (N). */
|
|
14
|
+
AuroraPacket[AuroraPacket["V2_FIRST"] = 78] = "V2_FIRST";
|
|
15
|
+
/** If this is the last packet in the message, this byte gets set to 79 (O). */
|
|
16
|
+
AuroraPacket[AuroraPacket["V2_LAST"] = 79] = "V2_LAST";
|
|
17
|
+
/** If this packet is the only packet in the message, the byte gets set to 80 (P). Note that this takes priority over the other conditions. */
|
|
18
|
+
AuroraPacket[AuroraPacket["V2_ONLY"] = 80] = "V2_ONLY";
|
|
19
|
+
/** If this packet is in the middle, the byte gets set to 81 (Q). */
|
|
20
|
+
AuroraPacket[AuroraPacket["V3_MIDDLE"] = 81] = "V3_MIDDLE";
|
|
21
|
+
/** If this packet is the first packet in the message, then this byte gets set to 82 (R). */
|
|
22
|
+
AuroraPacket[AuroraPacket["V3_FIRST"] = 82] = "V3_FIRST";
|
|
23
|
+
/** If this is the last packet in the message, this byte gets set to 83 (S). */
|
|
24
|
+
AuroraPacket[AuroraPacket["V3_LAST"] = 83] = "V3_LAST";
|
|
25
|
+
/** If this packet is the only packet in the message, the byte gets set to 84 (T). Note that this takes priority over the other conditions. */
|
|
26
|
+
AuroraPacket[AuroraPacket["V3_ONLY"] = 84] = "V3_ONLY";
|
|
27
|
+
})(AuroraPacket || (exports.AuroraPacket = AuroraPacket = {}));
|
|
28
|
+
/**
|
|
29
|
+
* Represents a Aurora Climbing device.
|
|
30
|
+
* Aurora Board
|
|
31
|
+
* {@link https://auroraclimbing.com}
|
|
32
|
+
*/
|
|
33
|
+
class Aurora extends device_model_js_1.Device {
|
|
34
|
+
constructor() {
|
|
35
|
+
super({
|
|
36
|
+
filters: [
|
|
37
|
+
{
|
|
38
|
+
services: [Aurora.AuroraUUID],
|
|
39
|
+
},
|
|
40
|
+
],
|
|
41
|
+
services: [
|
|
42
|
+
{
|
|
43
|
+
name: "UART Nordic Service",
|
|
44
|
+
id: "uart",
|
|
45
|
+
uuid: "6e400001-b5a3-f393-e0a9-e50e24dcca9e",
|
|
46
|
+
characteristics: [
|
|
47
|
+
{
|
|
48
|
+
name: "TX",
|
|
49
|
+
id: "tx",
|
|
50
|
+
uuid: "6e400002-b5a3-f393-e0a9-e50e24dcca9e",
|
|
51
|
+
},
|
|
52
|
+
// {
|
|
53
|
+
// name: "RX",
|
|
54
|
+
// id: "rx",
|
|
55
|
+
// uuid: "6e400003-b5a3-f393-e0a9-e50e24dcca9e",
|
|
56
|
+
// },
|
|
57
|
+
],
|
|
58
|
+
},
|
|
59
|
+
],
|
|
60
|
+
});
|
|
61
|
+
this.writeQueue = Promise.resolve();
|
|
62
|
+
/**
|
|
63
|
+
* Aurora boards only support messages of 20 bytes
|
|
64
|
+
* at a time. This method splits a full message into parts
|
|
65
|
+
* of 20 bytes
|
|
66
|
+
*
|
|
67
|
+
* @param buffer
|
|
68
|
+
*/
|
|
69
|
+
this.splitMessages = (buffer) => this.splitEvery(Aurora.maxBluetoothMessageSize, buffer).map((arr) => new Uint8Array(arr));
|
|
70
|
+
/**
|
|
71
|
+
* Configures the LEDs based on an array of climb placements.
|
|
72
|
+
* @param config - Array of climb placements for the LEDs. Each placement must include a color hex string.
|
|
73
|
+
* @returns {Promise<number[] | undefined>} A promise that resolves with the payload array for the Aurora board if LED settings were applied, or `undefined` if no action was taken.
|
|
74
|
+
*/
|
|
75
|
+
this.led = async (config = []) => {
|
|
76
|
+
// Handle Aurora LED board logic: process placements and send payload if connected
|
|
77
|
+
if (Array.isArray(config)) {
|
|
78
|
+
// Prepares byte arrays for transmission based on a list of climb placements.
|
|
79
|
+
const payload = this.prepBytes(config, this.apiLevel);
|
|
80
|
+
if (this.isConnected()) {
|
|
81
|
+
const characteristic = this.getWriteCharacteristic();
|
|
82
|
+
if (characteristic) {
|
|
83
|
+
await this.queueWrite(() => this.writeMessageSeries(characteristic, this.splitMessages(payload)));
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
return payload;
|
|
87
|
+
}
|
|
88
|
+
return undefined;
|
|
89
|
+
};
|
|
90
|
+
this.apiLevel = 2;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Sets the API level from the Aurora board name format:
|
|
94
|
+
* display name, optional #serial, optional trailing @apiLevel. Missing @apiLevel defaults to API level 2.
|
|
95
|
+
* @param name - The name of the device.
|
|
96
|
+
*/
|
|
97
|
+
setApiLevelFromDeviceName(name) {
|
|
98
|
+
const detectedApiLevel = this.getApiLevelFromDeviceName(name);
|
|
99
|
+
this.apiLevel = detectedApiLevel;
|
|
100
|
+
}
|
|
101
|
+
onBluetoothDeviceSelected(device) {
|
|
102
|
+
this.setApiLevelFromDeviceName(device.name);
|
|
103
|
+
}
|
|
104
|
+
getApiLevelFromDeviceName(name) {
|
|
105
|
+
var _a;
|
|
106
|
+
const apiLevel = (_a = name === null || name === void 0 ? void 0 : name.match(/@(\d+)$/)) === null || _a === void 0 ? void 0 : _a[1];
|
|
107
|
+
if (apiLevel === undefined) {
|
|
108
|
+
return 2;
|
|
109
|
+
}
|
|
110
|
+
return this.normalizeApiLevel(Number(apiLevel));
|
|
111
|
+
}
|
|
112
|
+
normalizeApiLevel(apiLevel) {
|
|
113
|
+
if (apiLevel !== 2 && apiLevel !== 3) {
|
|
114
|
+
throw new Error(`Unsupported Aurora Board API level: ${apiLevel}`);
|
|
115
|
+
}
|
|
116
|
+
return apiLevel;
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Calculates the checksum for a byte array by summing up all packet-data bytes in a single-byte variable.
|
|
120
|
+
* @param data - The array of bytes to calculate the checksum for.
|
|
121
|
+
* @returns {number} The calculated checksum value.
|
|
122
|
+
*/
|
|
123
|
+
checksum(data) {
|
|
124
|
+
let i = 0;
|
|
125
|
+
for (const value of data) {
|
|
126
|
+
i = (i + value) & 255;
|
|
127
|
+
}
|
|
128
|
+
return ~i & 255;
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Wraps a byte array with header and footer bytes for transmission.
|
|
132
|
+
* @param data - The array of bytes to wrap.
|
|
133
|
+
* @returns {number[]} The wrapped byte array.
|
|
134
|
+
*/
|
|
135
|
+
wrapBytes(data) {
|
|
136
|
+
if (data.length > Aurora.messageBodyMaxLength) {
|
|
137
|
+
return [];
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
- 0x1
|
|
141
|
+
- len(packets)
|
|
142
|
+
- checksum(packets)
|
|
143
|
+
- 0x2
|
|
144
|
+
- *packets
|
|
145
|
+
- 0x3
|
|
146
|
+
|
|
147
|
+
First byte is always 1, the second is a number of packets, then checksum, then 2, packets themselves, and finally 3.
|
|
148
|
+
*/
|
|
149
|
+
return [1, data.length, this.checksum(data), 2, ...data, 3];
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Encodes an API level 2 position into two bytes.
|
|
153
|
+
* The lowest 8 bits go in the first byte; the highest 2 bits are reserved for the second byte.
|
|
154
|
+
* @param position - The position to encode.
|
|
155
|
+
* @returns {number[]} The encoded byte array representing the position.
|
|
156
|
+
*/
|
|
157
|
+
validatePosition(position, maxPosition, apiLevel) {
|
|
158
|
+
if (!Number.isInteger(position) || position < 0 || position > maxPosition) {
|
|
159
|
+
throw new Error(`Aurora Board API level ${apiLevel} requires an integer LED position between 0 and ${maxPosition}`);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
encodePositionV2(position) {
|
|
163
|
+
this.validatePosition(position, 0x3ff, 2);
|
|
164
|
+
const position1 = position & 255;
|
|
165
|
+
const position2 = (position & 0x300) >> 8;
|
|
166
|
+
return [position1, position2];
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Encodes an API level 3 position into two bytes.
|
|
170
|
+
* The lowest 8 bits go in the first byte; the highest 8 bits go in the second byte.
|
|
171
|
+
* @param position - The position to encode.
|
|
172
|
+
* @returns {number[]} The encoded byte array representing the position.
|
|
173
|
+
*/
|
|
174
|
+
encodePositionV3(position) {
|
|
175
|
+
this.validatePosition(position, 0xffff, 3);
|
|
176
|
+
const position1 = position & 255;
|
|
177
|
+
const position2 = (position & 65280) >> 8;
|
|
178
|
+
return [position1, position2];
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Encodes a color string into a numeric representation.
|
|
182
|
+
* The rgb color, 3 bits for the R and G components, 2 bits for the B component, with the 3 R bits occupying the high end of the byte and the 2 B bits in the low end (hence 3 G bits in the middle).
|
|
183
|
+
* Format: 0bRRRGGGBB where RRR is 3 bits for red, GGG is 3 bits for green, BB is 2 bits for blue.
|
|
184
|
+
* @param color - The color string in hexadecimal format (e.g., 'FFFFFF').
|
|
185
|
+
* @returns The encoded /compressed color value.
|
|
186
|
+
*/
|
|
187
|
+
encodeColorV3(color) {
|
|
188
|
+
const r = parseInt(color.substring(0, 2), 16);
|
|
189
|
+
const g = parseInt(color.substring(2, 4), 16);
|
|
190
|
+
const b = parseInt(color.substring(4, 6), 16);
|
|
191
|
+
// Integer division: R and G divided by 32, B divided by 64
|
|
192
|
+
// Then pack into 0bRRRGGGBB format
|
|
193
|
+
const rBits = Math.floor(r / 32); // 0-7 (3 bits)
|
|
194
|
+
const gBits = Math.floor(g / 32); // 0-7 (3 bits)
|
|
195
|
+
const bBits = Math.floor(b / 64); // 0-3 (2 bits)
|
|
196
|
+
// Pack: RRR in bits 7-5, GGG in bits 4-2, BB in bits 1-0
|
|
197
|
+
return (rBits << 5) | (gBits << 2) | bBits;
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* Encodes a color string using API level 2's 2-bit RGB format.
|
|
201
|
+
* Format: 0bRRGGBB00. The lowest two bits are reserved for the high bits of the LED position.
|
|
202
|
+
* @param color - The color string in hexadecimal format (e.g., 'FFFFFF').
|
|
203
|
+
* @returns The encoded /compressed color value.
|
|
204
|
+
*/
|
|
205
|
+
encodeColorV2(color) {
|
|
206
|
+
const r = parseInt(color.substring(0, 2), 16);
|
|
207
|
+
const g = parseInt(color.substring(2, 4), 16);
|
|
208
|
+
const b = parseInt(color.substring(4, 6), 16);
|
|
209
|
+
const rBits = Math.floor(r / 64); // 0-3 (2 bits)
|
|
210
|
+
const gBits = Math.floor(g / 64); // 0-3 (2 bits)
|
|
211
|
+
const bBits = Math.floor(b / 64); // 0-3 (2 bits)
|
|
212
|
+
return (rBits << 6) | (gBits << 4) | (bBits << 2);
|
|
213
|
+
}
|
|
214
|
+
normalizeColor(color) {
|
|
215
|
+
const colorHex = color.trim().replace(/^#/, "").toUpperCase();
|
|
216
|
+
if (!/^[0-9A-F]{6}$/.test(colorHex)) {
|
|
217
|
+
throw new Error(`Invalid Aurora Board LED color: ${color}`);
|
|
218
|
+
}
|
|
219
|
+
return colorHex;
|
|
220
|
+
}
|
|
221
|
+
/**
|
|
222
|
+
* Encodes an API level 2 placement into two bytes.
|
|
223
|
+
* API level 2 stores a 10-bit position and a 2-bit-per-channel RGB color.
|
|
224
|
+
* @param position - The position to encode.
|
|
225
|
+
* @param ledColor - The color of the LED in hexadecimal format (e.g., 'FFFFFF').
|
|
226
|
+
* @returns The encoded byte array representing the placement.
|
|
227
|
+
*/
|
|
228
|
+
encodePlacementV2(position, ledColor) {
|
|
229
|
+
const [position1, position2] = this.encodePositionV2(position);
|
|
230
|
+
return [position1, this.encodeColorV2(ledColor) | position2];
|
|
231
|
+
}
|
|
232
|
+
/**
|
|
233
|
+
* Encodes an API level 3 placement into three bytes.
|
|
234
|
+
* API level 3 stores a 16-bit position and a 3/3/2-bit RGB color.
|
|
235
|
+
* @param position - The position to encode.
|
|
236
|
+
* @param ledColor - The color of the LED in hexadecimal format (e.g., 'FFFFFF').
|
|
237
|
+
* @returns The encoded byte array representing the placement.
|
|
238
|
+
*/
|
|
239
|
+
encodePlacementV3(position, ledColor) {
|
|
240
|
+
return [...this.encodePositionV3(position), this.encodeColorV3(ledColor)];
|
|
241
|
+
}
|
|
242
|
+
/**
|
|
243
|
+
* Resolves placements into LED positions and concrete hex colors.
|
|
244
|
+
* @param climbPlacementList - The list of climb placements containing position and color.
|
|
245
|
+
* @returns The resolved placements ready for API-level encoding.
|
|
246
|
+
*/
|
|
247
|
+
resolvePlacements(climbPlacementList) {
|
|
248
|
+
return climbPlacementList.flatMap((climbPlacement) => {
|
|
249
|
+
var _a, _b;
|
|
250
|
+
const color = (_b = (_a = climbPlacement.color) === null || _a === void 0 ? void 0 : _a.trim()) !== null && _b !== void 0 ? _b : "";
|
|
251
|
+
if (color === "") {
|
|
252
|
+
return [];
|
|
253
|
+
}
|
|
254
|
+
return [
|
|
255
|
+
{
|
|
256
|
+
position: climbPlacement.position,
|
|
257
|
+
colorHex: this.normalizeColor(color),
|
|
258
|
+
},
|
|
259
|
+
];
|
|
260
|
+
});
|
|
261
|
+
}
|
|
262
|
+
buildPayload(resolvedPlacements, markers, bytesPerPlacement, encodePlacement) {
|
|
263
|
+
const resultArray = [];
|
|
264
|
+
let tempArray = [markers.middle];
|
|
265
|
+
for (const climbPlacement of resolvedPlacements) {
|
|
266
|
+
if (tempArray.length + bytesPerPlacement > Aurora.messageBodyMaxLength) {
|
|
267
|
+
resultArray.push(tempArray);
|
|
268
|
+
tempArray = [markers.middle];
|
|
269
|
+
}
|
|
270
|
+
const encodedPlacement = encodePlacement(climbPlacement.position, climbPlacement.colorHex);
|
|
271
|
+
tempArray.push(...encodedPlacement);
|
|
272
|
+
}
|
|
273
|
+
resultArray.push(tempArray);
|
|
274
|
+
if (resultArray.length === 1) {
|
|
275
|
+
resultArray[0][0] = markers.only;
|
|
276
|
+
}
|
|
277
|
+
else if (resultArray.length > 1) {
|
|
278
|
+
resultArray[0][0] = markers.first;
|
|
279
|
+
resultArray[resultArray.length - 1][0] = markers.last;
|
|
280
|
+
}
|
|
281
|
+
const finalResultArray = [];
|
|
282
|
+
for (const currentArray of resultArray) {
|
|
283
|
+
finalResultArray.push(...this.wrapBytes(currentArray));
|
|
284
|
+
}
|
|
285
|
+
return finalResultArray;
|
|
286
|
+
}
|
|
287
|
+
/**
|
|
288
|
+
* Prepares API level 2 byte arrays for transmission based on a list of climb placements.
|
|
289
|
+
* @param climbPlacementList - The list of climb placements containing position and color.
|
|
290
|
+
* @returns The final byte array ready for transmission.
|
|
291
|
+
*/
|
|
292
|
+
prepBytesV2(climbPlacementList) {
|
|
293
|
+
return this.buildPayload(this.resolvePlacements(climbPlacementList), {
|
|
294
|
+
middle: AuroraPacket.V2_MIDDLE,
|
|
295
|
+
first: AuroraPacket.V2_FIRST,
|
|
296
|
+
last: AuroraPacket.V2_LAST,
|
|
297
|
+
only: AuroraPacket.V2_ONLY,
|
|
298
|
+
}, 2, (position, ledColor) => this.encodePlacementV2(position, ledColor));
|
|
299
|
+
}
|
|
300
|
+
/**
|
|
301
|
+
* Prepares API level 3 byte arrays for transmission based on a list of climb placements.
|
|
302
|
+
* @param climbPlacementList - The list of climb placements containing position and color.
|
|
303
|
+
* @returns The final byte array ready for transmission.
|
|
304
|
+
*/
|
|
305
|
+
prepBytesV3(climbPlacementList) {
|
|
306
|
+
return this.buildPayload(this.resolvePlacements(climbPlacementList), {
|
|
307
|
+
middle: AuroraPacket.V3_MIDDLE,
|
|
308
|
+
first: AuroraPacket.V3_FIRST,
|
|
309
|
+
last: AuroraPacket.V3_LAST,
|
|
310
|
+
only: AuroraPacket.V3_ONLY,
|
|
311
|
+
}, 3, (position, ledColor) => this.encodePlacementV3(position, ledColor));
|
|
312
|
+
}
|
|
313
|
+
prepBytes(climbPlacementList, apiLevel) {
|
|
314
|
+
return apiLevel === 2 ? this.prepBytesV2(climbPlacementList) : this.prepBytesV3(climbPlacementList);
|
|
315
|
+
}
|
|
316
|
+
/**
|
|
317
|
+
* Splits a collection into slices of the specified length.
|
|
318
|
+
* https://github.com/ramda/ramda/blob/master/source/splitEvery
|
|
319
|
+
* @param {Number} n
|
|
320
|
+
* @param {Array} list
|
|
321
|
+
* @return {Array<number[]>}
|
|
322
|
+
*/
|
|
323
|
+
splitEvery(n, list) {
|
|
324
|
+
if (n <= 0) {
|
|
325
|
+
throw new Error("First argument to splitEvery must be a positive integer");
|
|
326
|
+
}
|
|
327
|
+
const result = [];
|
|
328
|
+
let idx = 0;
|
|
329
|
+
while (idx < list.length) {
|
|
330
|
+
result.push(list.slice(idx, (idx += n)));
|
|
331
|
+
}
|
|
332
|
+
return result;
|
|
333
|
+
}
|
|
334
|
+
getWriteCharacteristic() {
|
|
335
|
+
var _a, _b;
|
|
336
|
+
return (_b = (_a = this.services.find((service) => service.id === "uart")) === null || _a === void 0 ? void 0 : _a.characteristics.find((char) => char.id === "tx")) === null || _b === void 0 ? void 0 : _b.characteristic;
|
|
337
|
+
}
|
|
338
|
+
/**
|
|
339
|
+
* Sends a series of messages to a device.
|
|
340
|
+
*/
|
|
341
|
+
async writeMessageSeries(characteristic, messages) {
|
|
342
|
+
for (const message of messages) {
|
|
343
|
+
if (!message) {
|
|
344
|
+
continue;
|
|
345
|
+
}
|
|
346
|
+
await this.writeMessageChunk(characteristic, message);
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
async queueWrite(operation) {
|
|
350
|
+
const queuedOperation = this.writeQueue.catch(() => undefined).then(operation);
|
|
351
|
+
this.writeQueue = queuedOperation.catch(() => undefined);
|
|
352
|
+
await queuedOperation;
|
|
353
|
+
}
|
|
354
|
+
async writeMessageChunk(characteristic, message) {
|
|
355
|
+
this.updateTimestamp();
|
|
356
|
+
const valueToWrite = new Uint8Array(message);
|
|
357
|
+
if (this.canWriteWithoutResponse(characteristic)) {
|
|
358
|
+
await characteristic.writeValueWithoutResponse(valueToWrite);
|
|
359
|
+
}
|
|
360
|
+
else {
|
|
361
|
+
await characteristic.writeValue(valueToWrite);
|
|
362
|
+
}
|
|
363
|
+
this.writeLast = message;
|
|
364
|
+
}
|
|
365
|
+
canWriteWithoutResponse(characteristic) {
|
|
366
|
+
return (characteristic.properties.writeWithoutResponse !== false &&
|
|
367
|
+
typeof characteristic.writeValueWithoutResponse === "function");
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
exports.Aurora = Aurora;
|
|
371
|
+
/**
|
|
372
|
+
* UUID for the Aurora Climbing Advertising service.
|
|
373
|
+
* This constant is used to identify the specific Bluetooth service for Aurora LED boards.
|
|
374
|
+
* @type {string}
|
|
375
|
+
* @static
|
|
376
|
+
* @readonly
|
|
377
|
+
* @constant
|
|
378
|
+
*/
|
|
379
|
+
Aurora.AuroraUUID = "4488b571-7806-4df6-bcff-a2897e4953ff";
|
|
380
|
+
/**
|
|
381
|
+
* Maximum length of the message body for byte wrapping.
|
|
382
|
+
* This value defines the limit for the size of messages that can be sent or received
|
|
383
|
+
* to ensure proper byte wrapping in communication.
|
|
384
|
+
* @type {number}
|
|
385
|
+
* @private
|
|
386
|
+
* @readonly
|
|
387
|
+
* @constant
|
|
388
|
+
*/
|
|
389
|
+
Aurora.messageBodyMaxLength = 255;
|
|
390
|
+
/**
|
|
391
|
+
* Maximum length of the Bluetooth message chunk.
|
|
392
|
+
* This value sets the upper limit for the size of individual Bluetooth messages
|
|
393
|
+
* sent to and from the device to comply with Bluetooth protocol constraints.
|
|
394
|
+
* @type {number}
|
|
395
|
+
* @private
|
|
396
|
+
* @readonly
|
|
397
|
+
* @constant
|
|
398
|
+
*/
|
|
399
|
+
Aurora.maxBluetoothMessageSize = 20;
|
|
400
|
+
/**
|
|
401
|
+
* Aurora Board
|
|
402
|
+
* {@link https://auroraboardapp.com}
|
|
403
|
+
*/
|
|
404
|
+
class AuroraBoard extends Aurora {
|
|
405
|
+
}
|
|
406
|
+
exports.AuroraBoard = AuroraBoard;
|
|
407
|
+
//# sourceMappingURL=aurora.model.js.map
|