@hangtime/grip-connect 0.5.5 → 0.5.7
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 +25 -31
- package/dist/index.d.ts +0 -4
- package/dist/index.js +0 -5
- package/dist/interfaces/callback.interface.d.ts +6 -0
- package/dist/interfaces/device/kilterboard.interface.d.ts +6 -67
- package/dist/interfaces/device/motherboard.interface.d.ts +0 -7
- package/dist/interfaces/device.interface.d.ts +32 -27
- package/dist/models/device/entralpi.model.js +7 -7
- package/dist/models/device/forceboard.model.js +4 -7
- package/dist/models/device/kilterboard.model.d.ts +27 -29
- package/dist/models/device/kilterboard.model.js +16 -23
- package/dist/models/device/motherboard.model.d.ts +12 -8
- package/dist/models/device/motherboard.model.js +22 -21
- package/dist/models/device/progressor.model.js +4 -7
- package/dist/models/device/wh-c06.model.d.ts +34 -2
- package/dist/models/device/wh-c06.model.js +80 -13
- package/dist/models/device.model.d.ts +161 -14
- package/dist/models/device.model.js +263 -5
- package/package.json +1 -1
- package/src/index.ts +0 -9
- package/src/interfaces/callback.interface.ts +7 -0
- package/src/interfaces/device/kilterboard.interface.ts +3 -76
- package/src/interfaces/device/motherboard.interface.ts +0 -8
- package/src/interfaces/device.interface.ts +33 -31
- package/src/models/device/entralpi.model.ts +7 -7
- package/src/models/device/forceboard.model.ts +4 -7
- package/src/models/device/kilterboard.model.ts +37 -36
- package/src/models/device/motherboard.model.ts +23 -22
- package/src/models/device/progressor.model.ts +4 -7
- package/src/models/device/wh-c06.model.ts +87 -15
- package/src/models/device.model.ts +316 -15
- package/dist/helpers/download.d.ts +0 -16
- package/dist/helpers/download.js +0 -106
- package/dist/helpers/is-active.d.ts +0 -41
- package/dist/helpers/is-active.js +0 -59
- package/dist/helpers/is-device.d.ts +0 -37
- package/dist/helpers/is-device.js +0 -39
- package/dist/helpers/tare.d.ts +0 -12
- package/dist/helpers/tare.js +0 -70
- package/src/helpers/download.ts +0 -123
- package/src/helpers/is-active.ts +0 -70
- package/src/helpers/is-device.ts +0 -50
- package/src/helpers/tare.ts +0 -76
package/README.md
CHANGED
|
@@ -43,60 +43,54 @@ $ npm install @hangtime/grip-connect
|
|
|
43
43
|
|
|
44
44
|
## Example usage (with a Motherboard)
|
|
45
45
|
|
|
46
|
-
Simply importing the
|
|
46
|
+
Simply importing the device you need from `@hangtime/grip-connect`.
|
|
47
47
|
|
|
48
48
|
```html
|
|
49
49
|
<button id="motherboard" type="button">Connect Motherboard</button>
|
|
50
50
|
```
|
|
51
51
|
|
|
52
52
|
```js
|
|
53
|
-
import { Motherboard
|
|
53
|
+
import { Motherboard } from "@hangtime/grip-connect"
|
|
54
54
|
|
|
55
|
-
|
|
55
|
+
// Initiate device
|
|
56
|
+
const motherboard = new Motherboard()
|
|
56
57
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
58
|
+
// Optional: Custom data handler
|
|
59
|
+
motherboard.notify((data) => {
|
|
60
|
+
// { massTotal: "0", massMax: "0", massAverage: "0", massLeft: "0", massCenter: "0", massRight: "0" }
|
|
61
|
+
console.log(data)
|
|
62
|
+
})
|
|
63
|
+
|
|
64
|
+
// Optional: Check if the device is active
|
|
65
|
+
motherboard.active(
|
|
66
|
+
(isActive) => { console.log(isActive) },
|
|
67
|
+
// Optionally using a weight threshold and duration
|
|
68
|
+
{ threshold: 2.5, duration: 1000 },
|
|
69
|
+
)
|
|
70
|
+
|
|
71
|
+
document.querySelector("#motherboard").addEventListener("click", () => {
|
|
72
|
+
// Connect to device
|
|
73
|
+
await motherboard.connect(
|
|
62
74
|
async () => {
|
|
63
|
-
//
|
|
64
|
-
motherboard.notify((data) => {
|
|
65
|
-
// { massTotal: "0", massMax: "0", massAverage: "0", massLeft: "0", massCenter: "0", massRight: "0" }
|
|
66
|
-
console.log(data)
|
|
67
|
-
})
|
|
68
|
-
|
|
69
|
-
// Reactive check if device is active
|
|
70
|
-
active(
|
|
71
|
-
(isActive) => {
|
|
72
|
-
console.log(isActive)
|
|
73
|
-
},
|
|
74
|
-
// Optionally using a weight threshold and duration
|
|
75
|
-
{ threshold: 2.5, duration: 1000 },
|
|
76
|
-
)
|
|
77
|
-
|
|
78
|
-
// Read device specific data: battery + firmware
|
|
75
|
+
// Example: Read device specific data
|
|
79
76
|
const batteryLevel = await motherboard.battery()
|
|
80
77
|
console.log(batteryLevel)
|
|
81
78
|
|
|
82
|
-
const firmwareVersion = await motherboard.firmware()
|
|
83
|
-
console.log(firmwareVersion)
|
|
84
|
-
|
|
85
79
|
// LEDs: "green", "red", "orange", or no argument to turn off
|
|
86
|
-
// await motherboard.led(
|
|
87
|
-
// await motherboard.led(
|
|
80
|
+
// await motherboard.led("red")
|
|
81
|
+
// await motherboard.led()
|
|
88
82
|
|
|
89
83
|
// Start weight streaming (for a minute) remove parameter for a continues stream
|
|
90
84
|
await motherboard.stream(60000)
|
|
91
85
|
|
|
92
86
|
// Manualy tare the device when the stream is running
|
|
93
|
-
// await tare(5000)
|
|
87
|
+
// await motherboard.tare(5000)
|
|
94
88
|
|
|
95
89
|
// Manually call stop method if stream is continues
|
|
96
90
|
// await motherboard.stop()
|
|
97
91
|
|
|
98
92
|
// Download data as CSV, JSON, or XML (default: CSV) format => timestamp, frame, battery, samples, masses
|
|
99
|
-
// download('json')
|
|
93
|
+
// motherboard.download('json')
|
|
100
94
|
},
|
|
101
95
|
(error) => {
|
|
102
96
|
// Optinal custom error handeling
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1 @@
|
|
|
1
1
|
export { Climbro, Entralpi, ForceBoard, KilterBoard, Motherboard, mySmartBoard, WHC06, Progressor, } from "./models/index";
|
|
2
|
-
export { isEntralpi, isKilterBoard, isMotherboard, isWHC06, isProgressor } from "./helpers/is-device";
|
|
3
|
-
export { download } from "./helpers/download";
|
|
4
|
-
export { active, isActive } from "./helpers/is-active";
|
|
5
|
-
export { tare } from "./helpers/tare";
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1 @@
|
|
|
1
1
|
export { Climbro, Entralpi, ForceBoard, KilterBoard, Motherboard, mySmartBoard, WHC06, Progressor, } from "./models/index";
|
|
2
|
-
// helpers
|
|
3
|
-
export { isEntralpi, isKilterBoard, isMotherboard, isWHC06, isProgressor } from "./helpers/is-device";
|
|
4
|
-
export { download } from "./helpers/download";
|
|
5
|
-
export { active, isActive } from "./helpers/is-active";
|
|
6
|
-
export { tare } from "./helpers/tare";
|
|
@@ -47,3 +47,9 @@ export type NotifyCallback = (data: massObject) => void;
|
|
|
47
47
|
* @param {string} data - The string data passed to the callback.
|
|
48
48
|
*/
|
|
49
49
|
export type WriteCallback = (data: string) => void;
|
|
50
|
+
/**
|
|
51
|
+
* Type definition for the callback function that is called when the activity status changes.
|
|
52
|
+
* @callback ActiveCallback
|
|
53
|
+
* @param {boolean} value - The new activity status (true if active, false if not).
|
|
54
|
+
*/
|
|
55
|
+
export type ActiveCallback = (data: boolean) => void;
|
|
@@ -1,76 +1,15 @@
|
|
|
1
1
|
import type { IDevice } from "../device.interface";
|
|
2
|
-
/**
|
|
3
|
-
* Represents a climbing placement with a position and role identifier.
|
|
4
|
-
*/
|
|
5
|
-
export interface ClimbPlacement {
|
|
6
|
-
/** The position of the hold placement. */
|
|
7
|
-
position: number;
|
|
8
|
-
/** The role ID associated with the climb placement. */
|
|
9
|
-
role_id: number;
|
|
10
|
-
}
|
|
11
2
|
/**
|
|
12
3
|
* Interface representing the KilterBoard device, extending the base Device interface.
|
|
13
4
|
*/
|
|
14
5
|
export interface IKilterBoard extends IDevice {
|
|
15
|
-
/**
|
|
16
|
-
* Calculates the checksum for a byte array.
|
|
17
|
-
* @param data - The array of bytes to calculate the checksum for.
|
|
18
|
-
* @returns The calculated checksum value.
|
|
19
|
-
*/
|
|
20
|
-
checksum(data: number[]): number;
|
|
21
|
-
/**
|
|
22
|
-
* Wraps a byte array with header and footer bytes for transmission.
|
|
23
|
-
* @param data - The array of bytes to wrap.
|
|
24
|
-
* @returns The wrapped byte array.
|
|
25
|
-
*/
|
|
26
|
-
wrapBytes(data: number[]): number[];
|
|
27
|
-
/**
|
|
28
|
-
* Encodes a position into a byte array.
|
|
29
|
-
* @param position - The position to encode.
|
|
30
|
-
* @returns The encoded byte array representing the position.
|
|
31
|
-
*/
|
|
32
|
-
encodePosition(position: number): number[];
|
|
33
|
-
/**
|
|
34
|
-
* Encodes a color string into a numeric representation.
|
|
35
|
-
* @param color - The color string in hexadecimal format.
|
|
36
|
-
* @returns The encoded/compressed color value.
|
|
37
|
-
*/
|
|
38
|
-
encodeColor(color: string): number;
|
|
39
|
-
/**
|
|
40
|
-
* Encodes a placement into a byte array.
|
|
41
|
-
* @param position - The position to encode.
|
|
42
|
-
* @param ledColor - The color of the LED in hexadecimal format.
|
|
43
|
-
* @returns The encoded byte array representing the placement.
|
|
44
|
-
*/
|
|
45
|
-
encodePlacement(position: number, ledColor: string): number[];
|
|
46
|
-
/**
|
|
47
|
-
* Prepares byte arrays for transmission based on a list of climb placements.
|
|
48
|
-
* @param climbPlacementList - The list of climb placements.
|
|
49
|
-
* @returns The final byte array ready for transmission.
|
|
50
|
-
*/
|
|
51
|
-
prepBytesV3(climbPlacementList: ClimbPlacement[]): number[];
|
|
52
|
-
/**
|
|
53
|
-
* Splits a collection into slices of the specified length.
|
|
54
|
-
* @param n - Number of elements per slice.
|
|
55
|
-
* @param list - Array to be sliced.
|
|
56
|
-
* @returns The sliced array.
|
|
57
|
-
*/
|
|
58
|
-
splitEvery(n: number, list: number[]): number[][];
|
|
59
|
-
/**
|
|
60
|
-
* Splits a message into 20-byte chunks for Bluetooth transmission.
|
|
61
|
-
* @param buffer - The message to split.
|
|
62
|
-
* @returns The array of Uint8Arrays.
|
|
63
|
-
*/
|
|
64
|
-
splitMessages(buffer: number[]): Uint8Array[];
|
|
65
|
-
/**
|
|
66
|
-
* Sends a series of messages to the device.
|
|
67
|
-
* @param messages - Array of Uint8Arrays to send.
|
|
68
|
-
*/
|
|
69
|
-
writeMessageSeries(messages: Uint8Array[]): Promise<void>;
|
|
70
6
|
/**
|
|
71
7
|
* Configures the LEDs based on an array of climb placements.
|
|
72
|
-
* @param
|
|
73
|
-
* @returns
|
|
8
|
+
* @param {{ position: number; role_id: number }[]} config - Array of climb placements for the LEDs.
|
|
9
|
+
* @returns {Promise<number[] | undefined>} A promise that resolves with the payload array for the Kilter Board if LED settings were applied, or `undefined` if no action was taken or for the Motherboard.
|
|
74
10
|
*/
|
|
75
|
-
led(config
|
|
11
|
+
led(config: {
|
|
12
|
+
position: number;
|
|
13
|
+
role_id: number;
|
|
14
|
+
}[]): Promise<number[] | undefined>;
|
|
76
15
|
}
|
|
@@ -3,13 +3,6 @@ import type { IDevice } from "../device.interface";
|
|
|
3
3
|
* Interface representing the Griptonite Motherboard device.
|
|
4
4
|
*/
|
|
5
5
|
export interface IMotherboard extends IDevice {
|
|
6
|
-
/**
|
|
7
|
-
* Applies calibration to a sample value.
|
|
8
|
-
* @param {number} sample - The sample value to calibrate.
|
|
9
|
-
* @param {number[][]} calibration - The calibration data.
|
|
10
|
-
* @returns {number} The calibrated sample value.
|
|
11
|
-
*/
|
|
12
|
-
applyCalibration(sample: number, calibration: number[][]): number;
|
|
13
6
|
/**
|
|
14
7
|
* Retrieves battery or voltage information from the device.
|
|
15
8
|
* @returns {Promise<string | undefined>} A Promise that resolves with the battery or voltage information.
|
|
@@ -34,81 +34,87 @@ export interface IDevice extends IBase {
|
|
|
34
34
|
/**
|
|
35
35
|
* Filters to identify the device during Bluetooth scanning.
|
|
36
36
|
* Used to match devices that meet specific criteria such as name, service UUIDs, etc.
|
|
37
|
+
* @type {BluetoothLEScanFilter[]}
|
|
38
|
+
* @public
|
|
39
|
+
* @readonly
|
|
37
40
|
*/
|
|
38
41
|
filters: BluetoothLEScanFilter[];
|
|
39
42
|
/**
|
|
40
43
|
* Array of services provided by the device.
|
|
41
44
|
* Services represent functionalities that the device supports, such as weight measurement, battery information, or custom services.
|
|
45
|
+
* @type {Service[]}
|
|
46
|
+
* @public
|
|
47
|
+
* @readonly
|
|
42
48
|
*/
|
|
43
49
|
services: Service[];
|
|
44
50
|
/**
|
|
45
51
|
* Reference to the `BluetoothDevice` object representing this device.
|
|
46
52
|
* This is the actual device object obtained from the Web Bluetooth API after a successful connection.
|
|
53
|
+
* @type {BluetoothDevice | undefined}
|
|
54
|
+
* @public
|
|
47
55
|
*/
|
|
48
56
|
bluetooth?: BluetoothDevice;
|
|
49
57
|
/**
|
|
50
58
|
* Object representing the set of commands available for this device.
|
|
51
59
|
* These commands allow communication with the device to perform various operations such as starting measurements, retrieving data, or calibrating the device.
|
|
60
|
+
* @type {Commands}
|
|
61
|
+
* @public
|
|
62
|
+
* @readonly
|
|
52
63
|
*/
|
|
53
64
|
commands: Commands;
|
|
54
65
|
/**
|
|
55
66
|
* Connects to a Bluetooth device.
|
|
56
67
|
* @param {Function} [onSuccess] - Optional callback function to execute on successful connection. Default logs success.
|
|
57
68
|
* @param {Function} [onError] - Optional callback function to execute on error. Default logs the error.
|
|
69
|
+
* @public
|
|
58
70
|
*/
|
|
59
71
|
connect(onSuccess?: () => void, onError?: (error: Error) => void): Promise<void>;
|
|
60
72
|
/**
|
|
61
73
|
* Disconnects the device if it is currently connected.
|
|
62
74
|
* - Checks if the device is connected via it's GATT server.
|
|
63
75
|
* - If the device is connected, it attempts to gracefully disconnect.
|
|
76
|
+
* @public
|
|
64
77
|
*/
|
|
65
78
|
disconnect(): void;
|
|
66
79
|
/**
|
|
67
|
-
*
|
|
68
|
-
*
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
*
|
|
73
|
-
* @
|
|
74
|
-
* @
|
|
75
|
-
* @returns {BluetoothRemoteGATTCharacteristic | undefined} The characteristic, if found.
|
|
76
|
-
*/
|
|
77
|
-
getCharacteristic(serviceId: string, characteristicId: string): BluetoothRemoteGATTCharacteristic | undefined;
|
|
78
|
-
/**
|
|
79
|
-
* Handles notifications received from a characteristic.
|
|
80
|
-
* @param {Event} event - The notification event.
|
|
80
|
+
* Exports the data in the specified format (CSV, JSON, XML) with a filename format:
|
|
81
|
+
* 'data-export-YYYY-MM-DD-HH-MM-SS.{format}'.
|
|
82
|
+
*
|
|
83
|
+
* @param {('csv' | 'json' | 'xml')} [format='csv'] - The format in which to download the data.
|
|
84
|
+
* Defaults to 'csv'. Accepted values are 'csv', 'json', and 'xml'.
|
|
85
|
+
*
|
|
86
|
+
* @returns {void} Initiates a download of the data in the specified format.
|
|
87
|
+
* @private
|
|
81
88
|
*/
|
|
82
|
-
|
|
89
|
+
download(format?: "csv" | "json" | "xml"): void;
|
|
83
90
|
/**
|
|
84
91
|
* Checks if a Bluetooth device is connected.
|
|
85
92
|
* @returns {boolean} A boolean indicating whether the device is connected.
|
|
93
|
+
* @public
|
|
86
94
|
*/
|
|
87
95
|
isConnected(): boolean;
|
|
88
96
|
/**
|
|
89
97
|
* Sets the callback function to be called when notifications are received.
|
|
90
98
|
* @param {NotifyCallback} callback - The callback function to be set.
|
|
91
99
|
* @returns {void}
|
|
100
|
+
* @public
|
|
92
101
|
*/
|
|
93
102
|
notify(callback: (data: massObject) => void): void;
|
|
94
|
-
/**
|
|
95
|
-
* Handles the 'connected' event.
|
|
96
|
-
* @param {Function} onSuccess - Callback function to execute on successful connection.
|
|
97
|
-
*/
|
|
98
|
-
onConnected(onSuccess: () => void): Promise<void>;
|
|
99
|
-
/**
|
|
100
|
-
* Handles the 'disconnected' event.
|
|
101
|
-
* @param {Event} event - The 'disconnected' event.
|
|
102
|
-
*/
|
|
103
|
-
onDisconnected(event: Event): void;
|
|
104
103
|
/**
|
|
105
104
|
* Reads the value of the specified characteristic from the device.
|
|
106
105
|
* @param {string} serviceId - The service ID where the characteristic belongs.
|
|
107
106
|
* @param {string} characteristicId - The characteristic ID to read from.
|
|
108
107
|
* @param {number} [duration=0] - The duration to wait before resolving the promise, in milliseconds.
|
|
109
108
|
* @returns {Promise<string | undefined>} A promise that resolves when the read operation is completed.
|
|
109
|
+
* @public
|
|
110
110
|
*/
|
|
111
111
|
read(serviceId: string, characteristicId: string, duration?: number): Promise<string | undefined>;
|
|
112
|
+
/**
|
|
113
|
+
* Initiates the tare calibration process.
|
|
114
|
+
* @param {number} duration - The duration time for tare calibration.
|
|
115
|
+
* @returns {void}
|
|
116
|
+
*/
|
|
117
|
+
tare(duration?: number): void;
|
|
112
118
|
/**
|
|
113
119
|
* Writes a message to the specified characteristic of a Bluetooth device and optionally provides a callback to handle responses.
|
|
114
120
|
* @param {string} serviceId - The service UUID of the Bluetooth device containing the target characteristic.
|
|
@@ -116,9 +122,8 @@ export interface IDevice extends IBase {
|
|
|
116
122
|
* @param {string | Uint8Array | undefined} message - The message to be written to the characteristic. It can be a string or a Uint8Array.
|
|
117
123
|
* @param {number} [duration=0] - Optional. The time in milliseconds to wait before resolving the promise. Defaults to 0 for immediate resolution.
|
|
118
124
|
* @param {WriteCallback} [callback=writeCallback] - Optional. A custom callback to handle the response after the write operation is successful.
|
|
119
|
-
*
|
|
120
125
|
* @returns {Promise<void>} A promise that resolves once the write operation is complete.
|
|
121
|
-
*
|
|
126
|
+
* @public
|
|
122
127
|
* @throws {Error} Throws an error if the characteristic is undefined.
|
|
123
128
|
*
|
|
124
129
|
* @example
|
|
@@ -1,7 +1,4 @@
|
|
|
1
1
|
import { Device } from "../device.model";
|
|
2
|
-
import { applyTare } from "../../helpers/tare";
|
|
3
|
-
import { checkActivity } from "../../helpers/is-active";
|
|
4
|
-
import { DownloadPackets } from "../../helpers/download";
|
|
5
2
|
export class Entralpi extends Device {
|
|
6
3
|
constructor() {
|
|
7
4
|
super({
|
|
@@ -162,10 +159,13 @@ export class Entralpi extends Device {
|
|
|
162
159
|
const receivedTime = Date.now();
|
|
163
160
|
const receivedData = (rawData.getUint16(0) / 100).toFixed(1);
|
|
164
161
|
const convertedData = Number(receivedData);
|
|
165
|
-
//
|
|
166
|
-
|
|
162
|
+
// Adjust weight by using the tare value
|
|
163
|
+
// If tare is 0, use the original weight, otherwise subtract tare and invert.
|
|
164
|
+
// This will display the romoved or 'no-hanging' weight.
|
|
165
|
+
const tare = this.applyTare(convertedData);
|
|
166
|
+
const numericData = tare === 0 ? convertedData : (convertedData - tare) * -1;
|
|
167
167
|
// Add data to downloadable Array
|
|
168
|
-
|
|
168
|
+
this.downloadPackets.push({
|
|
169
169
|
received: receivedTime,
|
|
170
170
|
sampleNum: this.dataPointCount,
|
|
171
171
|
battRaw: 0,
|
|
@@ -181,7 +181,7 @@ export class Entralpi extends Device {
|
|
|
181
181
|
// Calculate the average dynamically
|
|
182
182
|
this.massAverage = (this.massTotalSum / this.dataPointCount).toFixed(1);
|
|
183
183
|
// Check if device is being used
|
|
184
|
-
|
|
184
|
+
this.activityCheck(numericData);
|
|
185
185
|
// Notify with weight data
|
|
186
186
|
this.notifyCallback({
|
|
187
187
|
massMax: this.massMax,
|
|
@@ -1,7 +1,4 @@
|
|
|
1
1
|
import { Device } from "../device.model";
|
|
2
|
-
import { DownloadPackets, emptyDownloadPackets } from "../../helpers/download";
|
|
3
|
-
import { checkActivity } from "../../helpers/is-active";
|
|
4
|
-
import { applyTare } from "../../helpers/tare";
|
|
5
2
|
/**
|
|
6
3
|
* Represents a PitchSix Force Board device
|
|
7
4
|
*/
|
|
@@ -193,9 +190,9 @@ export class ForceBoard extends Device {
|
|
|
193
190
|
// Convert from LBS to KG
|
|
194
191
|
const convertedReceivedData = receivedData * 0.453592;
|
|
195
192
|
// Tare correction
|
|
196
|
-
const numericData = convertedReceivedData - applyTare(convertedReceivedData);
|
|
193
|
+
const numericData = convertedReceivedData - this.applyTare(convertedReceivedData);
|
|
197
194
|
// Add data to downloadable Array
|
|
198
|
-
|
|
195
|
+
this.downloadPackets.push({
|
|
199
196
|
received: receivedTime,
|
|
200
197
|
sampleNum: this.dataPointCount,
|
|
201
198
|
battRaw: 0,
|
|
@@ -211,7 +208,7 @@ export class ForceBoard extends Device {
|
|
|
211
208
|
// Calculate the average dynamically
|
|
212
209
|
this.massAverage = (this.massTotalSum / this.dataPointCount).toFixed(1);
|
|
213
210
|
// Check if device is being used
|
|
214
|
-
|
|
211
|
+
this.activityCheck(numericData);
|
|
215
212
|
// Notify with weight data
|
|
216
213
|
this.notifyCallback({
|
|
217
214
|
massMax: this.massMax,
|
|
@@ -249,7 +246,7 @@ export class ForceBoard extends Device {
|
|
|
249
246
|
*/
|
|
250
247
|
stream = async (duration = 0) => {
|
|
251
248
|
// Reset download packets
|
|
252
|
-
|
|
249
|
+
this.downloadPackets.length = 0;
|
|
253
250
|
// Start streaming data
|
|
254
251
|
await this.write("weight", "tx", new Uint8Array([0x04]), duration); // ASCII control character EOT (End of Transmission)
|
|
255
252
|
// Stop streaming if duration is set
|
|
@@ -35,14 +35,6 @@ export declare const KilterBoardPlacementRoles: {
|
|
|
35
35
|
led_color: string;
|
|
36
36
|
screen_color: string;
|
|
37
37
|
}[];
|
|
38
|
-
/**
|
|
39
|
-
* Represents climbs_placements from the Kilter Board application
|
|
40
|
-
*/
|
|
41
|
-
declare class ClimbPlacement {
|
|
42
|
-
position: number;
|
|
43
|
-
role_id: number;
|
|
44
|
-
constructor(position: number, role_id: number);
|
|
45
|
-
}
|
|
46
38
|
/**
|
|
47
39
|
* Represents a Aurora Climbing device
|
|
48
40
|
* Kilter Board, Tension Board, Decoy Board, Touchstone Board, Grasshopper Board, Aurora Board, So iLL Board
|
|
@@ -51,41 +43,45 @@ export declare class KilterBoard extends Device implements IKilterBoard {
|
|
|
51
43
|
/**
|
|
52
44
|
* UUID for the Aurora Climbing Advertising service.
|
|
53
45
|
* This constant is used to identify the specific Bluetooth service for Kilter Boards.
|
|
54
|
-
*
|
|
55
46
|
* @type {string}
|
|
47
|
+
* @static
|
|
48
|
+
* @readonly
|
|
49
|
+
* @constant
|
|
56
50
|
*/
|
|
57
|
-
static AuroraUUID: string;
|
|
51
|
+
static readonly AuroraUUID: string;
|
|
58
52
|
/**
|
|
59
53
|
* Maximum length of the message body for byte wrapping.
|
|
60
54
|
* This value defines the limit for the size of messages that can be sent or received
|
|
61
55
|
* to ensure proper byte wrapping in communication.
|
|
62
|
-
*
|
|
63
56
|
* @type {number}
|
|
64
57
|
* @private
|
|
58
|
+
* @readonly
|
|
59
|
+
* @constant
|
|
65
60
|
*/
|
|
66
|
-
private
|
|
61
|
+
private static readonly messageBodyMaxLength;
|
|
67
62
|
/**
|
|
68
63
|
* Maximum length of the Bluetooth message chunk.
|
|
69
64
|
* This value sets the upper limit for the size of individual Bluetooth messages
|
|
70
65
|
* sent to and from the device to comply with Bluetooth protocol constraints.
|
|
71
|
-
*
|
|
72
66
|
* @type {number}
|
|
73
67
|
* @private
|
|
68
|
+
* @readonly
|
|
69
|
+
* @constant
|
|
74
70
|
*/
|
|
75
|
-
private
|
|
71
|
+
private static readonly maxBluetoothMessageSize;
|
|
76
72
|
constructor();
|
|
77
73
|
/**
|
|
78
74
|
* Calculates the checksum for a byte array by summing up all bytes ot hre packet in a single-byte variable.
|
|
79
75
|
* @param data - The array of bytes to calculate the checksum for.
|
|
80
76
|
* @returns The calculated checksum value.
|
|
81
77
|
*/
|
|
82
|
-
checksum
|
|
78
|
+
private checksum;
|
|
83
79
|
/**
|
|
84
80
|
* Wraps a byte array with header and footer bytes for transmission.
|
|
85
81
|
* @param data - The array of bytes to wrap.
|
|
86
82
|
* @returns The wrapped byte array.
|
|
87
83
|
*/
|
|
88
|
-
wrapBytes
|
|
84
|
+
private wrapBytes;
|
|
89
85
|
/**
|
|
90
86
|
* Encodes a position into a byte array.
|
|
91
87
|
* The lowest 8 bits of the position get put in the first byte of the group.
|
|
@@ -93,27 +89,27 @@ export declare class KilterBoard extends Device implements IKilterBoard {
|
|
|
93
89
|
* @param position - The position to encode.
|
|
94
90
|
* @returns The encoded byte array representing the position.
|
|
95
91
|
*/
|
|
96
|
-
encodePosition
|
|
92
|
+
private encodePosition;
|
|
97
93
|
/**
|
|
98
94
|
* Encodes a color string into a numeric representation.
|
|
99
95
|
* 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).
|
|
100
96
|
* @param color - The color string in hexadecimal format (e.g., 'FFFFFF').
|
|
101
97
|
* @returns The encoded /compressed color value.
|
|
102
98
|
*/
|
|
103
|
-
encodeColor
|
|
99
|
+
private encodeColor;
|
|
104
100
|
/**
|
|
105
101
|
* Encodes a placement (requires a 16-bit position and a 24-bit rgb color. ) into a byte array.
|
|
106
102
|
* @param position - The position to encode.
|
|
107
103
|
* @param ledColor - The color of the LED in hexadecimal format (e.g., 'FFFFFF').
|
|
108
104
|
* @returns The encoded byte array representing the placement.
|
|
109
105
|
*/
|
|
110
|
-
encodePlacement
|
|
106
|
+
private encodePlacement;
|
|
111
107
|
/**
|
|
112
108
|
* Prepares byte arrays for transmission based on a list of climb placements.
|
|
113
|
-
* @param climbPlacementList - The list of climb placements containing position and role ID.
|
|
114
|
-
* @returns The final byte array ready for transmission.
|
|
109
|
+
* @param {{ position: number; role_id: number }[]} climbPlacementList - The list of climb placements containing position and role ID.
|
|
110
|
+
* @returns {number[]} The final byte array ready for transmission.
|
|
115
111
|
*/
|
|
116
|
-
prepBytesV3
|
|
112
|
+
private prepBytesV3;
|
|
117
113
|
/**
|
|
118
114
|
* Splits a collection into slices of the specified length.
|
|
119
115
|
* https://github.com/ramda/ramda/blob/master/source/splitEvery.js
|
|
@@ -121,7 +117,7 @@ export declare class KilterBoard extends Device implements IKilterBoard {
|
|
|
121
117
|
* @param {Array} list
|
|
122
118
|
* @return {Array}
|
|
123
119
|
*/
|
|
124
|
-
splitEvery
|
|
120
|
+
private splitEvery;
|
|
125
121
|
/**
|
|
126
122
|
* The kilter board only supports messages of 20 bytes
|
|
127
123
|
* at a time. This method splits a full message into parts
|
|
@@ -129,16 +125,18 @@ export declare class KilterBoard extends Device implements IKilterBoard {
|
|
|
129
125
|
*
|
|
130
126
|
* @param buffer
|
|
131
127
|
*/
|
|
132
|
-
splitMessages
|
|
128
|
+
private splitMessages;
|
|
133
129
|
/**
|
|
134
130
|
* Sends a series of messages to a device.
|
|
135
131
|
*/
|
|
136
|
-
writeMessageSeries
|
|
132
|
+
private writeMessageSeries;
|
|
137
133
|
/**
|
|
138
|
-
* Configures the LEDs based on an array of climb placements.
|
|
139
|
-
* @param {
|
|
134
|
+
* Configures the LEDs based on an array of climb placements.
|
|
135
|
+
* @param {{ position: number; role_id: number }[]} config - Array of climb placements for the LEDs.
|
|
140
136
|
* @returns {Promise<number[] | undefined>} A promise that resolves with the payload array for the Kilter Board if LED settings were applied, or `undefined` if no action was taken or for the Motherboard.
|
|
141
137
|
*/
|
|
142
|
-
led: (config
|
|
138
|
+
led: (config: {
|
|
139
|
+
position: number;
|
|
140
|
+
role_id: number;
|
|
141
|
+
}[]) => Promise<number[] | undefined>;
|
|
143
142
|
}
|
|
144
|
-
export {};
|
|
@@ -64,17 +64,6 @@ export const KilterBoardPlacementRoles = [
|
|
|
64
64
|
screen_color: "FFA500",
|
|
65
65
|
},
|
|
66
66
|
];
|
|
67
|
-
/**
|
|
68
|
-
* Represents climbs_placements from the Kilter Board application
|
|
69
|
-
*/
|
|
70
|
-
class ClimbPlacement {
|
|
71
|
-
position;
|
|
72
|
-
role_id;
|
|
73
|
-
constructor(position, role_id) {
|
|
74
|
-
this.position = position;
|
|
75
|
-
this.role_id = role_id;
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
67
|
/**
|
|
79
68
|
* Represents a Aurora Climbing device
|
|
80
69
|
* Kilter Board, Tension Board, Decoy Board, Touchstone Board, Grasshopper Board, Aurora Board, So iLL Board
|
|
@@ -83,28 +72,32 @@ export class KilterBoard extends Device {
|
|
|
83
72
|
/**
|
|
84
73
|
* UUID for the Aurora Climbing Advertising service.
|
|
85
74
|
* This constant is used to identify the specific Bluetooth service for Kilter Boards.
|
|
86
|
-
*
|
|
87
75
|
* @type {string}
|
|
76
|
+
* @static
|
|
77
|
+
* @readonly
|
|
78
|
+
* @constant
|
|
88
79
|
*/
|
|
89
80
|
static AuroraUUID = "4488b571-7806-4df6-bcff-a2897e4953ff";
|
|
90
81
|
/**
|
|
91
82
|
* Maximum length of the message body for byte wrapping.
|
|
92
83
|
* This value defines the limit for the size of messages that can be sent or received
|
|
93
84
|
* to ensure proper byte wrapping in communication.
|
|
94
|
-
*
|
|
95
85
|
* @type {number}
|
|
96
86
|
* @private
|
|
87
|
+
* @readonly
|
|
88
|
+
* @constant
|
|
97
89
|
*/
|
|
98
|
-
|
|
90
|
+
static messageBodyMaxLength = 255;
|
|
99
91
|
/**
|
|
100
92
|
* Maximum length of the Bluetooth message chunk.
|
|
101
93
|
* This value sets the upper limit for the size of individual Bluetooth messages
|
|
102
94
|
* sent to and from the device to comply with Bluetooth protocol constraints.
|
|
103
|
-
*
|
|
104
95
|
* @type {number}
|
|
105
96
|
* @private
|
|
97
|
+
* @readonly
|
|
98
|
+
* @constant
|
|
106
99
|
*/
|
|
107
|
-
|
|
100
|
+
static maxBluetoothMessageSize = 20;
|
|
108
101
|
constructor() {
|
|
109
102
|
super({
|
|
110
103
|
filters: [
|
|
@@ -151,7 +144,7 @@ export class KilterBoard extends Device {
|
|
|
151
144
|
* @returns The wrapped byte array.
|
|
152
145
|
*/
|
|
153
146
|
wrapBytes(data) {
|
|
154
|
-
if (data.length >
|
|
147
|
+
if (data.length > KilterBoard.messageBodyMaxLength) {
|
|
155
148
|
return [];
|
|
156
149
|
}
|
|
157
150
|
/**
|
|
@@ -206,14 +199,14 @@ export class KilterBoard extends Device {
|
|
|
206
199
|
}
|
|
207
200
|
/**
|
|
208
201
|
* Prepares byte arrays for transmission based on a list of climb placements.
|
|
209
|
-
* @param climbPlacementList - The list of climb placements containing position and role ID.
|
|
210
|
-
* @returns The final byte array ready for transmission.
|
|
202
|
+
* @param {{ position: number; role_id: number }[]} climbPlacementList - The list of climb placements containing position and role ID.
|
|
203
|
+
* @returns {number[]} The final byte array ready for transmission.
|
|
211
204
|
*/
|
|
212
205
|
prepBytesV3(climbPlacementList) {
|
|
213
206
|
const resultArray = [];
|
|
214
207
|
let tempArray = [KilterBoardPacket.V3_MIDDLE];
|
|
215
208
|
for (const climbPlacement of climbPlacementList) {
|
|
216
|
-
if (tempArray.length + 3 >
|
|
209
|
+
if (tempArray.length + 3 > KilterBoard.messageBodyMaxLength) {
|
|
217
210
|
resultArray.push(tempArray);
|
|
218
211
|
tempArray = [KilterBoardPacket.V3_MIDDLE];
|
|
219
212
|
}
|
|
@@ -263,7 +256,7 @@ export class KilterBoard extends Device {
|
|
|
263
256
|
*
|
|
264
257
|
* @param buffer
|
|
265
258
|
*/
|
|
266
|
-
splitMessages = (buffer) => this.splitEvery(
|
|
259
|
+
splitMessages = (buffer) => this.splitEvery(KilterBoard.maxBluetoothMessageSize, buffer).map((arr) => new Uint8Array(arr));
|
|
267
260
|
/**
|
|
268
261
|
* Sends a series of messages to a device.
|
|
269
262
|
*/
|
|
@@ -273,8 +266,8 @@ export class KilterBoard extends Device {
|
|
|
273
266
|
}
|
|
274
267
|
}
|
|
275
268
|
/**
|
|
276
|
-
* Configures the LEDs based on an array of climb placements.
|
|
277
|
-
* @param {
|
|
269
|
+
* Configures the LEDs based on an array of climb placements.
|
|
270
|
+
* @param {{ position: number; role_id: number }[]} config - Array of climb placements for the LEDs.
|
|
278
271
|
* @returns {Promise<number[] | undefined>} A promise that resolves with the payload array for the Kilter Board if LED settings were applied, or `undefined` if no action was taken or for the Motherboard.
|
|
279
272
|
*/
|
|
280
273
|
led = async (config) => {
|