@hangtime/grip-connect 0.4.0 → 0.4.2

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 (53) hide show
  1. package/README.md +11 -5
  2. package/dist/battery.d.ts +0 -2
  3. package/dist/battery.js +7 -10
  4. package/dist/calibration.js +3 -3
  5. package/dist/characteristic.js +1 -0
  6. package/dist/connect.js +4 -3
  7. package/dist/devices/kilterboard.d.ts +4 -0
  8. package/dist/devices/kilterboard.js +5 -1
  9. package/dist/disconnect.d.ts +4 -2
  10. package/dist/disconnect.js +6 -4
  11. package/dist/firmware.d.ts +0 -2
  12. package/dist/firmware.js +7 -10
  13. package/dist/hardware.d.ts +0 -2
  14. package/dist/hardware.js +5 -8
  15. package/dist/index.d.ts +1 -0
  16. package/dist/index.js +2 -0
  17. package/dist/is-active.d.ts +11 -7
  18. package/dist/is-active.js +20 -10
  19. package/dist/is-device.d.ts +31 -0
  20. package/dist/is-device.js +33 -0
  21. package/dist/led.d.ts +7 -3
  22. package/dist/led.js +31 -31
  23. package/dist/manufacturer.d.ts +0 -2
  24. package/dist/manufacturer.js +5 -8
  25. package/dist/read.js +0 -3
  26. package/dist/serial.d.ts +0 -2
  27. package/dist/serial.js +5 -8
  28. package/dist/stop.js +5 -5
  29. package/dist/stream.js +8 -8
  30. package/dist/text.d.ts +0 -2
  31. package/dist/text.js +5 -8
  32. package/dist/write.d.ts +1 -1
  33. package/dist/write.js +24 -25
  34. package/package.json +1 -1
  35. package/src/battery.ts +7 -10
  36. package/src/calibration.ts +3 -3
  37. package/src/characteristic.ts +1 -0
  38. package/src/connect.ts +4 -3
  39. package/src/devices/kilterboard.ts +6 -1
  40. package/src/disconnect.ts +6 -4
  41. package/src/firmware.ts +7 -10
  42. package/src/hardware.ts +5 -8
  43. package/src/index.ts +3 -0
  44. package/src/is-active.ts +22 -10
  45. package/src/is-device.ts +43 -0
  46. package/src/led.ts +34 -31
  47. package/src/manufacturer.ts +5 -8
  48. package/src/read.ts +0 -2
  49. package/src/serial.ts +5 -8
  50. package/src/stop.ts +5 -5
  51. package/src/stream.ts +8 -8
  52. package/src/text.ts +5 -8
  53. package/src/write.ts +24 -25
package/README.md CHANGED
@@ -60,10 +60,14 @@ motherboardButton.addEventListener("click", () => {
60
60
  console.log(data)
61
61
  })
62
62
 
63
- // Check if device is being used
64
- active((value) => {
65
- console.log(value)
66
- })
63
+ // Reactive check if device is active
64
+ active(
65
+ (isActive) => {
66
+ console.log(isActive)
67
+ },
68
+ // Optionally using a weight threshold and duration
69
+ { threshold: 2.5, duration: 1000 },
70
+ )
67
71
 
68
72
  // Read info: battery + firmware
69
73
  const batteryLevel = await battery(Motherboard)
