@hangtime/grip-connect 0.4.2 → 0.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +40 -43
- package/dist/characteristic.d.ts +1 -1
- 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 -15
- package/dist/index.js +3 -25
- package/dist/interfaces/base.interface.d.ts +17 -0
- package/dist/interfaces/device/climbro.interface.d.ts +6 -0
- package/dist/interfaces/device/climbro.interface.js +1 -0
- package/dist/interfaces/device/entralpi.interface.d.ts +52 -0
- package/dist/interfaces/device/entralpi.interface.js +1 -0
- package/dist/interfaces/device/forceboard.interface.d.ts +21 -0
- package/dist/interfaces/device/forceboard.interface.js +1 -0
- package/dist/interfaces/device/kilterboard.interface.d.ts +76 -0
- package/dist/interfaces/device/kilterboard.interface.js +1 -0
- package/dist/interfaces/device/motherboard.interface.d.ts +60 -0
- package/dist/interfaces/device/motherboard.interface.js +1 -0
- package/dist/interfaces/device/mysmartboard.interface.d.ts +6 -0
- package/dist/interfaces/device/mysmartboard.interface.js +1 -0
- package/dist/interfaces/device/progressor.interface.d.ts +27 -0
- package/dist/interfaces/device/progressor.interface.js +1 -0
- package/dist/interfaces/device/wh-c06.interface.d.ts +6 -0
- package/dist/interfaces/device/wh-c06.interface.js +1 -0
- package/dist/interfaces/device.interface.d.ts +90 -0
- package/dist/interfaces/device.interface.js +1 -0
- 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 +59 -0
- package/dist/models/device/entralpi.model.js +285 -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 +81 -0
- package/dist/models/device/motherboard.model.js +399 -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 +37 -0
- package/dist/models/device/progressor.model.js +185 -0
- package/dist/models/device/wh-c06.model.d.ts +15 -0
- package/dist/models/device/wh-c06.model.js +96 -0
- package/dist/models/device.model.d.ts +61 -0
- package/dist/models/device.model.js +154 -0
- package/dist/models/index.d.ts +8 -0
- package/dist/models/index.js +8 -0
- package/dist/read.d.ts +1 -1
- package/dist/read.js +1 -2
- package/dist/write.d.ts +1 -1
- package/dist/write.js +1 -2
- package/package.json +4 -2
- package/src/characteristic.ts +1 -1
- package/src/commands/forceboard.ts +6 -0
- package/src/commands/index.ts +4 -2
- package/src/index.ts +13 -30
- package/src/interfaces/base.interface.ts +19 -0
- package/src/interfaces/device/climbro.interface.ts +6 -0
- package/src/interfaces/device/entralpi.interface.ts +61 -0
- package/src/interfaces/device/forceboard.interface.ts +24 -0
- package/src/interfaces/device/kilterboard.interface.ts +85 -0
- package/src/interfaces/device/motherboard.interface.ts +70 -0
- package/src/interfaces/device/mysmartboard.interface.ts +6 -0
- package/src/interfaces/device/progressor.interface.ts +31 -0
- package/src/interfaces/device/wh-c06.interface.ts +6 -0
- package/src/interfaces/device.interface.ts +101 -0
- 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 +306 -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 +439 -0
- package/src/models/device/mysmartboard.model.ts +15 -0
- package/src/models/device/progressor.model.ts +193 -0
- package/src/models/device/wh-c06.model.ts +118 -0
- package/src/models/device.model.ts +177 -0
- package/src/models/index.ts +15 -0
- package/src/read.ts +2 -3
- package/src/write.ts +2 -3
- package/dist/battery.d.ts +0 -10
- package/dist/battery.js +0 -34
- 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 -8
- package/dist/disconnect.js +0 -14
- package/dist/firmware.d.ts +0 -10
- package/dist/firmware.js +0 -34
- package/dist/hardware.d.ts +0 -9
- package/dist/hardware.js +0 -22
- 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 -195
- package/dist/manufacturer.d.ts +0 -9
- package/dist/manufacturer.js +0 -22
- package/dist/notify.d.ts +0 -16
- package/dist/notify.js +0 -14
- package/dist/serial.d.ts +0 -9
- package/dist/serial.js +0 -27
- package/dist/stop.d.ts +0 -7
- package/dist/stop.js +0 -21
- package/dist/stream.d.ts +0 -8
- package/dist/stream.js +0 -41
- package/dist/text.d.ts +0 -12
- package/dist/text.js +0 -30
- package/dist/types/devices.d.ts +0 -38
- package/src/battery.ts +0 -36
- 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 -16
- package/src/firmware.ts +0 -36
- package/src/hardware.ts +0 -24
- package/src/is-connected.ts +0 -15
- package/src/led.ts +0 -210
- package/src/manufacturer.ts +0 -24
- package/src/notify.ts +0 -18
- package/src/serial.ts +0 -29
- package/src/stop.ts +0 -23
- package/src/stream.ts +0 -43
- package/src/text.ts +0 -32
- package/src/types/devices.ts +0 -39
- /package/dist/{types/devices.js → interfaces/base.interface.js} +0 -0
package/src/data/wh-c06.ts
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import { checkActivity } from "./../is-active"
|
|
2
|
-
import { notifyCallback } from "./../notify"
|
|
3
|
-
import { applyTare } from "./../tare"
|
|
4
|
-
|
|
5
|
-
// Constants
|
|
6
|
-
let MASS_MAX = "0"
|
|
7
|
-
let MASS_AVERAGE = "0"
|
|
8
|
-
let MASS_TOTAL_SUM = 0
|
|
9
|
-
let DATAPOINT_COUNT = 0
|
|
10
|
-
const WEIGHT_OFFSET = 10
|
|
11
|
-
// const STABLE_OFFSET = 14
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Handles data received from the WH-C06 device.
|
|
15
|
-
* @param {DataView} data - The received data.
|
|
16
|
-
*/
|
|
17
|
-
export const handleWHC06Data = (data: DataView): void => {
|
|
18
|
-
const weight = (data.getUint8(WEIGHT_OFFSET) << 8) | data.getUint8(WEIGHT_OFFSET + 1)
|
|
19
|
-
// const stable = (data.getUint8(STABLE_OFFSET) & 0xf0) >> 4
|
|
20
|
-
// const unit = data.getUint8(STABLE_OFFSET) & 0x0f
|
|
21
|
-
|
|
22
|
-
let numericData = weight / 100
|
|
23
|
-
|
|
24
|
-
// Tare correction
|
|
25
|
-
numericData -= applyTare(numericData)
|
|
26
|
-
|
|
27
|
-
// Update MASS_MAX
|
|
28
|
-
MASS_MAX = Math.max(Number(MASS_MAX), numericData).toFixed(1)
|
|
29
|
-
|
|
30
|
-
// Update running sum and count
|
|
31
|
-
const currentMassTotal = Math.max(-1000, numericData)
|
|
32
|
-
MASS_TOTAL_SUM += currentMassTotal
|
|
33
|
-
DATAPOINT_COUNT++
|
|
34
|
-
|
|
35
|
-
// Calculate the average dynamically
|
|
36
|
-
MASS_AVERAGE = (MASS_TOTAL_SUM / DATAPOINT_COUNT).toFixed(1)
|
|
37
|
-
|
|
38
|
-
// Check if device is being used
|
|
39
|
-
checkActivity(numericData)
|
|
40
|
-
|
|
41
|
-
// Notify with weight data
|
|
42
|
-
notifyCallback({
|
|
43
|
-
massMax: MASS_MAX,
|
|
44
|
-
massAverage: MASS_AVERAGE,
|
|
45
|
-
massTotal: Math.max(-1000, numericData).toFixed(1),
|
|
46
|
-
})
|
|
47
|
-
}
|
package/src/devices/climbro.ts
DELETED
package/src/devices/entralpi.ts
DELETED
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
import type { Device } from "../types/devices"
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Represents a Entralpi device
|
|
5
|
-
*/
|
|
6
|
-
export const Entralpi: Device = {
|
|
7
|
-
filters: [
|
|
8
|
-
{
|
|
9
|
-
name: "ENTRALPI",
|
|
10
|
-
},
|
|
11
|
-
],
|
|
12
|
-
services: [
|
|
13
|
-
{
|
|
14
|
-
name: "Device Information",
|
|
15
|
-
id: "device",
|
|
16
|
-
uuid: "0000180a-0000-1000-8000-00805f9b34fb",
|
|
17
|
-
characteristics: [],
|
|
18
|
-
},
|
|
19
|
-
{
|
|
20
|
-
name: "Battery Service",
|
|
21
|
-
id: "battery",
|
|
22
|
-
uuid: "0000180f-0000-1000-8000-00805f9b34fb",
|
|
23
|
-
characteristics: [],
|
|
24
|
-
},
|
|
25
|
-
{
|
|
26
|
-
name: "Generic Attribute",
|
|
27
|
-
id: "attribute",
|
|
28
|
-
uuid: "00001801-0000-1000-8000-00805f9b34fb",
|
|
29
|
-
characteristics: [],
|
|
30
|
-
},
|
|
31
|
-
{
|
|
32
|
-
name: "UART ISSC Transparent Service",
|
|
33
|
-
id: "uart",
|
|
34
|
-
uuid: "0000fff0-0000-1000-8000-00805f9b34fb",
|
|
35
|
-
characteristics: [
|
|
36
|
-
{
|
|
37
|
-
name: "TX",
|
|
38
|
-
id: "tx",
|
|
39
|
-
uuid: "0000fff5-0000-1000-8000-00805f9b34fb",
|
|
40
|
-
},
|
|
41
|
-
{
|
|
42
|
-
name: "RX",
|
|
43
|
-
id: "rx",
|
|
44
|
-
uuid: "0000fff4-0000-1000-8000-00805f9b34fb",
|
|
45
|
-
},
|
|
46
|
-
],
|
|
47
|
-
},
|
|
48
|
-
{
|
|
49
|
-
name: "Weight Scale",
|
|
50
|
-
id: "weight",
|
|
51
|
-
uuid: "0000181d-0000-1000-8000-00805f9b34fb",
|
|
52
|
-
characteristics: [],
|
|
53
|
-
},
|
|
54
|
-
{
|
|
55
|
-
name: "Generic Access",
|
|
56
|
-
id: "access",
|
|
57
|
-
uuid: "00001800-0000-1000-8000-00805f9b34fb",
|
|
58
|
-
characteristics: [],
|
|
59
|
-
},
|
|
60
|
-
],
|
|
61
|
-
}
|
package/src/devices/index.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
export { Climbro } from "./climbro"
|
|
2
|
-
|
|
3
|
-
export { Entralpi } from "./entralpi"
|
|
4
|
-
|
|
5
|
-
export { KilterBoard } from "./kilterboard"
|
|
6
|
-
|
|
7
|
-
export { Motherboard } from "./motherboard"
|
|
8
|
-
|
|
9
|
-
export { mySmartBoard } from "./mysmartboard"
|
|
10
|
-
|
|
11
|
-
export { WHC06 } from "./wh-c06"
|
|
12
|
-
|
|
13
|
-
export { Progressor } from "./progressor"
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import type { Device } from "../types/devices"
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Aurora Climbing Advertising service
|
|
5
|
-
*/
|
|
6
|
-
export const AuroraUUID = "4488b571-7806-4df6-bcff-a2897e4953ff"
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Represents a Aurora Climbing device
|
|
10
|
-
* Kilter Board, Tension Board, Decoy Board, Touchstone Board, Grasshopper Board, Aurora Board, So iLL Board
|
|
11
|
-
*/
|
|
12
|
-
export const KilterBoard: Device = {
|
|
13
|
-
filters: [
|
|
14
|
-
{
|
|
15
|
-
services: [AuroraUUID],
|
|
16
|
-
},
|
|
17
|
-
],
|
|
18
|
-
services: [
|
|
19
|
-
{
|
|
20
|
-
name: "UART Nordic Service",
|
|
21
|
-
id: "uart",
|
|
22
|
-
uuid: "6e400001-b5a3-f393-e0a9-e50e24dcca9e",
|
|
23
|
-
characteristics: [
|
|
24
|
-
{
|
|
25
|
-
name: "TX",
|
|
26
|
-
id: "tx",
|
|
27
|
-
uuid: "6e400002-b5a3-f393-e0a9-e50e24dcca9e",
|
|
28
|
-
},
|
|
29
|
-
// {
|
|
30
|
-
// name: "RX",
|
|
31
|
-
// id: "rx",
|
|
32
|
-
// uuid: "6e400003-b5a3-f393-e0a9-e50e24dcca9e",
|
|
33
|
-
// },
|
|
34
|
-
],
|
|
35
|
-
},
|
|
36
|
-
],
|
|
37
|
-
}
|
|
@@ -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,16 +0,0 @@
|
|
|
1
|
-
import type { Device } from "./types/devices"
|
|
2
|
-
import { isConnected } from "./is-connected"
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Disconnects the device if it is currently connected.
|
|
6
|
-
* - Checks if the device is connected via its GATT server.
|
|
7
|
-
* - If the device is connected, it attempts to gracefully disconnect.
|
|
8
|
-
* @param {Device} board - The device to be disconnected. The device must have a `gatt` property accessible through `board.device`.
|
|
9
|
-
*/
|
|
10
|
-
export const disconnect = (board: Device): void => {
|
|
11
|
-
// Verify that the device is connected using the provided helper function
|
|
12
|
-
if (isConnected(board)) {
|
|
13
|
-
// Safely attempt to disconnect the device's GATT server, if available
|
|
14
|
-
board.device?.gatt?.disconnect()
|
|
15
|
-
}
|
|
16
|
-
}
|
package/src/firmware.ts
DELETED
|
@@ -1,36 +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
|
-
*/
|
|
16
|
-
export const firmware = 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
|
-
// Read firmware version from the Motherboard
|
|
22
|
-
return await read(board, "device", "firmware", 250)
|
|
23
|
-
}
|
|
24
|
-
// If the device is connected and its name starts with "Progressor"
|
|
25
|
-
if (isProgressor(board)) {
|
|
26
|
-
// Write command to get firmware version information to the Progressor
|
|
27
|
-
let response: string | undefined = undefined
|
|
28
|
-
await write(board, "progressor", "tx", ProgressorCommands.GET_FW_VERSION, 250, (data) => {
|
|
29
|
-
response = data
|
|
30
|
-
})
|
|
31
|
-
return response
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
// If device is not found, return undefined
|
|
35
|
-
return undefined
|
|
36
|
-
}
|
package/src/hardware.ts
DELETED
|
@@ -1,24 +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
|
-
*/
|
|
13
|
-
export const hardware = async (board: Device): Promise<string | undefined> => {
|
|
14
|
-
// Check if the device is connected
|
|
15
|
-
if (isConnected(board)) {
|
|
16
|
-
// If the device is connected and it is a Motherboard device
|
|
17
|
-
if (isMotherboard(board)) {
|
|
18
|
-
// Read hardware version from the Motherboard
|
|
19
|
-
return await read(board, "device", "hardware", 250)
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
// If device is not found, return undefined
|
|
23
|
-
return
|
|
24
|
-
}
|
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,210 +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
|
-
}
|
|
209
|
-
return undefined
|
|
210
|
-
}
|
package/src/manufacturer.ts
DELETED
|
@@ -1,24 +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
|
-
*/
|
|
13
|
-
export const manufacturer = async (board: Device): Promise<string | undefined> => {
|
|
14
|
-
// Check if the device is connected
|
|
15
|
-
if (isConnected(board)) {
|
|
16
|
-
// If the device is connected and it is a Motherboard device
|
|
17
|
-
if (isMotherboard(board)) {
|
|
18
|
-
// Read manufacturer information from the Motherboard
|
|
19
|
-
return await read(board, "device", "manufacturer", 250)
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
// If device is not found, return undefined
|
|
23
|
-
return undefined
|
|
24
|
-
}
|
package/src/notify.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import type { massObject } from "./types/notify"
|
|
2
|
-
/** Define the type for the callback function */
|
|
3
|
-
type NotifyCallback = (data: massObject) => void
|
|
4
|
-
/**
|
|
5
|
-
* Defines the type for the callback function.
|
|
6
|
-
* @callback NotifyCallback
|
|
7
|
-
* @param {massObject} data - The data passed to the callback.
|
|
8
|
-
*/
|
|
9
|
-
export let notifyCallback: NotifyCallback
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Sets the callback function to be called when notifications are received.
|
|
13
|
-
* @param {NotifyCallback} callback - The callback function to be set.
|
|
14
|
-
* @returns {void}
|
|
15
|
-
*/
|
|
16
|
-
export const notify = (callback: NotifyCallback): void => {
|
|
17
|
-
notifyCallback = callback
|
|
18
|
-
}
|