@hangtime/grip-connect 0.5.0 → 0.5.1

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 (47) hide show
  1. package/README.md +17 -29
  2. package/dist/index.d.ts +0 -2
  3. package/dist/index.js +0 -2
  4. package/dist/interfaces/base.interface.d.ts +12 -0
  5. package/dist/interfaces/device/climbro.interface.d.ts +3 -0
  6. package/dist/interfaces/device/entralpi.interface.d.ts +49 -0
  7. package/dist/interfaces/device/forceboard.interface.d.ts +18 -0
  8. package/dist/interfaces/device/kilterboard.interface.d.ts +73 -0
  9. package/dist/interfaces/device/motherboard.interface.d.ts +53 -3
  10. package/dist/interfaces/device/mysmartboard.interface.d.ts +3 -0
  11. package/dist/interfaces/device/progressor.interface.d.ts +24 -0
  12. package/dist/interfaces/device/wh-c06.interface.d.ts +3 -0
  13. package/dist/interfaces/device.interface.d.ts +33 -19
  14. package/dist/models/device/entralpi.model.d.ts +22 -6
  15. package/dist/models/device/entralpi.model.js +48 -9
  16. package/dist/models/device/kilterboard.model.d.ts +1 -1
  17. package/dist/models/device/motherboard.model.d.ts +5 -0
  18. package/dist/models/device/motherboard.model.js +12 -4
  19. package/dist/models/device/progressor.model.d.ts +5 -0
  20. package/dist/models/device/progressor.model.js +12 -4
  21. package/dist/models/device/wh-c06.model.js +3 -4
  22. package/dist/models/device.model.d.ts +35 -19
  23. package/dist/models/device.model.js +76 -62
  24. package/package.json +1 -1
  25. package/src/index.ts +0 -4
  26. package/src/interfaces/base.interface.ts +14 -0
  27. package/src/interfaces/device/climbro.interface.ts +3 -1
  28. package/src/interfaces/device/entralpi.interface.ts +59 -2
  29. package/src/interfaces/device/forceboard.interface.ts +22 -2
  30. package/src/interfaces/device/kilterboard.interface.ts +83 -2
  31. package/src/interfaces/device/motherboard.interface.ts +62 -3
  32. package/src/interfaces/device/mysmartboard.interface.ts +3 -1
  33. package/src/interfaces/device/progressor.interface.ts +29 -2
  34. package/src/interfaces/device/wh-c06.interface.ts +3 -1
  35. package/src/interfaces/device.interface.ts +36 -20
  36. package/src/models/device/entralpi.model.ts +51 -9
  37. package/src/models/device/kilterboard.model.ts +1 -1
  38. package/src/models/device/motherboard.model.ts +13 -4
  39. package/src/models/device/progressor.model.ts +13 -4
  40. package/src/models/device/wh-c06.model.ts +4 -4
  41. package/src/models/device.model.ts +87 -69
  42. package/dist/notify.d.ts +0 -16
  43. package/dist/notify.js +0 -14
  44. package/dist/stop.d.ts +0 -7
  45. package/dist/stop.js +0 -20
  46. package/src/notify.ts +0 -18
  47. package/src/stop.ts +0 -22
@@ -1,5 +1,4 @@
1
1
  import { Device } from "../device.model";
2
- import { notifyCallback } from "../../notify";
3
2
  import { applyTare } from "../../tare";
4
3
  import { checkActivity } from "../../is-active";
5
4
  import { read } from "../../read";
