@hangtime/grip-connect 0.2.6 → 0.3.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 +24 -14
- package/package.json +1 -1
- package/src/battery.d.ts +3 -2
- package/src/battery.js +8 -2
- package/src/battery.ts +8 -2
- package/src/calibration.d.ts +3 -2
- package/src/calibration.js +6 -2
- package/src/calibration.ts +6 -2
- package/src/characteristic.d.ts +5 -4
- package/src/characteristic.js +9 -4
- package/src/characteristic.ts +14 -5
- package/src/commands/index.d.ts +2 -1
- package/src/commands/index.js +2 -1
- package/src/commands/index.ts +3 -1
- package/src/commands/{smartboard.d.ts → musclemeter.d.ts} +1 -1
- package/src/commands/{smartboard.js → musclemeter.js} +1 -1
- package/src/commands/{smartboard.ts → musclemeter.ts} +1 -1
- package/src/commands/mysmartboard.d.ts +6 -0
- package/src/commands/mysmartboard.js +5 -0
- package/src/commands/mysmartboard.ts +6 -0
- package/src/commands/progressor.d.ts +2 -0
- package/src/commands/progressor.js +3 -1
- package/src/commands/progressor.ts +3 -1
- package/src/connect.d.ts +3 -3
- package/src/connect.js +23 -30
- package/src/connect.ts +23 -30
- package/src/data.d.ts +13 -6
- package/src/data.js +112 -49
- package/src/data.ts +128 -62
- package/src/devices/climbro.d.ts +4 -0
- package/src/devices/climbro.js +4 -0
- package/src/devices/climbro.ts +4 -0
- package/src/devices/entralpi.d.ts +3 -0
- package/src/devices/entralpi.js +3 -0
- package/src/devices/entralpi.ts +3 -0
- package/src/devices/index.d.ts +2 -1
- package/src/devices/index.js +2 -1
- package/src/devices/index.ts +3 -1
- package/src/devices/motherboard.d.ts +3 -0
- package/src/devices/motherboard.js +3 -0
- package/src/devices/motherboard.ts +3 -0
- package/src/devices/musclemeter.d.ts +6 -0
- package/src/devices/musclemeter.js +8 -0
- package/src/devices/musclemeter.ts +10 -0
- package/src/devices/mysmartboard.d.ts +6 -0
- package/src/devices/mysmartboard.js +8 -0
- package/src/devices/mysmartboard.ts +10 -0
- package/src/devices/progressor.d.ts +3 -0
- package/src/devices/progressor.js +4 -1
- package/src/devices/progressor.ts +4 -2
- package/src/devices/types.d.ts +9 -0
- package/src/devices/types.ts +21 -12
- package/src/disconnect.d.ts +2 -2
- package/src/disconnect.js +4 -2
- package/src/disconnect.ts +4 -2
- package/src/download.d.ts +19 -0
- package/src/download.js +50 -0
- package/src/download.ts +73 -0
- package/src/index.d.ts +3 -1
- package/src/index.js +11 -3
- package/src/index.ts +12 -8
- package/src/info.d.ts +3 -2
- package/src/info.js +9 -2
- package/src/info.ts +9 -2
- package/src/is-connected.d.ts +3 -3
- package/src/is-connected.js +7 -4
- package/src/is-connected.ts +8 -4
- package/src/notify.d.ts +19 -1
- package/src/notify.js +10 -2
- package/src/notify.ts +21 -6
- package/src/read.d.ts +6 -2
- package/src/read.js +10 -6
- package/src/read.ts +10 -6
- package/src/stop.d.ts +3 -2
- package/src/stop.js +5 -2
- package/src/stop.ts +5 -2
- package/src/stream.d.ts +4 -2
- package/src/stream.js +13 -7
- package/src/stream.ts +13 -7
- package/src/tare.d.ts +12 -0
- package/src/tare.js +70 -0
- package/src/tare.ts +76 -0
- package/src/write.d.ts +11 -3
- package/src/write.js +21 -6
- package/src/write.ts +23 -6
- package/src/devices/smartboard.d.ts +0 -2
- package/src/devices/smartboard.js +0 -4
- package/src/devices/smartboard.ts +0 -6
package/README.md
CHANGED
|
@@ -5,18 +5,21 @@
|
|
|
5
5
|
The objective of this project is to create a Web Bluetooth API client that can establish connections with various
|
|
6
6
|
Force-Sensing Hangboards / Plates used by climbers for strength measurement. Examples of such hangboards include the
|
|
7
7
|
[Griptonite Motherboard](https://griptonite.io/shop/motherboard/), [Climbro](https://climbro.com/),
|
|
8
|
-
[
|
|
9
|
-
[Tindeq Progressor](https://tindeq.com/)
|
|
8
|
+
[mySmartBoard](https://www.smartboard-climbing.com/), [Entralpi](https://entralpi.com/),
|
|
9
|
+
[Tindeq Progressor](https://tindeq.com/) or [MAT Muscle Meter](https://www.matassessment.com/musclemeter)
|
|
10
10
|
|
|
11
11
|
Learn more: [Docs](https://stevie-ray.github.io/hangtime-grip-connect/) -
|
|
12
12
|
[Browser Support](https://caniuse.com/web-bluetooth)
|
|
13
13
|
|
|
14
14
|
## Try it out
|
|
15
15
|
|
|
16
|
-
[Chart](https://grip-connect.vercel.app/) - [Flappy Bird](https://grip-connect-flappy-bird.vercel.app/)
|
|
16
|
+
[Chart](https://grip-connect.vercel.app/) - [Flappy Bird](https://grip-connect-flappy-bird.vercel.app/) -
|
|
17
|
+
[Pong](https://grip-connect-pong.vercel.app/)
|
|
17
18
|
|
|
18
19
|
## Install
|
|
19
20
|
|
|
21
|
+
This project can be found in the [NPM package registry](https://www.npmjs.com/package/@hangtime/grip-connect).
|
|
22
|
+
|
|
20
23
|
```sh [npm]
|
|
21
24
|
$ npm install @hangtime/grip-connect
|
|
22
25
|
```
|
|
@@ -38,7 +41,7 @@ motherboardButton.addEventListener("click", () => {
|
|
|
38
41
|
connect(Motherboard, async () => {
|
|
39
42
|
// Listen for stream notifications
|
|
40
43
|
notify((data) => {
|
|
41
|
-
//
|
|
44
|
+
// { massTotal: "0", massMax: "0", massAverage: "0", massLeft: "0", massCenter: "0", massRight: "0" }
|
|
42
45
|
console.log(data)
|
|
43
46
|
})
|
|
44
47
|
|
|
@@ -49,9 +52,15 @@ motherboardButton.addEventListener("click", () => {
|
|
|
49
52
|
// Start weight streaming (for a minute) remove parameter for a continues stream
|
|
50
53
|
await stream(Motherboard, 60000)
|
|
51
54
|
|
|
55
|
+
// Manualy tare the device when the stream is running
|
|
56
|
+
// await tare(5000)
|
|
57
|
+
|
|
52
58
|
// Manually call stop method if stream is continues
|
|
53
59
|
// await stop(Motherboard)
|
|
54
60
|
|
|
61
|
+
// Download data to CSV: format => timestamp, frame, battery, samples, masses
|
|
62
|
+
// download()
|
|
63
|
+
|
|
55
64
|
// Disconnect from device after we are done
|
|
56
65
|
disconnect(Motherboard)
|
|
57
66
|
})
|
|
@@ -68,24 +77,24 @@ available services with us.
|
|
|
68
77
|
|
|
69
78
|
- ✅ Griptonite Motherboard
|
|
70
79
|
- ✅ Tindeq Progressor
|
|
71
|
-
-
|
|
80
|
+
- ☑️ Entralpi (not verified)
|
|
72
81
|
- ➡️ Climbro
|
|
73
|
-
- ➡️
|
|
82
|
+
- ➡️ mySmartBoard
|
|
83
|
+
- ➡️ MAT Muscle Meter
|
|
74
84
|
|
|
75
85
|
### Features
|
|
76
86
|
|
|
77
|
-
- ✅ Connect
|
|
78
|
-
- ✅
|
|
79
|
-
- ✅ Start data stream (live data)
|
|
80
|
-
- ✅ Stop data stream
|
|
87
|
+
- ✅ Connect / Disconnect
|
|
88
|
+
- ✅ Start / Stop data stream
|
|
81
89
|
- ✅ Battery status
|
|
82
90
|
- ✅ Read calibration
|
|
83
|
-
- ✅ Device info
|
|
91
|
+
- ✅ Device info: firmware / serial etc.
|
|
84
92
|
- ✅ Check if device is connected
|
|
85
|
-
-
|
|
93
|
+
- ✅ Peak / Average load
|
|
94
|
+
- ✅️ Tare / unladen weight
|
|
95
|
+
- ✅️ Download data to CVS
|
|
86
96
|
- ➡️ Endurance
|
|
87
|
-
- ➡️ Rate of Force Development
|
|
88
|
-
- ➡️ Repeaters
|
|
97
|
+
- ➡️ Rate of Force Development: RFD
|
|
89
98
|
- ➡️ Critical Force
|
|
90
99
|
|
|
91
100
|
## Development
|
|
@@ -104,6 +113,7 @@ A special thank you to:
|
|
|
104
113
|
- [@donaldharvey](https://github.com/donaldharvey) for a valuable example on connecting to the Motherboard.
|
|
105
114
|
- [@ecstrema](https://github.com/ecstrema) for providing [examples](https://github.com/ecstrema/entralpi-games) on how
|
|
106
115
|
to play games with the Entralpi.
|
|
116
|
+
- [Tindeq](https://tindeq.com/) for providing an open [Progressor API](https://tindeq.com/progressor_api/)
|
|
107
117
|
- [@StuartLittlefair](https://github.com/StuartLittlefair) for his
|
|
108
118
|
[PyTindeq](https://github.com/StuartLittlefair/PyTindeq) implementation.
|
|
109
119
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hangtime/grip-connect",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.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 Griptonite Motherboard, Climbro, SmartBoard, Entralpi or Tindeq Progressor",
|
|
5
5
|
"main": "src/index.ts",
|
|
6
6
|
"scripts": {
|
package/src/battery.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Device } from "./devices/types";
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
4
|
-
* @param board
|
|
3
|
+
* Retrieves battery or voltage information from the device.
|
|
4
|
+
* @param {Device} board - The device.
|
|
5
|
+
* @returns {Promise<void>} A Promise that resolves when the information is successfully retrieved.
|
|
5
6
|
*/
|
|
6
7
|
export declare const battery: (board: Device) => Promise<void>;
|
package/src/battery.js
CHANGED
|
@@ -4,15 +4,21 @@ import { isConnected } from "./is-connected";
|
|
|
4
4
|
import { Motherboard, Progressor } from "./devices";
|
|
5
5
|
import { ProgressorCommands } from "./commands";
|
|
6
6
|
/**
|
|
7
|
-
*
|
|
8
|
-
* @param board
|
|
7
|
+
* Retrieves battery or voltage information from the device.
|
|
8
|
+
* @param {Device} board - The device.
|
|
9
|
+
* @returns {Promise<void>} A Promise that resolves when the information is successfully retrieved.
|
|
9
10
|
*/
|
|
10
11
|
export const battery = async (board) => {
|
|
12
|
+
// Check if the device is connected
|
|
11
13
|
if (isConnected(board)) {
|
|
14
|
+
// If the device is connected and it is a Motherboard device
|
|
12
15
|
if (board.name === "Motherboard") {
|
|
16
|
+
// Read battery level information from the Motherboard
|
|
13
17
|
await read(Motherboard, "battery", "level", 250);
|
|
14
18
|
}
|
|
19
|
+
// If the device is connected and its name starts with "Progressor"
|
|
15
20
|
if (board.name && board.name.startsWith("Progressor")) {
|
|
21
|
+
// Write command to get battery voltage information to the Progressor
|
|
16
22
|
await write(Progressor, "progressor", "tx", ProgressorCommands.GET_BATT_VLTG, 250);
|
|
17
23
|
}
|
|
18
24
|
}
|
package/src/battery.ts
CHANGED
|
@@ -6,15 +6,21 @@ import { Motherboard, Progressor } from "./devices"
|
|
|
6
6
|
import { ProgressorCommands } from "./commands"
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
|
-
*
|
|
10
|
-
* @param board
|
|
9
|
+
* Retrieves battery or voltage information from the device.
|
|
10
|
+
* @param {Device} board - The device.
|
|
11
|
+
* @returns {Promise<void>} A Promise that resolves when the information is successfully retrieved.
|
|
11
12
|
*/
|
|
12
13
|
export const battery = async (board: Device): Promise<void> => {
|
|
14
|
+
// Check if the device is connected
|
|
13
15
|
if (isConnected(board)) {
|
|
16
|
+
// If the device is connected and it is a Motherboard device
|
|
14
17
|
if (board.name === "Motherboard") {
|
|
18
|
+
// Read battery level information from the Motherboard
|
|
15
19
|
await read(Motherboard, "battery", "level", 250)
|
|
16
20
|
}
|
|
21
|
+
// If the device is connected and its name starts with "Progressor"
|
|
17
22
|
if (board.name && board.name.startsWith("Progressor")) {
|
|
23
|
+
// Write command to get battery voltage information to the Progressor
|
|
18
24
|
await write(Progressor, "progressor", "tx", ProgressorCommands.GET_BATT_VLTG, 250)
|
|
19
25
|
}
|
|
20
26
|
}
|
package/src/calibration.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Device } from "./devices/types";
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
4
|
-
* @param board
|
|
3
|
+
* Writes a command to get calibration data from the device.
|
|
4
|
+
* @param {Device} board - The device.
|
|
5
|
+
* @returns {Promise<void>} A Promise that resolves when the command is successfully sent.
|
|
5
6
|
*/
|
|
6
7
|
export declare const calibration: (board: Device) => Promise<void>;
|
package/src/calibration.js
CHANGED
|
@@ -3,12 +3,16 @@ import { write } from "./write";
|
|
|
3
3
|
import { Motherboard } from "./devices";
|
|
4
4
|
import { MotherboardCommands } from "./commands";
|
|
5
5
|
/**
|
|
6
|
-
*
|
|
7
|
-
* @param board
|
|
6
|
+
* Writes a command to get calibration data from the device.
|
|
7
|
+
* @param {Device} board - The device.
|
|
8
|
+
* @returns {Promise<void>} A Promise that resolves when the command is successfully sent.
|
|
8
9
|
*/
|
|
9
10
|
export const calibration = async (board) => {
|
|
11
|
+
// Check if the device is connected
|
|
10
12
|
if (isConnected(board)) {
|
|
13
|
+
// If the device is connected, and it is a Motherboard device
|
|
11
14
|
if (board.name === "Motherboard") {
|
|
15
|
+
// Write the command to get calibration data to the device
|
|
12
16
|
await write(Motherboard, "uart", "tx", MotherboardCommands.GET_CALIBRATION, 2500);
|
|
13
17
|
}
|
|
14
18
|
}
|
package/src/calibration.ts
CHANGED
|
@@ -5,12 +5,16 @@ import { Motherboard } from "./devices"
|
|
|
5
5
|
import { MotherboardCommands } from "./commands"
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
|
-
*
|
|
9
|
-
* @param board
|
|
8
|
+
* Writes a command to get calibration data from the device.
|
|
9
|
+
* @param {Device} board - The device.
|
|
10
|
+
* @returns {Promise<void>} A Promise that resolves when the command is successfully sent.
|
|
10
11
|
*/
|
|
11
12
|
export const calibration = async (board: Device): Promise<void> => {
|
|
13
|
+
// Check if the device is connected
|
|
12
14
|
if (isConnected(board)) {
|
|
15
|
+
// If the device is connected, and it is a Motherboard device
|
|
13
16
|
if (board.name === "Motherboard") {
|
|
17
|
+
// Write the command to get calibration data to the device
|
|
14
18
|
await write(Motherboard, "uart", "tx", MotherboardCommands.GET_CALIBRATION, 2500)
|
|
15
19
|
}
|
|
16
20
|
}
|
package/src/characteristic.d.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
/// <reference types="web-bluetooth" />
|
|
2
2
|
import { Device } from "./devices/types";
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
5
|
-
* @param board
|
|
6
|
-
* @param serviceId
|
|
7
|
-
* @param characteristicId
|
|
4
|
+
* Retrieves the characteristic from the device's service.
|
|
5
|
+
* @param {Device} board - The device.
|
|
6
|
+
* @param {string} serviceId - The UUID of the service.
|
|
7
|
+
* @param {string} characteristicId - The UUID of the characteristic.
|
|
8
|
+
* @returns {BluetoothRemoteGATTCharacteristic | undefined} The characteristic, if found.
|
|
8
9
|
*/
|
|
9
10
|
export declare const getCharacteristic: (board: Device, serviceId: string, characteristicId: string) => BluetoothRemoteGATTCharacteristic | undefined;
|
package/src/characteristic.js
CHANGED
|
@@ -1,15 +1,20 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
* @param board
|
|
4
|
-
* @param serviceId
|
|
5
|
-
* @param characteristicId
|
|
2
|
+
* Retrieves the characteristic from the device's service.
|
|
3
|
+
* @param {Device} board - The device.
|
|
4
|
+
* @param {string} serviceId - The UUID of the service.
|
|
5
|
+
* @param {string} characteristicId - The UUID of the characteristic.
|
|
6
|
+
* @returns {BluetoothRemoteGATTCharacteristic | undefined} The characteristic, if found.
|
|
6
7
|
*/
|
|
7
8
|
export const getCharacteristic = (board, serviceId, characteristicId) => {
|
|
9
|
+
// Find the service with the specified serviceId
|
|
8
10
|
const boardService = board.services.find((service) => service.id === serviceId);
|
|
9
11
|
if (boardService) {
|
|
12
|
+
// If the service is found, find the characteristic with the specified characteristicId
|
|
10
13
|
const boardCharacteristic = boardService.characteristics.find((characteristic) => characteristic.id === characteristicId);
|
|
11
14
|
if (boardCharacteristic) {
|
|
15
|
+
// If the characteristic is found, return it
|
|
12
16
|
return boardCharacteristic.characteristic;
|
|
13
17
|
}
|
|
14
18
|
}
|
|
19
|
+
// Return undefined if the service or characteristic is not found
|
|
15
20
|
};
|
package/src/characteristic.ts
CHANGED
|
@@ -1,19 +1,28 @@
|
|
|
1
1
|
import { Device } from "./devices/types"
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
5
|
-
* @param board
|
|
6
|
-
* @param serviceId
|
|
7
|
-
* @param characteristicId
|
|
4
|
+
* Retrieves the characteristic from the device's service.
|
|
5
|
+
* @param {Device} board - The device.
|
|
6
|
+
* @param {string} serviceId - The UUID of the service.
|
|
7
|
+
* @param {string} characteristicId - The UUID of the characteristic.
|
|
8
|
+
* @returns {BluetoothRemoteGATTCharacteristic | undefined} The characteristic, if found.
|
|
8
9
|
*/
|
|
9
|
-
export const getCharacteristic = (
|
|
10
|
+
export const getCharacteristic = (
|
|
11
|
+
board: Device,
|
|
12
|
+
serviceId: string,
|
|
13
|
+
characteristicId: string,
|
|
14
|
+
): BluetoothRemoteGATTCharacteristic | undefined => {
|
|
15
|
+
// Find the service with the specified serviceId
|
|
10
16
|
const boardService = board.services.find((service) => service.id === serviceId)
|
|
11
17
|
if (boardService) {
|
|
18
|
+
// If the service is found, find the characteristic with the specified characteristicId
|
|
12
19
|
const boardCharacteristic = boardService.characteristics.find(
|
|
13
20
|
(characteristic) => characteristic.id === characteristicId,
|
|
14
21
|
)
|
|
15
22
|
if (boardCharacteristic) {
|
|
23
|
+
// If the characteristic is found, return it
|
|
16
24
|
return boardCharacteristic.characteristic
|
|
17
25
|
}
|
|
18
26
|
}
|
|
27
|
+
// Return undefined if the service or characteristic is not found
|
|
19
28
|
}
|
package/src/commands/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export { ClimbroCommands } from "./climbro";
|
|
2
2
|
export { EntralpiCommands } from "./entralpi";
|
|
3
3
|
export { MotherboardCommands } from "./motherboard";
|
|
4
|
+
export { MuscleMeterCommands } from "./musclemeter";
|
|
4
5
|
export { ProgressorCommands } from "./progressor";
|
|
5
|
-
export {
|
|
6
|
+
export { mySmartBoardCommands } from "./mysmartboard";
|
package/src/commands/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export { ClimbroCommands } from "./climbro";
|
|
2
2
|
export { EntralpiCommands } from "./entralpi";
|
|
3
3
|
export { MotherboardCommands } from "./motherboard";
|
|
4
|
+
export { MuscleMeterCommands } from "./musclemeter";
|
|
4
5
|
export { ProgressorCommands } from "./progressor";
|
|
5
|
-
export {
|
|
6
|
+
export { mySmartBoardCommands } from "./mysmartboard";
|
package/src/commands/index.ts
CHANGED
|
@@ -4,6 +4,8 @@ export { EntralpiCommands } from "./entralpi"
|
|
|
4
4
|
|
|
5
5
|
export { MotherboardCommands } from "./motherboard"
|
|
6
6
|
|
|
7
|
+
export { MuscleMeterCommands } from "./musclemeter"
|
|
8
|
+
|
|
7
9
|
export { ProgressorCommands } from "./progressor"
|
|
8
10
|
|
|
9
|
-
export {
|
|
11
|
+
export { mySmartBoardCommands } from "./mysmartboard"
|
package/src/connect.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Device } from "./devices/types";
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
4
|
-
* @param device
|
|
5
|
-
* @param onSuccess
|
|
3
|
+
* Connects to a Bluetooth device.
|
|
4
|
+
* @param {Device} board - The device to connect to.
|
|
5
|
+
* @param {Function} onSuccess - Callback function to execute on successful connection.
|
|
6
6
|
*/
|
|
7
7
|
export declare const connect: (board: Device, onSuccess: () => void) => Promise<void>;
|
package/src/connect.js
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { handleMotherboardData, handleProgressorData } from "./data";
|
|
1
|
+
import { handleEntralpiData, handleMotherboardData, handleProgressorData } from "./data";
|
|
3
2
|
let server;
|
|
4
3
|
const receiveBuffer = [];
|
|
5
4
|
/**
|
|
6
|
-
*
|
|
7
|
-
* @param
|
|
8
|
-
* @param
|
|
5
|
+
* Handles the 'disconnected' event.
|
|
6
|
+
* @param {Event} event - The 'disconnected' event.
|
|
7
|
+
* @param {Device} board - The device that is disconnected.
|
|
9
8
|
*/
|
|
10
9
|
const onDisconnected = (event, board) => {
|
|
11
10
|
board.device = undefined;
|
|
@@ -13,9 +12,9 @@ const onDisconnected = (event, board) => {
|
|
|
13
12
|
console.log(`Device ${device.name} is disconnected.`);
|
|
14
13
|
};
|
|
15
14
|
/**
|
|
16
|
-
*
|
|
17
|
-
* @param event
|
|
18
|
-
* @param
|
|
15
|
+
* Handles notifications received from a characteristic.
|
|
16
|
+
* @param {Event} event - The notification event.
|
|
17
|
+
* @param {Device} board - The device associated with the characteristic.
|
|
19
18
|
*/
|
|
20
19
|
const handleNotifications = (event, board) => {
|
|
21
20
|
const characteristic = event.target;
|
|
@@ -32,45 +31,37 @@ const handleNotifications = (event, board) => {
|
|
|
32
31
|
line.pop(); // Remove CR
|
|
33
32
|
const decoder = new TextDecoder("utf-8");
|
|
34
33
|
const receivedData = decoder.decode(new Uint8Array(line));
|
|
35
|
-
handleMotherboardData(
|
|
34
|
+
handleMotherboardData(receivedData);
|
|
36
35
|
}
|
|
37
36
|
}
|
|
38
37
|
else if (board.name === "ENTRALPI") {
|
|
39
38
|
if (value.buffer) {
|
|
40
39
|
const buffer = value.buffer;
|
|
41
40
|
const rawData = new DataView(buffer);
|
|
42
|
-
const receivedData = rawData.getUint16(0) / 100;
|
|
43
|
-
|
|
44
|
-
notifyCallback({
|
|
45
|
-
uuid: characteristic.uuid,
|
|
46
|
-
value: {
|
|
47
|
-
massTotal: receivedData,
|
|
48
|
-
},
|
|
49
|
-
});
|
|
50
|
-
}
|
|
41
|
+
const receivedData = (rawData.getUint16(0) / 100).toFixed(1);
|
|
42
|
+
handleEntralpiData(receivedData);
|
|
51
43
|
}
|
|
52
44
|
}
|
|
53
45
|
else if (board.name && board.name.startsWith("Progressor")) {
|
|
54
46
|
if (value.buffer) {
|
|
55
47
|
const buffer = value.buffer;
|
|
56
48
|
const rawData = new DataView(buffer);
|
|
57
|
-
handleProgressorData(
|
|
49
|
+
handleProgressorData(rawData);
|
|
58
50
|
}
|
|
59
51
|
}
|
|
60
52
|
else {
|
|
61
|
-
|
|
62
|
-
notifyCallback({ uuid: characteristic.uuid, value: value });
|
|
63
|
-
}
|
|
53
|
+
console.log(value);
|
|
64
54
|
}
|
|
65
55
|
}
|
|
66
56
|
};
|
|
67
57
|
/**
|
|
68
|
-
*
|
|
69
|
-
* @param
|
|
70
|
-
* @param
|
|
58
|
+
* Handles the 'connected' event.
|
|
59
|
+
* @param {Device} board - The connected device.
|
|
60
|
+
* @param {Function} onSuccess - Callback function to execute on successful connection.
|
|
71
61
|
*/
|
|
72
62
|
const onConnected = async (board, onSuccess) => {
|
|
73
63
|
try {
|
|
64
|
+
// Connect to GATT server and set up characteristics
|
|
74
65
|
const services = await server?.getPrimaryServices();
|
|
75
66
|
if (!services || services.length === 0) {
|
|
76
67
|
console.error("No services found");
|
|
@@ -109,19 +100,21 @@ const onConnected = async (board, onSuccess) => {
|
|
|
109
100
|
}
|
|
110
101
|
};
|
|
111
102
|
/**
|
|
112
|
-
*
|
|
113
|
-
* @param device
|
|
103
|
+
* Returns UUIDs of all services associated with the device.
|
|
104
|
+
* @param {Device} device - The device.
|
|
105
|
+
* @returns {string[]} Array of service UUIDs.
|
|
114
106
|
*/
|
|
115
107
|
const getAllServiceUUIDs = (device) => {
|
|
116
108
|
return device.services.map((service) => service.uuid);
|
|
117
109
|
};
|
|
118
110
|
/**
|
|
119
|
-
*
|
|
120
|
-
* @param device
|
|
121
|
-
* @param onSuccess
|
|
111
|
+
* Connects to a Bluetooth device.
|
|
112
|
+
* @param {Device} board - The device to connect to.
|
|
113
|
+
* @param {Function} onSuccess - Callback function to execute on successful connection.
|
|
122
114
|
*/
|
|
123
115
|
export const connect = async (board, onSuccess) => {
|
|
124
116
|
try {
|
|
117
|
+
// Request device and set up connection
|
|
125
118
|
const deviceServices = getAllServiceUUIDs(board);
|
|
126
119
|
// setup filter list
|
|
127
120
|
const filters = [];
|
package/src/connect.ts
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
import { Device } from "./devices/types"
|
|
2
|
-
import {
|
|
3
|
-
import { handleMotherboardData, handleProgressorData } from "./data"
|
|
2
|
+
import { handleEntralpiData, handleMotherboardData, handleProgressorData } from "./data"
|
|
4
3
|
|
|
5
4
|
let server: BluetoothRemoteGATTServer
|
|
6
5
|
const receiveBuffer: number[] = []
|
|
7
6
|
|
|
8
7
|
/**
|
|
9
|
-
*
|
|
10
|
-
* @param
|
|
11
|
-
* @param
|
|
8
|
+
* Handles the 'disconnected' event.
|
|
9
|
+
* @param {Event} event - The 'disconnected' event.
|
|
10
|
+
* @param {Device} board - The device that is disconnected.
|
|
12
11
|
*/
|
|
13
12
|
const onDisconnected = (event: Event, board: Device): void => {
|
|
14
13
|
board.device = undefined
|
|
@@ -16,9 +15,9 @@ const onDisconnected = (event: Event, board: Device): void => {
|
|
|
16
15
|
console.log(`Device ${device.name} is disconnected.`)
|
|
17
16
|
}
|
|
18
17
|
/**
|
|
19
|
-
*
|
|
20
|
-
* @param event
|
|
21
|
-
* @param
|
|
18
|
+
* Handles notifications received from a characteristic.
|
|
19
|
+
* @param {Event} event - The notification event.
|
|
20
|
+
* @param {Device} board - The device associated with the characteristic.
|
|
22
21
|
*/
|
|
23
22
|
const handleNotifications = (event: Event, board: Device): void => {
|
|
24
23
|
const characteristic: BluetoothRemoteGATTCharacteristic = event.target as BluetoothRemoteGATTCharacteristic
|
|
@@ -36,42 +35,34 @@ const handleNotifications = (event: Event, board: Device): void => {
|
|
|
36
35
|
if (line.length > 0 && line[line.length - 1] === 13) line.pop() // Remove CR
|
|
37
36
|
const decoder: TextDecoder = new TextDecoder("utf-8")
|
|
38
37
|
const receivedData: string = decoder.decode(new Uint8Array(line))
|
|
39
|
-
handleMotherboardData(
|
|
38
|
+
handleMotherboardData(receivedData)
|
|
40
39
|
}
|
|
41
40
|
} else if (board.name === "ENTRALPI") {
|
|
42
41
|
if (value.buffer) {
|
|
43
42
|
const buffer: ArrayBuffer = value.buffer
|
|
44
43
|
const rawData: DataView = new DataView(buffer)
|
|
45
|
-
const receivedData:
|
|
46
|
-
|
|
47
|
-
notifyCallback({
|
|
48
|
-
uuid: characteristic.uuid,
|
|
49
|
-
value: {
|
|
50
|
-
massTotal: receivedData,
|
|
51
|
-
},
|
|
52
|
-
})
|
|
53
|
-
}
|
|
44
|
+
const receivedData: string = (rawData.getUint16(0) / 100).toFixed(1)
|
|
45
|
+
handleEntralpiData(receivedData)
|
|
54
46
|
}
|
|
55
47
|
} else if (board.name && board.name.startsWith("Progressor")) {
|
|
56
48
|
if (value.buffer) {
|
|
57
49
|
const buffer: ArrayBuffer = value.buffer
|
|
58
50
|
const rawData: DataView = new DataView(buffer)
|
|
59
|
-
handleProgressorData(
|
|
51
|
+
handleProgressorData(rawData)
|
|
60
52
|
}
|
|
61
53
|
} else {
|
|
62
|
-
|
|
63
|
-
notifyCallback({ uuid: characteristic.uuid, value: value })
|
|
64
|
-
}
|
|
54
|
+
console.log(value)
|
|
65
55
|
}
|
|
66
56
|
}
|
|
67
57
|
}
|
|
68
58
|
/**
|
|
69
|
-
*
|
|
70
|
-
* @param
|
|
71
|
-
* @param
|
|
59
|
+
* Handles the 'connected' event.
|
|
60
|
+
* @param {Device} board - The connected device.
|
|
61
|
+
* @param {Function} onSuccess - Callback function to execute on successful connection.
|
|
72
62
|
*/
|
|
73
63
|
const onConnected = async (board: Device, onSuccess: () => void): Promise<void> => {
|
|
74
64
|
try {
|
|
65
|
+
// Connect to GATT server and set up characteristics
|
|
75
66
|
const services: BluetoothRemoteGATTService[] = await server?.getPrimaryServices()
|
|
76
67
|
|
|
77
68
|
if (!services || services.length === 0) {
|
|
@@ -118,19 +109,21 @@ const onConnected = async (board: Device, onSuccess: () => void): Promise<void>
|
|
|
118
109
|
}
|
|
119
110
|
}
|
|
120
111
|
/**
|
|
121
|
-
*
|
|
122
|
-
* @param device
|
|
112
|
+
* Returns UUIDs of all services associated with the device.
|
|
113
|
+
* @param {Device} device - The device.
|
|
114
|
+
* @returns {string[]} Array of service UUIDs.
|
|
123
115
|
*/
|
|
124
116
|
const getAllServiceUUIDs = (device: Device) => {
|
|
125
117
|
return device.services.map((service) => service.uuid)
|
|
126
118
|
}
|
|
127
119
|
/**
|
|
128
|
-
*
|
|
129
|
-
* @param device
|
|
130
|
-
* @param onSuccess
|
|
120
|
+
* Connects to a Bluetooth device.
|
|
121
|
+
* @param {Device} board - The device to connect to.
|
|
122
|
+
* @param {Function} onSuccess - Callback function to execute on successful connection.
|
|
131
123
|
*/
|
|
132
124
|
export const connect = async (board: Device, onSuccess: () => void): Promise<void> => {
|
|
133
125
|
try {
|
|
126
|
+
// Request device and set up connection
|
|
134
127
|
const deviceServices = getAllServiceUUIDs(board)
|
|
135
128
|
|
|
136
129
|
// setup filter list
|
package/src/data.d.ts
CHANGED
|
@@ -1,9 +1,16 @@
|
|
|
1
1
|
export declare const CALIBRATION: never[][];
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
* @param uuid - Unique identifier
|
|
6
|
-
* @param receivedData - Received data string
|
|
3
|
+
* Handles data received from the Motherboard device.
|
|
4
|
+
* @param {string} receivedData - The received data string.
|
|
7
5
|
*/
|
|
8
|
-
export declare const handleMotherboardData: (
|
|
9
|
-
|
|
6
|
+
export declare const handleMotherboardData: (receivedData: string) => void;
|
|
7
|
+
/**
|
|
8
|
+
* Handles data received from the Progressor device.
|
|
9
|
+
* @param {DataView} data - The received data.
|
|
10
|
+
*/
|
|
11
|
+
export declare const handleProgressorData: (data: DataView) => void;
|
|
12
|
+
/**
|
|
13
|
+
* Handles data received from the Entralpi device.
|
|
14
|
+
* @param {string} receivedData - The received data string.
|
|
15
|
+
*/
|
|
16
|
+
export declare const handleEntralpiData: (receivedData: string) => void;
|