@hangtime/grip-connect 0.4.0 → 0.4.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.
- package/README.md +3 -1
- package/dist/battery.js +5 -5
- package/dist/calibration.js +3 -3
- package/dist/connect.js +4 -3
- package/dist/devices/kilterboard.d.ts +4 -0
- package/dist/devices/kilterboard.js +5 -1
- package/dist/firmware.js +5 -5
- package/dist/hardware.js +3 -3
- package/dist/index.d.ts +1 -0
- package/dist/index.js +2 -0
- package/dist/is-device.d.ts +31 -0
- package/dist/is-device.js +33 -0
- package/dist/led.d.ts +7 -3
- package/dist/led.js +32 -31
- package/dist/manufacturer.js +3 -3
- package/dist/serial.js +3 -3
- package/dist/stop.js +5 -5
- package/dist/stream.js +8 -8
- package/dist/text.js +3 -3
- package/package.json +1 -1
- package/src/battery.ts +5 -5
- package/src/calibration.ts +3 -3
- package/src/connect.ts +4 -3
- package/src/devices/kilterboard.ts +6 -1
- package/src/firmware.ts +5 -5
- package/src/hardware.ts +3 -3
- package/src/index.ts +3 -0
- package/src/is-device.ts +43 -0
- package/src/led.ts +35 -31
- package/src/manufacturer.ts +3 -3
- package/src/serial.ts +3 -3
- package/src/stop.ts +5 -5
- package/src/stream.ts +8 -8
- package/src/text.ts +3 -3
package/README.md
CHANGED
|
@@ -72,7 +72,8 @@ motherboardButton.addEventListener("click", () => {
|
|
|
72
72
|
const firmwareVersion = await firmware(Motherboard)
|
|
73
73
|
console.log(firmwareVersion)
|
|
74
74
|
|
|
75
|
-
//
|
|
75
|
+
// LEDs: "green", "red", "orange", or no argument to turn off
|
|
76
|
+
// await led(Motherboard, "red")
|
|
76
77
|
// await led(Motherboard)
|
|
77
78
|
|
|
78
79
|
// Start weight streaming (for a minute) remove parameter for a continues stream
|
|
@@ -127,6 +128,7 @@ available services with us.
|
|
|
127
128
|
| [Hardware](https://stevie-ray.github.io/hangtime-grip-connect/api/hardware.html) | ✅ | | | | | | |
|
|
128
129
|
| [isActive](https://stevie-ray.github.io/hangtime-grip-connect/api/is-active.html) | ✅ | ✅ | ✅ | ✅ | | | |
|
|
129
130
|
| [isConnected](https://stevie-ray.github.io/hangtime-grip-connect/api/is-connected.html) | ✅ | ✅ | ✅ | ✅ | ✅ | | |
|
|
131
|
+
| [isDevice](https://stevie-ray.github.io/hangtime-grip-connect/api/is-device.html) | ✅ | ✅ | ✅ | ✅ | ✅ | | |
|
|
130
132
|
| [Led](https://stevie-ray.github.io/hangtime-grip-connect/api/led.html) | ✅ | | | | ✅ | | |
|
|
131
133
|
| [Manufacturer](https://stevie-ray.github.io/hangtime-grip-connect/api/manufacturer.html) | ✅ | | | | | | |
|
|
132
134
|
| [Notify](https://stevie-ray.github.io/hangtime-grip-connect/api/notify.html) | ✅ | ✅ | ✅ | ✅ | | | |
|
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 {
|
|
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.
|
|
@@ -17,15 +17,15 @@ export const battery = async (board) => {
|
|
|
17
17
|
// Check if the device is connected
|
|
18
18
|
if (isConnected(board)) {
|
|
19
19
|
// If the device is connected and it is a Motherboard device
|
|
20
|
-
if (board
|
|
20
|
+
if (isMotherboard(board)) {
|
|
21
21
|
// Read battery level information from the Motherboard
|
|
22
|
-
return await read(
|
|
22
|
+
return await read(board, "battery", "level", 250);
|
|
23
23
|
}
|
|
24
24
|
// If the device is connected and its name starts with "Progressor"
|
|
25
|
-
if (board
|
|
25
|
+
if (isProgressor(board)) {
|
|
26
26
|
// Write command to get battery voltage information to the Progressor
|
|
27
27
|
let response = undefined;
|
|
28
|
-
await write(
|
|
28
|
+
await write(board, "progressor", "tx", ProgressorCommands.GET_BATT_VLTG, 250, (data) => {
|
|
29
29
|
response = data;
|
|
30
30
|
});
|
|
31
31
|
return response;
|
package/dist/calibration.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { isConnected } from "./is-connected";
|
|
2
2
|
import { write } from "./write";
|
|
3
|
-
import {
|
|
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
|
|
14
|
+
if (isMotherboard(board)) {
|
|
15
15
|
// Write the command to get calibration data to the device
|
|
16
|
-
await write(
|
|
16
|
+
await write(board, "uart", "tx", MotherboardCommands.GET_CALIBRATION, 2500, (data) => {
|
|
17
17
|
console.log(data);
|
|
18
18
|
});
|
|
19
19
|
}
|
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
|
|
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
|
|
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
|
|
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: [
|
|
12
|
+
services: [AuroraUUID],
|
|
9
13
|
},
|
|
10
14
|
],
|
|
11
15
|
services: [
|
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.
|
|
@@ -17,15 +17,15 @@ export const firmware = async (board) => {
|
|
|
17
17
|
// Check if the device is connected
|
|
18
18
|
if (isConnected(board)) {
|
|
19
19
|
// If the device is connected and it is a Motherboard device
|
|
20
|
-
if (board
|
|
20
|
+
if (isMotherboard(board)) {
|
|
21
21
|
// Read firmware version from the Motherboard
|
|
22
|
-
return await read(
|
|
22
|
+
return await read(board, "device", "firmware", 250);
|
|
23
23
|
}
|
|
24
24
|
// If the device is connected and its name starts with "Progressor"
|
|
25
|
-
if (board
|
|
25
|
+
if (isProgressor(board)) {
|
|
26
26
|
// Write command to get firmware version information to the Progressor
|
|
27
27
|
let response = undefined;
|
|
28
|
-
await write(
|
|
28
|
+
await write(board, "progressor", "tx", ProgressorCommands.GET_FW_VERSION, 250, (data) => {
|
|
29
29
|
response = data;
|
|
30
30
|
});
|
|
31
31
|
return response;
|
package/dist/hardware.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { read } from "./read";
|
|
2
2
|
import { isConnected } from "./is-connected";
|
|
3
|
-
import {
|
|
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.
|
|
@@ -14,9 +14,9 @@ export const hardware = async (board) => {
|
|
|
14
14
|
// Check if the device is connected
|
|
15
15
|
if (isConnected(board)) {
|
|
16
16
|
// If the device is connected and it is a Motherboard device
|
|
17
|
-
if (board
|
|
17
|
+
if (isMotherboard(board)) {
|
|
18
18
|
// Read hardware version from the Motherboard
|
|
19
|
-
return await read(
|
|
19
|
+
return await read(board, "device", "hardware", 250);
|
|
20
20
|
}
|
|
21
21
|
// If device is not found, return undefined
|
|
22
22
|
return;
|
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
|
|
@@ -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[]} [
|
|
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,
|
|
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,45 @@ 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(
|
|
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[]} [
|
|
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,
|
|
167
|
-
//
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
if (
|
|
172
|
-
|
|
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
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
await write(
|
|
193
|
-
await write(
|
|
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);
|
|
193
|
+
return;
|
|
194
194
|
}
|
|
195
|
+
return;
|
|
195
196
|
};
|
package/dist/manufacturer.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { read } from "./read";
|
|
2
2
|
import { isConnected } from "./is-connected";
|
|
3
|
-
import {
|
|
3
|
+
import { isMotherboard } from "./is-device";
|
|
4
4
|
/**
|
|
5
5
|
* Retrieves manufacturer information from the device.
|
|
6
6
|
* - For Motherboard devices, it reads the manufacturer information.
|
|
@@ -14,9 +14,9 @@ export const manufacturer = async (board) => {
|
|
|
14
14
|
// Check if the device is connected
|
|
15
15
|
if (isConnected(board)) {
|
|
16
16
|
// If the device is connected and it is a Motherboard device
|
|
17
|
-
if (board
|
|
17
|
+
if (isMotherboard(board)) {
|
|
18
18
|
// Read manufacturer information from the Motherboard
|
|
19
|
-
return await read(
|
|
19
|
+
return await read(board, "device", "manufacturer", 250);
|
|
20
20
|
}
|
|
21
21
|
// If device is not found, return undefined
|
|
22
22
|
return;
|
package/dist/serial.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { write } from "./write";
|
|
2
2
|
import { isConnected } from "./is-connected";
|
|
3
|
-
import { Motherboard } from "./devices";
|
|
4
3
|
import { MotherboardCommands } from "./commands";
|
|
4
|
+
import { isMotherboard } from "./is-device";
|
|
5
5
|
/**
|
|
6
6
|
* Retrieves serial number from the device.
|
|
7
7
|
* - For Motherboard devices, it reads the serial number.
|
|
@@ -15,10 +15,10 @@ export const serial = async (board) => {
|
|
|
15
15
|
// Check if the device is connected
|
|
16
16
|
if (isConnected(board)) {
|
|
17
17
|
// If the device is connected and it is a Motherboard device
|
|
18
|
-
if (board
|
|
18
|
+
if (isMotherboard(board)) {
|
|
19
19
|
// Write serial number command to the Motherboard and read output
|
|
20
20
|
let response = undefined;
|
|
21
|
-
await write(
|
|
21
|
+
await write(board, "uart", "tx", MotherboardCommands.GET_SERIAL, 250, (data) => {
|
|
22
22
|
response = data;
|
|
23
23
|
});
|
|
24
24
|
return response;
|
package/dist/stop.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { write } from "./write";
|
|
2
2
|
import { isConnected } from "./is-connected";
|
|
3
|
-
import { Motherboard, Progressor } from "./devices";
|
|
4
3
|
import { MotherboardCommands, ProgressorCommands } from "./commands";
|
|
4
|
+
import { isMotherboard, isProgressor } from "./is-device";
|
|
5
5
|
/**
|
|
6
6
|
* Stops the data stream on the specified device.
|
|
7
7
|
* @param {Device} board - The device to stop the stream on.
|
|
@@ -9,13 +9,13 @@ import { MotherboardCommands, ProgressorCommands } from "./commands";
|
|
|
9
9
|
*/
|
|
10
10
|
export const stop = async (board) => {
|
|
11
11
|
if (isConnected(board)) {
|
|
12
|
-
if (board
|
|
12
|
+
if (isMotherboard(board)) {
|
|
13
13
|
// Stop stream on Motherboard
|
|
14
|
-
await write(
|
|
14
|
+
await write(board, "uart", "tx", MotherboardCommands.STOP_WEIGHT_MEAS, 0);
|
|
15
15
|
}
|
|
16
|
-
if (board
|
|
16
|
+
if (isProgressor(board)) {
|
|
17
17
|
// Stop stream on Progressor
|
|
18
|
-
await write(
|
|
18
|
+
await write(board, "progressor", "tx", ProgressorCommands.STOP_WEIGHT_MEAS, 0);
|
|
19
19
|
}
|
|
20
20
|
}
|
|
21
21
|
};
|
package/dist/stream.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { isConnected } from "./is-connected";
|
|
2
2
|
import { write } from "./write";
|
|
3
3
|
import { stop } from "./stop";
|
|
4
|
-
import {
|
|
4
|
+
import { isMotherboard, isProgressor } from "./is-device";
|
|
5
5
|
import { MotherboardCommands, ProgressorCommands } from "./commands";
|
|
6
6
|
import { emptyDownloadPackets } from "./download";
|
|
7
7
|
import { CALIBRATION } from "./data/motherboard";
|
|
@@ -17,24 +17,24 @@ export const stream = async (board, duration = 0) => {
|
|
|
17
17
|
// Reset download packets
|
|
18
18
|
emptyDownloadPackets();
|
|
19
19
|
// Device specific logic
|
|
20
|
-
if (board
|
|
20
|
+
if (isMotherboard(board)) {
|
|
21
21
|
// Read calibration data if not already available
|
|
22
22
|
if (!CALIBRATION[0].length) {
|
|
23
|
-
await calibration(
|
|
23
|
+
await calibration(board);
|
|
24
24
|
}
|
|
25
25
|
// Start streaming data
|
|
26
|
-
await write(
|
|
26
|
+
await write(board, "uart", "tx", MotherboardCommands.START_WEIGHT_MEAS, duration);
|
|
27
27
|
// Stop streaming if duration is set
|
|
28
28
|
if (duration !== 0) {
|
|
29
|
-
await stop(
|
|
29
|
+
await stop(board);
|
|
30
30
|
}
|
|
31
31
|
}
|
|
32
|
-
if (board
|
|
32
|
+
if (isProgressor(board)) {
|
|
33
33
|
// Start streaming data
|
|
34
|
-
await write(
|
|
34
|
+
await write(board, "progressor", "tx", ProgressorCommands.START_WEIGHT_MEAS, duration);
|
|
35
35
|
// Stop streaming if duration is set
|
|
36
36
|
if (duration !== 0) {
|
|
37
|
-
await stop(
|
|
37
|
+
await stop(board);
|
|
38
38
|
}
|
|
39
39
|
}
|
|
40
40
|
}
|
package/dist/text.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { write } from "./write";
|
|
2
2
|
import { isConnected } from "./is-connected";
|
|
3
|
-
import {
|
|
3
|
+
import { isMotherboard } from "./is-device";
|
|
4
4
|
import { MotherboardCommands } from "./commands";
|
|
5
5
|
/**
|
|
6
6
|
* Retrieves the entire 320 bytes of non-volatile memory from the device.
|
|
@@ -18,10 +18,10 @@ export const text = async (board) => {
|
|
|
18
18
|
// Check if the device is connected
|
|
19
19
|
if (isConnected(board)) {
|
|
20
20
|
// If the device is connected and it is a Motherboard device
|
|
21
|
-
if (board
|
|
21
|
+
if (isMotherboard(board)) {
|
|
22
22
|
// Write text information command to the Motherboard and read output
|
|
23
23
|
let response = undefined;
|
|
24
|
-
await write(
|
|
24
|
+
await write(board, "uart", "tx", MotherboardCommands.GET_TEXT, 250, (data) => {
|
|
25
25
|
response = data;
|
|
26
26
|
});
|
|
27
27
|
return response;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hangtime/grip-connect",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.1",
|
|
4
4
|
"description": "A client that can establish connections with various Force-Sensing Hangboards/Plates used by climbers for strength measurement. Examples of such hangboards include the Griptonite Motherboard, Climbro, SmartBoard, Entralpi or Tindeq Progressor",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
package/src/battery.ts
CHANGED
|
@@ -2,7 +2,7 @@ import type { Device } from "./types/devices"
|
|
|
2
2
|
import { write } from "./write"
|
|
3
3
|
import { read } from "./read"
|
|
4
4
|
import { isConnected } from "./is-connected"
|
|
5
|
-
import {
|
|
5
|
+
import { isMotherboard, isProgressor } from "./is-device"
|
|
6
6
|
import { ProgressorCommands } from "./commands"
|
|
7
7
|
|
|
8
8
|
/**
|
|
@@ -19,15 +19,15 @@ export const battery = async (board: Device): Promise<string | undefined> => {
|
|
|
19
19
|
// Check if the device is connected
|
|
20
20
|
if (isConnected(board)) {
|
|
21
21
|
// If the device is connected and it is a Motherboard device
|
|
22
|
-
if (board
|
|
22
|
+
if (isMotherboard(board)) {
|
|
23
23
|
// Read battery level information from the Motherboard
|
|
24
|
-
return await read(
|
|
24
|
+
return await read(board, "battery", "level", 250)
|
|
25
25
|
}
|
|
26
26
|
// If the device is connected and its name starts with "Progressor"
|
|
27
|
-
if (board
|
|
27
|
+
if (isProgressor(board)) {
|
|
28
28
|
// Write command to get battery voltage information to the Progressor
|
|
29
29
|
let response: string | undefined = undefined
|
|
30
|
-
await write(
|
|
30
|
+
await write(board, "progressor", "tx", ProgressorCommands.GET_BATT_VLTG, 250, (data) => {
|
|
31
31
|
response = data
|
|
32
32
|
})
|
|
33
33
|
return response
|
package/src/calibration.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { Device } from "./types/devices"
|
|
2
2
|
import { isConnected } from "./is-connected"
|
|
3
3
|
import { write } from "./write"
|
|
4
|
-
import {
|
|
4
|
+
import { isMotherboard } from "./is-device"
|
|
5
5
|
import { MotherboardCommands } from "./commands"
|
|
6
6
|
|
|
7
7
|
/**
|
|
@@ -13,9 +13,9 @@ export const calibration = async (board: Device): Promise<void> => {
|
|
|
13
13
|
// Check if the device is connected
|
|
14
14
|
if (isConnected(board)) {
|
|
15
15
|
// If the device is connected, and it is a Motherboard device
|
|
16
|
-
if (board
|
|
16
|
+
if (isMotherboard(board)) {
|
|
17
17
|
// Write the command to get calibration data to the device
|
|
18
|
-
await write(
|
|
18
|
+
await write(board, "uart", "tx", MotherboardCommands.GET_CALIBRATION, 2500, (data) => {
|
|
19
19
|
console.log(data)
|
|
20
20
|
})
|
|
21
21
|
}
|
package/src/connect.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { Device } from "./types/devices"
|
|
2
2
|
import { handleEntralpiData, handleMotherboardData, handleProgressorData, handleWHC06Data } from "./data"
|
|
3
|
+
import { isEntralpi, isMotherboard, isProgressor } from "./is-device"
|
|
3
4
|
|
|
4
5
|
let server: BluetoothRemoteGATTServer
|
|
5
6
|
const receiveBuffer: number[] = []
|
|
@@ -25,7 +26,7 @@ const handleNotifications = (event: Event, board: Device): void => {
|
|
|
25
26
|
|
|
26
27
|
if (value) {
|
|
27
28
|
// If the device is connected and it is a Motherboard device
|
|
28
|
-
if (board
|
|
29
|
+
if (isMotherboard(board)) {
|
|
29
30
|
for (let i = 0; i < value.byteLength; i++) {
|
|
30
31
|
receiveBuffer.push(value.getUint8(i))
|
|
31
32
|
}
|
|
@@ -38,14 +39,14 @@ const handleNotifications = (event: Event, board: Device): void => {
|
|
|
38
39
|
const receivedData: string = decoder.decode(new Uint8Array(line))
|
|
39
40
|
handleMotherboardData(receivedData)
|
|
40
41
|
}
|
|
41
|
-
} else if (board
|
|
42
|
+
} else if (isEntralpi(board)) {
|
|
42
43
|
if (value.buffer) {
|
|
43
44
|
const buffer: ArrayBuffer = value.buffer
|
|
44
45
|
const rawData: DataView = new DataView(buffer)
|
|
45
46
|
const receivedData: string = (rawData.getUint16(0) / 100).toFixed(1)
|
|
46
47
|
handleEntralpiData(receivedData)
|
|
47
48
|
}
|
|
48
|
-
} else if (board
|
|
49
|
+
} else if (isProgressor(board)) {
|
|
49
50
|
if (value.buffer) {
|
|
50
51
|
const buffer: ArrayBuffer = value.buffer
|
|
51
52
|
const rawData: DataView = new DataView(buffer)
|
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
import type { Device } from "../types/devices"
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* Aurora Climbing Advertising service
|
|
5
|
+
*/
|
|
6
|
+
export const AuroraUUID = "4488b571-7806-4df6-bcff-a2897e4953ff"
|
|
7
|
+
|
|
3
8
|
/**
|
|
4
9
|
* Represents a Aurora Climbing device
|
|
5
10
|
* Kilter Board, Tension Board, Decoy Board, Touchstone Board, Grasshopper Board, Aurora Board, So iLL Board
|
|
@@ -7,7 +12,7 @@ import type { Device } from "../types/devices"
|
|
|
7
12
|
export const KilterBoard: Device = {
|
|
8
13
|
filters: [
|
|
9
14
|
{
|
|
10
|
-
services: [
|
|
15
|
+
services: [AuroraUUID],
|
|
11
16
|
},
|
|
12
17
|
],
|
|
13
18
|
services: [
|
package/src/firmware.ts
CHANGED
|
@@ -2,8 +2,8 @@ import type { Device } from "./types/devices"
|
|
|
2
2
|
import { write } from "./write"
|
|
3
3
|
import { read } from "./read"
|
|
4
4
|
import { isConnected } from "./is-connected"
|
|
5
|
-
import { Motherboard, Progressor } from "./devices"
|
|
6
5
|
import { ProgressorCommands } from "./commands"
|
|
6
|
+
import { isMotherboard, isProgressor } from "./is-device"
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* Retrieves firmware version from the device.
|
|
@@ -19,15 +19,15 @@ export const firmware = async (board: Device): Promise<string | undefined> => {
|
|
|
19
19
|
// Check if the device is connected
|
|
20
20
|
if (isConnected(board)) {
|
|
21
21
|
// If the device is connected and it is a Motherboard device
|
|
22
|
-
if (board
|
|
22
|
+
if (isMotherboard(board)) {
|
|
23
23
|
// Read firmware version from the Motherboard
|
|
24
|
-
return await read(
|
|
24
|
+
return await read(board, "device", "firmware", 250)
|
|
25
25
|
}
|
|
26
26
|
// If the device is connected and its name starts with "Progressor"
|
|
27
|
-
if (board
|
|
27
|
+
if (isProgressor(board)) {
|
|
28
28
|
// Write command to get firmware version information to the Progressor
|
|
29
29
|
let response: string | undefined = undefined
|
|
30
|
-
await write(
|
|
30
|
+
await write(board, "progressor", "tx", ProgressorCommands.GET_FW_VERSION, 250, (data) => {
|
|
31
31
|
response = data
|
|
32
32
|
})
|
|
33
33
|
return response
|
package/src/hardware.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { Device } from "./types/devices"
|
|
2
2
|
import { read } from "./read"
|
|
3
3
|
import { isConnected } from "./is-connected"
|
|
4
|
-
import {
|
|
4
|
+
import { isMotherboard } from "./is-device"
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Retrieves hardware version from the device.
|
|
@@ -16,9 +16,9 @@ export const hardware = async (board: Device): Promise<string | undefined> => {
|
|
|
16
16
|
// Check if the device is connected
|
|
17
17
|
if (isConnected(board)) {
|
|
18
18
|
// If the device is connected and it is a Motherboard device
|
|
19
|
-
if (board
|
|
19
|
+
if (isMotherboard(board)) {
|
|
20
20
|
// Read hardware version from the Motherboard
|
|
21
|
-
return await read(
|
|
21
|
+
return await read(board, "device", "hardware", 250)
|
|
22
22
|
}
|
|
23
23
|
// If device is not found, return undefined
|
|
24
24
|
return
|
package/src/index.ts
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
// Export device types
|
|
2
2
|
export { Climbro, Entralpi, KilterBoard, Motherboard, mySmartBoard, WHC06, Progressor } from "./devices/index"
|
|
3
3
|
|
|
4
|
+
// Export isDevice functions
|
|
5
|
+
export { isEntralpi, isKilterboard, isMotherboard, isWHC06, isProgressor } from "./is-device"
|
|
6
|
+
|
|
4
7
|
// Export calibration function
|
|
5
8
|
export { calibration } from "./calibration"
|
|
6
9
|
|
package/src/is-device.ts
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { Device } from "./types/devices"
|
|
2
|
+
import { AuroraUUID } from "./devices/kilterboard"
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Checks if the given device is a Motherboard.
|
|
6
|
+
* @param {Device} [board] - The device to check.
|
|
7
|
+
* @returns {boolean} `true` if the device has a filter with the name "Motherboard", otherwise `false`.
|
|
8
|
+
*/
|
|
9
|
+
export const isMotherboard = (board?: Device): boolean =>
|
|
10
|
+
board?.filters.some((filter) => filter.name === "Motherboard") ?? false
|
|
11
|
+
/**
|
|
12
|
+
* Checks if the given device is a Progressor.
|
|
13
|
+
* @param {Device} [board] - The device to check.
|
|
14
|
+
* @returns {boolean} `true` if the device has a filter with a namePrefix of "Progressor", otherwise `false`.
|
|
15
|
+
*/
|
|
16
|
+
export const isProgressor = (board?: Device): boolean =>
|
|
17
|
+
board?.filters.some((filter) => filter.namePrefix === "Progressor") ?? false
|
|
18
|
+
/**
|
|
19
|
+
* Checks if the given device is an Entralpi device.
|
|
20
|
+
* @param {Device} [board] - The device to check.
|
|
21
|
+
* @returns {boolean} `true` if the device has a filter with the name "ENTRALPI", otherwise `false`.
|
|
22
|
+
*/
|
|
23
|
+
export const isEntralpi = (board?: Device): boolean =>
|
|
24
|
+
board?.filters.some((filter) => filter.name === "ENTRALPI") ?? false
|
|
25
|
+
/**
|
|
26
|
+
* Checks if the given device is a Kilterboard.
|
|
27
|
+
* @param {Device} [board] - The device to check.
|
|
28
|
+
* @returns {boolean} `true` if the device has a service UUID matching the Kilterboard Aurora UUID, otherwise `false`.
|
|
29
|
+
*/
|
|
30
|
+
export const isKilterboard = (board?: Device): boolean => {
|
|
31
|
+
return board?.filters.some((filter) => filter.services?.includes(AuroraUUID)) ?? false
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Checks if the given device is a WH-C06.
|
|
35
|
+
* @param {Device} [board] - The device to check.
|
|
36
|
+
* @returns {boolean} `true` if the device has a filter with the company identifier 0x0100, otherwise `false`.
|
|
37
|
+
*/
|
|
38
|
+
export const isWHC06 = (board?: Device): boolean =>
|
|
39
|
+
board?.filters.some((filter) =>
|
|
40
|
+
filter.manufacturerData?.some(
|
|
41
|
+
(data) => data.companyIdentifier === 0x0100, // Company identifier for WH-C06, also used by 'TomTom International BV': https://www.bluetooth.com/specifications/assigned-numbers/
|
|
42
|
+
),
|
|
43
|
+
) ?? false
|
package/src/led.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { Device } from "./types/devices"
|
|
2
2
|
import { write } from "./write"
|
|
3
3
|
import { isConnected } from "./is-connected"
|
|
4
|
-
import { KilterBoard, Motherboard } from "./devices"
|
|
5
4
|
import { KilterBoardPacket, KilterBoardPlacementRoles } from "./commands/kilterboard"
|
|
5
|
+
import { isKilterboard, isMotherboard } from "./is-device"
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* Maximum length of the message body for byte wrapping.
|
|
@@ -164,44 +164,48 @@ const splitMessages = (buffer: number[]) =>
|
|
|
164
164
|
/**
|
|
165
165
|
* Sends a series of messages to a device.
|
|
166
166
|
*/
|
|
167
|
-
async function writeMessageSeries(messages: Uint8Array[]) {
|
|
167
|
+
async function writeMessageSeries(board: Device, messages: Uint8Array[]) {
|
|
168
168
|
for (const message of messages) {
|
|
169
|
-
await write(
|
|
169
|
+
await write(board, "uart", "tx", message)
|
|
170
170
|
}
|
|
171
171
|
}
|
|
172
172
|
/**
|
|
173
173
|
* Sets the LEDs on the specified device.
|
|
174
|
+
*
|
|
175
|
+
* - 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.
|
|
176
|
+
* - For Motherboard: Sets the LED color based on a single color option. Defaults to turning the LEDs off if no configuration is provided.
|
|
177
|
+
*
|
|
174
178
|
* @param {Device} board - The device on which to set the LEDs.
|
|
175
|
-
* @param {ClimbPlacement[]} [
|
|
176
|
-
* @returns {Promise<number[] | undefined>} A promise that resolves with the payload array if LED settings were applied, or `undefined` if no action was taken.
|
|
179
|
+
* @param {"green" | "red" | "orange" | ClimbPlacement[]} [config] - Optional color or array of climb placements for the LEDs. Ignored if placements are provided.
|
|
180
|
+
* @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.
|
|
177
181
|
*/
|
|
178
|
-
export const led = async (
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
writeMessageSeries(splitMessages(payload))
|
|
189
|
-
}
|
|
190
|
-
return payload
|
|
182
|
+
export const led = async (
|
|
183
|
+
board: Device,
|
|
184
|
+
config?: "green" | "red" | "orange" | ClimbPlacement[],
|
|
185
|
+
): Promise<number[] | undefined> => {
|
|
186
|
+
// Handle Kilterboard logic: process placements and send payload if connected
|
|
187
|
+
if (isKilterboard(board) && Array.isArray(config)) {
|
|
188
|
+
// Prepares byte arrays for transmission based on a list of climb placements.
|
|
189
|
+
const payload = prepBytesV3(config)
|
|
190
|
+
if (isConnected(board)) {
|
|
191
|
+
await writeMessageSeries(board, splitMessages(payload))
|
|
191
192
|
}
|
|
193
|
+
return payload
|
|
192
194
|
}
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
await write(
|
|
205
|
-
await write(
|
|
195
|
+
// Handle Motherboard logic: set color if provided
|
|
196
|
+
if (isMotherboard(board)) {
|
|
197
|
+
const colorMapping: Record<string, number[][]> = {
|
|
198
|
+
green: [[0x00], [0x01]],
|
|
199
|
+
red: [[0x01], [0x00]],
|
|
200
|
+
orange: [[0x01], [0x01]],
|
|
201
|
+
off: [[0x00], [0x00]],
|
|
202
|
+
}
|
|
203
|
+
// Default to "off" color if config is not set or not found in colorMapping
|
|
204
|
+
const color = typeof config === "string" && colorMapping[config] ? config : "off"
|
|
205
|
+
const [redValue, greenValue] = colorMapping[color]
|
|
206
|
+
await write(board, "led", "red", new Uint8Array(redValue))
|
|
207
|
+
await write(board, "led", "green", new Uint8Array(greenValue), 1250)
|
|
208
|
+
return
|
|
206
209
|
}
|
|
210
|
+
return
|
|
207
211
|
}
|
package/src/manufacturer.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { Device } from "./types/devices"
|
|
2
2
|
import { read } from "./read"
|
|
3
3
|
import { isConnected } from "./is-connected"
|
|
4
|
-
import {
|
|
4
|
+
import { isMotherboard } from "./is-device"
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Retrieves manufacturer information from the device.
|
|
@@ -16,9 +16,9 @@ export const manufacturer = async (board: Device): Promise<string | undefined> =
|
|
|
16
16
|
// Check if the device is connected
|
|
17
17
|
if (isConnected(board)) {
|
|
18
18
|
// If the device is connected and it is a Motherboard device
|
|
19
|
-
if (board
|
|
19
|
+
if (isMotherboard(board)) {
|
|
20
20
|
// Read manufacturer information from the Motherboard
|
|
21
|
-
return await read(
|
|
21
|
+
return await read(board, "device", "manufacturer", 250)
|
|
22
22
|
}
|
|
23
23
|
// If device is not found, return undefined
|
|
24
24
|
return
|
package/src/serial.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { Device } from "./types/devices"
|
|
2
2
|
import { write } from "./write"
|
|
3
3
|
import { isConnected } from "./is-connected"
|
|
4
|
-
import { Motherboard } from "./devices"
|
|
5
4
|
import { MotherboardCommands } from "./commands"
|
|
5
|
+
import { isMotherboard } from "./is-device"
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* Retrieves serial number from the device.
|
|
@@ -17,10 +17,10 @@ export const serial = async (board: Device): Promise<string | undefined> => {
|
|
|
17
17
|
// Check if the device is connected
|
|
18
18
|
if (isConnected(board)) {
|
|
19
19
|
// If the device is connected and it is a Motherboard device
|
|
20
|
-
if (board
|
|
20
|
+
if (isMotherboard(board)) {
|
|
21
21
|
// Write serial number command to the Motherboard and read output
|
|
22
22
|
let response: string | undefined = undefined
|
|
23
|
-
await write(
|
|
23
|
+
await write(board, "uart", "tx", MotherboardCommands.GET_SERIAL, 250, (data) => {
|
|
24
24
|
response = data
|
|
25
25
|
})
|
|
26
26
|
return response
|
package/src/stop.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { Device } from "./types/devices"
|
|
2
2
|
import { write } from "./write"
|
|
3
3
|
import { isConnected } from "./is-connected"
|
|
4
|
-
import { Motherboard, Progressor } from "./devices"
|
|
5
4
|
import { MotherboardCommands, ProgressorCommands } from "./commands"
|
|
5
|
+
import { isMotherboard, isProgressor } from "./is-device"
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* Stops the data stream on the specified device.
|
|
@@ -11,13 +11,13 @@ import { MotherboardCommands, ProgressorCommands } from "./commands"
|
|
|
11
11
|
*/
|
|
12
12
|
export const stop = async (board: Device): Promise<void> => {
|
|
13
13
|
if (isConnected(board)) {
|
|
14
|
-
if (board
|
|
14
|
+
if (isMotherboard(board)) {
|
|
15
15
|
// Stop stream on Motherboard
|
|
16
|
-
await write(
|
|
16
|
+
await write(board, "uart", "tx", MotherboardCommands.STOP_WEIGHT_MEAS, 0)
|
|
17
17
|
}
|
|
18
|
-
if (board
|
|
18
|
+
if (isProgressor(board)) {
|
|
19
19
|
// Stop stream on Progressor
|
|
20
|
-
await write(
|
|
20
|
+
await write(board, "progressor", "tx", ProgressorCommands.STOP_WEIGHT_MEAS, 0)
|
|
21
21
|
}
|
|
22
22
|
}
|
|
23
23
|
}
|
package/src/stream.ts
CHANGED
|
@@ -2,7 +2,7 @@ import type { Device } from "./types/devices"
|
|
|
2
2
|
import { isConnected } from "./is-connected"
|
|
3
3
|
import { write } from "./write"
|
|
4
4
|
import { stop } from "./stop"
|
|
5
|
-
import {
|
|
5
|
+
import { isMotherboard, isProgressor } from "./is-device"
|
|
6
6
|
import { MotherboardCommands, ProgressorCommands } from "./commands"
|
|
7
7
|
import { emptyDownloadPackets } from "./download"
|
|
8
8
|
import { CALIBRATION } from "./data/motherboard"
|
|
@@ -19,24 +19,24 @@ export const stream = async (board: Device, duration = 0): Promise<void> => {
|
|
|
19
19
|
// Reset download packets
|
|
20
20
|
emptyDownloadPackets()
|
|
21
21
|
// Device specific logic
|
|
22
|
-
if (board
|
|
22
|
+
if (isMotherboard(board)) {
|
|
23
23
|
// Read calibration data if not already available
|
|
24
24
|
if (!CALIBRATION[0].length) {
|
|
25
|
-
await calibration(
|
|
25
|
+
await calibration(board)
|
|
26
26
|
}
|
|
27
27
|
// Start streaming data
|
|
28
|
-
await write(
|
|
28
|
+
await write(board, "uart", "tx", MotherboardCommands.START_WEIGHT_MEAS, duration)
|
|
29
29
|
// Stop streaming if duration is set
|
|
30
30
|
if (duration !== 0) {
|
|
31
|
-
await stop(
|
|
31
|
+
await stop(board)
|
|
32
32
|
}
|
|
33
33
|
}
|
|
34
|
-
if (board
|
|
34
|
+
if (isProgressor(board)) {
|
|
35
35
|
// Start streaming data
|
|
36
|
-
await write(
|
|
36
|
+
await write(board, "progressor", "tx", ProgressorCommands.START_WEIGHT_MEAS, duration)
|
|
37
37
|
// Stop streaming if duration is set
|
|
38
38
|
if (duration !== 0) {
|
|
39
|
-
await stop(
|
|
39
|
+
await stop(board)
|
|
40
40
|
}
|
|
41
41
|
}
|
|
42
42
|
}
|
package/src/text.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { Device } from "./types/devices"
|
|
2
2
|
import { write } from "./write"
|
|
3
3
|
import { isConnected } from "./is-connected"
|
|
4
|
-
import {
|
|
4
|
+
import { isMotherboard } from "./is-device"
|
|
5
5
|
import { MotherboardCommands } from "./commands"
|
|
6
6
|
|
|
7
7
|
/**
|
|
@@ -20,10 +20,10 @@ export const text = async (board: Device): Promise<string | undefined> => {
|
|
|
20
20
|
// Check if the device is connected
|
|
21
21
|
if (isConnected(board)) {
|
|
22
22
|
// If the device is connected and it is a Motherboard device
|
|
23
|
-
if (board
|
|
23
|
+
if (isMotherboard(board)) {
|
|
24
24
|
// Write text information command to the Motherboard and read output
|
|
25
25
|
let response: string | undefined = undefined
|
|
26
|
-
await write(
|
|
26
|
+
await write(board, "uart", "tx", MotherboardCommands.GET_TEXT, 250, (data) => {
|
|
27
27
|
response = data
|
|
28
28
|
})
|
|
29
29
|
return response
|