@@ -72,7 +76,8 @@ motherboardButton.addEventListener("click", () => {
72
76
  const firmwareVersion = await firmware(Motherboard)
73
77
  console.log(firmwareVersion)
74
78
 
75
- // trigger LEDs
79
+ // LEDs: "green", "red", "orange", or no argument to turn off
80
+ // await led(Motherboard, "red")
76
81
  // await led(Motherboard)
77
82
 
78
83
  // Start weight streaming (for a minute) remove parameter for a continues stream
@@ -127,6 +132,7 @@ available services with us.
127
132
  | [Hardware](https://stevie-ray.github.io/hangtime-grip-connect/api/hardware.html) | ✅ | | | | | | |
128
133
  | [isActive](https://stevie-ray.github.io/hangtime-grip-connect/api/is-active.html) | ✅ | ✅ | ✅ | ✅ | | | |
129
134
  | [isConnected](https://stevie-ray.github.io/hangtime-grip-connect/api/is-connected.html) | ✅ | ✅ | ✅ | ✅ | ✅ | | |
135
+ | [isDevice](https://stevie-ray.github.io/hangtime-grip-connect/api/is-device.html) | ✅ | ✅ | ✅ | ✅ | ✅ | | |
130
136
  | [Led](https://stevie-ray.github.io/hangtime-grip-connect/api/led.html) | ✅ | | | | ✅ | | |
131
137
  | [Manufacturer](https://stevie-ray.github.io/hangtime-grip-connect/api/manufacturer.html) | ✅ | | | | | | |
132
138
  | [Notify](https://stevie-ray.github.io/hangtime-grip-connect/api/notify.html) | ✅ | ✅ | ✅ | ✅ | | | |
package/dist/battery.d.ts CHANGED
@@ -6,7 +6,5 @@ import type { Device } from "./types/devices";
6
6
  *
7
7
  * @param {Device} board - The device from which to retrieve battery information.
8
8
  * @returns {Promise<string | undefined>} A Promise that resolves with the battery or voltage information,
9
- * or rejects with an error if the device is not connected.
10
- * @throws {Error} Throws an error if the device is not connected.
11
9
  */
12
10
  export declare const battery: (board: Device) => Promise<string | undefined>;
package/dist/battery.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { write } from "./write";
2
2
  import { read } from "./read";
3
3
  import { isConnected } from "./is-connected";
4
- import { Motherboard, Progressor } from "./devices";
4
+ import { isMotherboard, isProgressor } from "./is-device";
5
5
  import { ProgressorCommands } from "./commands";
6
6
  /**
7
7
  * Retrieves battery or voltage information from the device.
@@ -10,28 +10,25 @@ import { ProgressorCommands } from "./commands";
10
10
  *
11
11
  * @param {Device} board - The device from which to retrieve battery information.
12
12
  * @returns {Promise<string | undefined>} A Promise that resolves with the battery or voltage information,
13
- * or rejects with an error if the device is not connected.
14
- * @throws {Error} Throws an error if the device is not connected.
15
13
  */
16
14
  export const battery = async (board) => {
17
15
  // Check if the device is connected
18
16
  if (isConnected(board)) {
19
17
  // If the device is connected and it is a Motherboard device
20
- if (board.filters.some((filter) => filter.name === "Motherboard")) {
18
+ if (isMotherboard(board)) {
21
19
  // Read battery level information from the Motherboard
22
- return await read(Motherboard, "battery", "level", 250);
20
+ return await read(board, "battery", "level", 250);
23
21
  }
24
22
  // If the device is connected and its name starts with "Progressor"
25
- if (board.filters.some((filter) => filter.namePrefix === "Progressor")) {
23
+ if (isProgressor(board)) {
26
24
  // Write command to get battery voltage information to the Progressor
27
25
  let response = undefined;
28
- await write(Progressor, "progressor", "tx", ProgressorCommands.GET_BATT_VLTG, 250, (data) => {
26
+ await write(board, "progressor", "tx", ProgressorCommands.GET_BATT_VLTG, 250, (data) => {
29
27
  response = data;
30
28
  });
31
29
  return response;
32
30
  }
33
- // If device is not found, return undefined
34
- return;
35
31
  }
36
- throw new Error("Not connected.");
32
+ // If device is not found, return undefined
33
+ return undefined;
37
34
  };
@@ -1,6 +1,6 @@
1
1
  import { isConnected } from "./is-connected";
2
2
  import { write } from "./write";
3
- import { Motherboard } from "./devices";
3
+ import { isMotherboard } from "./is-device";
4
4
  import { MotherboardCommands } from "./commands";
5
5
  /**
6
6
  * Writes a command to get calibration data from the device.
@@ -11,9 +11,9 @@ export const calibration = async (board) => {
11
11
  // Check if the device is connected
12
12
  if (isConnected(board)) {
13
13
  // If the device is connected, and it is a Motherboard device
14
- if (board.filters.some((filter) => filter.name === "Motherboard")) {
14
+ if (isMotherboard(board)) {
15
15
  // Write the command to get calibration data to the device
16
- await write(Motherboard, "uart", "tx", MotherboardCommands.GET_CALIBRATION, 2500, (data) => {
16
+ await write(board, "uart", "tx", MotherboardCommands.GET_CALIBRATION, 2500, (data) => {
17
17
  console.log(data);
18
18
  });
19
19
  }
@@ -17,4 +17,5 @@ export const getCharacteristic = (board, serviceId, characteristicId) => {
17
17
  }
18
18
  }
19
19
  // Return undefined if the service or characteristic is not found
20
+ return undefined;
20
21
  };
package/dist/connect.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import { handleEntralpiData, handleMotherboardData, handleProgressorData, handleWHC06Data } from "./data";
2
+ import { isEntralpi, isMotherboard, isProgressor } from "./is-device";
2
3
  let server;
3
4
  const receiveBuffer = [];
4
5
  /**
@@ -21,7 +22,7 @@ const handleNotifications = (event, board) => {
21
22
  const value = characteristic.value;
22
23
  if (value) {
23
24
  // If the device is connected and it is a Motherboard device
24
- if (board.filters.some((filter) => filter.name === "Motherboard")) {
25
+ if (isMotherboard(board)) {
25
26
  for (let i = 0; i < value.byteLength; i++) {
26
27
  receiveBuffer.push(value.getUint8(i));
27
28
  }
@@ -35,7 +36,7 @@ const handleNotifications = (event, board) => {
35
36
  handleMotherboardData(receivedData);
36
37
  }
37
38
  }
38
- else if (board.filters.some((filter) => filter.name === "ENTRALPI")) {
39
+ else if (isEntralpi(board)) {
39
40
  if (value.buffer) {
40
41
  const buffer = value.buffer;
41
42
  const rawData = new DataView(buffer);
@@ -43,7 +44,7 @@ const handleNotifications = (event, board) => {
43
44
  handleEntralpiData(receivedData);
44
45
  }
45
46
  }
46
- else if (board.filters.some((filter) => filter.namePrefix === "Progressor")) {
47
+ else if (isProgressor(board)) {
47
48
  if (value.buffer) {
48
49
  const buffer = value.buffer;
49
50
  const rawData = new DataView(buffer);
@@ -1,4 +1,8 @@
1
1
  import type { Device } from "../types/devices";
2
+ /**
3
+ * Aurora Climbing Advertising service
4
+ */
5
+ export declare const AuroraUUID = "4488b571-7806-4df6-bcff-a2897e4953ff";
2
6
  /**
3
7
  * Represents a Aurora Climbing device
4
8
  * Kilter Board, Tension Board, Decoy Board, Touchstone Board, Grasshopper Board, Aurora Board, So iLL Board
@@ -1,3 +1,7 @@
1
+ /**
2
+ * Aurora Climbing Advertising service
3
+ */
4
+ export const AuroraUUID = "4488b571-7806-4df6-bcff-a2897e4953ff";
1
5
  /**
2
6
  * Represents a Aurora Climbing device
3
7
  * Kilter Board, Tension Board, Decoy Board, Touchstone Board, Grasshopper Board, Aurora Board, So iLL Board
@@ -5,7 +9,7 @@
5
9
  export const KilterBoard = {
6
10
  filters: [
7
11
  {
8
- services: ["4488b571-7806-4df6-bcff-a2897e4953ff"], // Aurora Climbing Advertising service
12
+ services: [AuroraUUID],
9
13
  },
10
14
  ],
11
15
  services: [
@@ -1,6 +1,8 @@
1
1
  import type { Device } from "./types/devices";
2
2
  /**
3
- * Disconnects the device if it is connected.
4
- * @param {Device} board - The device to disconnect.
3
+ * Disconnects the device if it is currently connected.
4
+ * - Checks if the device is connected via its GATT server.
5
+ * - If the device is connected, it attempts to gracefully disconnect.
6
+ * @param {Device} board - The device to be disconnected. The device must have a `gatt` property accessible through `board.device`.
5
7
  */
6
8
  export declare const disconnect: (board: Device) => void;
@@ -1,12 +1,14 @@
1
1
  import { isConnected } from "./is-connected";
2
2
  /**
3
- * Disconnects the device if it is connected.
4
- * @param {Device} board - The device to disconnect.
3
+ * Disconnects the device if it is currently connected.
4
+ * - Checks if the device is connected via its GATT server.
5
+ * - If the device is connected, it attempts to gracefully disconnect.
6
+ * @param {Device} board - The device to be disconnected. The device must have a `gatt` property accessible through `board.device`.
5
7
  */
6
8
  export const disconnect = (board) => {
7
- // Check if the device is connected
9
+ // Verify that the device is connected using the provided helper function
8
10
  if (isConnected(board)) {
9
- // Disconnect the device using optional chaining
11
+ // Safely attempt to disconnect the device's GATT server, if available
10
12
  board.device?.gatt?.disconnect();
11
13
  }
12
14
  };
@@ -6,7 +6,5 @@ import type { Device } from "./types/devices";
6
6
  *
7
7
  * @param {Device} board - The device from which to retrieve firmware version.
8
8
  * @returns {Promise<string>} A Promise that resolves with the firmware version,
9
- * or rejects with an error if the device is not connected.
10
- * @throws {Error} Throws an error if the device is not connected.
11
9
  */
12
10
  export declare const firmware: (board: Device) => Promise<string | undefined>;
package/dist/firmware.js CHANGED
@@ -1,8 +1,8 @@
1
1
  import { write } from "./write";
2
2
  import { read } from "./read";
3
3
  import { isConnected } from "./is-connected";
4
- import { Motherboard, Progressor } from "./devices";
5
4
  import { ProgressorCommands } from "./commands";
5
+ import { isMotherboard, isProgressor } from "./is-device";
6
6
  /**
7
7
  * Retrieves firmware version from the device.
8
8
  * - For Motherboard devices, it reads the firmare version.
@@ -10,28 +10,25 @@ import { ProgressorCommands } from "./commands";
10
10
  *
11
11
  * @param {Device} board - The device from which to retrieve firmware version.
12
12
  * @returns {Promise<string>} A Promise that resolves with the firmware version,
13
- * or rejects with an error if the device is not connected.
14
- * @throws {Error} Throws an error if the device is not connected.
15
13
  */
16
14
  export const firmware = async (board) => {
17
15
  // Check if the device is connected
18
16
  if (isConnected(board)) {
19
17
  // If the device is connected and it is a Motherboard device
20
- if (board.filters.some((filter) => filter.name === "Motherboard")) {
18
+ if (isMotherboard(board)) {
21
19
  // Read firmware version from the Motherboard
22
- return await read(Motherboard, "device", "firmware", 250);
20
+ return await read(board, "device", "firmware", 250);
23
21
  }
24
22
  // If the device is connected and its name starts with "Progressor"
25
- if (board.filters.some((filter) => filter.namePrefix === "Progressor")) {
23
+ if (isProgressor(board)) {
26
24
  // Write command to get firmware version information to the Progressor
27
25
  let response = undefined;
28
- await write(Progressor, "progressor", "tx", ProgressorCommands.GET_FW_VERSION, 250, (data) => {
26
+ await write(board, "progressor", "tx", ProgressorCommands.GET_FW_VERSION, 250, (data) => {
29
27
  response = data;
30
28
  });
31
29
  return response;
32
30
  }
33
- // If device is not found, return undefined
34
- return;
35
31
  }
36
- throw new Error("Not connected.");
32
+ // If device is not found, return undefined
33
+ return undefined;
37
34
  };
@@ -5,7 +5,5 @@ import type { Device } from "./types/devices";
5
5
  *
6
6
  * @param {Device} board - The device from which to retrieve hardware version.
7
7
  * @returns {Promise<string>} A Promise that resolves with the hardware version,
8
- * or rejects with an error if the device is not connected.
9
- * @throws {Error} Throws an error if the device is not connected.
10
8
  */
11
9
  export declare const hardware: (board: Device) => Promise<string | undefined>;
package/dist/hardware.js CHANGED
@@ -1,25 +1,22 @@
1
1
  import { read } from "./read";
2
2
  import { isConnected } from "./is-connected";
3
- import { Motherboard } from "./devices";
3
+ import { isMotherboard } from "./is-device";
4
4
  /**
5
5
  * Retrieves hardware version from the device.
6
6
  * - For Motherboard devices, it reads the hardware version.
7
7
  *
8
8
  * @param {Device} board - The device from which to retrieve hardware version.
9
9
  * @returns {Promise<string>} A Promise that resolves with the hardware version,
10
- * or rejects with an error if the device is not connected.
11
- * @throws {Error} Throws an error if the device is not connected.
12
10
  */
13
11
  export const hardware = async (board) => {
14
12
  // Check if the device is connected
15
13
  if (isConnected(board)) {
16
14
  // If the device is connected and it is a Motherboard device
17
- if (board.filters.some((filter) => filter.name === "Motherboard")) {
15
+ if (isMotherboard(board)) {
18
16
  // Read hardware version from the Motherboard
19
- return await read(Motherboard, "device", "hardware", 250);
17
+ return await read(board, "device", "hardware", 250);
20
18
  }
21
- // If device is not found, return undefined
22
- return;
23
19
  }
24
- throw new Error("Not connected.");
20
+ // If device is not found, return undefined
21
+ return;
25
22
  };
package/dist/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  export { Climbro, Entralpi, KilterBoard, Motherboard, mySmartBoard, WHC06, Progressor } from "./devices/index";
2
+ export { isEntralpi, isKilterboard, isMotherboard, isWHC06, isProgressor } from "./is-device";
2
3
  export { calibration } from "./calibration";
3
4
  export { download } from "./download";
4
5
  export { connect } from "./connect";
package/dist/index.js CHANGED
@@ -1,5 +1,7 @@
1
1
  // Export device types
2
2
  export { Climbro, Entralpi, KilterBoard, Motherboard, mySmartBoard, WHC06, Progressor } from "./devices/index";
3
+ // Export isDevice functions
4
+ export { isEntralpi, isKilterboard, isMotherboard, isWHC06, isProgressor } from "./is-device";
3
5
  // Export calibration function
4
6
  export { calibration } from "./calibration";
5
7
  // Export download function
@@ -9,16 +9,24 @@ type IsActiveCallback = (value: boolean) => void;
9
9
  */
10
10
  export declare let isActive: boolean;
11
11
  /**
12
- * Sets the callback function to be called when the activity status changes.
12
+ * Sets the callback function to be called when the activity status changes,
13
+ * and optionally sets the configuration for threshold and duration.
13
14
  *
14
15
  * This function allows you to specify a callback that will be invoked whenever
15
16
  * the activity status changes, indicating whether the device is currently active.
17
+ * It also allows optionally configuring the threshold and duration used to determine activity.
16
18
  *
17
19
  * @param {IsActiveCallback} callback - The callback function to be set. This function
18
20
  * receives a boolean value indicating the new activity status.
21
+ * @param {object} [options] - Optional configuration object containing the threshold and duration.
22
+ * @param {number} [options.threshold=2.5] - The threshold value for determining activity.
23
+ * @param {number} [options.duration=1000] - The duration (in milliseconds) to monitor the input for activity.
19
24
  * @returns {void}
20
25
  */
21
- export declare const active: (callback: IsActiveCallback) => void;
26
+ export declare const active: (callback: IsActiveCallback, options?: {
27
+ threshold?: number;
28
+ duration?: number;
29
+ }) => void;
22
30
  /**
23
31
  * Checks if a dynamic value is active based on a threshold and duration.
24
32
  *
@@ -27,11 +35,7 @@ export declare const active: (callback: IsActiveCallback) => void;
27
35
  * the previous state, the callback function is called with the updated activity status.
28
36
  *
29
37
  * @param {number} input - The dynamic value to check for activity status.
30
- * @param {number} [threshold=2.5] - The threshold value to determine if the input is considered active.
31
- * Defaults to 2.5 if not provided.
32
- * @param {number} [duration=1000] - The duration (in milliseconds) to monitor the input for activity.
33
- * Defaults to 1000 milliseconds if not provided.
34
38
  * @returns {Promise<void>} A promise that resolves once the activity check is complete.
35
39
  */
36
- export declare const checkActivity: (input: number, threshold?: number, duration?: number) => Promise<void>;
40
+ export declare const checkActivity: (input: number) => Promise<void>;
37
41
  export {};
package/dist/is-active.js CHANGED
@@ -5,17 +5,31 @@ let activeCallback;
5
5
  */
6
6
  export let isActive = false;
7
7
  /**
8
- * Sets the callback function to be called when the activity status changes.
8
+ * Configuration for threshold and duration.
9
+ */
10
+ let config = { threshold: 2.5, duration: 1000 };
11
+ /**
12
+ * Sets the callback function to be called when the activity status changes,
13
+ * and optionally sets the configuration for threshold and duration.
9
14
  *
10
15
  * This function allows you to specify a callback that will be invoked whenever
11
16
  * the activity status changes, indicating whether the device is currently active.
17
+ * It also allows optionally configuring the threshold and duration used to determine activity.
12
18
  *
13
19
  * @param {IsActiveCallback} callback - The callback function to be set. This function
14
20
  * receives a boolean value indicating the new activity status.
21
+ * @param {object} [options] - Optional configuration object containing the threshold and duration.
22
+ * @param {number} [options.threshold=2.5] - The threshold value for determining activity.
23
+ * @param {number} [options.duration=1000] - The duration (in milliseconds) to monitor the input for activity.
15
24
  * @returns {void}
16
25
  */
17
- export const active = (callback) => {
26
+ export const active = (callback, options) => {
18
27
  activeCallback = callback;
28
+ // Update the config values only if provided, otherwise use defaults
29
+ config = {
30
+ threshold: options?.threshold ?? config.threshold, // Use new threshold if provided, else use default
31
+ duration: options?.duration ?? config.duration, // Use new duration if provided, else use default
32
+ };
19
33
  };
20
34
  /**
21
35
  * Checks if a dynamic value is active based on a threshold and duration.
@@ -25,18 +39,14 @@ export const active = (callback) => {
25
39
  * the previous state, the callback function is called with the updated activity status.
26
40
  *
27
41
  * @param {number} input - The dynamic value to check for activity status.
28
- * @param {number} [threshold=2.5] - The threshold value to determine if the input is considered active.
29
- * Defaults to 2.5 if not provided.
30
- * @param {number} [duration=1000] - The duration (in milliseconds) to monitor the input for activity.
31
- * Defaults to 1000 milliseconds if not provided.
32
42
  * @returns {Promise<void>} A promise that resolves once the activity check is complete.
33
43
  */
34
- export const checkActivity = (input, threshold = 2.5, duration = 1000) => {
44
+ export const checkActivity = (input) => {
35
45
  return new Promise((resolve) => {
36
46
  // Check the activity status after the specified duration
37
47
  setTimeout(() => {
38
- // Determine the activity status based on the threshold
39
- const activeNow = input > threshold;
48
+ // Determine the activity status based on the stored threshold in the config
49
+ const activeNow = input > config.threshold;
40
50
  if (isActive !== activeNow) {
41
51
  isActive = activeNow;
42
52
  if (activeCallback) {
@@ -44,6 +54,6 @@ export const checkActivity = (input, threshold = 2.5, duration = 1000) => {
44
54
  }
45
55
  }
46
56
  resolve();
47
- }, duration);
57
+ }, config.duration);
48
58
  });
49
59
  };
@@ -0,0 +1,31 @@
1
+ import type { Device } from "./types/devices";
2
+ /**
3
+ * Checks if the given device is a Motherboard.
4
+ * @param {Device} [board] - The device to check.
5
+ * @returns {boolean} `true` if the device has a filter with the name "Motherboard", otherwise `false`.
6
+ */
7
+ export declare const isMotherboard: (board?: Device) => boolean;
8
+ /**
9
+ * Checks if the given device is a Progressor.
10
+ * @param {Device} [board] - The device to check.
11
+ * @returns {boolean} `true` if the device has a filter with a namePrefix of "Progressor", otherwise `false`.
12
+ */
13
+ export declare const isProgressor: (board?: Device) => boolean;
14
+ /**
15
+ * Checks if the given device is an Entralpi device.
16
+ * @param {Device} [board] - The device to check.
17
+ * @returns {boolean} `true` if the device has a filter with the name "ENTRALPI", otherwise `false`.
18
+ */
19
+ export declare const isEntralpi: (board?: Device) => boolean;
20
+ /**
21
+ * Checks if the given device is a Kilterboard.
22
+ * @param {Device} [board] - The device to check.
23
+ * @returns {boolean} `true` if the device has a service UUID matching the Kilterboard Aurora UUID, otherwise `false`.
24
+ */
25
+ export declare const isKilterboard: (board?: Device) => boolean;
26
+ /**
27
+ * Checks if the given device is a WH-C06.
28
+ * @param {Device} [board] - The device to check.
29
+ * @returns {boolean} `true` if the device has a filter with the company identifier 0x0100, otherwise `false`.
30
+ */
31
+ export declare const isWHC06: (board?: Device) => boolean;
@@ -0,0 +1,33 @@
1
+ import { AuroraUUID } from "./devices/kilterboard";
2
+ /**
3
+ * Checks if the given device is a Motherboard.
4
+ * @param {Device} [board] - The device to check.
5
+ * @returns {boolean} `true` if the device has a filter with the name "Motherboard", otherwise `false`.
6
+ */
7
+ export const isMotherboard = (board) => board?.filters.some((filter) => filter.name === "Motherboard") ?? false;
8
+ /**
9
+ * Checks if the given device is a Progressor.
10
+ * @param {Device} [board] - The device to check.
11
+ * @returns {boolean} `true` if the device has a filter with a namePrefix of "Progressor", otherwise `false`.
12
+ */
13
+ export const isProgressor = (board) => board?.filters.some((filter) => filter.namePrefix === "Progressor") ?? false;
14
+ /**
15
+ * Checks if the given device is an Entralpi device.
16
+ * @param {Device} [board] - The device to check.
17
+ * @returns {boolean} `true` if the device has a filter with the name "ENTRALPI", otherwise `false`.
18
+ */
19
+ export const isEntralpi = (board) => board?.filters.some((filter) => filter.name === "ENTRALPI") ?? false;
20
+ /**
21
+ * Checks if the given device is a Kilterboard.
22
+ * @param {Device} [board] - The device to check.
23
+ * @returns {boolean} `true` if the device has a service UUID matching the Kilterboard Aurora UUID, otherwise `false`.
24
+ */
25
+ export const isKilterboard = (board) => {
26
+ return board?.filters.some((filter) => filter.services?.includes(AuroraUUID)) ?? false;
27
+ };
28
+ /**
29
+ * Checks if the given device is a WH-C06.
30
+ * @param {Device} [board] - The device to check.
31
+ * @returns {boolean} `true` if the device has a filter with the company identifier 0x0100, otherwise `false`.
32
+ */
33
+ export const isWHC06 = (board) => board?.filters.some((filter) => filter.manufacturerData?.some((data) => data.companyIdentifier === 0x0100)) ?? false;
package/dist/led.d.ts CHANGED
@@ -12,9 +12,13 @@ declare class ClimbPlacement {
12
12
  export declare function prepBytesV3(climbPlacementList: ClimbPlacement[]): number[];
13
13
  /**
14
14
  * Sets the LEDs on the specified device.
15
+ *
16
+ * - For Kilter Board: Configures the LEDs based on an array of climb placements. If a configuration is provided, it prepares and sends a payload to the device.
17
+ * - For Motherboard: Sets the LED color based on a single color option. Defaults to turning the LEDs off if no configuration is provided.
18
+ *
15
19
  * @param {Device} board - The device on which to set the LEDs.
16
- * @param {ClimbPlacement[]} [placement] - An optional array of climb placements for LED positioning.
17
- * @returns {Promise<number[] | undefined>} A promise that resolves with the payload array if LED settings were applied, or `undefined` if no action was taken.
20
+ * @param {"green" | "red" | "orange" | ClimbPlacement[]} [config] - Optional color or array of climb placements for the LEDs. Ignored if placements are provided.
21
+ * @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.
18
22
  */
19
- export declare const led: (board: Device, placement?: ClimbPlacement[]) => Promise<number[] | undefined>;
23
+ export declare const led: (board: Device, config?: "green" | "red" | "orange" | ClimbPlacement[]) => Promise<number[] | undefined>;
20
24
  export {};
package/dist/led.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { write } from "./write";
2
2
  import { isConnected } from "./is-connected";
3
- import { KilterBoard, Motherboard } from "./devices";
4
3
  import { KilterBoardPacket, KilterBoardPlacementRoles } from "./commands/kilterboard";
4
+ import { isKilterboard, isMotherboard } from "./is-device";
5
5
  /**
6
6
  * Maximum length of the message body for byte wrapping.
7
7
  */
@@ -152,44 +152,44 @@ const splitMessages = (buffer) => splitEvery(MAX_BLUETOOTH_MESSAGE_SIZE, buffer)
152
152
  /**
153
153
  * Sends a series of messages to a device.
154
154
  */
155
- async function writeMessageSeries(messages) {
155
+ async function writeMessageSeries(board, messages) {
156
156
  for (const message of messages) {
157
- await write(KilterBoard, "uart", "tx", message);
157
+ await write(board, "uart", "tx", message);
158
158
  }
159
159
  }
160
160
  /**
161
161
  * Sets the LEDs on the specified device.
162
+ *
163
+ * - For Kilter Board: Configures the LEDs based on an array of climb placements. If a configuration is provided, it prepares and sends a payload to the device.
164
+ * - For Motherboard: Sets the LED color based on a single color option. Defaults to turning the LEDs off if no configuration is provided.
165
+ *
162
166
  * @param {Device} board - The device on which to set the LEDs.
163
- * @param {ClimbPlacement[]} [placement] - An optional array of climb placements for LED positioning.
164
- * @returns {Promise<number[] | undefined>} A promise that resolves with the payload array if LED settings were applied, or `undefined` if no action was taken.
167
+ * @param {"green" | "red" | "orange" | ClimbPlacement[]} [config] - Optional color or array of climb placements for the LEDs. Ignored if placements are provided.
168
+ * @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.
165
169
  */
166
- export const led = async (board, placement) => {
167
- // Check if the filter contains the Aurora Climbing Advertising service
168
- const AuroraUUID = "4488b571-7806-4df6-bcff-a2897e4953ff";
169
- if (board.filters.some((filter) => filter.services?.includes(AuroraUUID))) {
170
- // The Aurora Boards needs a LED / Postion Placememnet Array
171
- if (placement) {
172
- // Prepares byte arrays for transmission based on a list of climb placements.
173
- const payload = prepBytesV3(placement);
174
- // Sends the payload to the device by splitting it into messages and writing each message.
175
- if (isConnected(board)) {
176
- writeMessageSeries(splitMessages(payload));
177
- }
178
- return payload;
170
+ export const led = async (board, config) => {
171
+ // Handle Kilterboard logic: process placements and send payload if connected
172
+ if (isKilterboard(board) && Array.isArray(config)) {
173
+ // Prepares byte arrays for transmission based on a list of climb placements.
174
+ const payload = prepBytesV3(config);
175
+ if (isConnected(board)) {
176
+ await writeMessageSeries(board, splitMessages(payload));
179
177
  }
178
+ return payload;
180
179
  }
181
- if (board.filters.some((filter) => filter.name === "Motherboard")) {
182
- console.log("Green");
183
- await write(Motherboard, "led", "red", new Uint8Array([0x00]));
184
- await write(Motherboard, "led", "green", new Uint8Array([0x01]), 1250);
185
- console.log("Red");
186
- await write(Motherboard, "led", "red", new Uint8Array([0x01]));
187
- await write(Motherboard, "led", "green", new Uint8Array([0x00]), 1250);
188
- console.log("Orage");
189
- await write(Motherboard, "led", "red", new Uint8Array([0x01]));
190
- await write(Motherboard, "led", "green", new Uint8Array([0x01]), 1250);
191
- console.log("Off");
192
- await write(Motherboard, "led", "red", new Uint8Array([0x00]));
193
- await write(Motherboard, "led", "green", new Uint8Array([0x00]), 1250);
180
+ // Handle Motherboard logic: set color if provided
181
+ if (isMotherboard(board)) {
182
+ const colorMapping = {
183
+ green: [[0x00], [0x01]],
184
+ red: [[0x01], [0x00]],
185
+ orange: [[0x01], [0x01]],
186
+ off: [[0x00], [0x00]],
187
+ };
188
+ // Default to "off" color if config is not set or not found in colorMapping
189
+ const color = typeof config === "string" && colorMapping[config] ? config : "off";
190
+ const [redValue, greenValue] = colorMapping[color];
191
+ await write(board, "led", "red", new Uint8Array(redValue));
192
+ await write(board, "led", "green", new Uint8Array(greenValue), 1250);
194
193
  }
194
+ return undefined;
195
195
  };
@@ -5,7 +5,5 @@ import type { Device } from "./types/devices";
5
5
  *
6
6
  * @param {Device} board - The device from which to retrieve manufacturer information.
7
7
  * @returns {Promise<string>} A Promise that resolves with the manufacturer information,
8
- * or rejects with an error if the device is not connected.
9
- * @throws {Error} Throws an error if the device is not connected.
10
8
  */
11
9
  export declare const manufacturer: (board: Device) => Promise<string | undefined>;