@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.
Files changed (41) hide show
  1. package/README.md +25 -31
  2. package/dist/index.d.ts +0 -4
  3. package/dist/index.js +0 -5
  4. package/dist/interfaces/callback.interface.d.ts +6 -0
  5. package/dist/interfaces/device/motherboard.interface.d.ts +0 -7
  6. package/dist/interfaces/device.interface.d.ts +32 -27
  7. package/dist/models/device/entralpi.model.js +7 -7
  8. package/dist/models/device/forceboard.model.js +4 -7
  9. package/dist/models/device/kilterboard.model.d.ts +10 -6
  10. package/dist/models/device/kilterboard.model.js +12 -8
  11. package/dist/models/device/motherboard.model.d.ts +12 -8
  12. package/dist/models/device/motherboard.model.js +22 -21
  13. package/dist/models/device/progressor.model.js +4 -7
  14. package/dist/models/device/wh-c06.model.d.ts +11 -6
  15. package/dist/models/device/wh-c06.model.js +30 -16
  16. package/dist/models/device.model.d.ts +161 -14
  17. package/dist/models/device.model.js +263 -5
  18. package/package.json +1 -1
  19. package/src/index.ts +0 -9
  20. package/src/interfaces/callback.interface.ts +7 -0
  21. package/src/interfaces/device/motherboard.interface.ts +0 -8
  22. package/src/interfaces/device.interface.ts +33 -31
  23. package/src/models/device/entralpi.model.ts +7 -7
  24. package/src/models/device/forceboard.model.ts +4 -7
  25. package/src/models/device/kilterboard.model.ts +23 -9
  26. package/src/models/device/motherboard.model.ts +23 -22
  27. package/src/models/device/progressor.model.ts +4 -7
  28. package/src/models/device/wh-c06.model.ts +38 -17
  29. package/src/models/device.model.ts +316 -15
  30. package/dist/helpers/download.d.ts +0 -16
  31. package/dist/helpers/download.js +0 -106
  32. package/dist/helpers/is-active.d.ts +0 -41
  33. package/dist/helpers/is-active.js +0 -59
  34. package/dist/helpers/is-device.d.ts +0 -37
  35. package/dist/helpers/is-device.js +0 -39
  36. package/dist/helpers/tare.d.ts +0 -12
  37. package/dist/helpers/tare.js +0 -70
  38. package/src/helpers/download.ts +0 -123
  39. package/src/helpers/is-active.ts +0 -70
  40. package/src/helpers/is-device.ts +0 -50
  41. package/src/helpers/tare.ts +0 -76
