@hangtime/grip-connect 0.5.8 → 0.5.9

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.
@@ -62,18 +62,55 @@ export interface IDevice extends IBase {
62
62
  * @readonly
63
63
  */
64
64
  commands: Commands;
65
+ /**
66
+ * Sets the callback function to be called when the activity status changes,
67
+ * and optionally sets the configuration for threshold and duration.
68
+ *
69
+ * This function allows you to specify a callback that will be invoked whenever
70
+ * the activity status changes, indicating whether the device is currently active.
71
+ * It also allows optionally configuring the threshold and duration used to determine activity.
72
+ *
73
+ * @param {ActiveCallback} callback - The callback function to be set. This function
74
+ * receives a boolean value indicating the new activity status.
75
+ * @param {object} [options] - Optional configuration object containing the threshold and duration.
76
+ * @param {number} [options.threshold=2.5] - The threshold value for determining activity.
77
+ * @param {number} [options.duration=1000] - The duration (in milliseconds) to monitor the input for activity.
78
+ * @returns {void}
79
+ * @public
80
+ *
81
+ * @example
82
+ * device.active((isActive) => {
83
+ * console.log(`Device is ${isActive ? 'active' : 'inactive'}`);
84
+ * }, { threshold: 3.0, duration: 1500 });
85
+ */
86
+ active(callback?: (data: boolean) => void, options?: {
87
+ threshold?: number;
88
+ duration?: number;
89
+ }): void;
65
90
  /**
66
91
  * Connects to a Bluetooth device.
67
92
  * @param {Function} [onSuccess] - Optional callback function to execute on successful connection. Default logs success.
68
93
  * @param {Function} [onError] - Optional callback function to execute on error. Default logs the error.
69
94
  * @public
95
+ *
96
+ * @example
97
+ * device.connect(
98
+ * () => console.log("Connected successfully"),
99
+ * (error) => console.error("Connection failed:", error)
100
+ * );
70
101
  */
71
102
  connect(onSuccess?: () => void, onError?: (error: Error) => void): Promise<void>;
72
103
  /**
73
104
  * Disconnects the device if it is currently connected.
74
- * - Checks if the device is connected via it's GATT server.
75
- * - If the device is connected, it attempts to gracefully disconnect.
105
+ * - Removes all notification listeners from the device's characteristics.
106
+ * - Removes the 'gattserverdisconnected' event listener.
107
+ * - Attempts to gracefully disconnect the device's GATT server.
108
+ * - Resets relevant properties to their initial states.
109
+ * @returns {void}
76
110
  * @public
111
+ *
112
+ * @example
113
+ * device.disconnect();
77
114
  */
78
115
  disconnect(): void;
79
116
  /**
@@ -85,12 +122,22 @@ export interface IDevice extends IBase {
85
122
  *
86
123
  * @returns {void} Initiates a download of the data in the specified format.
87
124
  * @private
125
+ *
126
+ * @example
127
+ * device.download('json');
88
128
  */
89
129
  download(format?: "csv" | "json" | "xml"): void;
90
130
  /**
91
131
  * Checks if a Bluetooth device is connected.
92
132
  * @returns {boolean} A boolean indicating whether the device is connected.
93
133
  * @public
134
+ *
135
+ * @example
136
+ * if (device.isConnected()) {
137
+ * console.log('Device is connected');
138
+ * } else {
139
+ * console.log('Device is not connected');
140
+ * }
94
141
  */
95
142
  isConnected(): boolean;
96
143
  /**
@@ -98,6 +145,11 @@ export interface IDevice extends IBase {
98
145
  * @param {NotifyCallback} callback - The callback function to be set.
99
146
  * @returns {void}
100
147
  * @public
148
+ *
149
+ * @example
150
+ * device.notify((data) => {
151
+ * console.log('Received notification:', data);
152
+ * });
101
153
  */
102
154
  notify(callback: (data: massObject) => void): void;
103
155
  /**
@@ -107,14 +159,27 @@ export interface IDevice extends IBase {
107
159
  * @param {number} [duration=0] - The duration to wait before resolving the promise, in milliseconds.
108
160
  * @returns {Promise<string | undefined>} A promise that resolves when the read operation is completed.
109
161
  * @public
162
+ *
163
+ * @example
164
+ * const value = await device.read('battery', 'level', 1000);
165
+ * console.log('Battery level:', value);
110
166
  */
111
167
  read(serviceId: string, characteristicId: string, duration?: number): Promise<string | undefined>;
112
168
  /**
113
169
  * Initiates the tare calibration process.
114
170
  * @param {number} duration - The duration time for tare calibration.
115
- * @returns {void}
171
+ * @returns {boolean} A boolean indicating whether the tare calibration was successful.
172
+ * @public
173
+ *
174
+ * @example
175
+ * const success = device.tare(5000);
176
+ * if (success) {
177
+ * console.log('Tare calibration started');
178
+ * } else {
179
+ * console.log('Tare calibration failed to start');
180
+ * }
116
181
  */
117
- tare(duration?: number): void;
182
+ tare(duration?: number): boolean;
118
183
  /**
119
184
  * Writes a message to the specified characteristic of a Bluetooth device and optionally provides a callback to handle responses.
120
185
  * @param {string} serviceId - The service UUID of the Bluetooth device containing the target characteristic.
@@ -22,9 +22,9 @@ export declare class Entralpi extends Device implements IEntralpi {
22
22
  * and updates mass data including maximum and average values.
23
23
  * It also handles command responses for retrieving device information.
24
24
  *
25
- * @param {Event} event - The notification event.
25
+ * @param {BluetoothRemoteGATTCharacteristic} characteristic - The notification event.
26
26
  */
27
- handleNotifications: (event: Event) => void;
27
+ handleNotifications: (characteristic: BluetoothRemoteGATTCharacteristic) => void;
28
28
  /**
29
29
  * Retrieves hardware version from the device.
30
30
  * @returns {Promise<string>} A Promise that resolves with the hardware version.
@@ -147,10 +147,9 @@ export class Entralpi extends Device {
147
147
  * and updates mass data including maximum and average values.
148
148
  * It also handles command responses for retrieving device information.
149
149
  *
150
- * @param {Event} event - The notification event.
150
+ * @param {BluetoothRemoteGATTCharacteristic} characteristic - The notification event.
151
151
  */
152
- handleNotifications = (event) => {
153
- const characteristic = event.target;
152
+ handleNotifications = (characteristic) => {
154
153
  const value = characteristic.value;
155
154
  if (value) {
156
155
  if (value.buffer) {
@@ -15,9 +15,9 @@ export declare class ForceBoard extends Device implements IForceBoard {
15
15
  * and updates mass data including maximum and average values.
16
16
  * It also handles command responses for retrieving device information.
17
17
  *
18
- * @param {Event} event - The notification event.
18
+ * @param {BluetoothRemoteGATTCharacteristic} characteristic - The notification event.
19
19
  */
20
- handleNotifications: (event: Event) => void;
20
+ handleNotifications: (characteristic: BluetoothRemoteGATTCharacteristic) => void;
21
21
  /**
22
22
  * Retrieves humidity level from the device.
23
23
  * @returns {Promise<string>} A Promise that resolves with the humidity level,
@@ -176,10 +176,9 @@ export class ForceBoard extends Device {
176
176
  * and updates mass data including maximum and average values.
177
177
  * It also handles command responses for retrieving device information.
178
178
  *
179
- * @param {Event} event - The notification event.
179
+ * @param {BluetoothRemoteGATTCharacteristic} characteristic - The notification event.
180
180
  */
181
- handleNotifications = (event) => {
182
- const characteristic = event.target;
181
+ handleNotifications = (characteristic) => {
183
182
  const value = characteristic.value;
184
183
  if (value) {
185
184
  if (value.buffer) {
@@ -60,9 +60,9 @@ export declare class Motherboard extends Device implements IMotherboard {
60
60
  * to extract samples, calibrate masses, and update running averages of mass data.
61
61
  * If the received data is not a valid hex packet, it returns the unprocessed data.
62
62
  *
63
- * @param {Event} event - The notification event.
63
+ * @param {BluetoothRemoteGATTCharacteristic} characteristic - The notification event.
64
64
  */
65
- handleNotifications: (event: Event) => void;
65
+ handleNotifications: (characteristic: BluetoothRemoteGATTCharacteristic) => void;
66
66
  /**
67
67
  * Retrieves hardware version from the device.
68
68
  * @returns {Promise<string>} A Promise that resolves with the hardware version,
@@ -186,10 +186,9 @@ export class Motherboard extends Device {
186
186
  * to extract samples, calibrate masses, and update running averages of mass data.
187
187
  * If the received data is not a valid hex packet, it returns the unprocessed data.
188
188
  *
189
- * @param {Event} event - The notification event.
189
+ * @param {BluetoothRemoteGATTCharacteristic} characteristic - The notification event.
190
190
  */
191
- handleNotifications = (event) => {
192
- const characteristic = event.target;
191
+ handleNotifications = (characteristic) => {
193
192
  const value = characteristic.value;
194
193
  if (value) {
195
194
  if (value.buffer) {
@@ -20,9 +20,9 @@ export declare class Progressor extends Device implements IProgressor {
20
20
  * and updates mass data including maximum and average values.
21
21
  * It also handles command responses for retrieving device information.
22
22
  *
23
- * @param {Event} event - The notification event.
23
+ * @param {BluetoothRemoteGATTCharacteristic} characteristic - The notification event.
24
24
  */
25
- handleNotifications: (event: Event) => void;
25
+ handleNotifications: (characteristic: BluetoothRemoteGATTCharacteristic) => void;
26
26
  /**
27
27
  * Stops the data stream on the specified device.
28
28
  * @returns {Promise<void>} A promise that resolves when the stream is stopped.
@@ -111,10 +111,9 @@ export class Progressor extends Device {
111
111
  * and updates mass data including maximum and average values.
112
112
  * It also handles command responses for retrieving device information.
113
113
  *
114
- * @param {Event} event - The notification event.
114
+ * @param {BluetoothRemoteGATTCharacteristic} characteristic - The notification event.
115
115
  */
116
- handleNotifications = (event) => {
117
- const characteristic = event.target;
116
+ handleNotifications = (characteristic) => {
118
117
  const value = characteristic.value;
119
118
  if (value) {
120
119
  if (value.buffer) {
@@ -154,6 +154,11 @@ export declare abstract class Device extends BaseModel implements IDevice {
154
154
  * @param {number} [options.duration=1000] - The duration (in milliseconds) to monitor the input for activity.
155
155
  * @returns {void}
156
156
  * @public
157
+ *
158
+ * @example
159
+ * device.active((isActive) => {
160
+ * console.log(`Device is ${isActive ? 'active' : 'inactive'}`);
161
+ * }, { threshold: 3.0, duration: 1500 });
157
162
  */
158
163
  active: (callback: ActiveCallback, options?: {
159
164
  threshold?: number;
@@ -168,6 +173,9 @@ export declare abstract class Device extends BaseModel implements IDevice {
168
173
  *
169
174
  * @param {number} input - The dynamic value to check for activity status.
170
175
  * @returns {Promise<void>} A promise that resolves once the activity check is complete.
176
+ *
177
+ * @example
178
+ * await device.activityCheck(5.0);
171
179
  */
172
180
  protected activityCheck: (input: number) => Promise<void>;
173
181
  /**
@@ -175,31 +183,55 @@ export declare abstract class Device extends BaseModel implements IDevice {
175
183
  * @param {Function} [onSuccess] - Optional callback function to execute on successful connection. Default logs success.
176
184
  * @param {Function} [onError] - Optional callback function to execute on error. Default logs the error.
177
185
  * @public
186
+ *
187
+ * @example
188
+ * device.connect(
189
+ * () => console.log("Connected successfully"),
190
+ * (error) => console.error("Connection failed:", error)
191
+ * );
178
192
  */
179
193
  connect: (onSuccess?: () => void, onError?: (error: Error) => void) => Promise<void>;
180
194
  /**
181
195
  * Disconnects the device if it is currently connected.
182
- * - Checks if the device is connected via it's GATT server.
183
- * - If the device is connected, it attempts to gracefully disconnect.
196
+ * - Removes all notification listeners from the device's characteristics.
197
+ * - Removes the 'gattserverdisconnected' event listener.
198
+ * - Attempts to gracefully disconnect the device's GATT server.
199
+ * - Resets relevant properties to their initial states.
200
+ * @returns {void}
184
201
  * @public
202
+ *
203
+ * @example
204
+ * device.disconnect();
185
205
  */
186
206
  disconnect: () => void;
187
207
  /**
188
208
  * Converts the `downloadPackets` array into a CSV formatted string.
189
209
  * @returns {string} A CSV string representation of the `downloadPackets` data, with each packet on a new line.
190
210
  * @private
211
+ *
212
+ * @example
213
+ * const csvData = device.downloadToCSV();
214
+ * console.log(csvData);
191
215
  */
192
216
  private downloadToCSV;
193
217
  /**
194
218
  * Converts an array of DownloadPacket objects to a JSON string.
195
219
  * @returns {string} JSON string representation of the data.
196
220
  * @private
221
+ *
222
+ * @example
223
+ * const jsonData = device.downloadToJSON();
224
+ * console.log(jsonData);
197
225
  */
198
226
  private downloadToJSON;
199
227
  /**
200
228
  * Converts an array of DownloadPacket objects to an XML string.
201
229
  * @returns {string} XML string representation of the data.
202
230
  * @private
231
+ *
232
+ * @example
233
+ * const xmlData = device.downloadToXML();
234
+ * console.log(xmlData);
203
235
  */
204
236
  private downloadToXML;
205
237
  /**
@@ -211,12 +243,19 @@ export declare abstract class Device extends BaseModel implements IDevice {
211
243
  *
212
244
  * @returns {void} Initiates a download of the data in the specified format.
213
245
  * @private
246
+ *
247
+ * @example
248
+ * device.download('json');
214
249
  */
215
250
  download: (format?: "csv" | "json" | "xml") => void;
216
251
  /**
217
252
  * Returns UUIDs of all services associated with the device.
218
253
  * @returns {string[]} Array of service UUIDs.
219
254
  * @protected
255
+ *
256
+ * @example
257
+ * const serviceUUIDs = device.getAllServiceUUIDs();
258
+ * console.log(serviceUUIDs);
220
259
  */
221
260
  protected getAllServiceUUIDs: () => string[];
222
261
  /**
@@ -225,18 +264,33 @@ export declare abstract class Device extends BaseModel implements IDevice {
225
264
  * @param {string} characteristicId - The UUID of the characteristic.
226
265
  * @returns {BluetoothRemoteGATTCharacteristic | undefined} The characteristic, if found.
227
266
  * @protected
267
+ *
268
+ * @example
269
+ * const characteristic = device.getCharacteristic('battery', 'level');
270
+ * if (characteristic) {
271
+ * console.log('Characteristic found');
272
+ * }
228
273
  */
229
274
  protected getCharacteristic: (serviceId: string, characteristicId: string) => BluetoothRemoteGATTCharacteristic | undefined;
230
275
  /**
231
276
  * Handles notifications received from a characteristic.
232
- * @param {Event} event - The notification event.
233
- * @protected
277
+ * @param {BluetoothRemoteGATTCharacteristic} characteristic - The notification event.
278
+ *
279
+ * @example
280
+ * device.handleNotifications(someCharacteristic);
234
281
  */
235
- protected handleNotifications: (event: Event) => void;
282
+ protected handleNotifications: (characteristic: BluetoothRemoteGATTCharacteristic) => void;
236
283
  /**
237
284
  * Checks if a Bluetooth device is connected.
238
285
  * @returns {boolean} A boolean indicating whether the device is connected.
239
286
  * @public
287
+ *
288
+ * @example
289
+ * if (device.isConnected()) {
290
+ * console.log('Device is connected');
291
+ * } else {
292
+ * console.log('Device is not connected');
293
+ * }
240
294
  */
241
295
  isConnected: () => boolean;
242
296
  /**
@@ -244,18 +298,31 @@ export declare abstract class Device extends BaseModel implements IDevice {
244
298
  * @param {NotifyCallback} callback - The callback function to be set.
245
299
  * @returns {void}
246
300
  * @public
301
+ *
302
+ * @example
303
+ * device.notify((data) => {
304
+ * console.log('Received notification:', data);
305
+ * });
247
306
  */
248
307
  notify: (callback: NotifyCallback) => void;
249
308
  /**
250
309
  * Handles the 'connected' event.
251
310
  * @param {Function} onSuccess - Callback function to execute on successful connection.
252
311
  * @public
312
+ *
313
+ * @example
314
+ * device.onConnected(() => {
315
+ * console.log('Device connected successfully');
316
+ * });
253
317
  */
254
318
  protected onConnected: (onSuccess: () => void) => Promise<void>;
255
319
  /**
256
320
  * Handles the 'disconnected' event.
257
321
  * @param {Event} event - The 'disconnected' event.
258
322
  * @public
323
+ *
324
+ * @example
325
+ * device.onDisconnected(event);
259
326
  */
260
327
  protected onDisconnected: (event: Event) => void;
261
328
  /**
@@ -265,20 +332,36 @@ export declare abstract class Device extends BaseModel implements IDevice {
265
332
  * @param {number} [duration=0] - The duration to wait before resolving the promise, in milliseconds.
266
333
  * @returns {Promise<string | undefined>} A promise that resolves when the read operation is completed.
267
334
  * @public
335
+ *
336
+ * @example
337
+ * const value = await device.read('battery', 'level', 1000);
338
+ * console.log('Battery level:', value);
268
339
  */
269
340
  read: (serviceId: string, characteristicId: string, duration?: number) => Promise<string | undefined>;
270
341
  /**
271
342
  * Initiates the tare calibration process.
272
343
  * @param {number} duration - The duration time for tare calibration.
273
- * @returns {void}
344
+ * @returns {boolean} A boolean indicating whether the tare calibration was successful.
274
345
  * @public
346
+ *
347
+ * @example
348
+ * const success = device.tare(5000);
349
+ * if (success) {
350
+ * console.log('Tare calibration started');
351
+ * } else {
352
+ * console.log('Tare calibration failed to start');
353
+ * }
275
354
  */
276
- tare(duration?: number): void;
355
+ tare(duration?: number): boolean;
277
356
  /**
278
357
  * Apply tare calibration to the provided sample.
279
358
  * @param {number} sample - The sample to calibrate.
280
359
  * @returns {number} The calibrated tare value.
281
360
  * @protected
361
+ *
362
+ * @example
363
+ * const calibratedSample = device.applyTare(rawSample);
364
+ * console.log('Calibrated sample:', calibratedSample);
282
365
  */
283
366
  protected applyTare(sample: number): number;
284
367
  /**