@hangtime/grip-connect 0.4.1 → 0.5.0
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 +58 -45
- package/dist/characteristic.d.ts +1 -1
- package/dist/characteristic.js +1 -0
- package/dist/commands/forceboard.d.ts +6 -0
- package/dist/commands/forceboard.js +5 -0
- package/dist/commands/index.d.ts +3 -2
- package/dist/commands/index.js +3 -2
- package/dist/index.d.ts +1 -13
- package/dist/index.js +3 -23
- package/dist/interfaces/base.interface.d.ts +5 -0
- package/dist/interfaces/device/climbro.interface.d.ts +3 -0
- package/dist/interfaces/device/climbro.interface.js +1 -0
- package/dist/interfaces/device/entralpi.interface.d.ts +3 -0
- package/dist/interfaces/device/entralpi.interface.js +1 -0
- package/dist/interfaces/device/forceboard.interface.d.ts +3 -0
- package/dist/interfaces/device/forceboard.interface.js +1 -0
- package/dist/interfaces/device/kilterboard.interface.d.ts +3 -0
- package/dist/interfaces/device/kilterboard.interface.js +1 -0
- package/dist/interfaces/device/motherboard.interface.d.ts +10 -0
- package/dist/interfaces/device/motherboard.interface.js +1 -0
- package/dist/interfaces/device/mysmartboard.interface.d.ts +3 -0
- package/dist/interfaces/device/mysmartboard.interface.js +1 -0
- package/dist/interfaces/device/progressor.interface.d.ts +3 -0
- package/dist/interfaces/device/progressor.interface.js +1 -0
- package/dist/interfaces/device/wh-c06.interface.d.ts +3 -0
- package/dist/interfaces/device/wh-c06.interface.js +1 -0
- package/dist/interfaces/device.interface.d.ts +76 -0
- package/dist/interfaces/device.interface.js +1 -0
- package/dist/is-active.d.ts +11 -7
- package/dist/is-active.js +20 -10
- package/dist/is-device.d.ts +19 -13
- package/dist/is-device.js +19 -13
- package/dist/models/base.model.d.ts +7 -0
- package/dist/models/base.model.js +10 -0
- package/dist/models/device/climbro.model.d.ts +9 -0
- package/dist/models/device/climbro.model.js +13 -0
- package/dist/models/device/entralpi.model.d.ts +43 -0
- package/dist/models/device/entralpi.model.js +246 -0
- package/dist/models/device/forceboard.model.d.ts +23 -0
- package/dist/models/device/forceboard.model.js +201 -0
- package/dist/models/device/kilterboard.model.d.ts +85 -0
- package/dist/models/device/kilterboard.model.js +213 -0
- package/dist/models/device/motherboard.model.d.ts +76 -0
- package/dist/models/device/motherboard.model.js +391 -0
- package/dist/models/device/mysmartboard.model.d.ts +9 -0
- package/dist/models/device/mysmartboard.model.js +13 -0
- package/dist/models/device/progressor.model.d.ts +32 -0
- package/dist/models/device/progressor.model.js +177 -0
- package/dist/models/device/wh-c06.model.d.ts +15 -0
- package/dist/models/device/wh-c06.model.js +97 -0
- package/dist/models/device.model.d.ts +45 -0
- package/dist/models/device.model.js +140 -0
- package/dist/models/index.d.ts +8 -0
- package/dist/models/index.js +8 -0
- package/dist/notify.js +1 -1
- package/dist/read.d.ts +1 -1
- package/dist/read.js +1 -5
- package/dist/stop.d.ts +1 -1
- package/dist/stop.js +1 -2
- package/dist/write.d.ts +2 -2
- package/dist/write.js +24 -26
- package/package.json +4 -2
- package/src/characteristic.ts +2 -1
- package/src/commands/forceboard.ts +6 -0
- package/src/commands/index.ts +4 -2
- package/src/index.ts +14 -27
- package/src/interfaces/base.interface.ts +5 -0
- package/src/interfaces/device/climbro.interface.ts +4 -0
- package/src/interfaces/device/entralpi.interface.ts +4 -0
- package/src/interfaces/device/forceboard.interface.ts +4 -0
- package/src/interfaces/device/kilterboard.interface.ts +4 -0
- package/src/interfaces/device/motherboard.interface.ts +11 -0
- package/src/interfaces/device/mysmartboard.interface.ts +4 -0
- package/src/interfaces/device/progressor.interface.ts +4 -0
- package/src/interfaces/device/wh-c06.interface.ts +4 -0
- package/src/interfaces/device.interface.ts +85 -0
- package/src/is-active.ts +22 -10
- package/src/is-device.ts +23 -16
- package/src/models/base.model.ts +16 -0
- package/src/models/device/climbro.model.ts +15 -0
- package/src/models/device/entralpi.model.ts +264 -0
- package/src/models/device/forceboard.model.ts +206 -0
- package/src/models/device/kilterboard.model.ts +229 -0
- package/src/models/device/motherboard.model.ts +430 -0
- package/src/models/device/mysmartboard.model.ts +15 -0
- package/src/models/device/progressor.model.ts +184 -0
- package/src/models/device/wh-c06.model.ts +118 -0
- package/src/models/device.model.ts +159 -0
- package/src/models/index.ts +15 -0
- package/src/notify.ts +1 -1
- package/src/read.ts +2 -5
- package/src/stop.ts +2 -3
- package/src/write.ts +25 -27
- package/dist/battery.d.ts +0 -12
- package/dist/battery.js +0 -37
- package/dist/calibration.d.ts +0 -7
- package/dist/calibration.js +0 -21
- package/dist/connect.d.ts +0 -8
- package/dist/connect.js +0 -163
- package/dist/data/entralpi.d.ts +0 -5
- package/dist/data/entralpi.js +0 -33
- package/dist/data/index.d.ts +0 -4
- package/dist/data/index.js +0 -4
- package/dist/data/motherboard.d.ts +0 -10
- package/dist/data/motherboard.js +0 -141
- package/dist/data/progressor.d.ts +0 -9
- package/dist/data/progressor.js +0 -78
- package/dist/data/wh-c06.d.ts +0 -5
- package/dist/data/wh-c06.js +0 -38
- package/dist/devices/climbro.d.ts +0 -6
- package/dist/devices/climbro.js +0 -8
- package/dist/devices/entralpi.d.ts +0 -5
- package/dist/devices/entralpi.js +0 -59
- package/dist/devices/index.d.ts +0 -7
- package/dist/devices/index.js +0 -7
- package/dist/devices/kilterboard.d.ts +0 -10
- package/dist/devices/kilterboard.js +0 -34
- package/dist/devices/motherboard.d.ts +0 -5
- package/dist/devices/motherboard.js +0 -81
- package/dist/devices/mysmartboard.d.ts +0 -6
- package/dist/devices/mysmartboard.js +0 -8
- package/dist/devices/progressor.d.ts +0 -5
- package/dist/devices/progressor.js +0 -37
- package/dist/devices/wh-c06.d.ts +0 -6
- package/dist/devices/wh-c06.js +0 -17
- package/dist/disconnect.d.ts +0 -6
- package/dist/disconnect.js +0 -12
- package/dist/firmware.d.ts +0 -12
- package/dist/firmware.js +0 -37
- package/dist/hardware.d.ts +0 -11
- package/dist/hardware.js +0 -25
- package/dist/is-connected.d.ts +0 -7
- package/dist/is-connected.js +0 -13
- package/dist/led.d.ts +0 -24
- package/dist/led.js +0 -196
- package/dist/manufacturer.d.ts +0 -11
- package/dist/manufacturer.js +0 -25
- package/dist/serial.d.ts +0 -11
- package/dist/serial.js +0 -30
- package/dist/stream.d.ts +0 -8
- package/dist/stream.js +0 -41
- package/dist/text.d.ts +0 -14
- package/dist/text.js +0 -33
- package/dist/types/devices.d.ts +0 -38
- package/src/battery.ts +0 -39
- package/src/calibration.ts +0 -23
- package/src/connect.ts +0 -187
- package/src/data/entralpi.ts +0 -41
- package/src/data/index.ts +0 -7
- package/src/data/motherboard.ts +0 -163
- package/src/data/progressor.ts +0 -79
- package/src/data/wh-c06.ts +0 -47
- package/src/devices/climbro.ts +0 -10
- package/src/devices/entralpi.ts +0 -61
- package/src/devices/index.ts +0 -13
- package/src/devices/kilterboard.ts +0 -37
- package/src/devices/motherboard.ts +0 -83
- package/src/devices/mysmartboard.ts +0 -10
- package/src/devices/progressor.ts +0 -38
- package/src/devices/wh-c06.ts +0 -19
- package/src/disconnect.ts +0 -14
- package/src/firmware.ts +0 -39
- package/src/hardware.ts +0 -27
- package/src/is-connected.ts +0 -15
- package/src/led.ts +0 -211
- package/src/manufacturer.ts +0 -27
- package/src/serial.ts +0 -32
- package/src/stream.ts +0 -43
- package/src/text.ts +0 -35
- package/src/types/devices.ts +0 -39
- /package/dist/{types/devices.js → interfaces/base.interface.js} +0 -0
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
import type { Device } from "../types/devices"
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Represents a Griptonite Motherboard device
|
|
5
|
-
*/
|
|
6
|
-
export const Motherboard: Device = {
|
|
7
|
-
filters: [{ name: "Motherboard" }],
|
|
8
|
-
services: [
|
|
9
|
-
{
|
|
10
|
-
name: "Device Information",
|
|
11
|
-
id: "device",
|
|
12
|
-
uuid: "0000180a-0000-1000-8000-00805f9b34fb",
|
|
13
|
-
characteristics: [
|
|
14
|
-
// {
|
|
15
|
-
// name: 'Serial Number (Blocked)',
|
|
16
|
-
// id: 'serial'
|
|
17
|
-
// uuid: '00002a25-0000-1000-8000-00805f9b34fb'
|
|
18
|
-
// },
|
|
19
|
-
{
|
|
20
|
-
name: "Firmware Revision",
|
|
21
|
-
id: "firmware",
|
|
22
|
-
uuid: "00002a26-0000-1000-8000-00805f9b34fb",
|
|
23
|
-
},
|
|
24
|
-
{
|
|
25
|
-
name: "Hardware Revision",
|
|
26
|
-
id: "hardware",
|
|
27
|
-
uuid: "00002a27-0000-1000-8000-00805f9b34fb",
|
|
28
|
-
},
|
|
29
|
-
{
|
|
30
|
-
name: "Manufacturer Name",
|
|
31
|
-
id: "manufacturer",
|
|
32
|
-
uuid: "00002a29-0000-1000-8000-00805f9b34fb",
|
|
33
|
-
},
|
|
34
|
-
],
|
|
35
|
-
},
|
|
36
|
-
{
|
|
37
|
-
name: "Battery Service",
|
|
38
|
-
id: "battery",
|
|
39
|
-
uuid: "0000180f-0000-1000-8000-00805f9b34fb",
|
|
40
|
-
characteristics: [
|
|
41
|
-
{
|
|
42
|
-
name: "Battery Level",
|
|
43
|
-
id: "level",
|
|
44
|
-
uuid: "00002a19-0000-1000-8000-00805f9b34fb",
|
|
45
|
-
},
|
|
46
|
-
],
|
|
47
|
-
},
|
|
48
|
-
{
|
|
49
|
-
name: "LED Service",
|
|
50
|
-
id: "led",
|
|
51
|
-
uuid: "10ababcd-15e1-28ff-de13-725bea03b127",
|
|
52
|
-
characteristics: [
|
|
53
|
-
{
|
|
54
|
-
name: "Red LED",
|
|
55
|
-
id: "red",
|
|
56
|
-
uuid: "10ab1524-15e1-28ff-de13-725bea03b127",
|
|
57
|
-
},
|
|
58
|
-
{
|
|
59
|
-
name: "Green LED",
|
|
60
|
-
id: "green",
|
|
61
|
-
uuid: "10ab1525-15e1-28ff-de13-725bea03b127",
|
|
62
|
-
},
|
|
63
|
-
],
|
|
64
|
-
},
|
|
65
|
-
{
|
|
66
|
-
name: "UART Nordic Service",
|
|
67
|
-
id: "uart",
|
|
68
|
-
uuid: "6e400001-b5a3-f393-e0a9-e50e24dcca9e",
|
|
69
|
-
characteristics: [
|
|
70
|
-
{
|
|
71
|
-
name: "TX",
|
|
72
|
-
id: "tx",
|
|
73
|
-
uuid: "6e400002-b5a3-f393-e0a9-e50e24dcca9e",
|
|
74
|
-
},
|
|
75
|
-
{
|
|
76
|
-
name: "RX",
|
|
77
|
-
id: "rx",
|
|
78
|
-
uuid: "6e400003-b5a3-f393-e0a9-e50e24dcca9e",
|
|
79
|
-
},
|
|
80
|
-
],
|
|
81
|
-
},
|
|
82
|
-
],
|
|
83
|
-
}
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import type { Device } from "../types/devices"
|
|
2
|
-
/**
|
|
3
|
-
* Represents a Tindeq Progressor device
|
|
4
|
-
*/
|
|
5
|
-
export const Progressor: Device = {
|
|
6
|
-
filters: [{ namePrefix: "Progressor" }],
|
|
7
|
-
services: [
|
|
8
|
-
{
|
|
9
|
-
name: "Progressor Service",
|
|
10
|
-
id: "progressor",
|
|
11
|
-
uuid: "7e4e1701-1ea6-40c9-9dcc-13d34ffead57",
|
|
12
|
-
characteristics: [
|
|
13
|
-
{
|
|
14
|
-
name: "Notify",
|
|
15
|
-
id: "rx",
|
|
16
|
-
uuid: "7e4e1702-1ea6-40c9-9dcc-13d34ffead57",
|
|
17
|
-
},
|
|
18
|
-
{
|
|
19
|
-
name: "Write",
|
|
20
|
-
id: "tx",
|
|
21
|
-
uuid: "7e4e1703-1ea6-40c9-9dcc-13d34ffead57",
|
|
22
|
-
},
|
|
23
|
-
],
|
|
24
|
-
},
|
|
25
|
-
{
|
|
26
|
-
name: "Nordic Device Firmware Update (DFU) Service",
|
|
27
|
-
id: "dfu",
|
|
28
|
-
uuid: "0000fe59-0000-1000-8000-00805f9b34fb",
|
|
29
|
-
characteristics: [
|
|
30
|
-
{
|
|
31
|
-
name: "Buttonless DFU",
|
|
32
|
-
id: "dfu",
|
|
33
|
-
uuid: "8ec90003-f315-4f60-9fb8-838830daea50",
|
|
34
|
-
},
|
|
35
|
-
],
|
|
36
|
-
},
|
|
37
|
-
],
|
|
38
|
-
}
|
package/src/devices/wh-c06.ts
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import type { Device } from "../types/devices"
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Represents a Weiheng - WH-C06 (or MAT Muscle Meter) device
|
|
5
|
-
* Enable 'Experimental Web Platform features' Chrome Flags.
|
|
6
|
-
*/
|
|
7
|
-
export const WHC06: Device = {
|
|
8
|
-
filters: [
|
|
9
|
-
{
|
|
10
|
-
// namePrefix: "IF_B7",
|
|
11
|
-
manufacturerData: [
|
|
12
|
-
{
|
|
13
|
-
companyIdentifier: 0x0100, // 256
|
|
14
|
-
},
|
|
15
|
-
],
|
|
16
|
-
},
|
|
17
|
-
],
|
|
18
|
-
services: [],
|
|
19
|
-
}
|
package/src/disconnect.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import type { Device } from "./types/devices"
|
|
2
|
-
import { isConnected } from "./is-connected"
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Disconnects the device if it is connected.
|
|
6
|
-
* @param {Device} board - The device to disconnect.
|
|
7
|
-
*/
|
|
8
|
-
export const disconnect = (board: Device): void => {
|
|
9
|
-
// Check if the device is connected
|
|
10
|
-
if (isConnected(board)) {
|
|
11
|
-
// Disconnect the device using optional chaining
|
|
12
|
-
board.device?.gatt?.disconnect()
|
|
13
|
-
}
|
|
14
|
-
}
|
package/src/firmware.ts
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import type { Device } from "./types/devices"
|
|
2
|
-
import { write } from "./write"
|
|
3
|
-
import { read } from "./read"
|
|
4
|
-
import { isConnected } from "./is-connected"
|
|
5
|
-
import { ProgressorCommands } from "./commands"
|
|
6
|
-
import { isMotherboard, isProgressor } from "./is-device"
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Retrieves firmware version from the device.
|
|
10
|
-
* - For Motherboard devices, it reads the firmare version.
|
|
11
|
-
* - For Progressor devices, it sends a command to retrieve firware version.
|
|
12
|
-
*
|
|
13
|
-
* @param {Device} board - The device from which to retrieve firmware version.
|
|
14
|
-
* @returns {Promise<string>} A Promise that resolves with the firmware version,
|
|
15
|
-
* or rejects with an error if the device is not connected.
|
|
16
|
-
* @throws {Error} Throws an error if the device is not connected.
|
|
17
|
-
*/
|
|
18
|
-
export const firmware = async (board: Device): Promise<string | undefined> => {
|
|
19
|
-
// Check if the device is connected
|
|
20
|
-
if (isConnected(board)) {
|
|
21
|
-
// If the device is connected and it is a Motherboard device
|
|
22
|
-
if (isMotherboard(board)) {
|
|
23
|
-
// Read firmware version from the Motherboard
|
|
24
|
-
return await read(board, "device", "firmware", 250)
|
|
25
|
-
}
|
|
26
|
-
// If the device is connected and its name starts with "Progressor"
|
|
27
|
-
if (isProgressor(board)) {
|
|
28
|
-
// Write command to get firmware version information to the Progressor
|
|
29
|
-
let response: string | undefined = undefined
|
|
30
|
-
await write(board, "progressor", "tx", ProgressorCommands.GET_FW_VERSION, 250, (data) => {
|
|
31
|
-
response = data
|
|
32
|
-
})
|
|
33
|
-
return response
|
|
34
|
-
}
|
|
35
|
-
// If device is not found, return undefined
|
|
36
|
-
return
|
|
37
|
-
}
|
|
38
|
-
throw new Error("Not connected.")
|
|
39
|
-
}
|
package/src/hardware.ts
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import type { Device } from "./types/devices"
|
|
2
|
-
import { read } from "./read"
|
|
3
|
-
import { isConnected } from "./is-connected"
|
|
4
|
-
import { isMotherboard } from "./is-device"
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Retrieves hardware version from the device.
|
|
8
|
-
* - For Motherboard devices, it reads the hardware version.
|
|
9
|
-
*
|
|
10
|
-
* @param {Device} board - The device from which to retrieve hardware version.
|
|
11
|
-
* @returns {Promise<string>} A Promise that resolves with the hardware version,
|
|
12
|
-
* or rejects with an error if the device is not connected.
|
|
13
|
-
* @throws {Error} Throws an error if the device is not connected.
|
|
14
|
-
*/
|
|
15
|
-
export const hardware = async (board: Device): Promise<string | undefined> => {
|
|
16
|
-
// Check if the device is connected
|
|
17
|
-
if (isConnected(board)) {
|
|
18
|
-
// If the device is connected and it is a Motherboard device
|
|
19
|
-
if (isMotherboard(board)) {
|
|
20
|
-
// Read hardware version from the Motherboard
|
|
21
|
-
return await read(board, "device", "hardware", 250)
|
|
22
|
-
}
|
|
23
|
-
// If device is not found, return undefined
|
|
24
|
-
return
|
|
25
|
-
}
|
|
26
|
-
throw new Error("Not connected.")
|
|
27
|
-
}
|
package/src/is-connected.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import type { Device } from "./types/devices"
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Checks if a Bluetooth device is connected.
|
|
5
|
-
* @param {Device} board - The device to check for connection.
|
|
6
|
-
* @returns {boolean} A boolean indicating whether the device is connected.
|
|
7
|
-
*/
|
|
8
|
-
export const isConnected = (board?: Device): boolean => {
|
|
9
|
-
// Check if the device is defined and available
|
|
10
|
-
if (!board?.device) {
|
|
11
|
-
return false
|
|
12
|
-
}
|
|
13
|
-
// Check if the device is connected
|
|
14
|
-
return !!board.device.gatt?.connected
|
|
15
|
-
}
|
package/src/led.ts
DELETED
|
@@ -1,211 +0,0 @@
|
|
|
1
|
-
import type { Device } from "./types/devices"
|
|
2
|
-
import { write } from "./write"
|
|
3
|
-
import { isConnected } from "./is-connected"
|
|
4
|
-
import { KilterBoardPacket, KilterBoardPlacementRoles } from "./commands/kilterboard"
|
|
5
|
-
import { isKilterboard, isMotherboard } from "./is-device"
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Maximum length of the message body for byte wrapping.
|
|
9
|
-
*/
|
|
10
|
-
const MESSAGE_BODY_MAX_LENGTH = 255
|
|
11
|
-
/**
|
|
12
|
-
* Maximum length of the the bluetooth chunk.
|
|
13
|
-
*/
|
|
14
|
-
const MAX_BLUETOOTH_MESSAGE_SIZE = 20
|
|
15
|
-
/**
|
|
16
|
-
* Calculates the checksum for a byte array by summing up all bytes ot hre packet in a single-byte variable.
|
|
17
|
-
* @param data - The array of bytes to calculate the checksum for.
|
|
18
|
-
* @returns The calculated checksum value.
|
|
19
|
-
*/
|
|
20
|
-
function checksum(data: number[]) {
|
|
21
|
-
let i = 0
|
|
22
|
-
for (const value of data) {
|
|
23
|
-
i = (i + value) & 255
|
|
24
|
-
}
|
|
25
|
-
return ~i & 255
|
|
26
|
-
}
|
|
27
|
-
/**
|
|
28
|
-
* Wraps a byte array with header and footer bytes for transmission.
|
|
29
|
-
* @param data - The array of bytes to wrap.
|
|
30
|
-
* @returns The wrapped byte array.
|
|
31
|
-
*/
|
|
32
|
-
function wrapBytes(data: number[]) {
|
|
33
|
-
if (data.length > MESSAGE_BODY_MAX_LENGTH) {
|
|
34
|
-
return []
|
|
35
|
-
}
|
|
36
|
-
/**
|
|
37
|
-
- 0x1
|
|
38
|
-
- len(packets)
|
|
39
|
-
- checksum(packets)
|
|
40
|
-
- 0x2
|
|
41
|
-
- *packets
|
|
42
|
-
- 0x3
|
|
43
|
-
|
|
44
|
-
First byte is always 1, the second is a number of packets, then checksum, then 2, packets themselves, and finally 3.
|
|
45
|
-
*/
|
|
46
|
-
return [1, data.length, checksum(data), 2, ...data, 3]
|
|
47
|
-
}
|
|
48
|
-
class ClimbPlacement {
|
|
49
|
-
position: number
|
|
50
|
-
role_id: number
|
|
51
|
-
|
|
52
|
-
constructor(position: number, role_id: number) {
|
|
53
|
-
this.position = position
|
|
54
|
-
this.role_id = role_id
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
/**
|
|
58
|
-
* Encodes a position into a byte array.
|
|
59
|
-
* The lowest 8 bits of the position get put in the first byte of the group.
|
|
60
|
-
* The highest 8 bits of the position get put in the second byte of the group.
|
|
61
|
-
* @param position - The position to encode.
|
|
62
|
-
* @returns The encoded byte array representing the position.
|
|
63
|
-
*/
|
|
64
|
-
function encodePosition(position: number) {
|
|
65
|
-
const position1 = position & 255
|
|
66
|
-
const position2 = (position & 65280) >> 8
|
|
67
|
-
|
|
68
|
-
return [position1, position2]
|
|
69
|
-
}
|
|
70
|
-
/**
|
|
71
|
-
* Encodes a color string into a numeric representation.
|
|
72
|
-
* The rgb color, 3 bits for the R and G components, 2 bits for the B component, with the 3 R bits occupying the high end of the byte and the 2 B bits in the low end (hence 3 G bits in the middle).
|
|
73
|
-
* @param color - The color string in hexadecimal format (e.g., 'FFFFFF').
|
|
74
|
-
* @returns The encoded /compressed color value.
|
|
75
|
-
*/
|
|
76
|
-
function encodeColor(color: string) {
|
|
77
|
-
const substring = color.substring(0, 2)
|
|
78
|
-
const substring2 = color.substring(2, 4)
|
|
79
|
-
|
|
80
|
-
const parsedSubstring = parseInt(substring, 16) / 32
|
|
81
|
-
const parsedSubstring2 = parseInt(substring2, 16) / 32
|
|
82
|
-
const parsedResult = (parsedSubstring << 5) | (parsedSubstring2 << 2)
|
|
83
|
-
|
|
84
|
-
const substring3 = color.substring(4, 6)
|
|
85
|
-
const parsedSubstring3 = parseInt(substring3, 16) / 64
|
|
86
|
-
const finalParsedResult = parsedResult | parsedSubstring3
|
|
87
|
-
|
|
88
|
-
return finalParsedResult
|
|
89
|
-
}
|
|
90
|
-
/**
|
|
91
|
-
* Encodes a placement (requires a 16-bit position and a 24-bit rgb color. ) into a byte array.
|
|
92
|
-
* @param position - The position to encode.
|
|
93
|
-
* @param ledColor - The color of the LED in hexadecimal format (e.g., 'FFFFFF').
|
|
94
|
-
* @returns The encoded byte array representing the placement.
|
|
95
|
-
*/
|
|
96
|
-
function encodePlacement(position: number, ledColor: string) {
|
|
97
|
-
return [...encodePosition(position), encodeColor(ledColor)]
|
|
98
|
-
}
|
|
99
|
-
/**
|
|
100
|
-
* Prepares byte arrays for transmission based on a list of climb placements.
|
|
101
|
-
* @param climbPlacementList - The list of climb placements containing position and role ID.
|
|
102
|
-
* @returns The final byte array ready for transmission.
|
|
103
|
-
*/
|
|
104
|
-
export function prepBytesV3(climbPlacementList: ClimbPlacement[]) {
|
|
105
|
-
const resultArray: number[][] = []
|
|
106
|
-
let tempArray: number[] = [KilterBoardPacket.V3_MIDDLE]
|
|
107
|
-
|
|
108
|
-
for (const climbPlacement of climbPlacementList) {
|
|
109
|
-
if (tempArray.length + 3 > MESSAGE_BODY_MAX_LENGTH) {
|
|
110
|
-
resultArray.push(tempArray)
|
|
111
|
-
tempArray = [KilterBoardPacket.V3_MIDDLE]
|
|
112
|
-
}
|
|
113
|
-
const role = KilterBoardPlacementRoles.find((placement) => placement.id === climbPlacement.role_id)
|
|
114
|
-
if (!role) {
|
|
115
|
-
throw new Error(`Role with id ${climbPlacement.role_id} not found in placement_roles`)
|
|
116
|
-
}
|
|
117
|
-
const encodedPlacement = encodePlacement(climbPlacement.position, role.led_color)
|
|
118
|
-
tempArray.push(...encodedPlacement)
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
resultArray.push(tempArray)
|
|
122
|
-
|
|
123
|
-
if (resultArray.length === 1) {
|
|
124
|
-
resultArray[0][0] = KilterBoardPacket.V3_ONLY
|
|
125
|
-
} else if (resultArray.length > 1) {
|
|
126
|
-
resultArray[0][0] = KilterBoardPacket.V3_FIRST
|
|
127
|
-
resultArray[resultArray.length - 1][0] = KilterBoardPacket.V3_LAST
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
const finalResultArray: number[] = []
|
|
131
|
-
for (const currentArray of resultArray) {
|
|
132
|
-
finalResultArray.push(...wrapBytes(currentArray))
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
return finalResultArray
|
|
136
|
-
}
|
|
137
|
-
/**
|
|
138
|
-
* Splits a collection into slices of the specified length.
|
|
139
|
-
* https://github.com/ramda/ramda/blob/master/source/splitEvery.js
|
|
140
|
-
* @param {Number} n
|
|
141
|
-
* @param {Array} list
|
|
142
|
-
* @return {Array}
|
|
143
|
-
*/
|
|
144
|
-
function splitEvery(n: number, list: number[]) {
|
|
145
|
-
if (n <= 0) {
|
|
146
|
-
throw new Error("First argument to splitEvery must be a positive integer")
|
|
147
|
-
}
|
|
148
|
-
const result = []
|
|
149
|
-
let idx = 0
|
|
150
|
-
while (idx < list.length) {
|
|
151
|
-
result.push(list.slice(idx, (idx += n)))
|
|
152
|
-
}
|
|
153
|
-
return result
|
|
154
|
-
}
|
|
155
|
-
/**
|
|
156
|
-
* The kilter board only supports messages of 20 bytes
|
|
157
|
-
* at a time. This method splits a full message into parts
|
|
158
|
-
* of 20 bytes
|
|
159
|
-
*
|
|
160
|
-
* @param buffer
|
|
161
|
-
*/
|
|
162
|
-
const splitMessages = (buffer: number[]) =>
|
|
163
|
-
splitEvery(MAX_BLUETOOTH_MESSAGE_SIZE, buffer).map((arr) => new Uint8Array(arr))
|
|
164
|
-
/**
|
|
165
|
-
* Sends a series of messages to a device.
|
|
166
|
-
*/
|
|
167
|
-
async function writeMessageSeries(board: Device, messages: Uint8Array[]) {
|
|
168
|
-
for (const message of messages) {
|
|
169
|
-
await write(board, "uart", "tx", message)
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
/**
|
|
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
|
-
*
|
|
178
|
-
* @param {Device} board - The device on which to set the LEDs.
|
|
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.
|
|
181
|
-
*/
|
|
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))
|
|
192
|
-
}
|
|
193
|
-
return payload
|
|
194
|
-
}
|
|
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
|
|
209
|
-
}
|
|
210
|
-
return
|
|
211
|
-
}
|
package/src/manufacturer.ts
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import type { Device } from "./types/devices"
|
|
2
|
-
import { read } from "./read"
|
|
3
|
-
import { isConnected } from "./is-connected"
|
|
4
|
-
import { isMotherboard } from "./is-device"
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Retrieves manufacturer information from the device.
|
|
8
|
-
* - For Motherboard devices, it reads the manufacturer information.
|
|
9
|
-
*
|
|
10
|
-
* @param {Device} board - The device from which to retrieve manufacturer information.
|
|
11
|
-
* @returns {Promise<string>} A Promise that resolves with the manufacturer information,
|
|
12
|
-
* or rejects with an error if the device is not connected.
|
|
13
|
-
* @throws {Error} Throws an error if the device is not connected.
|
|
14
|
-
*/
|
|
15
|
-
export const manufacturer = async (board: Device): Promise<string | undefined> => {
|
|
16
|
-
// Check if the device is connected
|
|
17
|
-
if (isConnected(board)) {
|
|
18
|
-
// If the device is connected and it is a Motherboard device
|
|
19
|
-
if (isMotherboard(board)) {
|
|
20
|
-
// Read manufacturer information from the Motherboard
|
|
21
|
-
return await read(board, "device", "manufacturer", 250)
|
|
22
|
-
}
|
|
23
|
-
// If device is not found, return undefined
|
|
24
|
-
return
|
|
25
|
-
}
|
|
26
|
-
throw new Error("Not connected.")
|
|
27
|
-
}
|
package/src/serial.ts
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import type { Device } from "./types/devices"
|
|
2
|
-
import { write } from "./write"
|
|
3
|
-
import { isConnected } from "./is-connected"
|
|
4
|
-
import { MotherboardCommands } from "./commands"
|
|
5
|
-
import { isMotherboard } from "./is-device"
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Retrieves serial number from the device.
|
|
9
|
-
* - For Motherboard devices, it reads the serial number.
|
|
10
|
-
*
|
|
11
|
-
* @param {Device} board - The device from which to retrieve serial number.
|
|
12
|
-
* @returns {Promise<string>} A Promise that resolves with the serial number,
|
|
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
|
-
*/
|
|
16
|
-
export const serial = async (board: Device): Promise<string | undefined> => {
|
|
17
|
-
// Check if the device is connected
|
|
18
|
-
if (isConnected(board)) {
|
|
19
|
-
// If the device is connected and it is a Motherboard device
|
|
20
|
-
if (isMotherboard(board)) {
|
|
21
|
-
// Write serial number command to the Motherboard and read output
|
|
22
|
-
let response: string | undefined = undefined
|
|
23
|
-
await write(board, "uart", "tx", MotherboardCommands.GET_SERIAL, 250, (data) => {
|
|
24
|
-
response = data
|
|
25
|
-
})
|
|
26
|
-
return response
|
|
27
|
-
}
|
|
28
|
-
// If device is not found, return undefined
|
|
29
|
-
return
|
|
30
|
-
}
|
|
31
|
-
throw new Error("Not connected.")
|
|
32
|
-
}
|
package/src/stream.ts
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import type { Device } from "./types/devices"
|
|
2
|
-
import { isConnected } from "./is-connected"
|
|
3
|
-
import { write } from "./write"
|
|
4
|
-
import { stop } from "./stop"
|
|
5
|
-
import { isMotherboard, isProgressor } from "./is-device"
|
|
6
|
-
import { MotherboardCommands, ProgressorCommands } from "./commands"
|
|
7
|
-
import { emptyDownloadPackets } from "./download"
|
|
8
|
-
import { CALIBRATION } from "./data/motherboard"
|
|
9
|
-
import { calibration } from "./calibration"
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Starts streaming data from the specified device.
|
|
13
|
-
* @param {Device} board - The device to stream data from.
|
|
14
|
-
* @param {number} [duration=0] - The duration of the stream in milliseconds. If set to 0, stream will continue indefinitely.
|
|
15
|
-
* @returns {Promise<void>} A promise that resolves when the streaming operation is completed.
|
|
16
|
-
*/
|
|
17
|
-
export const stream = async (board: Device, duration = 0): Promise<void> => {
|
|
18
|
-
if (isConnected(board)) {
|
|
19
|
-
// Reset download packets
|
|
20
|
-
emptyDownloadPackets()
|
|
21
|
-
// Device specific logic
|
|
22
|
-
if (isMotherboard(board)) {
|
|
23
|
-
// Read calibration data if not already available
|
|
24
|
-
if (!CALIBRATION[0].length) {
|
|
25
|
-
await calibration(board)
|
|
26
|
-
}
|
|
27
|
-
// Start streaming data
|
|
28
|
-
await write(board, "uart", "tx", MotherboardCommands.START_WEIGHT_MEAS, duration)
|
|
29
|
-
// Stop streaming if duration is set
|
|
30
|
-
if (duration !== 0) {
|
|
31
|
-
await stop(board)
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
if (isProgressor(board)) {
|
|
35
|
-
// Start streaming data
|
|
36
|
-
await write(board, "progressor", "tx", ProgressorCommands.START_WEIGHT_MEAS, duration)
|
|
37
|
-
// Stop streaming if duration is set
|
|
38
|
-
if (duration !== 0) {
|
|
39
|
-
await stop(board)
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
}
|
package/src/text.ts
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import type { Device } from "./types/devices"
|
|
2
|
-
import { write } from "./write"
|
|
3
|
-
import { isConnected } from "./is-connected"
|
|
4
|
-
import { isMotherboard } from "./is-device"
|
|
5
|
-
import { MotherboardCommands } from "./commands"
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Retrieves the entire 320 bytes of non-volatile memory from the device.
|
|
9
|
-
*
|
|
10
|
-
* The memory consists of 10 segments, each 32 bytes long. If any segment was previously written,
|
|
11
|
-
* the corresponding data will appear in the response. Unused portions of the memory are
|
|
12
|
-
* padded with whitespace.
|
|
13
|
-
*
|
|
14
|
-
* @param {Device} board - The device from which to retrieve text information.
|
|
15
|
-
* @returns {Promise<string>} A Promise that resolves with the 320-byte memory content as a string,
|
|
16
|
-
* which includes both the written data and any unused, whitespace-padded segments.
|
|
17
|
-
* @throws {Error} Throws an error if the device is not connected.
|
|
18
|
-
*/
|
|
19
|
-
export const text = async (board: Device): Promise<string | undefined> => {
|
|
20
|
-
// Check if the device is connected
|
|
21
|
-
if (isConnected(board)) {
|
|
22
|
-
// If the device is connected and it is a Motherboard device
|
|
23
|
-
if (isMotherboard(board)) {
|
|
24
|
-
// Write text information command to the Motherboard and read output
|
|
25
|
-
let response: string | undefined = undefined
|
|
26
|
-
await write(board, "uart", "tx", MotherboardCommands.GET_TEXT, 250, (data) => {
|
|
27
|
-
response = data
|
|
28
|
-
})
|
|
29
|
-
return response
|
|
30
|
-
}
|
|
31
|
-
// If device is not found, return undefined
|
|
32
|
-
return
|
|
33
|
-
}
|
|
34
|
-
throw new Error("Not connected.")
|
|
35
|
-
}
|
package/src/types/devices.ts
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Represents a characteristic of a Bluetooth service.
|
|
3
|
-
*/
|
|
4
|
-
interface Characteristic {
|
|
5
|
-
/** Name of the characteristic */
|
|
6
|
-
name: string
|
|
7
|
-
/** Identifier of the characteristic */
|
|
8
|
-
id: string
|
|
9
|
-
/** UUID of the characteristic */
|
|
10
|
-
uuid: string
|
|
11
|
-
/** Reference to the characteristic object */
|
|
12
|
-
characteristic?: BluetoothRemoteGATTCharacteristic
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Represents a Bluetooth service.
|
|
17
|
-
*/
|
|
18
|
-
interface Service {
|
|
19
|
-
/** Name of the service */
|
|
20
|
-
name: string
|
|
21
|
-
/** Identifier of the service */
|
|
22
|
-
id: string
|
|
23
|
-
/** UUID of the service */
|
|
24
|
-
uuid: string
|
|
25
|
-
/** Array of characteristics belonging to this service */
|
|
26
|
-
characteristics: Characteristic[]
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* Represents a Bluetooth device.
|
|
31
|
-
*/
|
|
32
|
-
export interface Device {
|
|
33
|
-
/** Filters to indentify the device */
|
|
34
|
-
filters: BluetoothLEScanFilter[]
|
|
35
|
-
/** Array of services provided by the device */
|
|
36
|
-
services: Service[]
|
|
37
|
-
/** Reference to the BluetoothDevice object representing this device */
|
|
38
|
-
device?: BluetoothDevice
|
|
39
|
-
}
|
|
File without changes
|