@hangtime/grip-connect 0.0.11 → 0.1.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 +3 -5
- package/package.json +1 -1
- package/src/calibrate.d.ts +6 -0
- package/src/calibrate.js +15 -0
- package/src/calibrate.ts +16 -0
- package/src/connect.js +6 -2
- package/src/connect.ts +13 -9
- package/src/devices/climbro.d.ts +2 -0
- package/src/devices/climbro.js +4 -0
- package/src/devices/climbro.ts +6 -0
- package/src/devices/index.d.ts +3 -1
- package/src/devices/index.js +3 -1
- package/src/devices/index.ts +5 -1
- package/src/devices/moterboard.ts +2 -2
- package/src/devices/smartboard.d.ts +2 -0
- package/src/devices/smartboard.js +4 -0
- package/src/devices/smartboard.ts +6 -0
- package/src/index.d.ts +3 -2
- package/src/index.js +5 -2
- package/src/index.ts +7 -2
- package/src/stream.d.ts +6 -0
- package/src/stream.js +25 -0
- package/src/stream.ts +26 -0
package/README.md
CHANGED
|
@@ -63,7 +63,7 @@ Simply importing the utilities you need from `@hangtime/grip-connect`. Devices t
|
|
|
63
63
|
```
|
|
64
64
|
|
|
65
65
|
```js
|
|
66
|
-
import { Motherboard, connect, disconnect,
|
|
66
|
+
import { Motherboard, calibrate, connect, disconnect, notify, read, stream } from "@hangtime/grip-connect"
|
|
67
67
|
|
|
68
68
|
const motherboardButton = document.querySelector("#motherboard")
|
|
69
69
|
|
|
@@ -81,13 +81,11 @@ motherboardButton.addEventListener("click", () => {
|
|
|
81
81
|
await read(Motherboard, "device", "firmware", 250)
|
|
82
82
|
|
|
83
83
|
// read calibration (required before reading data)
|
|
84
|
-
await
|
|
84
|
+
await calibrate(Motherboard)
|
|
85
85
|
|
|
86
86
|
// start streaming for a minute
|
|
87
|
-
await
|
|
87
|
+
await stream(Motherboard, 60000)
|
|
88
88
|
|
|
89
|
-
// end stream
|
|
90
|
-
await write(Motherboard, "uart", "tx", "", 0)
|
|
91
89
|
// disconnect from device after we are done
|
|
92
90
|
disconnect(Motherboard)
|
|
93
91
|
})
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hangtime/grip-connect",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "0.1.0",
|
|
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 Motherboard, Climbro, SmartBoard, Entralpi or Tindeq Progressor",
|
|
5
5
|
"main": "src/index.ts",
|
|
6
6
|
"scripts": {
|
package/src/calibrate.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Motherboard } from "./devices";
|
|
2
|
+
import { write } from "./write";
|
|
3
|
+
/**
|
|
4
|
+
* read calibration
|
|
5
|
+
* @param board
|
|
6
|
+
*/
|
|
7
|
+
export const calibrate = async (board) => {
|
|
8
|
+
if (!board.device)
|
|
9
|
+
return;
|
|
10
|
+
if (board.device.gatt?.connected) {
|
|
11
|
+
if (board.name === "Motherboard") {
|
|
12
|
+
await write(Motherboard, "uart", "tx", "C", 2500);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
};
|
package/src/calibrate.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Device } from "./devices/types"
|
|
2
|
+
import { Motherboard } from "./devices"
|
|
3
|
+
import { write } from "./write"
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* read calibration
|
|
7
|
+
* @param board
|
|
8
|
+
*/
|
|
9
|
+
export const calibrate = async (board: Device): Promise<void> => {
|
|
10
|
+
if (!board.device) return
|
|
11
|
+
if (board.device.gatt?.connected) {
|
|
12
|
+
if (board.name === "Motherboard") {
|
|
13
|
+
await write(Motherboard, "uart", "tx", "C", 2500)
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
}
|
package/src/connect.js
CHANGED
|
@@ -37,8 +37,12 @@ const handleNotifications = (event, board) => {
|
|
|
37
37
|
}
|
|
38
38
|
}
|
|
39
39
|
else if (board.name === "ENTRALPI") {
|
|
40
|
-
|
|
41
|
-
|
|
40
|
+
if (value.buffer) {
|
|
41
|
+
const buffer = value.buffer;
|
|
42
|
+
const rawData = new DataView(buffer);
|
|
43
|
+
const receivedData = rawData.getUint16(0) / 100;
|
|
44
|
+
handleEntralpiData(characteristic.uuid, receivedData);
|
|
45
|
+
}
|
|
42
46
|
}
|
|
43
47
|
else if (board.name === "Tindeq") {
|
|
44
48
|
// TODO: handle Tindeq notify
|
package/src/connect.ts
CHANGED
|
@@ -22,25 +22,29 @@ const onDisconnected = (event: Event, board: Device): void => {
|
|
|
22
22
|
* @param onNotify
|
|
23
23
|
*/
|
|
24
24
|
const handleNotifications = (event: Event, board: Device): void => {
|
|
25
|
-
const characteristic = event.target as BluetoothRemoteGATTCharacteristic
|
|
26
|
-
const value = characteristic.value
|
|
25
|
+
const characteristic: BluetoothRemoteGATTCharacteristic = event.target as BluetoothRemoteGATTCharacteristic
|
|
26
|
+
const value: DataView | undefined = characteristic.value
|
|
27
27
|
if (value) {
|
|
28
28
|
if (board.name === "Motherboard") {
|
|
29
|
-
for (let i = 0; i < value.byteLength; i++) {
|
|
29
|
+
for (let i: number = 0; i < value.byteLength; i++) {
|
|
30
30
|
receiveBuffer.push(value.getUint8(i))
|
|
31
31
|
}
|
|
32
32
|
|
|
33
33
|
let idx: number
|
|
34
34
|
while ((idx = receiveBuffer.indexOf(10)) >= 0) {
|
|
35
|
-
const line = receiveBuffer.splice(0, idx + 1).slice(0, -1) // Combine and remove LF
|
|
35
|
+
const line: number[] = receiveBuffer.splice(0, idx + 1).slice(0, -1) // Combine and remove LF
|
|
36
36
|
if (line.length > 0 && line[line.length - 1] === 13) line.pop() // Remove CR
|
|
37
|
-
const decoder = new TextDecoder("utf-8")
|
|
38
|
-
const receivedData = decoder.decode(new Uint8Array(line))
|
|
37
|
+
const decoder: TextDecoder = new TextDecoder("utf-8")
|
|
38
|
+
const receivedData: string = decoder.decode(new Uint8Array(line))
|
|
39
39
|
handleMotherboardData(characteristic.uuid, receivedData)
|
|
40
40
|
}
|
|
41
41
|
} else if (board.name === "ENTRALPI") {
|
|
42
|
-
|
|
43
|
-
|
|
42
|
+
if (value.buffer) {
|
|
43
|
+
const buffer: ArrayBuffer = value.buffer
|
|
44
|
+
const rawData: DataView = new DataView(buffer)
|
|
45
|
+
const receivedData: number = rawData.getUint16(0) / 100
|
|
46
|
+
handleEntralpiData(characteristic.uuid, receivedData)
|
|
47
|
+
}
|
|
44
48
|
} else if (board.name === "Tindeq") {
|
|
45
49
|
// TODO: handle Tindeq notify
|
|
46
50
|
} else {
|
|
@@ -57,7 +61,7 @@ const handleNotifications = (event: Event, board: Device): void => {
|
|
|
57
61
|
*/
|
|
58
62
|
const onConnected = async (board: Device, onSuccess: () => void): Promise<void> => {
|
|
59
63
|
try {
|
|
60
|
-
const services = await server?.getPrimaryServices()
|
|
64
|
+
const services: BluetoothRemoteGATTService[] = await server?.getPrimaryServices()
|
|
61
65
|
|
|
62
66
|
if (!services || services.length === 0) {
|
|
63
67
|
console.error("No services found")
|
package/src/devices/index.d.ts
CHANGED
package/src/devices/index.js
CHANGED
package/src/devices/index.ts
CHANGED
|
@@ -185,8 +185,8 @@ export function handleMotherboardData(uuid: string, receivedData: string): void
|
|
|
185
185
|
packet.masses[i] = applyCalibration(packet.samples[i], CALIBRATION[i])
|
|
186
186
|
}
|
|
187
187
|
// invert center and right values
|
|
188
|
-
packet.masses[1] *= -1
|
|
189
|
-
packet.masses[2] *= -1
|
|
188
|
+
packet.masses[1] *= -1
|
|
189
|
+
packet.masses[2] *= -1
|
|
190
190
|
// map to variables
|
|
191
191
|
const left: number = packet.masses[0]
|
|
192
192
|
const center: number = packet.masses[1]
|
package/src/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { Climbro, Entralpi, Motherboard, SmartBoard, Tindeq } from "./devices/index";
|
|
2
|
+
export { calibrate } from "./calibrate";
|
|
2
3
|
export { connect } from "./connect";
|
|
3
4
|
export { disconnect } from "./disconnect";
|
|
4
5
|
export { notify } from "./notify";
|
|
5
6
|
export { read } from "./read";
|
|
6
|
-
export {
|
|
7
|
+
export { stream } from "./stream";
|
package/src/index.js
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { Climbro, Entralpi, Motherboard, SmartBoard, Tindeq } from "./devices/index";
|
|
2
|
+
export { calibrate } from "./calibrate";
|
|
2
3
|
export { connect } from "./connect";
|
|
3
4
|
export { disconnect } from "./disconnect";
|
|
4
5
|
export { notify } from "./notify";
|
|
5
6
|
export { read } from "./read";
|
|
6
|
-
export {
|
|
7
|
+
export { stream } from "./stream";
|
|
8
|
+
// WARNING: Writing to device can seriously damage the device
|
|
9
|
+
// export { write } from "./write"
|
package/src/index.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { Climbro, Entralpi, Motherboard, SmartBoard, Tindeq } from "./devices/index"
|
|
2
|
+
|
|
3
|
+
export { calibrate } from "./calibrate"
|
|
2
4
|
|
|
3
5
|
export { connect } from "./connect"
|
|
4
6
|
|
|
@@ -8,4 +10,7 @@ export { notify } from "./notify"
|
|
|
8
10
|
|
|
9
11
|
export { read } from "./read"
|
|
10
12
|
|
|
11
|
-
export {
|
|
13
|
+
export { stream } from "./stream"
|
|
14
|
+
|
|
15
|
+
// WARNING: Writing to device can seriously damage the device
|
|
16
|
+
// export { write } from "./write"
|
package/src/stream.d.ts
ADDED
package/src/stream.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { Motherboard, Tindeq } from "./devices";
|
|
2
|
+
import { write } from "./write";
|
|
3
|
+
/**
|
|
4
|
+
* stream output
|
|
5
|
+
* @param board
|
|
6
|
+
*/
|
|
7
|
+
export const stream = async (board, duration = 0) => {
|
|
8
|
+
if (!board.device)
|
|
9
|
+
return;
|
|
10
|
+
if (board.device.gatt?.connected) {
|
|
11
|
+
if (board.name === "Motherboard") {
|
|
12
|
+
// TODO: add check if device is recalibrated
|
|
13
|
+
// start stream
|
|
14
|
+
await write(Motherboard, "uart", "tx", "S30", duration);
|
|
15
|
+
// end stream
|
|
16
|
+
await write(Motherboard, "uart", "tx", "", 0);
|
|
17
|
+
}
|
|
18
|
+
if (board.name === "Tindeq") {
|
|
19
|
+
// start stream
|
|
20
|
+
await write(Tindeq, "progressor", "tx", "e", duration);
|
|
21
|
+
// end stream
|
|
22
|
+
await write(Tindeq, "progressor", "tx", "f", 0);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
};
|
package/src/stream.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { Device } from "./devices/types"
|
|
2
|
+
import { Motherboard, Tindeq } from "./devices"
|
|
3
|
+
import { write } from "./write"
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* stream output
|
|
7
|
+
* @param board
|
|
8
|
+
*/
|
|
9
|
+
export const stream = async (board: Device, duration: number = 0): Promise<void> => {
|
|
10
|
+
if (!board.device) return
|
|
11
|
+
if (board.device.gatt?.connected) {
|
|
12
|
+
if (board.name === "Motherboard") {
|
|
13
|
+
// TODO: add check if device is recalibrated
|
|
14
|
+
// start stream
|
|
15
|
+
await write(Motherboard, "uart", "tx", "S30", duration)
|
|
16
|
+
// end stream
|
|
17
|
+
await write(Motherboard, "uart", "tx", "", 0)
|
|
18
|
+
}
|
|
19
|
+
if (board.name === "Tindeq") {
|
|
20
|
+
// start stream
|
|
21
|
+
await write(Tindeq, "progressor", "tx", "e", duration)
|
|
22
|
+
// end stream
|
|
23
|
+
await write(Tindeq, "progressor", "tx", "f", 0)
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|