@@ -24,7 +23,7 @@ export class Entralpi extends Device {
24
23
  characteristics: [
25
24
  {
26
25
  name: "System ID",
27
- id: "id",
26
+ id: "system",
28
27
  uuid: "00002a23-0000-1000-8000-00805f9b34fb",
29
28
  },
30
29
  {
@@ -132,7 +131,7 @@ export class Entralpi extends Device {
132
131
  }
133
132
  /**
134
133
  * Retrieves battery or voltage information from the device.
135
- * @returns {Promise<string | undefined>} A Promise that resolves with the battery or voltage information,
134
+ * @returns {Promise<string | undefined>} A Promise that resolves with the battery or voltage information.
136
135
  */
137
136
  battery = async () => {
138
137
  if (this.isConnected()) {
@@ -141,9 +140,22 @@ export class Entralpi extends Device {
141
140
  // If device is not found, return undefined
142
141
  return undefined;
143
142
  };
143
+ /**
144
+ * Retrieves IEEE 11073-20601 Regulatory Certification from the device.
145
+ * @returns {Promise<string>} A Promise that resolves with the certification.
146
+ */
147
+ certification = async () => {
148
+ // Check if the device is connected
149
+ if (this.isConnected()) {
150
+ // Read certification from the device
151
+ return await read(this, "device", "certification", 250);
152
+ }
153
+ // If device is not found, return undefined
154
+ return undefined;
155
+ };
144
156
  /**
145
157
  * Retrieves firmware version from the device.
146
- * @returns {Promise<string>} A Promise that resolves with the firmware version,
158
+ * @returns {Promise<string>} A Promise that resolves with the firmware version.
147
159
  */
148
160
  firmware = async () => {
149
161
  // Check if the device is connected
@@ -183,7 +195,7 @@ export class Entralpi extends Device {
183
195
  // Check if device is being used
184
196
  checkActivity(numericData);
185
197
  // Notify with weight data
186
- notifyCallback({
198
+ this.notifyCallback({
187
199
  massMax: MASS_MAX,
188
200
  massAverage: MASS_AVERAGE,
189
201
  massTotal: Math.max(-1000, numericData).toFixed(1),
@@ -193,7 +205,7 @@ export class Entralpi extends Device {
193
205
  };
194
206
  /**
195
207
  * Retrieves hardware version from the device.
196
- * @returns {Promise<string>} A Promise that resolves with the hardware version,
208
+ * @returns {Promise<string>} A Promise that resolves with the hardware version.
197
209
  */
198
210
  hardware = async () => {
199
211
  // Check if the device is connected
@@ -206,7 +218,7 @@ export class Entralpi extends Device {
206
218
  };
207
219
  /**
208
220
  * Retrieves manufacturer information from the device.
209
- * @returns {Promise<string>} A Promise that resolves with the manufacturer information,
221
+ * @returns {Promise<string>} A Promise that resolves with the manufacturer information.
210
222
  */
211
223
  manufacturer = async () => {
212
224
  // Check if the device is connected
@@ -219,7 +231,7 @@ export class Entralpi extends Device {
219
231
  };
220
232
  /**
221
233
  * Retrieves model number from the device.
222
- * @returns {Promise<string>} A Promise that resolves with the model number,
234
+ * @returns {Promise<string>} A Promise that resolves with the model number.
223
235
  */
224
236
  model = async () => {
225
237
  // Check if the device is connected
@@ -230,9 +242,23 @@ export class Entralpi extends Device {
230
242
  // If device is not found, return undefined
231
243
  return undefined;
232
244
  };
245
+ /**
246
+ * Retrieves PnP ID from the device, a set of values that used to create a device ID value that is unique for this device.
247
+ * Included in the characteristic is a Vendor ID Source field, a Vendor ID field, a Product ID field and a Product Version field
248
+ * @returns {Promise<string>} A Promise that resolves with the PnP ID.
249
+ */
250
+ pnp = async () => {
251
+ // Check if the device is connected
252
+ if (this.isConnected()) {
253
+ // Read software version from the Entralpi
254
+ return await read(this, "device", "pnp", 250);
255
+ }
256
+ // If device is not found, return undefined
257
+ return undefined;
258
+ };
233
259
  /**
234
260
  * Retrieves software version from the device.
235
- * @returns {Promise<string>} A Promise that resolves with the software version,
261
+ * @returns {Promise<string>} A Promise that resolves with the software version.
236
262
  */
237
263
  software = async () => {
238
264
  // Check if the device is connected
@@ -243,4 +269,17 @@ export class Entralpi extends Device {
243
269
  // If device is not found, return undefined
244
270
  return undefined;
245
271
  };
272
+ /**
273
+ * Retrieves system id from the device.
274
+ * @returns {Promise<string>} A Promise that resolves with the system id.
275
+ */
276
+ system = async () => {
277
+ // Check if the device is connected
278
+ if (this.isConnected()) {
279
+ // Read system id from the device
280
+ return await read(this, "device", "system", 250);
281
+ }
282
+ // If device is not found, return undefined
283
+ return undefined;
284
+ };
246
285
  }
@@ -80,6 +80,6 @@ export declare class KilterBoard extends Device implements IKilterBoard {
80
80
  * @param {ClimbPlacement[]} [config] - Optional color or array of climb placements for the LEDs. Ignored if placements are provided.
81
81
  * @returns {Promise<number[] | undefined>} A promise that resolves with the payload array for the Kilter Board if LED settings were applied, or `undefined` if no action was taken or for the Motherboard.
82
82
  */
83
- led: (config?: "green" | "red" | "orange" | ClimbPlacement[]) => Promise<number[] | undefined>;
83
+ led: (config?: ClimbPlacement[]) => Promise<number[] | undefined>;
84
84
  }
85
85
  export {};
@@ -57,6 +57,11 @@ export declare class Motherboard extends Device implements IMotherboard {
57
57
  * @returns {Promise<string>} A Promise that resolves with the serial number,
58
58
  */
59
59
  serial: () => Promise<string | undefined>;
60
+ /**
61
+ * Stops the data stream on the specified device.
62
+ * @returns {Promise<void>} A promise that resolves when the stream is stopped.
63
+ */
64
+ stop: () => Promise<void>;
60
65
  /**
61
66
  * Starts streaming data from the specified device.
62
67
  * @param {number} [duration=0] - The duration of the stream in milliseconds. If set to 0, stream will continue indefinitely.
@@ -1,5 +1,4 @@
1
1
  import { Device } from "../device.model";
2
- import { notifyCallback } from "../../notify";
3
2
  import { write, writeCallback } from "../../write";
4
3
  import { applyTare } from "../../tare";
5
4
  import { MotherboardCommands } from "../../commands";
@@ -7,7 +6,6 @@ import { checkActivity } from "../../is-active";
7
6
  import { lastWrite } from "../../write";
8
7
  import { DownloadPackets, emptyDownloadPackets } from "../../download";
9
8
  import { read } from "../../read";
10
- import { stop } from "../../stop";
11
9
  // Constants
12
10
  const PACKET_LENGTH = 32;
13
11
  const NUM_SAMPLES = 3;
@@ -255,7 +253,7 @@ export class Motherboard extends Device {
255
253
  // Check if device is being used
256
254
  checkActivity(center);
257
255
  // Notify with weight data
258
- notifyCallback({
256
+ this.notifyCallback({
259
257
  massTotal: Math.max(-1000, left + center + right).toFixed(1),
260
258
  massMax: MASS_MAX,
261
259
  massAverage: MASS_AVERAGE,
@@ -344,6 +342,16 @@ export class Motherboard extends Device {
344
342
  // If device is not found, return undefined
345
343
  return undefined;
346
344
  };
345
+ /**
346
+ * Stops the data stream on the specified device.
347
+ * @returns {Promise<void>} A promise that resolves when the stream is stopped.
348
+ */
349
+ stop = async () => {
350
+ if (this.isConnected()) {
351
+ // Stop stream of device
352
+ await write(this, "uart", "tx", MotherboardCommands.STOP_WEIGHT_MEAS, 0);
353
+ }
354
+ };
347
355
  /**
348
356
  * Starts streaming data from the specified device.
349
357
  * @param {number} [duration=0] - The duration of the stream in milliseconds. If set to 0, stream will continue indefinitely.
@@ -362,7 +370,7 @@ export class Motherboard extends Device {
362
370
  await write(this, "uart", "tx", MotherboardCommands.START_WEIGHT_MEAS, duration);
363
371
  // Stop streaming if duration is set
364
372
  if (duration !== 0) {
365
- await stop(this);
373
+ await this.stop();
366
374
  }
367
375
  }
368
376
  };
@@ -23,6 +23,11 @@ export declare class Progressor extends Device implements IProgressor {
23
23
  * @param {Event} event - The notification event.
24
24
  */
25
25
  handleNotifications: (event: Event) => void;
26
+ /**
27
+ * Stops the data stream on the specified device.
28
+ * @returns {Promise<void>} A promise that resolves when the stream is stopped.
29
+ */
30
+ stop: () => Promise<void>;
26
31
  /**
27
32
  * Starts streaming data from the specified device.
28
33
  * @param {number} [duration=0] - The duration of the stream in milliseconds. If set to 0, stream will continue indefinitely.
@@ -1,12 +1,10 @@
1
1
  import { Device } from "../device.model";
2
- import { notifyCallback } from "../../notify";
3
2
  import { applyTare } from "../../tare";
4
3
  import { checkActivity } from "../../is-active";
5
4
  import { ProgressorCommands, ProgressorResponses } from "../../commands/progressor";
6
5
  import struct from "../../struct";
7
6
  import { DownloadPackets, emptyDownloadPackets } from "../../download";
8
7
  import { lastWrite, write, writeCallback } from "../../write";
9
- import { stop } from "../../stop";
10
8
  // Constants
11
9
  let MASS_MAX = "0";
12
10
  let MASS_AVERAGE = "0";
@@ -125,7 +123,7 @@ export class Progressor extends Device {
125
123
  MASS_AVERAGE = (MASS_TOTAL_SUM / DATAPOINT_COUNT).toFixed(1);
126
124
  // Check if device is being used
127
125
  checkActivity(weight);
128
- notifyCallback({
126
+ this.notifyCallback({
129
127
  massMax: MASS_MAX,
130
128
  massAverage: MASS_AVERAGE,
131
129
  massTotal: Math.max(-1000, weight).toFixed(1),
@@ -157,6 +155,16 @@ export class Progressor extends Device {
157
155
  }
158
156
  }
159
157
  };
158
+ /**
159
+ * Stops the data stream on the specified device.
160
+ * @returns {Promise<void>} A promise that resolves when the stream is stopped.
161
+ */
162
+ stop = async () => {
163
+ if (this.isConnected()) {
164
+ // Stop stream of device
165
+ await write(this, "progressor", "tx", ProgressorCommands.STOP_WEIGHT_MEAS, 0);
166
+ }
167
+ };
160
168
  /**
161
169
  * Starts streaming data from the specified device.
162
170
  * @param {number} [duration=0] - The duration of the stream in milliseconds. If set to 0, stream will continue indefinitely.
@@ -170,7 +178,7 @@ export class Progressor extends Device {
170
178
  await write(this, "progressor", "tx", ProgressorCommands.START_WEIGHT_MEAS, duration);
171
179
  // Stop streaming if duration is set
172
180
  if (duration !== 0) {
173
- await stop(this);
181
+ await this.stop();
174
182
  }
175
183
  }
176
184
  };
@@ -1,7 +1,6 @@
1
1
  import { Device } from "../device.model";
2
2
  import { applyTare } from "../../tare";
3
3
  import { checkActivity } from "../../is-active";
4
- import { notifyCallback } from "../../notify";
5
4
  // Constants
6
5
  let MASS_MAX = "0";
7
6
  let MASS_AVERAGE = "0";
@@ -45,13 +44,13 @@ export class WHC06 extends Device {
45
44
  if (!this.bluetooth.gatt) {
46
45
  throw new Error("GATT is not available on this device");
47
46
  }
47
+ // Device has no services / characteristics
48
+ onSuccess();
48
49
  // WH-C06
49
50
  const MANUFACTURER_ID = 256; // 0x0100
50
51
  this.bluetooth.addEventListener("advertisementreceived", (event) => {
51
52
  const data = event.manufacturerData.get(MANUFACTURER_ID);
52
53
  if (data) {
53
- // Device has no services / characteristics
54
- onSuccess();
55
54
  // Handle recieved data
56
55
  const weight = (data.getUint8(WEIGHT_OFFSET) << 8) | data.getUint8(WEIGHT_OFFSET + 1);
57
56
  // const stable = (data.getUint8(STABLE_OFFSET) & 0xf0) >> 4
@@ -70,7 +69,7 @@ export class WHC06 extends Device {
70
69
  // Check if device is being used
71
70
  checkActivity(numericData);
72
71
  // Notify with weight data
73
- notifyCallback({
72
+ this.notifyCallback({
74
73
  massMax: MASS_MAX,
75
74
  massAverage: MASS_AVERAGE,
76
75
  massTotal: Math.max(-1000, numericData).toFixed(1),
@@ -1,45 +1,61 @@
1
1
  import { BaseModel } from "./../models/base.model";
2
2
  import type { IDevice, Service } from "../interfaces/device.interface";
3
+ import type { massObject } from "./../types/notify";
4
+ /** Define the type for the callback function */
5
+ type NotifyCallback = (data: massObject) => void;
3
6
  export declare class Device extends BaseModel implements IDevice {
4
7
  filters: BluetoothLEScanFilter[];
5
8
  services: Service[];
6
9
  bluetooth?: BluetoothDevice | undefined;
7
10
  constructor(device: Partial<IDevice>);
8
11
  /**
9
- * Handles the 'disconnected' event.
10
- * @param {Event} event - The 'disconnected' event.
11
- */
12
- onDisconnected: (event: Event) => void;
13
- /**
14
- * Handles notifications received from a characteristic.
15
- * @param {Event} event - The notification event.
12
+ * Connects to a Bluetooth device.
13
+ * @param {Function} [onSuccess] - Optional callback function to execute on successful connection. Default logs success.
14
+ * @param {Function} [onError] - Optional callback function to execute on error. Default logs the error.
16
15
  */
17
- handleNotifications: (event: Event) => void;
16
+ connect: (onSuccess?: () => void, onError?: (error: Error) => void) => Promise<void>;
18
17
  /**
19
- * Handles the 'connected' event.
20
- * @param {Function} onSuccess - Callback function to execute on successful connection.
18
+ * Disconnects the device if it is currently connected.
19
+ * - Checks if the device is connected via it's GATT server.
20
+ * - If the device is connected, it attempts to gracefully disconnect.
21
21
  */
22
- onConnected: (onSuccess: () => void) => Promise<void>;
22
+ disconnect: () => void;
23
23
  /**
24
24
  * Returns UUIDs of all services associated with the device.
25
25
  * @returns {string[]} Array of service UUIDs.
26
26
  */
27
27
  getAllServiceUUIDs: () => string[];
28
28
  /**
29
- * Connects to a Bluetooth device.
30
- * @param {Function} [onSuccess] - Optional callback function to execute on successful connection. Default logs success.
31
- * @param {Function} [onError] - Optional callback function to execute on error. Default logs the error.
29
+ * Handles notifications received from a characteristic.
30
+ * @param {Event} event - The notification event.
32
31
  */
33
- connect: (onSuccess?: () => void, onError?: (error: Error) => void) => Promise<void>;
32
+ handleNotifications: (event: Event) => void;
34
33
  /**
35
34
  * Checks if a Bluetooth device is connected.
36
35
  * @returns {boolean} A boolean indicating whether the device is connected.
37
36
  */
38
37
  isConnected: () => boolean;
39
38
  /**
40
- * Disconnects the device if it is currently connected.
41
- * - Checks if the device is connected via it's GATT server.
42
- * - If the device is connected, it attempts to gracefully disconnect.
39
+ * Sets the callback function to be called when notifications are received.
40
+ * @param {NotifyCallback} callback - The callback function to be set.
41
+ * @returns {void}
43
42
  */
44
- disconnect: () => void;
43
+ notify: (callback: NotifyCallback) => void;
44
+ /**
45
+ * Defines the type for the callback function.
46
+ * @callback NotifyCallback
47
+ * @param {massObject} data - The data passed to the callback.
48
+ */
49
+ notifyCallback: NotifyCallback;
50
+ /**
51
+ * Handles the 'connected' event.
52
+ * @param {Function} onSuccess - Callback function to execute on successful connection.
53
+ */
54
+ onConnected: (onSuccess: () => void) => Promise<void>;
55
+ /**
56
+ * Handles the 'disconnected' event.
57
+ * @param {Event} event - The 'disconnected' event.
58
+ */
59
+ onDisconnected: (event: Event) => void;
45
60
  }
61
+ export {};
@@ -11,13 +11,51 @@ export class Device extends BaseModel {
11
11
  this.bluetooth = device.bluetooth;
12
12
  }
13
13
  /**
14
- * Handles the 'disconnected' event.
15
- * @param {Event} event - The 'disconnected' event.
14
+ * Connects to a Bluetooth device.
15
+ * @param {Function} [onSuccess] - Optional callback function to execute on successful connection. Default logs success.
16
+ * @param {Function} [onError] - Optional callback function to execute on error. Default logs the error.
16
17
  */
17
- onDisconnected = (event) => {
18
- this.bluetooth = undefined;
19
- const device = event.target;
20
- throw new Error(`Device ${device.name} is disconnected.`);
18
+ connect = async (onSuccess = () => console.log("Connected successfully"), onError = (error) => console.error(error)) => {
19
+ try {
20
+ // Request device and set up connection
21
+ const deviceServices = this.getAllServiceUUIDs();
22
+ this.bluetooth = await navigator.bluetooth.requestDevice({
23
+ filters: this.filters,
24
+ optionalServices: deviceServices,
25
+ });
26
+ if (!this.bluetooth.gatt) {
27
+ throw new Error("GATT is not available on this device");
28
+ }
29
+ this.bluetooth.addEventListener("gattserverdisconnected", (event) => {
30
+ this.onDisconnected(event);
31
+ });
32
+ server = await this.bluetooth.gatt.connect();
33
+ if (server.connected) {
34
+ await this.onConnected(onSuccess);
35
+ }
36
+ }
37
+ catch (error) {
38
+ onError(error);
39
+ }
40
+ };
41
+ /**
42
+ * Disconnects the device if it is currently connected.
43
+ * - Checks if the device is connected via it's GATT server.
44
+ * - If the device is connected, it attempts to gracefully disconnect.
45
+ */
46
+ disconnect = () => {
47
+ // Verify that the device is connected using the provided helper function
48
+ if (this.isConnected()) {
49
+ // Safely attempt to disconnect the device's GATT server, if available
50
+ this.bluetooth?.gatt?.disconnect();
51
+ }
52
+ };
53
+ /**
54
+ * Returns UUIDs of all services associated with the device.
55
+ * @returns {string[]} Array of service UUIDs.
56
+ */
57
+ getAllServiceUUIDs = () => {
58
+ return this.services.map((service) => service.uuid);
21
59
  };
22
60
  /**
23
61
  * Handles notifications received from a characteristic.
@@ -38,6 +76,32 @@ export class Device extends BaseModel {
38
76
  }
39
77
  }
40
78
  };
79
+ /**
80
+ * Checks if a Bluetooth device is connected.
81
+ * @returns {boolean} A boolean indicating whether the device is connected.
82
+ */
83
+ isConnected = () => {
84
+ // Check if the device is defined and available
85
+ if (!this?.bluetooth) {
86
+ return false;
87
+ }
88
+ // Check if the device is connected
89
+ return !!this.bluetooth.gatt?.connected;
90
+ };
91
+ /**
92
+ * Sets the callback function to be called when notifications are received.
93
+ * @param {NotifyCallback} callback - The callback function to be set.
94
+ * @returns {void}
95
+ */
96
+ notify = (callback) => {
97
+ this.notifyCallback = callback;
98
+ };
99
+ /**
100
+ * Defines the type for the callback function.
101
+ * @callback NotifyCallback
102
+ * @param {massObject} data - The data passed to the callback.
103
+ */
104
+ notifyCallback = (data) => console.log(data);
41
105
  /**
42
106
  * Handles the 'connected' event.
43
107
  * @param {Function} onSuccess - Callback function to execute on successful connection.
@@ -79,62 +143,12 @@ export class Device extends BaseModel {
79
143
  onSuccess();
80
144
  };
81
145
  /**
82
- * Returns UUIDs of all services associated with the device.
83
- * @returns {string[]} Array of service UUIDs.
84
- */
85
- getAllServiceUUIDs = () => {
86
- return this.services.map((service) => service.uuid);
87
- };
88
- /**
89
- * Connects to a Bluetooth device.
90
- * @param {Function} [onSuccess] - Optional callback function to execute on successful connection. Default logs success.
91
- * @param {Function} [onError] - Optional callback function to execute on error. Default logs the error.
92
- */
93
- connect = async (onSuccess = () => console.log("Connected successfully"), onError = (error) => console.error(error)) => {
94
- try {
95
- // Request device and set up connection
96
- const deviceServices = this.getAllServiceUUIDs();
97
- this.bluetooth = await navigator.bluetooth.requestDevice({
98
- filters: this.filters,
99
- optionalServices: deviceServices,
100
- });
101
- if (!this.bluetooth.gatt) {
102
- throw new Error("GATT is not available on this device");
103
- }
104
- this.bluetooth.addEventListener("gattserverdisconnected", (event) => {
105
- this.onDisconnected(event);
106
- });
107
- server = await this.bluetooth.gatt.connect();
108
- if (server.connected) {
109
- await this.onConnected(onSuccess);
110
- }
111
- }
112
- catch (error) {
113
- onError(error);
114
- }
115
- };
116
- /**
117
- * Checks if a Bluetooth device is connected.
118
- * @returns {boolean} A boolean indicating whether the device is connected.
119
- */
120
- isConnected = () => {
121
- // Check if the device is defined and available
122
- if (!this?.bluetooth) {
123
- return false;
124
- }
125
- // Check if the device is connected
126
- return !!this.bluetooth.gatt?.connected;
127
- };
128
- /**
129
- * Disconnects the device if it is currently connected.
130
- * - Checks if the device is connected via it's GATT server.
131
- * - If the device is connected, it attempts to gracefully disconnect.
146
+ * Handles the 'disconnected' event.
147
+ * @param {Event} event - The 'disconnected' event.
132
148
  */
133
- disconnect = () => {
134
- // Verify that the device is connected using the provided helper function
135
- if (this.isConnected()) {
136
- // Safely attempt to disconnect the device's GATT server, if available
137
- this.bluetooth?.gatt?.disconnect();
138
- }
149
+ onDisconnected = (event) => {
150
+ this.bluetooth = undefined;
151
+ const device = event.target;
152
+ throw new Error(`Device ${device.name} is disconnected.`);
139
153
  };
140
154
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hangtime/grip-connect",
3
- "version": "0.5.0",
3
+ "version": "0.5.1",
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
@@ -17,8 +17,4 @@ export { download } from "./download"
17
17
 
18
18
  export { active, isActive } from "./is-active"
19
19
 
20
- export { notify } from "./notify"
21
-
22
- export { stop } from "./stop"
23
-
24
20
  export { tare } from "./tare"
@@ -1,5 +1,19 @@
1
+ /**
2
+ * Represents the base properties for an entity.
3
+ */
1
4
  export interface IBase {
5
+ /**
6
+ * Unique identifier for the entity (optional).
7
+ */
2
8
  id?: string
9
+
10
+ /**
11
+ * The date and time when the entity was created (optional).
12
+ */
3
13
  createdAt?: Date
14
+
15
+ /**
16
+ * The date and time when the entity was last updated (optional).
17
+ */
4
18
  updatedAt?: Date
5
19
  }
@@ -1,4 +1,6 @@
1
1
  import type { IDevice } from "../device.interface"
2
-
2
+ /**
3
+ * Interface representing the Climbro device, extending the base Device interface.
4
+ */
3
5
  // eslint-disable-next-line @typescript-eslint/no-empty-object-type
4
6
  export interface IClimbro extends IDevice {}
@@ -1,4 +1,61 @@
1
1
  import type { IDevice } from "../device.interface"
2
2
 
3
- // eslint-disable-next-line @typescript-eslint/no-empty-object-type
4
- export interface IEntralpi extends IDevice {}
3
+ /**
4
+ * Interface representing the Entralpi device, extending the base Device interface.
5
+ */
6
+ export interface IEntralpi extends IDevice {
7
+ /**
8
+ * Retrieves battery or voltage information from the device.
9
+ * @returns {Promise<string | undefined>} A Promise that resolves with the battery or voltage information.
10
+ */
11
+ battery(): Promise<string | undefined>
12
+
13
+ /**
14
+ * Retrieves IEEE 11073-20601 Regulatory Certification from the device.
15
+ * @returns {Promise<string | undefined>} A Promise that resolves with the firmware version.
16
+ */
17
+ certification(): Promise<string | undefined>
18
+
19
+ /**
20
+ * Retrieves firmware version from the device.
21
+ * @returns {Promise<string | undefined>} A Promise that resolves with the firmware version.
22
+ */
23
+ firmware(): Promise<string | undefined>
24
+
25
+ /**
26
+ * Retrieves hardware version from the device.
27
+ * @returns {Promise<string | undefined>} A Promise that resolves with the hardware version.
28
+ */
29
+ hardware(): Promise<string | undefined>
30
+
31
+ /**
32
+ * Retrieves manufacturer information from the device.
33
+ * @returns {Promise<string | undefined>} A Promise that resolves with the manufacturer information.
34
+ */
35
+ manufacturer(): Promise<string | undefined>
36
+
37
+ /**
38
+ * Retrieves model number from the device.
39
+ * @returns {Promise<string | undefined>} A Promise that resolves with the model number.
40
+ */
41
+ model(): Promise<string | undefined>
42
+
43
+ /**
44
+ * Retrieves PnP ID from the device, a set of values that used to create a device ID value that is unique for this device.
45
+ * Included in the characteristic is a Vendor ID Source field, a Vendor ID field, a Product ID field and a Product Version field
46
+ * @returns {Promise<string | undefined>} A Promise that resolves with the PnP ID.
47
+ */
48
+ pnp(): Promise<string | undefined>
49
+
50
+ /**
51
+ * Retrieves software version from the device.
52
+ * @returns {Promise<string | undefined>} A Promise that resolves with the software version.
53
+ */
54
+ software(): Promise<string | undefined>
55
+
56
+ /**
57
+ * Retrieves system id from the device.
58
+ * @returns {Promise<string | undefined>} A Promise that resolves with the system id.
59
+ */
60
+ system(): Promise<string | undefined>
61
+ }