@hangtime/grip-connect 0.5.6 → 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/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 +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 +4 -7
- 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 +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/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 +23 -9
- 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 +38 -17
- 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;
|
|
@@ -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
|
|
@@ -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,
|
|
@@ -1,35 +1,36 @@
|
|
|
1
1
|
import { Device } from "../device.model";
|
|
2
|
-
import { applyTare } from "../../helpers/tare";
|
|
3
|
-
import { checkActivity } from "../../helpers/is-active";
|
|
4
|
-
import { DownloadPackets, emptyDownloadPackets } from "../../helpers/download";
|
|
5
2
|
/**
|
|
6
3
|
* Represents a Griptonite Motherboard device
|
|
7
4
|
*/
|
|
8
5
|
export class Motherboard extends Device {
|
|
9
6
|
/**
|
|
10
7
|
* Length of the packet received from the device.
|
|
11
|
-
* @private
|
|
12
8
|
* @type {number}
|
|
9
|
+
* @static
|
|
10
|
+
* @readonly
|
|
11
|
+
* @constant
|
|
13
12
|
*/
|
|
14
|
-
|
|
13
|
+
static packetLength = 32;
|
|
15
14
|
/**
|
|
16
15
|
* Number of samples contained in the data packet.
|
|
17
|
-
* @private
|
|
18
16
|
* @type {number}
|
|
17
|
+
* @static
|
|
18
|
+
* @readonly
|
|
19
|
+
* @constant
|
|
19
20
|
*/
|
|
20
|
-
|
|
21
|
+
static samplesNumber = 3;
|
|
21
22
|
/**
|
|
22
23
|
* Buffer to store received data from the device.
|
|
23
|
-
* @private
|
|
24
24
|
* @type {number[]}
|
|
25
|
+
* @private
|
|
25
26
|
*/
|
|
26
27
|
receiveBuffer = [];
|
|
27
28
|
/**
|
|
28
29
|
* Calibration data for each sensor of the device.
|
|
29
|
-
* @private
|
|
30
30
|
* @type {number[][][]}
|
|
31
|
+
* @private
|
|
31
32
|
*/
|
|
32
|
-
|
|
33
|
+
calibrationData = [[], [], [], []];
|
|
33
34
|
constructor() {
|
|
34
35
|
super({
|
|
35
36
|
filters: [{ name: "Motherboard" }],
|
|
@@ -206,7 +207,7 @@ export class Motherboard extends Device {
|
|
|
206
207
|
// Check if the line is entirely hex characters
|
|
207
208
|
const isAllHex = /^[0-9A-Fa-f]+$/g.test(receivedData);
|
|
208
209
|
// Handle streaming packet
|
|
209
|
-
if (isAllHex && receivedData.length ===
|
|
210
|
+
if (isAllHex && receivedData.length === Motherboard.packetLength) {
|
|
210
211
|
// Base-16 decode the string: convert hex pairs to byte values
|
|
211
212
|
const bytes = Array.from({ length: receivedData.length / 2 }, (_, i) => Number(`0x${receivedData.substring(i * 2, i * 2 + 2)}`));
|
|
212
213
|
// Translate header into packet, number of samples from the packet length
|
|
@@ -218,7 +219,7 @@ export class Motherboard extends Device {
|
|
|
218
219
|
masses: [],
|
|
219
220
|
};
|
|
220
221
|
const dataView = new DataView(new Uint8Array(bytes).buffer);
|
|
221
|
-
for (let i = 0; i <
|
|
222
|
+
for (let i = 0; i < Motherboard.samplesNumber; i++) {
|
|
222
223
|
const sampleStart = 4 + 3 * i;
|
|
223
224
|
// Use DataView to read the 24-bit unsigned integer
|
|
224
225
|
const rawValue = dataView.getUint8(sampleStart) |
|
|
@@ -229,13 +230,13 @@ export class Motherboard extends Device {
|
|
|
229
230
|
if (packet.samples[i] >= 0x7fffff) {
|
|
230
231
|
packet.samples[i] -= 0x1000000;
|
|
231
232
|
}
|
|
232
|
-
packet.masses[i] = this.applyCalibration(packet.samples[i], this.
|
|
233
|
+
packet.masses[i] = this.applyCalibration(packet.samples[i], this.calibrationData[i]);
|
|
233
234
|
}
|
|
234
235
|
// invert center and right values
|
|
235
236
|
packet.masses[1] *= -1;
|
|
236
237
|
packet.masses[2] *= -1;
|
|
237
238
|
// Add data to downloadable Array
|
|
238
|
-
|
|
239
|
+
this.downloadPackets.push({
|
|
239
240
|
received: packet.received,
|
|
240
241
|
sampleNum: packet.battRaw,
|
|
241
242
|
battRaw: packet.received,
|
|
@@ -246,9 +247,9 @@ export class Motherboard extends Device {
|
|
|
246
247
|
let center = packet.masses[1];
|
|
247
248
|
let right = packet.masses[2];
|
|
248
249
|
// Tare correction
|
|
249
|
-
left -= applyTare(left);
|
|
250
|
-
center -= applyTare(center);
|
|
251
|
-
right -= applyTare(right);
|
|
250
|
+
left -= this.applyTare(left);
|
|
251
|
+
center -= this.applyTare(center);
|
|
252
|
+
right -= this.applyTare(right);
|
|
252
253
|
this.massMax = Math.max(Number(this.massMax), Math.max(-1000, left + center + right)).toFixed(1);
|
|
253
254
|
// Update running sum and count
|
|
254
255
|
const currentMassTotal = Math.max(-1000, left + center + right);
|
|
@@ -257,7 +258,7 @@ export class Motherboard extends Device {
|
|
|
257
258
|
// Calculate the average dynamically
|
|
258
259
|
this.massAverage = (this.massTotalSum / this.dataPointCount).toFixed(1);
|
|
259
260
|
// Check if device is being used
|
|
260
|
-
|
|
261
|
+
this.activityCheck(center);
|
|
261
262
|
// Notify with weight data
|
|
262
263
|
this.notifyCallback({
|
|
263
264
|
massTotal: Math.max(-1000, left + center + right).toFixed(1),
|
|
@@ -273,7 +274,7 @@ export class Motherboard extends Device {
|
|
|
273
274
|
if ((receivedData.match(/,/g) || []).length === 3) {
|
|
274
275
|
const parts = receivedData.split(",");
|
|
275
276
|
const numericParts = parts.map((x) => parseFloat(x));
|
|
276
|
-
this.
|
|
277
|
+
this.calibrationData[numericParts[0]].push(numericParts.slice(1));
|
|
277
278
|
}
|
|
278
279
|
}
|
|
279
280
|
else {
|
|
@@ -344,9 +345,9 @@ export class Motherboard extends Device {
|
|
|
344
345
|
*/
|
|
345
346
|
stream = async (duration = 0) => {
|
|
346
347
|
// Reset download packets
|
|
347
|
-
|
|
348
|
+
this.downloadPackets.length = 0;
|
|
348
349
|
// Read calibration data if not already available
|
|
349
|
-
if (!this.
|
|
350
|
+
if (!this.calibrationData[0].length) {
|
|
350
351
|
await this.calibration();
|
|
351
352
|
}
|
|
352
353
|
// Start streaming data
|
|
@@ -1,8 +1,5 @@
|
|
|
1
1
|
import { Device } from "../device.model";
|
|
2
2
|
import struct from "../../helpers/struct";
|
|
3
|
-
import { checkActivity } from "../../helpers/is-active";
|
|
4
|
-
import { DownloadPackets, emptyDownloadPackets } from "../../helpers/download";
|
|
5
|
-
import { applyTare } from "../../helpers/tare";
|
|
6
3
|
/**
|
|
7
4
|
* Represents the possible responses of a Tindeq Progressor device.
|
|
8
5
|
*/
|
|
@@ -132,9 +129,9 @@ export class Progressor extends Device {
|
|
|
132
129
|
for (let [weight, seconds] of iterable) {
|
|
133
130
|
if (typeof weight === "number" && !isNaN(weight) && typeof seconds === "number" && !isNaN(seconds)) {
|
|
134
131
|
// Tare correction
|
|
135
|
-
const numericData = weight - applyTare(weight);
|
|
132
|
+
const numericData = weight - this.applyTare(weight);
|
|
136
133
|
// Add data to downloadable Array
|
|
137
|
-
|
|
134
|
+
this.downloadPackets.push({
|
|
138
135
|
received: receivedTime,
|
|
139
136
|
sampleNum: seconds,
|
|
140
137
|
battRaw: 0,
|
|
@@ -150,7 +147,7 @@ export class Progressor extends Device {
|
|
|
150
147
|
// Calculate the average dynamically
|
|
151
148
|
this.massAverage = (this.massTotalSum / this.dataPointCount).toFixed(1);
|
|
152
149
|
// Check if device is being used
|
|
153
|
-
|
|
150
|
+
this.activityCheck(numericData);
|
|
154
151
|
this.notifyCallback({
|
|
155
152
|
massMax: this.massMax,
|
|
156
153
|
massAverage: this.massAverage,
|
|
@@ -197,7 +194,7 @@ export class Progressor extends Device {
|
|
|
197
194
|
*/
|
|
198
195
|
stream = async (duration = 0) => {
|
|
199
196
|
// Reset download packets
|
|
200
|
-
|
|
197
|
+
this.downloadPackets.length = 0;
|
|
201
198
|
// Start streaming data
|
|
202
199
|
await this.write("progressor", "tx", this.commands.START_WEIGHT_MEAS, duration);
|
|
203
200
|
// Stop streaming if duration is set
|