@@ -3,27 +3,55 @@ export class Device extends BaseModel {
3
3
  /**
4
4
  * Filters to identify the device during Bluetooth scanning.
5
5
  * Used to match devices that meet specific criteria such as name, service UUIDs, etc.
6
+ * @type {BluetoothLEScanFilter[]}
7
+ * @public
8
+ * @readonly
6
9
  */
7
10
  filters;
8
11
  /**
9
12
  * Array of services provided by the device.
10
13
  * Services represent functionalities that the device supports, such as weight measurement, battery information, or custom services.
14
+ * @type {Service[]}
15
+ * @public
16
+ * @readonly
11
17
  */
12
18
  services;
13
19
  /**
14
20
  * Reference to the `BluetoothDevice` object representing this device.
15
21
  * This is the actual device object obtained from the Web Bluetooth API after a successful connection.
22
+ * @type {BluetoothDevice | undefined}
23
+ * @public
16
24
  */
17
25
  bluetooth;
18
26
  /**
19
27
  * Object representing the set of commands available for this device.
20
28
  * These commands allow communication with the device to perform various operations such as starting measurements, retrieving data, or calibrating the device.
29
+ * @type {Commands}
30
+ * @public
31
+ * @readonly
21
32
  */
22
33
  commands;
23
34
  /**
24
35
  * The BluetoothRemoteGATTServer interface of the Web Bluetooth API represents a GATT Server on a remote device.
36
+ * @type {BluetoothRemoteGATTServer | undefined}
37
+ * @private
25
38
  */
26
39
  server;
40
+ /**
41
+ * The last message written to the device.
42
+ * @type {string | Uint8Array | null}
43
+ * @protected
44
+ */
45
+ writeLast = null;
46
+ /**
47
+ * Indicates whether the device is currently active.
48
+ * @type {boolean}
49
+ */
50
+ isActive = false;
51
+ /**
52
+ * Configuration for threshold and duration.
53
+ */
54
+ activeConfig = { threshold: 2.5, duration: 1000 };
27
55
  /**
28
56
  * Maximum mass recorded from the device, initialized to "0".
29
57
  * @type {string}
@@ -50,6 +78,38 @@ export class Device extends BaseModel {
50
78
  * @protected
51
79
  */
52
80
  dataPointCount;
81
+ /**
82
+ * Array of DownloadPacket entries.
83
+ * This array holds packets that contain data downloaded from the device.
84
+ * @type {DownloadPacket[]}
85
+ * @protected
86
+ */
87
+ downloadPackets = []; // Initialize an empty array of DownloadPacket entries
88
+ /**
89
+ * Represents the current tare value for calibration.
90
+ * @type {number}
91
+ */
92
+ tareCurrent = 0;
93
+ /**
94
+ * Indicates whether the tare calibration process is active.
95
+ * @type {boolean}
96
+ */
97
+ tareActive = false;
98
+ /**
99
+ * Timestamp when the tare calibration process started.
100
+ * @type {number | null}
101
+ */
102
+ tareStartTime = null;
103
+ /**
104
+ * Array holding the samples collected during tare calibration.
105
+ * @type {number[]}
106
+ */
107
+ tareSamples = [];
108
+ /**
109
+ * Duration time for the tare calibration process.
110
+ * @type {number}
111
+ */
112
+ tareDuration = 5000;
53
113
  /**
54
114
  * Optional callback for handling write operations.
55
115
  * @callback NotifyCallback
@@ -67,10 +127,13 @@ export class Device extends BaseModel {
67
127
  */
68
128
  writeCallback = (data) => console.log(data);
69
129
  /**
70
- * The last message written to the device.
71
- * @type {string | Uint8Array | null}
130
+ * Optional callback for handling write operations.
131
+ * @callback ActiveCallback
132
+ * @param {string} data - The data passed to the callback.
133
+ * @type {ActiveCallback | undefined}
134
+ * @protected
72
135
  */
73
- writeLast = null;
136
+ activeCallback = (data) => console.log(data);
74
137
  constructor(device) {
75
138
  super(device);
76
139
  this.filters = device.filters || [];
@@ -82,10 +145,61 @@ export class Device extends BaseModel {
82
145
  this.massTotalSum = 0;
83
146
  this.dataPointCount = 0;
84
147
  }
148
+ /**
149
+ * Sets the callback function to be called when the activity status changes,
150
+ * and optionally sets the configuration for threshold and duration.
151
+ *
152
+ * This function allows you to specify a callback that will be invoked whenever
153
+ * the activity status changes, indicating whether the device is currently active.
154
+ * It also allows optionally configuring the threshold and duration used to determine activity.
155
+ *
156
+ * @param {ActiveCallback} callback - The callback function to be set. This function
157
+ * receives a boolean value indicating the new activity status.
158
+ * @param {object} [options] - Optional configuration object containing the threshold and duration.
159
+ * @param {number} [options.threshold=2.5] - The threshold value for determining activity.
160
+ * @param {number} [options.duration=1000] - The duration (in milliseconds) to monitor the input for activity.
161
+ * @returns {void}
162
+ * @public
163
+ */
164
+ active = (callback, options) => {
165
+ this.activeCallback = callback;
166
+ // Update the config values only if provided, otherwise use defaults
167
+ this.activeConfig = {
168
+ threshold: options?.threshold ?? this.activeConfig.threshold, // Use new threshold if provided, else use default
169
+ duration: options?.duration ?? this.activeConfig.duration, // Use new duration if provided, else use default
170
+ };
171
+ };
172
+ /**
173
+ * Checks if a dynamic value is active based on a threshold and duration.
174
+ *
175
+ * This function assesses whether a given dynamic value surpasses a specified threshold
176
+ * and remains active for a specified duration. If the activity status changes from
177
+ * the previous state, the callback function is called with the updated activity status.
178
+ *
179
+ * @param {number} input - The dynamic value to check for activity status.
180
+ * @returns {Promise<void>} A promise that resolves once the activity check is complete.
181
+ */
182
+ activityCheck = (input) => {
183
+ return new Promise((resolve) => {
184
+ // Check the activity status after the specified duration
185
+ setTimeout(() => {
186
+ // Determine the activity status based on the stored threshold in the config
187
+ const activeNow = input > this.activeConfig.threshold;
188
+ if (this.isActive !== activeNow) {
189
+ this.isActive = activeNow;
190
+ if (this.activeCallback) {
191
+ this.activeCallback(activeNow);
192
+ }
193
+ }
194
+ resolve();
195
+ }, this.activeConfig.duration);
196
+ });
197
+ };
85
198
  /**
86
199
  * Connects to a Bluetooth device.
87
200
  * @param {Function} [onSuccess] - Optional callback function to execute on successful connection. Default logs success.
88
201
  * @param {Function} [onError] - Optional callback function to execute on error. Default logs the error.
202
+ * @public
89
203
  */
90
204
  connect = async (onSuccess = () => console.log("Connected successfully"), onError = (error) => console.error(error)) => {
91
205
  try {
@@ -114,6 +228,7 @@ export class Device extends BaseModel {
114
228
  * Disconnects the device if it is currently connected.
115
229
  * - Checks if the device is connected via it's GATT server.
116
230
  * - If the device is connected, it attempts to gracefully disconnect.
231
+ * @public
117
232
  */
118
233
  disconnect = () => {
119
234
  // Verify that the device is connected using the provided helper function
@@ -122,9 +237,110 @@ export class Device extends BaseModel {
122
237
  this.bluetooth?.gatt?.disconnect();
123
238
  }
124
239
  };
240
+ /**
241
+ * Converts the `downloadPackets` array into a CSV formatted string.
242
+ * @returns {string} A CSV string representation of the `downloadPackets` data, with each packet on a new line.
243
+ * @private
244
+ */
245
+ downloadToCSV = () => {
246
+ return this.downloadPackets
247
+ .map((packet) => [
248
+ packet.received.toString(),
249
+ packet.sampleNum.toString(),
250
+ packet.battRaw.toString(),
251
+ ...packet.samples.map(String),
252
+ ...packet.masses.map(String),
253
+ ]
254
+ .map((v) => v.replace(/"/g, '""'))
255
+ .map((v) => `"${v}"`)
256
+ .join(","))
257
+ .join("\r\n");
258
+ };
259
+ /**
260
+ * Converts an array of DownloadPacket objects to a JSON string.
261
+ * @returns {string} JSON string representation of the data.
262
+ * @private
263
+ */
264
+ downloadToJSON = () => {
265
+ // Pretty print JSON with 2-space indentation
266
+ return JSON.stringify(this.downloadPackets, null, 2);
267
+ };
268
+ /**
269
+ * Converts an array of DownloadPacket objects to an XML string.
270
+ * @returns {string} XML string representation of the data.
271
+ * @private
272
+ */
273
+ downloadToXML = () => {
274
+ const xmlPackets = this.downloadPackets
275
+ .map((packet) => {
276
+ const samples = packet.samples.map((sample) => `<sample>${sample}</sample>`).join("");
277
+ const masses = packet.masses.map((mass) => `<mass>${mass}</mass>`).join("");
278
+ return `
279
+ <packet>
280
+ <received>${packet.received}</received>
281
+ <sampleNum>${packet.sampleNum}</sampleNum>
282
+ <battRaw>${packet.battRaw}</battRaw>
283
+ <samples>${samples}</samples>
284
+ <masses>${masses}</masses>
285
+ </packet>
286
+ `;
287
+ })
288
+ .join("");
289
+ return `<DownloadPackets>${xmlPackets}</DownloadPackets>`;
290
+ };
291
+ /**
292
+ * Exports the data in the specified format (CSV, JSON, XML) with a filename format:
293
+ * 'data-export-YYYY-MM-DD-HH-MM-SS.{format}'.
294
+ *
295
+ * @param {('csv' | 'json' | 'xml')} [format='csv'] - The format in which to download the data.
296
+ * Defaults to 'csv'. Accepted values are 'csv', 'json', and 'xml'.
297
+ *
298
+ * @returns {void} Initiates a download of the data in the specified format.
299
+ * @private
300
+ */
301
+ download = (format = "csv") => {
302
+ let content = "";
303
+ let mimeType = "";
304
+ let fileName = "";
305
+ if (format === "csv") {
306
+ content = this.downloadToCSV();
307
+ mimeType = "text/csv";
308
+ }
309
+ else if (format === "json") {
310
+ content = this.downloadToJSON();
311
+ mimeType = "application/json";
312
+ }
313
+ else if (format === "xml") {
314
+ content = this.downloadToXML();
315
+ mimeType = "application/xml";
316
+ }
317
+ const now = new Date();
318
+ // YYYY-MM-DD
319
+ const date = now.toISOString().split("T")[0];
320
+ // HH-MM-SS
321
+ const time = now.toTimeString().split(" ")[0].replace(/:/g, "-");
322
+ fileName = `data-export-${date}-${time}.${format}`;
323
+ // Create a Blob object containing the data
324
+ const blob = new Blob([content], { type: mimeType });
325
+ // Create a URL for the Blob
326
+ const url = window.URL.createObjectURL(blob);
327
+ // Create a link element
328
+ const link = document.createElement("a");
329
+ // Set link attributes
330
+ link.href = url;
331
+ link.setAttribute("download", fileName);
332
+ // Append link to document body
333
+ document.body.appendChild(link);
334
+ // Programmatically click the link to trigger the download
335
+ link.click();
336
+ // Clean up: remove the link and revoke the URL
337
+ document.body.removeChild(link);
338
+ window.URL.revokeObjectURL(url);
339
+ };
125
340
  /**
126
341
  * Returns UUIDs of all services associated with the device.
127
342
  * @returns {string[]} Array of service UUIDs.
343
+ * @protected
128
344
  */
129
345
  getAllServiceUUIDs = () => {
130
346
  return this.services.map((service) => service.uuid);
@@ -134,6 +350,7 @@ export class Device extends BaseModel {
134
350
  * @param {string} serviceId - The UUID of the service.
135
351
  * @param {string} characteristicId - The UUID of the characteristic.
136
352
  * @returns {BluetoothRemoteGATTCharacteristic | undefined} The characteristic, if found.
353
+ * @protected
137
354
  */
138
355
  getCharacteristic = (serviceId, characteristicId) => {
139
356
  // Find the service with the specified serviceId
@@ -152,6 +369,7 @@ export class Device extends BaseModel {
152
369
  /**
153
370
  * Handles notifications received from a characteristic.
154
371
  * @param {Event} event - The notification event.
372
+ * @protected
155
373
  */
156
374
  handleNotifications = (event) => {
157
375
  const characteristic = event.target;
@@ -171,6 +389,7 @@ export class Device extends BaseModel {
171
389
  /**
172
390
  * Checks if a Bluetooth device is connected.
173
391
  * @returns {boolean} A boolean indicating whether the device is connected.
392
+ * @public
174
393
  */
175
394
  isConnected = () => {
176
395
  // Check if the device is defined and available
@@ -184,6 +403,7 @@ export class Device extends BaseModel {
184
403
  * Sets the callback function to be called when notifications are received.
185
404
  * @param {NotifyCallback} callback - The callback function to be set.
186
405
  * @returns {void}
406
+ * @public
187
407
  */
188
408
  notify = (callback) => {
189
409
  this.notifyCallback = callback;
@@ -191,6 +411,7 @@ export class Device extends BaseModel {
191
411
  /**
192
412
  * Handles the 'connected' event.
193
413
  * @param {Function} onSuccess - Callback function to execute on successful connection.
414
+ * @public
194
415
  */
195
416
  onConnected = async (onSuccess) => {
196
417
  // Connect to GATT server and set up characteristics
@@ -231,6 +452,7 @@ export class Device extends BaseModel {
231
452
  /**
232
453
  * Handles the 'disconnected' event.
233
454
  * @param {Event} event - The 'disconnected' event.
455
+ * @public
234
456
  */
235
457
  onDisconnected = (event) => {
236
458
  this.bluetooth = undefined;
@@ -243,6 +465,7 @@ export class Device extends BaseModel {
243
465
  * @param {string} characteristicId - The characteristic ID to read from.
244
466
  * @param {number} [duration=0] - The duration to wait before resolving the promise, in milliseconds.
245
467
  * @returns {Promise<string | undefined>} A promise that resolves when the read operation is completed.
468
+ * @public
246
469
  */
247
470
  read = async (serviceId, characteristicId, duration = 0) => {
248
471
  if (!this.isConnected()) {
@@ -273,6 +496,42 @@ export class Device extends BaseModel {
273
496
  }
274
497
  return decodedValue;
275
498
  };
499
+ /**
500
+ * Initiates the tare calibration process.
501
+ * @param {number} duration - The duration time for tare calibration.
502
+ * @returns {void}
503
+ * @public
504
+ */
505
+ tare(duration = 5000) {
506
+ this.tareActive = true;
507
+ this.tareDuration = duration;
508
+ this.tareSamples = [];
509
+ this.tareStartTime = Date.now();
510
+ }
511
+ /**
512
+ * Apply tare calibration to the provided sample.
513
+ * @param {number} sample - The sample to calibrate.
514
+ * @returns {number} The calibrated tare value.
515
+ * @protected
516
+ */
517
+ applyTare(sample) {
518
+ if (this.tareActive && this.tareStartTime) {
519
+ // Add current sample to the tare samples array
520
+ this.tareSamples.push(sample);
521
+ // Check if the tare calibration duration has passed
522
+ if (Date.now() - this.tareStartTime >= this.tareDuration) {
523
+ // Calculate the average of the tare samples
524
+ const total = this.tareSamples.reduce((acc, sample) => acc + sample, 0);
525
+ this.tareCurrent = total / this.tareSamples.length;
526
+ // Reset the tare calibration process
527
+ this.tareActive = false;
528
+ this.tareStartTime = null;
529
+ this.tareSamples = [];
530
+ }
531
+ }
532
+ // Return the current tare-adjusted value
533
+ return this.tareCurrent;
534
+ }
276
535
  /**
277
536
  * Writes a message to the specified characteristic of a Bluetooth device and optionally provides a callback to handle responses.
278
537
  * @param {string} serviceId - The service UUID of the Bluetooth device containing the target characteristic.
@@ -280,9 +539,8 @@ export class Device extends BaseModel {
280
539
  * @param {string | Uint8Array | undefined} message - The message to be written to the characteristic. It can be a string or a Uint8Array.
281
540
  * @param {number} [duration=0] - Optional. The time in milliseconds to wait before resolving the promise. Defaults to 0 for immediate resolution.
282
541
  * @param {WriteCallback} [callback=writeCallback] - Optional. A custom callback to handle the response after the write operation is successful.
283
- *
284
542
  * @returns {Promise<void>} A promise that resolves once the write operation is complete.
285
- *
543
+ * @public
286
544
  * @throws {Error} Throws an error if the characteristic is undefined.
287
545
  *
288
546
  * @example
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hangtime/grip-connect",
3
- "version": "0.5.6",
3
+ "version": "0.5.7",
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/index.ts CHANGED
@@ -8,12 +8,3 @@ export {
8
8
  WHC06,
9
9
  Progressor,
10
10
  } from "./models/index"
11
-
12
- // helpers
13
- export { isEntralpi, isKilterBoard, isMotherboard, isWHC06, isProgressor } from "./helpers/is-device"
14
-
15
- export { download } from "./helpers/download"
16
-
17
- export { active, isActive } from "./helpers/is-active"
18
-
19
- export { tare } from "./helpers/tare"
@@ -54,3 +54,10 @@ export type NotifyCallback = (data: massObject) => void
54
54
  * @param {string} data - The string data passed to the callback.
55
55
  */
56
56
  export type WriteCallback = (data: string) => void
57
+
58
+ /**
59
+ * Type definition for the callback function that is called when the activity status changes.
60
+ * @callback ActiveCallback
61
+ * @param {boolean} value - The new activity status (true if active, false if not).
62
+ */
63
+ export type ActiveCallback = (data: boolean) => void
@@ -4,14 +4,6 @@ import type { IDevice } from "../device.interface"
4
4
  * Interface representing the Griptonite Motherboard device.
5
5
  */
6
6
  export interface IMotherboard extends IDevice {
7
- /**
8
- * Applies calibration to a sample value.
9
- * @param {number} sample - The sample value to calibrate.
10
- * @param {number[][]} calibration - The calibration data.
11
- * @returns {number} The calibrated sample value.
12
- */
13
- applyCalibration(sample: number, calibration: number[][]): number
14
-
15
7
  /**
16
8
  * Retrieves battery or voltage information from the device.
17
9
  * @returns {Promise<string | undefined>} A Promise that resolves with the battery or voltage information.
@@ -37,24 +37,35 @@ export interface IDevice extends IBase {
37
37
  /**
38
38
  * Filters to identify the device during Bluetooth scanning.
39
39
  * Used to match devices that meet specific criteria such as name, service UUIDs, etc.
40
+ * @type {BluetoothLEScanFilter[]}
41
+ * @public
42
+ * @readonly
40
43
  */
41
44
  filters: BluetoothLEScanFilter[]
42
45
 
43
46
  /**
44
47
  * Array of services provided by the device.
45
48
  * Services represent functionalities that the device supports, such as weight measurement, battery information, or custom services.
49
+ * @type {Service[]}
50
+ * @public
51
+ * @readonly
46
52
  */
47
53
  services: Service[]
48
54
 
49
55
  /**
50
56
  * Reference to the `BluetoothDevice` object representing this device.
51
57
  * This is the actual device object obtained from the Web Bluetooth API after a successful connection.
58
+ * @type {BluetoothDevice | undefined}
59
+ * @public
52
60
  */
53
61
  bluetooth?: BluetoothDevice
54
62
 
55
63
  /**
56
64
  * Object representing the set of commands available for this device.
57
65
  * These commands allow communication with the device to perform various operations such as starting measurements, retrieving data, or calibrating the device.
66
+ * @type {Commands}
67
+ * @public
68
+ * @readonly
58
69
  */
59
70
  commands: Commands
60
71
 
@@ -62,6 +73,7 @@ export interface IDevice extends IBase {
62
73
  * Connects to a Bluetooth device.
63
74
  * @param {Function} [onSuccess] - Optional callback function to execute on successful connection. Default logs success.
64
75
  * @param {Function} [onError] - Optional callback function to execute on error. Default logs the error.
76
+ * @public
65
77
  */
66
78
  connect(onSuccess?: () => void, onError?: (error: Error) => void): Promise<void>
67
79
 
@@ -69,32 +81,26 @@ export interface IDevice extends IBase {
69
81
  * Disconnects the device if it is currently connected.
70
82
  * - Checks if the device is connected via it's GATT server.
71
83
  * - If the device is connected, it attempts to gracefully disconnect.
84
+ * @public
72
85
  */
73
86
  disconnect(): void
74
87
 
75
88
  /**
76
- * Returns UUIDs of all services associated with the device.
77
- * @returns {string[]} Array of service UUIDs.
78
- */
79
- getAllServiceUUIDs(): string[]
80
-
81
- /**
82
- * Retrieves the characteristic from the device's service.
83
- * @param {string} serviceId - The UUID of the service.
84
- * @param {string} characteristicId - The UUID of the characteristic.
85
- * @returns {BluetoothRemoteGATTCharacteristic | undefined} The characteristic, if found.
86
- */
87
- getCharacteristic(serviceId: string, characteristicId: string): BluetoothRemoteGATTCharacteristic | undefined
88
-
89
- /**
90
- * Handles notifications received from a characteristic.
91
- * @param {Event} event - The notification event.
89
+ * Exports the data in the specified format (CSV, JSON, XML) with a filename format:
90
+ * 'data-export-YYYY-MM-DD-HH-MM-SS.{format}'.
91
+ *
92
+ * @param {('csv' | 'json' | 'xml')} [format='csv'] - The format in which to download the data.
93
+ * Defaults to 'csv'. Accepted values are 'csv', 'json', and 'xml'.
94
+ *
95
+ * @returns {void} Initiates a download of the data in the specified format.
96
+ * @private
92
97
  */
93
- handleNotifications(event: Event): void
98
+ download(format?: "csv" | "json" | "xml"): void
94
99
 
95
100
  /**
96
101
  * Checks if a Bluetooth device is connected.
97
102
  * @returns {boolean} A boolean indicating whether the device is connected.
103
+ * @public
98
104
  */
99
105
  isConnected(): boolean
100
106
 
@@ -102,30 +108,27 @@ export interface IDevice extends IBase {
102
108
  * Sets the callback function to be called when notifications are received.
103
109
  * @param {NotifyCallback} callback - The callback function to be set.
104
110
  * @returns {void}
111
+ * @public
105
112
  */
106
113
  notify(callback: (data: massObject) => void): void
107
114
 
108
- /**
109
- * Handles the 'connected' event.
110
- * @param {Function} onSuccess - Callback function to execute on successful connection.
111
- */
112
- onConnected(onSuccess: () => void): Promise<void>
113
-
114
- /**
115
- * Handles the 'disconnected' event.
116
- * @param {Event} event - The 'disconnected' event.
117
- */
118
- onDisconnected(event: Event): void
119
-
120
115
  /**
121
116
  * Reads the value of the specified characteristic from the device.
122
117
  * @param {string} serviceId - The service ID where the characteristic belongs.
123
118
  * @param {string} characteristicId - The characteristic ID to read from.
124
119
  * @param {number} [duration=0] - The duration to wait before resolving the promise, in milliseconds.
125
120
  * @returns {Promise<string | undefined>} A promise that resolves when the read operation is completed.
121
+ * @public
126
122
  */
127
123
  read(serviceId: string, characteristicId: string, duration?: number): Promise<string | undefined>
128
124
 
125
+ /**
126
+ * Initiates the tare calibration process.
127
+ * @param {number} duration - The duration time for tare calibration.
128
+ * @returns {void}
129
+ */
130
+ tare(duration?: number): void
131
+
129
132
  /**
130
133
  * Writes a message to the specified characteristic of a Bluetooth device and optionally provides a callback to handle responses.
131
134
  * @param {string} serviceId - The service UUID of the Bluetooth device containing the target characteristic.
@@ -133,9 +136,8 @@ export interface IDevice extends IBase {
133
136
  * @param {string | Uint8Array | undefined} message - The message to be written to the characteristic. It can be a string or a Uint8Array.
134
137
  * @param {number} [duration=0] - Optional. The time in milliseconds to wait before resolving the promise. Defaults to 0 for immediate resolution.
135
138
  * @param {WriteCallback} [callback=writeCallback] - Optional. A custom callback to handle the response after the write operation is successful.
136
- *
137
139
  * @returns {Promise<void>} A promise that resolves once the write operation is complete.
138
- *
140
+ * @public
139
141
  * @throws {Error} Throws an error if the characteristic is undefined.
140
142
  *
141
143
  * @example
@@ -1,8 +1,5 @@
1
1
  import { Device } from "../device.model"
2
2
  import type { IEntralpi } from "../../interfaces/device/entralpi.interface"
3
- import { applyTare } from "../../helpers/tare"
4
- import { checkActivity } from "../../helpers/is-active"
5
- import { DownloadPackets } from "../../helpers/download"
6
3
 
7
4
  export class Entralpi extends Device implements IEntralpi {
8
5
  constructor() {
@@ -170,10 +167,13 @@ export class Entralpi extends Device implements IEntralpi {
170
167
  const receivedData: string = (rawData.getUint16(0) / 100).toFixed(1)
171
168
 
172
169
  const convertedData = Number(receivedData)
173
- // Tare correction
174
- const numericData = convertedData - applyTare(convertedData)
170
+ // Adjust weight by using the tare value
171
+ // If tare is 0, use the original weight, otherwise subtract tare and invert.
172
+ // This will display the romoved or 'no-hanging' weight.
173
+ const tare = this.applyTare(convertedData)
174
+ const numericData = tare === 0 ? convertedData : (convertedData - tare) * -1
175
175
  // Add data to downloadable Array
176
- DownloadPackets.push({
176
+ this.downloadPackets.push({
177
177
  received: receivedTime,
178
178
  sampleNum: this.dataPointCount,
179
179
  battRaw: 0,
@@ -193,7 +193,7 @@ export class Entralpi extends Device implements IEntralpi {
193
193
  this.massAverage = (this.massTotalSum / this.dataPointCount).toFixed(1)
194
194
 
195
195
  // Check if device is being used
196
- checkActivity(numericData)
196
+ this.activityCheck(numericData)
197
197
 
198
198
  // Notify with weight data
199
199
  this.notifyCallback({
@@ -1,8 +1,5 @@
1
1
  import { Device } from "../device.model"
2
2
  import type { IForceBoard } from "../../interfaces/device/forceboard.interface"
3
- import { DownloadPackets, emptyDownloadPackets } from "../../helpers/download"
4
- import { checkActivity } from "../../helpers/is-active"
5
- import { applyTare } from "../../helpers/tare"
6
3
 
7
4
  /**
8
5
  * Represents a PitchSix Force Board device
@@ -198,9 +195,9 @@ export class ForceBoard extends Device implements IForceBoard {
198
195
  // Convert from LBS to KG
199
196
  const convertedReceivedData = receivedData * 0.453592
200
197
  // Tare correction
201
- const numericData = convertedReceivedData - applyTare(convertedReceivedData)
198
+ const numericData = convertedReceivedData - this.applyTare(convertedReceivedData)
202
199
  // Add data to downloadable Array
203
- DownloadPackets.push({
200
+ this.downloadPackets.push({
204
201
  received: receivedTime,
205
202
  sampleNum: this.dataPointCount,
206
203
  battRaw: 0,
@@ -220,7 +217,7 @@ export class ForceBoard extends Device implements IForceBoard {
220
217
  this.massAverage = (this.massTotalSum / this.dataPointCount).toFixed(1)
221
218
 
222
219
  // Check if device is being used
223
- checkActivity(numericData)
220
+ this.activityCheck(numericData)
224
221
 
225
222
  // Notify with weight data
226
223
  this.notifyCallback({
@@ -263,7 +260,7 @@ export class ForceBoard extends Device implements IForceBoard {
263
260
  */
264
261
  stream = async (duration = 0): Promise<void> => {
265
262
  // Reset download packets
266
- emptyDownloadPackets()
263
+ this.downloadPackets.length = 0
267
264
  // Start streaming data
268
265
  await this.write("weight", "tx", new Uint8Array([0x04]), duration) // ASCII control character EOT (End of Transmission)
269
266
  // Stop streaming if duration is set