@hangtime/grip-connect 0.5.6 → 0.5.8
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 +32 -35
- 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/motherboard.interface.d.ts +0 -7
- package/dist/interfaces/device.interface.d.ts +32 -27
- package/dist/models/device/entralpi.model.js +8 -10
- package/dist/models/device/forceboard.model.js +35 -35
- package/dist/models/device/kilterboard.model.d.ts +10 -6
- package/dist/models/device/kilterboard.model.js +12 -8
- 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 +26 -20
- package/dist/models/device/wh-c06.model.d.ts +11 -6
- package/dist/models/device/wh-c06.model.js +30 -16
- package/dist/models/device.model.d.ts +161 -14
- package/dist/models/device.model.js +264 -9
- package/package.json +1 -1
- package/src/index.ts +0 -9
- package/src/interfaces/callback.interface.ts +7 -0
- package/src/interfaces/device/motherboard.interface.ts +0 -8
- package/src/interfaces/device.interface.ts +33 -31
- package/src/models/device/entralpi.model.ts +8 -10
- package/src/models/device/forceboard.model.ts +35 -36
- package/src/models/device/kilterboard.model.ts +23 -9
- package/src/models/device/motherboard.model.ts +23 -22
- package/src/models/device/progressor.model.ts +26 -20
- package/src/models/device/wh-c06.model.ts +38 -17
- package/src/models/device.model.ts +317 -19
- 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/struct.d.ts +0 -9
- package/dist/helpers/struct.js +0 -203
- 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/struct.ts +0 -239
- package/src/helpers/tare.ts +0 -76
package/README.md
CHANGED
|
@@ -43,68 +43,65 @@ $ 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) => {
|
|
67
|
+
console.log(isActive)
|
|
68
|
+
},
|
|
69
|
+
// Optionally using a weight threshold and duration
|
|
70
|
+
{ threshold: 2.5, duration: 1000 },
|
|
71
|
+
)
|
|
72
|
+
|
|
73
|
+
document.querySelector("#motherboard").addEventListener("click", async () => {
|
|
74
|
+
// Connect to device
|
|
75
|
+
await motherboard.connect(
|
|
62
76
|
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
|
|
77
|
+
// Example: Read device specific data
|
|
79
78
|
const batteryLevel = await motherboard.battery()
|
|
80
79
|
console.log(batteryLevel)
|
|
81
80
|
|
|
82
|
-
const firmwareVersion = await motherboard.firmware()
|
|
83
|
-
console.log(firmwareVersion)
|
|
84
|
-
|
|
85
81
|
// LEDs: "green", "red", "orange", or no argument to turn off
|
|
86
|
-
// await motherboard.led(
|
|
87
|
-
// await motherboard.led(
|
|
82
|
+
// await motherboard.led("red")
|
|
83
|
+
// await motherboard.led()
|
|
88
84
|
|
|
89
|
-
// Start weight streaming (for
|
|
90
|
-
await motherboard.stream(
|
|
85
|
+
// Start weight streaming (for 30s) remove parameter for a continues stream
|
|
86
|
+
await motherboard.stream(30000)
|
|
91
87
|
|
|
92
88
|
// Manualy tare the device when the stream is running
|
|
93
|
-
// await tare(5000)
|
|
89
|
+
// await motherboard.tare(5000)
|
|
94
90
|
|
|
95
91
|
// Manually call stop method if stream is continues
|
|
96
92
|
// await motherboard.stop()
|
|
97
93
|
|
|
98
94
|
// Download data as CSV, JSON, or XML (default: CSV) format => timestamp, frame, battery, samples, masses
|
|
99
|
-
// download('json')
|
|
95
|
+
// motherboard.download('json')
|
|
96
|
+
|
|
97
|
+
// Optionally disconnect from device after we are done
|
|
98
|
+
motherboard.disconnect(Motherboard)
|
|
100
99
|
},
|
|
101
100
|
(error) => {
|
|
102
101
|
// Optinal custom error handeling
|
|
103
102
|
console.error(error.message)
|
|
104
103
|
},
|
|
105
104
|
)
|
|
106
|
-
// Disconnect from device after we are done
|
|
107
|
-
motherboard.disconnect(Motherboard)
|
|
108
105
|
})
|
|
109
106
|
```
|
|
110
107
|
|
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;
|
|
@@ -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({
|
|
@@ -157,15 +154,16 @@ export class Entralpi extends Device {
|
|
|
157
154
|
const value = characteristic.value;
|
|
158
155
|
if (value) {
|
|
159
156
|
if (value.buffer) {
|
|
160
|
-
const buffer = value.buffer;
|
|
161
|
-
const rawData = new DataView(buffer);
|
|
162
157
|
const receivedTime = Date.now();
|
|
163
|
-
const receivedData = (
|
|
158
|
+
const receivedData = (value.getUint16(0) / 100).toFixed(1);
|
|
164
159
|
const convertedData = Number(receivedData);
|
|
165
|
-
//
|
|
166
|
-
|
|
160
|
+
// Adjust weight by using the tare value
|
|
161
|
+
// If tare is 0, use the original weight, otherwise subtract tare and invert.
|
|
162
|
+
// This will display the removed or 'no-hanging' weight.
|
|
163
|
+
const tare = this.applyTare(convertedData);
|
|
164
|
+
const numericData = tare === 0 ? convertedData : (convertedData - tare) * -1;
|
|
167
165
|
// Add data to downloadable Array
|
|
168
|
-
|
|
166
|
+
this.downloadPackets.push({
|
|
169
167
|
received: receivedTime,
|
|
170
168
|
sampleNum: this.dataPointCount,
|
|
171
169
|
battRaw: 0,
|
|
@@ -181,7 +179,7 @@ export class Entralpi extends Device {
|
|
|
181
179
|
// Calculate the average dynamically
|
|
182
180
|
this.massAverage = (this.massTotalSum / this.dataPointCount).toFixed(1);
|
|
183
181
|
// Check if device is being used
|
|
184
|
-
|
|
182
|
+
this.activityCheck(numericData);
|
|
185
183
|
// Notify with weight data
|
|
186
184
|
this.notifyCallback({
|
|
187
185
|
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
|
*/
|
|
@@ -186,38 +183,41 @@ export class ForceBoard extends Device {
|
|
|
186
183
|
const value = characteristic.value;
|
|
187
184
|
if (value) {
|
|
188
185
|
if (value.buffer) {
|
|
189
|
-
const buffer = value.buffer;
|
|
190
|
-
const rawData = new DataView(buffer);
|
|
191
186
|
const receivedTime = Date.now();
|
|
192
|
-
const
|
|
193
|
-
//
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
187
|
+
const dataArray = new Uint8Array(value.buffer);
|
|
188
|
+
// Skip the first 2 bytes, which are the command and length
|
|
189
|
+
// The data is sent in groups of 3 bytes
|
|
190
|
+
for (let i = 2; i < dataArray.length; i += 3) {
|
|
191
|
+
const receivedData = (dataArray[i] << 16) | (dataArray[i + 1] << 8) | dataArray[i + 2];
|
|
192
|
+
// Convert from LBS to KG
|
|
193
|
+
const convertedReceivedData = receivedData * 0.453592;
|
|
194
|
+
// Tare correction
|
|
195
|
+
const numericData = convertedReceivedData - this.applyTare(convertedReceivedData);
|
|
196
|
+
// Add data to downloadable Array
|
|
197
|
+
this.downloadPackets.push({
|
|
198
|
+
received: receivedTime,
|
|
199
|
+
sampleNum: this.dataPointCount,
|
|
200
|
+
battRaw: 0,
|
|
201
|
+
samples: [convertedReceivedData],
|
|
202
|
+
masses: [numericData],
|
|
203
|
+
});
|
|
204
|
+
// Update massMax
|
|
205
|
+
this.massMax = Math.max(Number(this.massMax), numericData).toFixed(1);
|
|
206
|
+
// Update running sum and count
|
|
207
|
+
const currentMassTotal = Math.max(-1000, numericData);
|
|
208
|
+
this.massTotalSum += currentMassTotal;
|
|
209
|
+
this.dataPointCount++;
|
|
210
|
+
// Calculate the average dynamically
|
|
211
|
+
this.massAverage = (this.massTotalSum / this.dataPointCount).toFixed(1);
|
|
212
|
+
// Check if device is being used
|
|
213
|
+
this.activityCheck(numericData);
|
|
214
|
+
// Notify with weight data
|
|
215
|
+
this.notifyCallback({
|
|
216
|
+
massMax: this.massMax,
|
|
217
|
+
massAverage: this.massAverage,
|
|
218
|
+
massTotal: Math.max(-1000, numericData).toFixed(1),
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
221
|
}
|
|
222
222
|
}
|
|
223
223
|
};
|
|
@@ -249,7 +249,7 @@ export class ForceBoard extends Device {
|
|
|
249
249
|
*/
|
|
250
250
|
stream = async (duration = 0) => {
|
|
251
251
|
// Reset download packets
|
|
252
|
-
|
|
252
|
+
this.downloadPackets.length = 0;
|
|
253
253
|
// Start streaming data
|
|
254
254
|
await this.write("weight", "tx", new Uint8Array([0x04]), duration); // ASCII control character EOT (End of Transmission)
|
|
255
255
|
// Stop streaming if duration is set
|
|
@@ -43,28 +43,32 @@ export declare class KilterBoard extends Device implements IKilterBoard {
|
|
|
43
43
|
/**
|
|
44
44
|
* UUID for the Aurora Climbing Advertising service.
|
|
45
45
|
* This constant is used to identify the specific Bluetooth service for Kilter Boards.
|
|
46
|
-
*
|
|
47
46
|
* @type {string}
|
|
47
|
+
* @static
|
|
48
|
+
* @readonly
|
|
49
|
+
* @constant
|
|
48
50
|
*/
|
|
49
|
-
static AuroraUUID: string;
|
|
51
|
+
static readonly AuroraUUID: string;
|
|
50
52
|
/**
|
|
51
53
|
* Maximum length of the message body for byte wrapping.
|
|
52
54
|
* This value defines the limit for the size of messages that can be sent or received
|
|
53
55
|
* to ensure proper byte wrapping in communication.
|
|
54
|
-
*
|
|
55
56
|
* @type {number}
|
|
56
57
|
* @private
|
|
58
|
+
* @readonly
|
|
59
|
+
* @constant
|
|
57
60
|
*/
|
|
58
|
-
private
|
|
61
|
+
private static readonly messageBodyMaxLength;
|
|
59
62
|
/**
|
|
60
63
|
* Maximum length of the Bluetooth message chunk.
|
|
61
64
|
* This value sets the upper limit for the size of individual Bluetooth messages
|
|
62
65
|
* sent to and from the device to comply with Bluetooth protocol constraints.
|
|
63
|
-
*
|
|
64
66
|
* @type {number}
|
|
65
67
|
* @private
|
|
68
|
+
* @readonly
|
|
69
|
+
* @constant
|
|
66
70
|
*/
|
|
67
|
-
private
|
|
71
|
+
private static readonly maxBluetoothMessageSize;
|
|
68
72
|
constructor();
|
|
69
73
|
/**
|
|
70
74
|
* Calculates the checksum for a byte array by summing up all bytes ot hre packet in a single-byte variable.
|
|
@@ -72,28 +72,32 @@ export class KilterBoard extends Device {
|
|
|
72
72
|
/**
|
|
73
73
|
* UUID for the Aurora Climbing Advertising service.
|
|
74
74
|
* This constant is used to identify the specific Bluetooth service for Kilter Boards.
|
|
75
|
-
*
|
|
76
75
|
* @type {string}
|
|
76
|
+
* @static
|
|
77
|
+
* @readonly
|
|
78
|
+
* @constant
|
|
77
79
|
*/
|
|
78
80
|
static AuroraUUID = "4488b571-7806-4df6-bcff-a2897e4953ff";
|
|
79
81
|
/**
|
|
80
82
|
* Maximum length of the message body for byte wrapping.
|
|
81
83
|
* This value defines the limit for the size of messages that can be sent or received
|
|
82
84
|
* to ensure proper byte wrapping in communication.
|
|
83
|
-
*
|
|
84
85
|
* @type {number}
|
|
85
86
|
* @private
|
|
87
|
+
* @readonly
|
|
88
|
+
* @constant
|
|
86
89
|
*/
|
|
87
|
-
|
|
90
|
+
static messageBodyMaxLength = 255;
|
|
88
91
|
/**
|
|
89
92
|
* Maximum length of the Bluetooth message chunk.
|
|
90
93
|
* This value sets the upper limit for the size of individual Bluetooth messages
|
|
91
94
|
* sent to and from the device to comply with Bluetooth protocol constraints.
|
|
92
|
-
*
|
|
93
95
|
* @type {number}
|
|
94
96
|
* @private
|
|
97
|
+
* @readonly
|
|
98
|
+
* @constant
|
|
95
99
|
*/
|
|
96
|
-
|
|
100
|
+
static maxBluetoothMessageSize = 20;
|
|
97
101
|
constructor() {
|
|
98
102
|
super({
|
|
99
103
|
filters: [
|
|
@@ -140,7 +144,7 @@ export class KilterBoard extends Device {
|
|
|
140
144
|
* @returns The wrapped byte array.
|
|
141
145
|
*/
|
|
142
146
|
wrapBytes(data) {
|
|
143
|
-
if (data.length >
|
|
147
|
+
if (data.length > KilterBoard.messageBodyMaxLength) {
|
|
144
148
|
return [];
|
|
145
149
|
}
|
|
146
150
|
/**
|
|
@@ -202,7 +206,7 @@ export class KilterBoard extends Device {
|
|
|
202
206
|
const resultArray = [];
|
|
203
207
|
let tempArray = [KilterBoardPacket.V3_MIDDLE];
|
|
204
208
|
for (const climbPlacement of climbPlacementList) {
|
|
205
|
-
if (tempArray.length + 3 >
|
|
209
|
+
if (tempArray.length + 3 > KilterBoard.messageBodyMaxLength) {
|
|
206
210
|
resultArray.push(tempArray);
|
|
207
211
|
tempArray = [KilterBoardPacket.V3_MIDDLE];
|
|
208
212
|
}
|
|
@@ -252,7 +256,7 @@ export class KilterBoard extends Device {
|
|
|
252
256
|
*
|
|
253
257
|
* @param buffer
|
|
254
258
|
*/
|
|
255
|
-
splitMessages = (buffer) => this.splitEvery(
|
|
259
|
+
splitMessages = (buffer) => this.splitEvery(KilterBoard.maxBluetoothMessageSize, buffer).map((arr) => new Uint8Array(arr));
|
|
256
260
|
/**
|
|
257
261
|
* Sends a series of messages to a device.
|
|
258
262
|
*/
|
|
@@ -6,28 +6,32 @@ import type { IMotherboard } from "../../interfaces/device/motherboard.interface
|
|
|
6
6
|
export declare class Motherboard extends Device implements IMotherboard {
|
|
7
7
|
/**
|
|
8
8
|
* Length of the packet received from the device.
|
|
9
|
-
* @private
|
|
10
9
|
* @type {number}
|
|
10
|
+
* @static
|
|
11
|
+
* @readonly
|
|
12
|
+
* @constant
|
|
11
13
|
*/
|
|
12
|
-
private
|
|
14
|
+
private static readonly packetLength;
|
|
13
15
|
/**
|
|
14
16
|
* Number of samples contained in the data packet.
|
|
15
|
-
* @private
|
|
16
17
|
* @type {number}
|
|
18
|
+
* @static
|
|
19
|
+
* @readonly
|
|
20
|
+
* @constant
|
|
17
21
|
*/
|
|
18
|
-
private
|
|
22
|
+
private static readonly samplesNumber;
|
|
19
23
|
/**
|
|
20
24
|
* Buffer to store received data from the device.
|
|
21
|
-
* @private
|
|
22
25
|
* @type {number[]}
|
|
26
|
+
* @private
|
|
23
27
|
*/
|
|
24
28
|
private receiveBuffer;
|
|
25
29
|
/**
|
|
26
30
|
* Calibration data for each sensor of the device.
|
|
27
|
-
* @private
|
|
28
31
|
* @type {number[][][]}
|
|
32
|
+
* @private
|
|
29
33
|
*/
|
|
30
|
-
private
|
|
34
|
+
private calibrationData;
|
|
31
35
|
constructor();
|
|
32
36
|
/**
|
|
33
37
|
* Applies calibration to a sample value.
|
|
@@ -35,7 +39,7 @@ export declare class Motherboard extends Device implements IMotherboard {
|
|
|
35
39
|
* @param {number[][]} calibration - The calibration data.
|
|
36
40
|
* @returns {number} The calibrated sample value.
|
|
37
41
|
*/
|
|
38
|
-
applyCalibration
|
|
42
|
+
private applyCalibration;
|
|
39
43
|
/**
|
|
40
44
|
* Retrieves battery or voltage information from the device.
|
|
41
45
|
* @returns {Promise<string | undefined>} A Promise that resolves with the battery or voltage information,
|