@hangtime/grip-connect 0.0.10 → 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 +9 -10
- 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/entralpi.js +8 -6
- package/src/devices/entralpi.ts +8 -6
- 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.js +16 -10
- package/src/devices/moterboard.ts +16 -12
- 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
|
|
|
@@ -75,19 +75,17 @@ motherboardButton.addEventListener("click", () => {
|
|
|
75
75
|
})
|
|
76
76
|
|
|
77
77
|
// read battery + device info
|
|
78
|
-
await read(Motherboard, "battery", "level",
|
|
79
|
-
await read(Motherboard, "device", "manufacturer",
|
|
80
|
-
await read(Motherboard, "device", "hardware",
|
|
81
|
-
await read(Motherboard, "device", "firmware",
|
|
78
|
+
await read(Motherboard, "battery", "level", 250)
|
|
79
|
+
await read(Motherboard, "device", "manufacturer", 250)
|
|
80
|
+
await read(Motherboard, "device", "hardware", 250)
|
|
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
|
-
// start
|
|
87
|
-
await
|
|
86
|
+
// start streaming for a minute
|
|
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
|
})
|
|
@@ -100,6 +98,7 @@ A special thank you to:
|
|
|
100
98
|
|
|
101
99
|
- [@CassimLadha](https://github.com/CassimLadha) for sharing insights on reading the Motherboards data.
|
|
102
100
|
- [@donaldharvey](https://github.com/donaldharvey) for a valuable example on connecting to the motherboard.
|
|
101
|
+
- [@ecstrema](https://github.com/ecstrema) for providing an example on how to play games with the entralpi.
|
|
103
102
|
|
|
104
103
|
## Disclamer
|
|
105
104
|
|
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/entralpi.js
CHANGED
|
@@ -57,10 +57,12 @@ export const Entralpi = {
|
|
|
57
57
|
* @param receivedData - Received data string
|
|
58
58
|
*/
|
|
59
59
|
export function handleEntralpiData(uuid, receivedData) {
|
|
60
|
-
notifyCallback
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
60
|
+
if (notifyCallback) {
|
|
61
|
+
notifyCallback({
|
|
62
|
+
uuid,
|
|
63
|
+
value: {
|
|
64
|
+
massTotal: receivedData,
|
|
65
|
+
},
|
|
66
|
+
});
|
|
67
|
+
}
|
|
66
68
|
}
|
package/src/devices/entralpi.ts
CHANGED
|
@@ -60,10 +60,12 @@ export const Entralpi: Device = {
|
|
|
60
60
|
* @param receivedData - Received data string
|
|
61
61
|
*/
|
|
62
62
|
export function handleEntralpiData(uuid: string, receivedData: number): void {
|
|
63
|
-
notifyCallback
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
63
|
+
if (notifyCallback) {
|
|
64
|
+
notifyCallback({
|
|
65
|
+
uuid,
|
|
66
|
+
value: {
|
|
67
|
+
massTotal: receivedData,
|
|
68
|
+
},
|
|
69
|
+
})
|
|
70
|
+
}
|
|
69
71
|
}
|
package/src/devices/index.d.ts
CHANGED
package/src/devices/index.js
CHANGED
package/src/devices/index.ts
CHANGED
|
@@ -98,7 +98,7 @@ const applyCalibration = (sample, calibration) => {
|
|
|
98
98
|
// Change the sign to negative
|
|
99
99
|
sign = -1;
|
|
100
100
|
// Reflect the sample around the zero calibration point
|
|
101
|
-
sample = 2 * zeroCalibration -
|
|
101
|
+
sample = /* 2 * zeroCalibration */ -sample;
|
|
102
102
|
}
|
|
103
103
|
// Iterate through the calibration data
|
|
104
104
|
for (let i = 1; i < calibration.length; i++) {
|
|
@@ -156,18 +156,24 @@ export function handleMotherboardData(uuid, receivedData) {
|
|
|
156
156
|
return;
|
|
157
157
|
packet.masses[i] = applyCalibration(packet.samples[i], CALIBRATION[i]);
|
|
158
158
|
}
|
|
159
|
+
// invert center and right values
|
|
160
|
+
packet.masses[1] *= -1;
|
|
161
|
+
packet.masses[2] *= -1;
|
|
162
|
+
// map to variables
|
|
159
163
|
const left = packet.masses[0];
|
|
160
164
|
const center = packet.masses[1];
|
|
161
165
|
const right = packet.masses[2];
|
|
162
|
-
notifyCallback
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
166
|
+
if (notifyCallback) {
|
|
167
|
+
notifyCallback({
|
|
168
|
+
uuid,
|
|
169
|
+
value: {
|
|
170
|
+
massTotal: Math.max(-1000, left + right + center).toFixed(1),
|
|
171
|
+
massLeft: Math.max(-1000, left).toFixed(1),
|
|
172
|
+
massRight: Math.max(-1000, right).toFixed(1),
|
|
173
|
+
massCenter: Math.max(-1000, center).toFixed(1),
|
|
174
|
+
},
|
|
175
|
+
});
|
|
176
|
+
}
|
|
171
177
|
}
|
|
172
178
|
else if ((receivedData.match(/,/g) || []).length === 3) {
|
|
173
179
|
console.log(receivedData);
|
|
@@ -105,7 +105,7 @@ const applyCalibration = (sample: number, calibration: number[][]): number => {
|
|
|
105
105
|
sign = -1
|
|
106
106
|
|
|
107
107
|
// Reflect the sample around the zero calibration point
|
|
108
|
-
sample = 2 * zeroCalibration -
|
|
108
|
+
sample = /* 2 * zeroCalibration */ -sample
|
|
109
109
|
}
|
|
110
110
|
|
|
111
111
|
// Iterate through the calibration data
|
|
@@ -184,20 +184,24 @@ export function handleMotherboardData(uuid: string, receivedData: string): void
|
|
|
184
184
|
if (!CALIBRATION[0].length) return
|
|
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
|
|
190
|
+
// map to variables
|
|
188
191
|
const left: number = packet.masses[0]
|
|
189
192
|
const center: number = packet.masses[1]
|
|
190
193
|
const right: number = packet.masses[2]
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
194
|
+
if (notifyCallback) {
|
|
195
|
+
notifyCallback({
|
|
196
|
+
uuid,
|
|
197
|
+
value: {
|
|
198
|
+
massTotal: Math.max(-1000, left + right + center).toFixed(1),
|
|
199
|
+
massLeft: Math.max(-1000, left).toFixed(1),
|
|
200
|
+
massRight: Math.max(-1000, right).toFixed(1),
|
|
201
|
+
massCenter: Math.max(-1000, center).toFixed(1),
|
|
202
|
+
},
|
|
203
|
+
})
|
|
204
|
+
}
|
|
201
205
|
} else if ((receivedData.match(/,/g) || []).length === 3) {
|
|
202
206
|
console.log(receivedData)
|
|
203
207
|
// if the returned notification is a calibration string add them to the array
|
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
|
+
}
|