@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 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, read, write, notify } from "@hangtime/grip-connect"
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 write(Motherboard, "uart", "tx", "C", 2500)
84
+ await calibrate(Motherboard)
85
85
 
86
86
  // start streaming for a minute
87
- await write(Motherboard, "uart", "tx", "S30", 60000)
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.11",
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": {
@@ -0,0 +1,6 @@
1
+ import { Device } from "./devices/types";
2
+ /**
3
+ * read calibration
4
+ * @param board
5
+ */
6
+ export declare const calibrate: (board: Device) => Promise<void>;
@@ -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
+ };
@@ -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
- const receivedData = value.getInt16(0) / 100;
41
- handleEntralpiData(characteristic.uuid, receivedData);
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
- const receivedData: number = value.getInt16(0) / 100
43
- handleEntralpiData(characteristic.uuid, receivedData)
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")
@@ -0,0 +1,2 @@
1
+ import { Device } from "./types";
2
+ export declare const Climbro: Device;
@@ -0,0 +1,4 @@
1
+ export const Climbro = {
2
+ name: "Climbro",
3
+ services: [],
4
+ };
@@ -0,0 +1,6 @@
1
+ import { Device } from "./types"
2
+
3
+ export const Climbro: Device = {
4
+ name: "Climbro",
5
+ services: [],
6
+ }
@@ -1,3 +1,5 @@
1
- export { Motherboard } from "./moterboard";
1
+ export { Climbro } from "./climbro";
2
2
  export { Entralpi } from "./entralpi";
3
+ export { Motherboard } from "./moterboard";
4
+ export { SmartBoard } from "./smartboard";
3
5
  export { Tindeq } from "./tindeq";
@@ -1,3 +1,5 @@
1
- export { Motherboard } from "./moterboard";
1
+ export { Climbro } from "./climbro";
2
2
  export { Entralpi } from "./entralpi";
3
+ export { Motherboard } from "./moterboard";
4
+ export { SmartBoard } from "./smartboard";
3
5
  export { Tindeq } from "./tindeq";
@@ -1,5 +1,9 @@
1
- export { Motherboard } from "./moterboard"
1
+ export { Climbro } from "./climbro"
2
2
 
3
3
  export { Entralpi } from "./entralpi"
4
4
 
5
+ export { Motherboard } from "./moterboard"
6
+
7
+ export { SmartBoard } from "./smartboard"
8
+
5
9
  export { Tindeq } from "./tindeq"
@@ -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]
@@ -0,0 +1,2 @@
1
+ import { Device } from "./types";
2
+ export declare const SmartBoard: Device;
@@ -0,0 +1,4 @@
1
+ export const SmartBoard = {
2
+ name: "SmartBoard",
3
+ services: [],
4
+ };
@@ -0,0 +1,6 @@
1
+ import { Device } from "./types"
2
+
3
+ export const SmartBoard: Device = {
4
+ name: "SmartBoard",
5
+ services: [],
6
+ }
package/src/index.d.ts CHANGED
@@ -1,6 +1,7 @@
1
- export { Motherboard, Entralpi, Tindeq } from "./devices/index";
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 { write } from "./write";
7
+ export { stream } from "./stream";
package/src/index.js CHANGED
@@ -1,6 +1,9 @@
1
- export { Motherboard, Entralpi, Tindeq } from "./devices/index";
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 { write } from "./write";
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 { Motherboard, Entralpi, Tindeq } from "./devices/index"
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 { write } from "./write"
13
+ export { stream } from "./stream"
14
+
15
+ // WARNING: Writing to device can seriously damage the device
16
+ // export { write } from "./write"
@@ -0,0 +1,6 @@
1
+ import { Device } from "./devices/types";
2
+ /**
3
+ * stream output
4
+ * @param board
5
+ */
6
+ export declare const stream: (board: Device, duration?: number) => Promise<void>;
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
+ }