@hangtime/grip-connect 0.5.2 → 0.5.4
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 +1 -1
- package/dist/{download.d.ts → helpers/download.d.ts} +1 -1
- package/dist/helpers/is-device.d.ts +16 -16
- package/dist/helpers/is-device.js +18 -18
- package/dist/index.d.ts +4 -4
- package/dist/index.js +4 -5
- package/dist/interfaces/callback.interface.d.ts +49 -0
- package/dist/interfaces/command.interface.d.ts +85 -0
- package/dist/interfaces/device/forceboard.interface.d.ts +16 -0
- package/dist/interfaces/device.interface.d.ts +21 -21
- package/dist/models/device/entralpi.model.d.ts +1 -1
- package/dist/models/device/entralpi.model.js +19 -76
- package/dist/models/device/forceboard.model.d.ts +24 -0
- package/dist/models/device/forceboard.model.js +81 -23
- package/dist/models/device/kilterboard.model.d.ts +61 -2
- package/dist/models/device/kilterboard.model.js +91 -11
- package/dist/models/device/motherboard.model.d.ts +24 -1
- package/dist/models/device/motherboard.model.js +79 -100
- package/dist/models/device/progressor.model.d.ts +1 -1
- package/dist/models/device/progressor.model.js +76 -52
- package/dist/models/device/wh-c06.model.d.ts +7 -0
- package/dist/models/device/wh-c06.model.js +18 -17
- package/dist/models/device.model.d.ts +73 -24
- package/dist/models/device.model.js +125 -78
- package/package.json +1 -1
- package/src/{download.ts → helpers/download.ts} +1 -1
- package/src/helpers/is-device.ts +23 -23
- package/src/index.ts +4 -5
- package/src/interfaces/callback.interface.ts +56 -0
- package/src/interfaces/command.interface.ts +106 -0
- package/src/interfaces/device/forceboard.interface.ts +19 -0
- package/src/interfaces/device.interface.ts +24 -23
- package/src/models/device/entralpi.model.ts +19 -77
- package/src/models/device/forceboard.model.ts +93 -23
- package/src/models/device/kilterboard.model.ts +93 -13
- package/src/models/device/motherboard.model.ts +84 -105
- package/src/models/device/progressor.model.ts +79 -52
- package/src/models/device/wh-c06.model.ts +20 -18
- package/src/models/device.model.ts +143 -88
- package/dist/commands/climbro.d.ts +0 -6
- package/dist/commands/climbro.js +0 -5
- package/dist/commands/entralpi.d.ts +0 -6
- package/dist/commands/entralpi.js +0 -5
- package/dist/commands/forceboard.d.ts +0 -6
- package/dist/commands/forceboard.js +0 -5
- package/dist/commands/index.d.ts +0 -7
- package/dist/commands/index.js +0 -7
- package/dist/commands/kilterboard.d.ts +0 -35
- package/dist/commands/kilterboard.js +0 -65
- package/dist/commands/motherboard.d.ts +0 -6
- package/dist/commands/motherboard.js +0 -13
- package/dist/commands/mysmartboard.d.ts +0 -6
- package/dist/commands/mysmartboard.js +0 -5
- package/dist/commands/progressor.d.ts +0 -17
- package/dist/commands/progressor.js +0 -30
- package/dist/commands/wh-c06.d.ts +0 -6
- package/dist/commands/wh-c06.js +0 -5
- package/dist/types/commands.d.ts +0 -18
- package/dist/types/notify.d.ts +0 -14
- package/src/commands/climbro.ts +0 -6
- package/src/commands/entralpi.ts +0 -6
- package/src/commands/forceboard.ts +0 -6
- package/src/commands/index.ts +0 -13
- package/src/commands/kilterboard.ts +0 -64
- package/src/commands/motherboard.ts +0 -14
- package/src/commands/mysmartboard.ts +0 -6
- package/src/commands/progressor.ts +0 -31
- package/src/commands/wh-c06.ts +0 -6
- package/src/types/commands.ts +0 -21
- package/src/types/notify.ts +0 -14
- /package/dist/{download.js → helpers/download.js} +0 -0
- /package/dist/{is-active.d.ts → helpers/is-active.d.ts} +0 -0
- /package/dist/{is-active.js → helpers/is-active.js} +0 -0
- /package/dist/{tare.d.ts → helpers/tare.d.ts} +0 -0
- /package/dist/{tare.js → helpers/tare.js} +0 -0
- /package/dist/{types/commands.js → interfaces/callback.interface.js} +0 -0
- /package/dist/{types/download.js → interfaces/command.interface.js} +0 -0
- /package/dist/{types/download.d.ts → interfaces/download.interface.d.ts} +0 -0
- /package/dist/{types/notify.js → interfaces/download.interface.js} +0 -0
- /package/src/{is-active.ts → helpers/is-active.ts} +0 -0
- /package/src/{tare.ts → helpers/tare.ts} +0 -0
- /package/src/{types/download.ts → interfaces/download.interface.ts} +0 -0
|
@@ -1,14 +1,79 @@
|
|
|
1
1
|
import { BaseModel } from "./../models/base.model";
|
|
2
2
|
import type { IDevice, Service } from "../interfaces/device.interface";
|
|
3
|
-
import type {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
|
|
8
|
-
|
|
3
|
+
import type { NotifyCallback, WriteCallback } from "../interfaces/callback.interface";
|
|
4
|
+
import type { Commands } from "../interfaces/command.interface";
|
|
5
|
+
export declare abstract class Device extends BaseModel implements IDevice {
|
|
6
|
+
/**
|
|
7
|
+
* Filters to identify the device during Bluetooth scanning.
|
|
8
|
+
* Used to match devices that meet specific criteria such as name, service UUIDs, etc.
|
|
9
|
+
*/
|
|
9
10
|
filters: BluetoothLEScanFilter[];
|
|
11
|
+
/**
|
|
12
|
+
* Array of services provided by the device.
|
|
13
|
+
* Services represent functionalities that the device supports, such as weight measurement, battery information, or custom services.
|
|
14
|
+
*/
|
|
10
15
|
services: Service[];
|
|
16
|
+
/**
|
|
17
|
+
* Reference to the `BluetoothDevice` object representing this device.
|
|
18
|
+
* This is the actual device object obtained from the Web Bluetooth API after a successful connection.
|
|
19
|
+
*/
|
|
11
20
|
bluetooth?: BluetoothDevice | undefined;
|
|
21
|
+
/**
|
|
22
|
+
* Object representing the set of commands available for this device.
|
|
23
|
+
* These commands allow communication with the device to perform various operations such as starting measurements, retrieving data, or calibrating the device.
|
|
24
|
+
*/
|
|
25
|
+
commands: Commands;
|
|
26
|
+
/**
|
|
27
|
+
* The BluetoothRemoteGATTServer interface of the Web Bluetooth API represents a GATT Server on a remote device.
|
|
28
|
+
*/
|
|
29
|
+
private server;
|
|
30
|
+
/**
|
|
31
|
+
* Maximum mass recorded from the device, initialized to "0".
|
|
32
|
+
* @type {string}
|
|
33
|
+
* @protected
|
|
34
|
+
*/
|
|
35
|
+
protected massMax: string;
|
|
36
|
+
/**
|
|
37
|
+
* Average mass calculated from the device data, initialized to "0".
|
|
38
|
+
* @type {string}
|
|
39
|
+
* @protected
|
|
40
|
+
*/
|
|
41
|
+
protected massAverage: string;
|
|
42
|
+
/**
|
|
43
|
+
* Total sum of all mass data points recorded from the device.
|
|
44
|
+
* Used to calculate the average mass.
|
|
45
|
+
* @type {number}
|
|
46
|
+
* @protected
|
|
47
|
+
*/
|
|
48
|
+
protected massTotalSum: number;
|
|
49
|
+
/**
|
|
50
|
+
* Number of data points received from the device.
|
|
51
|
+
* Used to calculate the average mass.
|
|
52
|
+
* @type {number}
|
|
53
|
+
* @protected
|
|
54
|
+
*/
|
|
55
|
+
protected dataPointCount: number;
|
|
56
|
+
/**
|
|
57
|
+
* Optional callback for handling write operations.
|
|
58
|
+
* @callback NotifyCallback
|
|
59
|
+
* @param {massObject} data - The data passed to the callback.
|
|
60
|
+
* @type {NotifyCallback | undefined}
|
|
61
|
+
* @protected
|
|
62
|
+
*/
|
|
63
|
+
protected notifyCallback: NotifyCallback;
|
|
64
|
+
/**
|
|
65
|
+
* Optional callback for handling write operations.
|
|
66
|
+
* @callback WriteCallback
|
|
67
|
+
* @param {string} data - The data passed to the callback.
|
|
68
|
+
* @type {WriteCallback | undefined}
|
|
69
|
+
* @protected
|
|
70
|
+
*/
|
|
71
|
+
protected writeCallback: WriteCallback;
|
|
72
|
+
/**
|
|
73
|
+
* The last message written to the device.
|
|
74
|
+
* @type {string | Uint8Array | null}
|
|
75
|
+
*/
|
|
76
|
+
protected writeLast: string | Uint8Array | null;
|
|
12
77
|
constructor(device: Partial<IDevice>);
|
|
13
78
|
/**
|
|
14
79
|
* Connects to a Bluetooth device.
|
|
@@ -50,12 +115,6 @@ export declare class Device extends BaseModel implements IDevice {
|
|
|
50
115
|
* @returns {void}
|
|
51
116
|
*/
|
|
52
117
|
notify: (callback: NotifyCallback) => void;
|
|
53
|
-
/**
|
|
54
|
-
* Defines the type for the callback function.
|
|
55
|
-
* @callback NotifyCallback
|
|
56
|
-
* @param {massObject} data - The data passed to the callback.
|
|
57
|
-
*/
|
|
58
|
-
notifyCallback: NotifyCallback;
|
|
59
118
|
/**
|
|
60
119
|
* Handles the 'connected' event.
|
|
61
120
|
* @param {Function} onSuccess - Callback function to execute on successful connection.
|
|
@@ -71,9 +130,9 @@ export declare class Device extends BaseModel implements IDevice {
|
|
|
71
130
|
* @param {string} serviceId - The service ID where the characteristic belongs.
|
|
72
131
|
* @param {string} characteristicId - The characteristic ID to read from.
|
|
73
132
|
* @param {number} [duration=0] - The duration to wait before resolving the promise, in milliseconds.
|
|
74
|
-
* @returns {Promise<string>} A promise that resolves when the read operation is completed.
|
|
133
|
+
* @returns {Promise<string | undefined>} A promise that resolves when the read operation is completed.
|
|
75
134
|
*/
|
|
76
|
-
read: (serviceId: string, characteristicId: string, duration?: number) => Promise<string>;
|
|
135
|
+
read: (serviceId: string, characteristicId: string, duration?: number) => Promise<string | undefined>;
|
|
77
136
|
/**
|
|
78
137
|
* Writes a message to the specified characteristic of a Bluetooth device and optionally provides a callback to handle responses.
|
|
79
138
|
* @param {string} serviceId - The service UUID of the Bluetooth device containing the target characteristic.
|
|
@@ -93,14 +152,4 @@ export declare class Device extends BaseModel implements IDevice {
|
|
|
93
152
|
* });
|
|
94
153
|
*/
|
|
95
154
|
write: (serviceId: string, characteristicId: string, message: string | Uint8Array | undefined, duration?: number, callback?: WriteCallback) => Promise<void>;
|
|
96
|
-
/**
|
|
97
|
-
* A default write callback that logs the response
|
|
98
|
-
*/
|
|
99
|
-
writeCallback: WriteCallback;
|
|
100
|
-
/**
|
|
101
|
-
* The last message written to the device.
|
|
102
|
-
* @type {string | Uint8Array | null}
|
|
103
|
-
*/
|
|
104
|
-
writeLast: string | Uint8Array | null;
|
|
105
155
|
}
|
|
106
|
-
export {};
|
|
@@ -1,14 +1,86 @@
|
|
|
1
1
|
import { BaseModel } from "./../models/base.model";
|
|
2
|
-
let server;
|
|
3
2
|
export class Device extends BaseModel {
|
|
3
|
+
/**
|
|
4
|
+
* Filters to identify the device during Bluetooth scanning.
|
|
5
|
+
* Used to match devices that meet specific criteria such as name, service UUIDs, etc.
|
|
6
|
+
*/
|
|
4
7
|
filters;
|
|
8
|
+
/**
|
|
9
|
+
* Array of services provided by the device.
|
|
10
|
+
* Services represent functionalities that the device supports, such as weight measurement, battery information, or custom services.
|
|
11
|
+
*/
|
|
5
12
|
services;
|
|
13
|
+
/**
|
|
14
|
+
* Reference to the `BluetoothDevice` object representing this device.
|
|
15
|
+
* This is the actual device object obtained from the Web Bluetooth API after a successful connection.
|
|
16
|
+
*/
|
|
6
17
|
bluetooth;
|
|
18
|
+
/**
|
|
19
|
+
* Object representing the set of commands available for this device.
|
|
20
|
+
* These commands allow communication with the device to perform various operations such as starting measurements, retrieving data, or calibrating the device.
|
|
21
|
+
*/
|
|
22
|
+
commands;
|
|
23
|
+
/**
|
|
24
|
+
* The BluetoothRemoteGATTServer interface of the Web Bluetooth API represents a GATT Server on a remote device.
|
|
25
|
+
*/
|
|
26
|
+
server;
|
|
27
|
+
/**
|
|
28
|
+
* Maximum mass recorded from the device, initialized to "0".
|
|
29
|
+
* @type {string}
|
|
30
|
+
* @protected
|
|
31
|
+
*/
|
|
32
|
+
massMax;
|
|
33
|
+
/**
|
|
34
|
+
* Average mass calculated from the device data, initialized to "0".
|
|
35
|
+
* @type {string}
|
|
36
|
+
* @protected
|
|
37
|
+
*/
|
|
38
|
+
massAverage;
|
|
39
|
+
/**
|
|
40
|
+
* Total sum of all mass data points recorded from the device.
|
|
41
|
+
* Used to calculate the average mass.
|
|
42
|
+
* @type {number}
|
|
43
|
+
* @protected
|
|
44
|
+
*/
|
|
45
|
+
massTotalSum;
|
|
46
|
+
/**
|
|
47
|
+
* Number of data points received from the device.
|
|
48
|
+
* Used to calculate the average mass.
|
|
49
|
+
* @type {number}
|
|
50
|
+
* @protected
|
|
51
|
+
*/
|
|
52
|
+
dataPointCount;
|
|
53
|
+
/**
|
|
54
|
+
* Optional callback for handling write operations.
|
|
55
|
+
* @callback NotifyCallback
|
|
56
|
+
* @param {massObject} data - The data passed to the callback.
|
|
57
|
+
* @type {NotifyCallback | undefined}
|
|
58
|
+
* @protected
|
|
59
|
+
*/
|
|
60
|
+
notifyCallback = (data) => console.log(data);
|
|
61
|
+
/**
|
|
62
|
+
* Optional callback for handling write operations.
|
|
63
|
+
* @callback WriteCallback
|
|
64
|
+
* @param {string} data - The data passed to the callback.
|
|
65
|
+
* @type {WriteCallback | undefined}
|
|
66
|
+
* @protected
|
|
67
|
+
*/
|
|
68
|
+
writeCallback = (data) => console.log(data);
|
|
69
|
+
/**
|
|
70
|
+
* The last message written to the device.
|
|
71
|
+
* @type {string | Uint8Array | null}
|
|
72
|
+
*/
|
|
73
|
+
writeLast = null;
|
|
7
74
|
constructor(device) {
|
|
8
75
|
super(device);
|
|
9
76
|
this.filters = device.filters || [];
|
|
10
77
|
this.services = device.services || [];
|
|
78
|
+
this.commands = device.commands || {};
|
|
11
79
|
this.bluetooth = device.bluetooth;
|
|
80
|
+
this.massMax = "0";
|
|
81
|
+
this.massAverage = "0";
|
|
82
|
+
this.massTotalSum = 0;
|
|
83
|
+
this.dataPointCount = 0;
|
|
12
84
|
}
|
|
13
85
|
/**
|
|
14
86
|
* Connects to a Bluetooth device.
|
|
@@ -29,8 +101,8 @@ export class Device extends BaseModel {
|
|
|
29
101
|
this.bluetooth.addEventListener("gattserverdisconnected", (event) => {
|
|
30
102
|
this.onDisconnected(event);
|
|
31
103
|
});
|
|
32
|
-
server = await this.bluetooth.gatt.connect();
|
|
33
|
-
if (server.connected) {
|
|
104
|
+
this.server = await this.bluetooth.gatt.connect();
|
|
105
|
+
if (this.server.connected) {
|
|
34
106
|
await this.onConnected(onSuccess);
|
|
35
107
|
}
|
|
36
108
|
}
|
|
@@ -116,19 +188,13 @@ export class Device extends BaseModel {
|
|
|
116
188
|
notify = (callback) => {
|
|
117
189
|
this.notifyCallback = callback;
|
|
118
190
|
};
|
|
119
|
-
/**
|
|
120
|
-
* Defines the type for the callback function.
|
|
121
|
-
* @callback NotifyCallback
|
|
122
|
-
* @param {massObject} data - The data passed to the callback.
|
|
123
|
-
*/
|
|
124
|
-
notifyCallback = (data) => console.log(data);
|
|
125
191
|
/**
|
|
126
192
|
* Handles the 'connected' event.
|
|
127
193
|
* @param {Function} onSuccess - Callback function to execute on successful connection.
|
|
128
194
|
*/
|
|
129
195
|
onConnected = async (onSuccess) => {
|
|
130
196
|
// Connect to GATT server and set up characteristics
|
|
131
|
-
const services = await server
|
|
197
|
+
const services = await this.server?.getPrimaryServices();
|
|
132
198
|
if (!services || services.length === 0) {
|
|
133
199
|
throw new Error("No services found");
|
|
134
200
|
}
|
|
@@ -176,41 +242,36 @@ export class Device extends BaseModel {
|
|
|
176
242
|
* @param {string} serviceId - The service ID where the characteristic belongs.
|
|
177
243
|
* @param {string} characteristicId - The characteristic ID to read from.
|
|
178
244
|
* @param {number} [duration=0] - The duration to wait before resolving the promise, in milliseconds.
|
|
179
|
-
* @returns {Promise<string>} A promise that resolves when the read operation is completed.
|
|
245
|
+
* @returns {Promise<string | undefined>} A promise that resolves when the read operation is completed.
|
|
180
246
|
*/
|
|
181
|
-
read = (serviceId, characteristicId, duration = 0) => {
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
else {
|
|
210
|
-
reject(new Error("Characteristic is undefined"));
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
});
|
|
247
|
+
read = async (serviceId, characteristicId, duration = 0) => {
|
|
248
|
+
if (!this.isConnected()) {
|
|
249
|
+
return undefined;
|
|
250
|
+
}
|
|
251
|
+
// Get the characteristic from the service
|
|
252
|
+
const characteristic = this.getCharacteristic(serviceId, characteristicId);
|
|
253
|
+
if (!characteristic) {
|
|
254
|
+
throw new Error("Characteristic is undefined");
|
|
255
|
+
}
|
|
256
|
+
// Decode the value based on characteristicId and serviceId
|
|
257
|
+
let decodedValue;
|
|
258
|
+
const decoder = new TextDecoder("utf-8");
|
|
259
|
+
// Read the value from the characteristic
|
|
260
|
+
const value = await characteristic.readValue();
|
|
261
|
+
if ((serviceId === "battery" || serviceId === "humidity" || serviceId === "temperature") &&
|
|
262
|
+
characteristicId === "level") {
|
|
263
|
+
// This is battery-specific; return the first byte as the level
|
|
264
|
+
decodedValue = value.getUint8(0).toString();
|
|
265
|
+
}
|
|
266
|
+
else {
|
|
267
|
+
// Otherwise use a UTF-8 decoder
|
|
268
|
+
decodedValue = decoder.decode(value);
|
|
269
|
+
}
|
|
270
|
+
// Wait for the specified duration before returning the result
|
|
271
|
+
if (duration > 0) {
|
|
272
|
+
await new Promise((resolve) => setTimeout(resolve, duration));
|
|
273
|
+
}
|
|
274
|
+
return decodedValue;
|
|
214
275
|
};
|
|
215
276
|
/**
|
|
216
277
|
* Writes a message to the specified characteristic of a Bluetooth device and optionally provides a callback to handle responses.
|
|
@@ -231,40 +292,26 @@ export class Device extends BaseModel {
|
|
|
231
292
|
* });
|
|
232
293
|
*/
|
|
233
294
|
write = async (serviceId, characteristicId, message, duration = 0, callback = this.writeCallback) => {
|
|
234
|
-
if
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
if (duration > 0) {
|
|
255
|
-
await new Promise((resolve) => setTimeout(resolve, duration));
|
|
256
|
-
}
|
|
295
|
+
// Check if not connected or no message is provided
|
|
296
|
+
if (!this.isConnected() || message === undefined) {
|
|
297
|
+
return undefined;
|
|
298
|
+
}
|
|
299
|
+
// Get the characteristic from the service
|
|
300
|
+
const characteristic = this.getCharacteristic(serviceId, characteristicId);
|
|
301
|
+
if (!characteristic) {
|
|
302
|
+
throw new Error("Characteristic is undefined");
|
|
303
|
+
}
|
|
304
|
+
// Convert the message to Uint8Array if it's a string
|
|
305
|
+
const valueToWrite = typeof message === "string" ? new TextEncoder().encode(message) : message;
|
|
306
|
+
// Write the value to the characteristic
|
|
307
|
+
await characteristic.writeValue(valueToWrite);
|
|
308
|
+
// Update the last written message
|
|
309
|
+
this.writeLast = message;
|
|
310
|
+
// Assign the provided callback to `writeCallback`
|
|
311
|
+
this.writeCallback = callback;
|
|
312
|
+
// If a duration is specified, resolve the promise after the duration
|
|
313
|
+
if (duration > 0) {
|
|
314
|
+
await new Promise((resolve) => setTimeout(resolve, duration));
|
|
257
315
|
}
|
|
258
316
|
};
|
|
259
|
-
/**
|
|
260
|
-
* A default write callback that logs the response
|
|
261
|
-
*/
|
|
262
|
-
writeCallback = (data) => {
|
|
263
|
-
console.log(data);
|
|
264
|
-
};
|
|
265
|
-
/**
|
|
266
|
-
* The last message written to the device.
|
|
267
|
-
* @type {string | Uint8Array | null}
|
|
268
|
-
*/
|
|
269
|
-
writeLast = null;
|
|
270
317
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hangtime/grip-connect",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.4",
|
|
4
4
|
"description": "Griptonite Motherboard, Tindeq Progressor, PitchSix Force Board, WHC-06, Entralpi, Climbro, mySmartBoard: Web Bluetooth API Force-Sensing strength analysis for climbers",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
package/src/helpers/is-device.ts
CHANGED
|
@@ -1,49 +1,49 @@
|
|
|
1
|
+
import { KilterBoard } from "../models"
|
|
1
2
|
import type { Device } from "./../models/device.model"
|
|
2
|
-
import { AuroraUUID } from "./../models/device/kilterboard.model"
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
|
-
* Checks if the given device is an Entralpi
|
|
6
|
-
* @param {Device} [
|
|
5
|
+
* Checks if the given device is an Entralpi.
|
|
6
|
+
* @param {Device} [device] - The device to check.
|
|
7
7
|
* @returns {boolean} `true` if the device has a filter with the name "ENTRALPI", otherwise `false`.
|
|
8
8
|
*/
|
|
9
|
-
export const isEntralpi = (
|
|
10
|
-
|
|
9
|
+
export const isEntralpi = (device?: Device): boolean =>
|
|
10
|
+
device?.filters.some((filter) => filter.name === "ENTRALPI") ?? false
|
|
11
11
|
/**
|
|
12
12
|
* Checks if the given device is a Force Board.
|
|
13
|
-
* @param {Device} [
|
|
13
|
+
* @param {Device} [device] - The device to check.
|
|
14
14
|
* @returns {boolean} `true` if the device has a filter with the name "Force Board", otherwise `false`.
|
|
15
15
|
*/
|
|
16
|
-
export const isForceBoard = (
|
|
17
|
-
|
|
16
|
+
export const isForceBoard = (device?: Device): boolean =>
|
|
17
|
+
device?.filters.some((filter) => filter.name === "Force Board") ?? false
|
|
18
18
|
/**
|
|
19
|
-
* Checks if the given device is a
|
|
20
|
-
* @param {Device} [
|
|
21
|
-
* @returns {boolean} `true` if the device has a service UUID matching the
|
|
19
|
+
* Checks if the given device is a Kilter Board.
|
|
20
|
+
* @param {Device} [device] - The device to check.
|
|
21
|
+
* @returns {boolean} `true` if the device has a service UUID matching the Kilter Board Aurora UUID, otherwise `false`.
|
|
22
22
|
*/
|
|
23
|
-
export const
|
|
24
|
-
return
|
|
23
|
+
export const isKilterBoard = (device?: Device): boolean => {
|
|
24
|
+
return device?.filters.some((filter) => filter.services?.includes(KilterBoard.AuroraUUID)) ?? false
|
|
25
25
|
}
|
|
26
26
|
/**
|
|
27
27
|
* Checks if the given device is a Motherboard.
|
|
28
|
-
* @param {Device} [
|
|
29
|
-
* @returns {boolean} `true` if the device has a filter with the name "
|
|
28
|
+
* @param {Device} [device] - The device to check.
|
|
29
|
+
* @returns {boolean} `true` if the device has a filter with the name "Motherdevice", otherwise `false`.
|
|
30
30
|
*/
|
|
31
|
-
export const isMotherboard = (
|
|
32
|
-
|
|
31
|
+
export const isMotherboard = (device?: Device): boolean =>
|
|
32
|
+
device?.filters.some((filter) => filter.name === "Motherdevice") ?? false
|
|
33
33
|
/**
|
|
34
34
|
* Checks if the given device is a Progressor.
|
|
35
|
-
* @param {Device} [
|
|
35
|
+
* @param {Device} [device] - The device to check.
|
|
36
36
|
* @returns {boolean} `true` if the device has a filter with a namePrefix of "Progressor", otherwise `false`.
|
|
37
37
|
*/
|
|
38
|
-
export const isProgressor = (
|
|
39
|
-
|
|
38
|
+
export const isProgressor = (device?: Device): boolean =>
|
|
39
|
+
device?.filters.some((filter) => filter.namePrefix === "Progressor") ?? false
|
|
40
40
|
/**
|
|
41
41
|
* Checks if the given device is a WH-C06.
|
|
42
|
-
* @param {Device} [
|
|
42
|
+
* @param {Device} [device] - The device to check.
|
|
43
43
|
* @returns {boolean} `true` if the device has a filter with the company identifier 0x0100, otherwise `false`.
|
|
44
44
|
*/
|
|
45
|
-
export const isWHC06 = (
|
|
46
|
-
|
|
45
|
+
export const isWHC06 = (device?: Device): boolean =>
|
|
46
|
+
device?.filters.some((filter) =>
|
|
47
47
|
filter.manufacturerData?.some(
|
|
48
48
|
(data) => data.companyIdentifier === 0x0100, // Company identifier for WH-C06, also used by 'TomTom International BV': https://www.bluetooth.com/specifications/assigned-numbers/
|
|
49
49
|
),
|
package/src/index.ts
CHANGED
|
@@ -10,11 +10,10 @@ export {
|
|
|
10
10
|
} from "./models/index"
|
|
11
11
|
|
|
12
12
|
// helpers
|
|
13
|
-
export { isEntralpi,
|
|
13
|
+
export { isEntralpi, isKilterBoard, isMotherboard, isWHC06, isProgressor } from "./helpers/is-device"
|
|
14
14
|
|
|
15
|
-
|
|
16
|
-
export { download } from "./download"
|
|
15
|
+
export { download } from "./helpers/download"
|
|
17
16
|
|
|
18
|
-
export { active, isActive } from "./is-active"
|
|
17
|
+
export { active, isActive } from "./helpers/is-active"
|
|
19
18
|
|
|
20
|
-
export { tare } from "./tare"
|
|
19
|
+
export { tare } from "./helpers/tare"
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Represents the mass data collected from a device.
|
|
3
|
+
*/
|
|
4
|
+
export interface massObject {
|
|
5
|
+
/**
|
|
6
|
+
* The total mass measured from the device.
|
|
7
|
+
* This is the overall weight or force reading.
|
|
8
|
+
*/
|
|
9
|
+
massTotal: string
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* The maximum mass recorded during the session.
|
|
13
|
+
* This is the highest weight or force value detected.
|
|
14
|
+
*/
|
|
15
|
+
massMax: string
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* The average mass calculated from all the recorded data points.
|
|
19
|
+
* This represents the mean value of the mass measurements.
|
|
20
|
+
*/
|
|
21
|
+
massAverage: string
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* The mass recorded on the left side of the device (optional for Motherboard devices).
|
|
25
|
+
* Used for devices that measure force across multiple zones.
|
|
26
|
+
*/
|
|
27
|
+
massLeft?: string
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* The mass recorded at the center of the device (optional for Motherboard devices).
|
|
31
|
+
* Used for devices that measure force distribution across a center zone.
|
|
32
|
+
*/
|
|
33
|
+
massCenter?: string
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* The mass recorded on the right side of the device (optional for Motherboard devices).
|
|
37
|
+
* Used for devices that measure force across multiple zones.
|
|
38
|
+
*/
|
|
39
|
+
massRight?: string
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Defines the type for a callback function that handles mass data notifications.
|
|
44
|
+
* The callback receives a `massObject` as the parameter.
|
|
45
|
+
* @callback NotifyCallback
|
|
46
|
+
* @param {massObject} data - The mass data passed to the callback.
|
|
47
|
+
*/
|
|
48
|
+
export type NotifyCallback = (data: massObject) => void
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Defines the type for a callback function that handles write operations to the device.
|
|
52
|
+
* The callback receives the data string written to the device.
|
|
53
|
+
* @callback WriteCallback
|
|
54
|
+
* @param {string} data - The string data passed to the callback.
|
|
55
|
+
*/
|
|
56
|
+
export type WriteCallback = (data: string) => void
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Represents the available commands for various devices such as the Motherboard and Tindeq Progressor.
|
|
3
|
+
*/
|
|
4
|
+
export interface Commands {
|
|
5
|
+
// Motherboard, Progressor
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Starts a weight measurement on the device.
|
|
9
|
+
* Used to begin collecting weight or force data.
|
|
10
|
+
*/
|
|
11
|
+
START_WEIGHT_MEAS?: string
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Stops the current weight measurement on the device.
|
|
15
|
+
* Used to end the data collection.
|
|
16
|
+
*/
|
|
17
|
+
STOP_WEIGHT_MEAS?: string
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Puts the device to sleep or in a low-power mode.
|
|
21
|
+
* The format can be a string or a number depending on the device.
|
|
22
|
+
*/
|
|
23
|
+
SLEEP?: number | string
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Retrieves the serial number of the device.
|
|
27
|
+
* This command fetches the unique identifier assigned by the manufacturer.
|
|
28
|
+
*/
|
|
29
|
+
GET_SERIAL?: string
|
|
30
|
+
|
|
31
|
+
// Griptonite Motherboard
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Retrieves textual information from the device.
|
|
35
|
+
* May include readable data.
|
|
36
|
+
*/
|
|
37
|
+
GET_TEXT?: string
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Starts or stops a debug data stream from the device.
|
|
41
|
+
* Used for diagnostic purposes or to monitor real-time data.
|
|
42
|
+
*/
|
|
43
|
+
DEBUG_STREAM?: string
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Retrieves calibration data from the device.
|
|
47
|
+
* Used to ensure accurate measurements by applying calibration points.
|
|
48
|
+
*/
|
|
49
|
+
GET_CALIBRATION?: string
|
|
50
|
+
|
|
51
|
+
// Tindeq Progressor
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Tares the scale, zeroing the current weight measurement.
|
|
55
|
+
* Used to reset the baseline for weight data.
|
|
56
|
+
*/
|
|
57
|
+
TARE_SCALE?: string
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Starts measuring the peak rate of force development (RFD).
|
|
61
|
+
* Captures how quickly force is applied over time.
|
|
62
|
+
*/
|
|
63
|
+
START_PEAK_RFD_MEAS?: string
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Starts measuring a series of peak RFD measurements.
|
|
67
|
+
* This captures multiple RFD data points over a period of time.
|
|
68
|
+
*/
|
|
69
|
+
START_PEAK_RFD_MEAS_SERIES?: string
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Adds a calibration point to the device.
|
|
73
|
+
* Used to improve the accuracy of future measurements.
|
|
74
|
+
*/
|
|
75
|
+
ADD_CALIB_POINT?: string
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Saves the current calibration settings to the device.
|
|
79
|
+
* Ensures the device remembers the calibration for future sessions.
|
|
80
|
+
*/
|
|
81
|
+
SAVE_CALIB?: string
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Retrieves the firmware version of the device.
|
|
85
|
+
* Useful for ensuring compatibility and tracking updates.
|
|
86
|
+
*/
|
|
87
|
+
GET_FW_VERSION?: string
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Retrieves error information from the device.
|
|
91
|
+
* Provides details on any faults or issues that occurred during operation.
|
|
92
|
+
*/
|
|
93
|
+
GET_ERR_INFO?: string
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Clears the error information on the device.
|
|
97
|
+
* Used to reset error logs after troubleshooting or repair.
|
|
98
|
+
*/
|
|
99
|
+
CLR_ERR_INFO?: string
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Retrieves the battery voltage level of the device.
|
|
103
|
+
* Provides insight into the device's remaining battery power.
|
|
104
|
+
*/
|
|
105
|
+
GET_BATT_VLTG?: string
|
|
106
|
+
}
|
|
@@ -21,4 +21,23 @@ export interface IForceBoard extends IDevice {
|
|
|
21
21
|
* @returns {Promise<string | undefined>} A Promise that resolves with the manufacturer information.
|
|
22
22
|
*/
|
|
23
23
|
manufacturer(): Promise<string | undefined>
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Stops the data stream on the specified device.
|
|
27
|
+
* @returns {Promise<void>} A promise that resolves when the stream is stopped.
|
|
28
|
+
*/
|
|
29
|
+
stop(): Promise<void>
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Starts streaming data from the specified device.
|
|
33
|
+
* @param {number} [duration=0] - The duration of the stream in milliseconds. If set to 0, stream will continue indefinitely.
|
|
34
|
+
* @returns {Promise<void>} A promise that resolves when the streaming operation is completed.
|
|
35
|
+
*/
|
|
36
|
+
stream(duration?: number): Promise<void>
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Retrieves temperature information from the device.
|
|
40
|
+
* @returns {Promise<string | undefined>} A Promise that resolves with the humidity level.
|
|
41
|
+
*/
|
|
42
|
+
temperature(): Promise<string | undefined>
|
|
24
43
|
}
|