@hangtime/grip-connect 0.3.9 → 0.4.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 +81 -65
- package/dist/battery.d.ts +8 -3
- package/dist/battery.js +16 -4
- package/dist/calibration.js +3 -1
- package/dist/commands/kilterboard.js +1 -1
- package/dist/connect.d.ts +3 -2
- package/dist/connect.js +44 -41
- package/dist/data/motherboard.d.ts +6 -2
- package/dist/data/motherboard.js +8 -3
- package/dist/data/progressor.d.ts +6 -2
- package/dist/data/progressor.js +10 -7
- package/dist/firmware.d.ts +12 -0
- package/dist/firmware.js +37 -0
- package/dist/hardware.d.ts +11 -0
- package/dist/hardware.js +25 -0
- package/dist/index.d.ts +6 -2
- package/dist/index.js +8 -4
- package/dist/led.js +4 -4
- package/dist/manufacturer.d.ts +11 -0
- package/dist/manufacturer.js +25 -0
- package/dist/read.d.ts +2 -2
- package/dist/read.js +3 -5
- package/dist/serial.d.ts +11 -0
- package/dist/serial.js +30 -0
- package/dist/text.d.ts +14 -0
- package/dist/text.js +33 -0
- package/dist/write.d.ts +26 -8
- package/dist/write.js +50 -47
- package/package.json +1 -1
- package/src/battery.ts +17 -5
- package/src/calibration.ts +3 -1
- package/src/commands/kilterboard.ts +1 -1
- package/src/connect.ts +49 -40
- package/src/data/motherboard.ts +8 -3
- package/src/data/progressor.ts +10 -7
- package/src/firmware.ts +39 -0
- package/src/hardware.ts +27 -0
- package/src/index.ts +8 -5
- package/src/led.ts +4 -4
- package/src/manufacturer.ts +27 -0
- package/src/read.ts +5 -7
- package/src/serial.ts +32 -0
- package/src/text.ts +35 -0
- package/src/types/download.ts +1 -1
- package/src/write.ts +57 -45
- package/dist/info.d.ts +0 -7
- package/dist/info.js +0 -30
- package/src/info.ts +0 -32
package/README.md
CHANGED
|
@@ -7,8 +7,7 @@ Force-Sensing Hangboards / Dynamometers / Plates / LED system boards used by cli
|
|
|
7
7
|
the [Griptonite Motherboard](https://griptonite.io/shop/motherboard/), [Climbro](https://climbro.com/),
|
|
8
8
|
[mySmartBoard](https://www.smartboard-climbing.com/), [Entralpi](https://entralpi.com/),
|
|
9
9
|
[Tindeq Progressor](https://tindeq.com/) or
|
|
10
|
-
[Weiheng WH-C06](https://weihengmanufacturer.com/products/wh-c06-bluetooth-300kg-hanging-scale/)
|
|
11
|
-
[MAT Muscle Meter](https://www.matassessment.com/musclemeter).
|
|
10
|
+
[Weiheng WH-C06](https://weihengmanufacturer.com/products/wh-c06-bluetooth-300kg-hanging-scale/).
|
|
12
11
|
|
|
13
12
|
And LED system boards from [Aurora Climbing](https://auroraclimbing.com/) like the
|
|
14
13
|
[Kilter Board](https://settercloset.com/pages/the-kilter-board),
|
|
@@ -47,80 +46,97 @@ Simply importing the utilities you need from `@hangtime/grip-connect`.
|
|
|
47
46
|
```
|
|
48
47
|
|
|
49
48
|
```js
|
|
50
|
-
import { Motherboard, active, battery, connect, disconnect,
|
|
49
|
+
import { Motherboard, active, battery, connect, disconnect, firmware, notify, stream } from "@hangtime/grip-connect"
|
|
51
50
|
|
|
52
51
|
const motherboardButton = document.querySelector("#motherboard")
|
|
53
52
|
|
|
54
53
|
motherboardButton.addEventListener("click", () => {
|
|
55
|
-
connect(
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
//
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
54
|
+
connect(
|
|
55
|
+
Motherboard,
|
|
56
|
+
async () => {
|
|
57
|
+
// Listen for stream notifications
|
|
58
|
+
notify((data) => {
|
|
59
|
+
// { massTotal: "0", massMax: "0", massAverage: "0", massLeft: "0", massCenter: "0", massRight: "0" }
|
|
60
|
+
console.log(data)
|
|
61
|
+
})
|
|
62
|
+
|
|
63
|
+
// Check if device is being used
|
|
64
|
+
active((value) => {
|
|
65
|
+
console.log(value)
|
|
66
|
+
})
|
|
67
|
+
|
|
68
|
+
// Read info: battery + firmware
|
|
69
|
+
const batteryLevel = await battery(Motherboard)
|
|
70
|
+
console.log(batteryLevel)
|
|
71
|
+
|
|
72
|
+
const firmwareVersion = await firmware(Motherboard)
|
|
73
|
+
console.log(firmwareVersion)
|
|
74
|
+
|
|
75
|
+
// trigger LEDs
|
|
76
|
+
// await led(Motherboard)
|
|
77
|
+
|
|
78
|
+
// Start weight streaming (for a minute) remove parameter for a continues stream
|
|
79
|
+
await stream(Motherboard, 60000)
|
|
80
|
+
|
|
81
|
+
// Manualy tare the device when the stream is running
|
|
82
|
+
// await tare(5000)
|
|
83
|
+
|
|
84
|
+
// Manually call stop method if stream is continues
|
|
85
|
+
// await stop(Motherboard)
|
|
86
|
+
|
|
87
|
+
// Download data as CSV, JSON, or XML (default: CSV) format => timestamp, frame, battery, samples, masses
|
|
88
|
+
// download('json')
|
|
89
|
+
|
|
90
|
+
// Disconnect from device after we are done
|
|
91
|
+
disconnect(Motherboard)
|
|
92
|
+
},
|
|
93
|
+
(error) => {
|
|
94
|
+
// Optinal custom error handeling
|
|
95
|
+
console.error(error.message)
|
|
96
|
+
},
|
|
97
|
+
)
|
|
89
98
|
})
|
|
90
99
|
```
|
|
91
100
|
|
|
92
|
-
##
|
|
101
|
+
## Device support
|
|
93
102
|
|
|
94
|
-
|
|
103
|
+
- ✅ Griptonite - Motherboard
|
|
104
|
+
- ✅ Tindeq - Progressor
|
|
105
|
+
- ✅ Weiheng - WH-C06
|
|
106
|
+
- By default [watchAdvertisements](https://chromestatus.com/feature/5180688812736512) isn't supported . For Chrome,
|
|
107
|
+
enable it at `chrome://flags/#enable-experimental-web-platform-features`.
|
|
108
|
+
- ✅ Kilter Board
|
|
109
|
+
- ⏳ Entralpi (not verified)
|
|
110
|
+
- ➡️ Climbro
|
|
111
|
+
- ➡️ Smartboard Climbing - mySmartBoard
|
|
112
|
+
|
|
113
|
+
## Features
|
|
114
|
+
|
|
115
|
+
**Help wanted:** Do you own any of the missing devices? Use Google Chrome's Bluetooth Internals
|
|
95
116
|
`chrome://bluetooth-internals/#devices` and press `Start Scan` to look for your device, click on `Inspect` and share all
|
|
96
117
|
available services with us.
|
|
97
118
|
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
- ✅
|
|
101
|
-
- ✅
|
|
102
|
-
-
|
|
103
|
-
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
-
|
|
107
|
-
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
- ✅
|
|
112
|
-
- ✅
|
|
113
|
-
- ✅
|
|
114
|
-
- ✅
|
|
115
|
-
- ✅
|
|
116
|
-
- ✅
|
|
117
|
-
- ✅
|
|
118
|
-
- ✅
|
|
119
|
-
- ✅️ Tare / unladen weight
|
|
120
|
-
- ✅️ Download data (CSV, JSON, XML)
|
|
121
|
-
- ➡️ Endurance
|
|
122
|
-
- ➡️ Rate of Force Development: RFD
|
|
123
|
-
- ➡️ Critical Force
|
|
119
|
+
| | Motherboard | Progressor | WH-C06 | Entralpi | Kilter Board | Climbro | mySmartBoard |
|
|
120
|
+
| ---------------------------------------------------------------------------------------- | ----------- | ---------- | ------ | -------- | ------------ | ------- | ------------ |
|
|
121
|
+
| [Battery](https://stevie-ray.github.io/hangtime-grip-connect/api/battery.html) | ✅ | ✅ | | | | | |
|
|
122
|
+
| [Calibration](https://stevie-ray.github.io/hangtime-grip-connect/api/calibration.html) | ✅ | | | | | | |
|
|
123
|
+
| [Connect](https://stevie-ray.github.io/hangtime-grip-connect/api/connect.html) | ✅ | ✅ | ✅ | ✅ | ✅ | | |
|
|
124
|
+
| [Disconnect](https://stevie-ray.github.io/hangtime-grip-connect/api/disconnect.html) | ✅ | ✅ | ✅ | ✅ | ✅ | | |
|
|
125
|
+
| [Download](https://stevie-ray.github.io/hangtime-grip-connect/api/download.html) | ✅ | ✅ | | | | | |
|
|
126
|
+
| [Firmware](https://stevie-ray.github.io/hangtime-grip-connect/api/firmware.html) | ✅ | ✅ | | | | | |
|
|
127
|
+
| [Hardware](https://stevie-ray.github.io/hangtime-grip-connect/api/hardware.html) | ✅ | | | | | | |
|
|
128
|
+
| [isActive](https://stevie-ray.github.io/hangtime-grip-connect/api/is-active.html) | ✅ | ✅ | ✅ | ✅ | | | |
|
|
129
|
+
| [isConnected](https://stevie-ray.github.io/hangtime-grip-connect/api/is-connected.html) | ✅ | ✅ | ✅ | ✅ | ✅ | | |
|
|
130
|
+
| [Led](https://stevie-ray.github.io/hangtime-grip-connect/api/led.html) | ✅ | | | | ✅ | | |
|
|
131
|
+
| [Manufacturer](https://stevie-ray.github.io/hangtime-grip-connect/api/manufacturer.html) | ✅ | | | | | | |
|
|
132
|
+
| [Notify](https://stevie-ray.github.io/hangtime-grip-connect/api/notify.html) | ✅ | ✅ | ✅ | ✅ | | | |
|
|
133
|
+
| [Read](https://stevie-ray.github.io/hangtime-grip-connect/api/read.html) | ✅ | | | | | | |
|
|
134
|
+
| [Serial](https://stevie-ray.github.io/hangtime-grip-connect/api/serial.html) | ✅ | | | | | | |
|
|
135
|
+
| [Stop](https://stevie-ray.github.io/hangtime-grip-connect/api/stop.html) | ✅ | ✅ | | | | | |
|
|
136
|
+
| [Stream](https://stevie-ray.github.io/hangtime-grip-connect/api/stream.html) | ✅ | ✅ | | | | | |
|
|
137
|
+
| [Tare](https://stevie-ray.github.io/hangtime-grip-connect/api/tare.html) | ✅ | ✅ | ✅ | ✅ | | | |
|
|
138
|
+
| [Text](https://stevie-ray.github.io/hangtime-grip-connect/api/text.html) | ✅ | | | | | | |
|
|
139
|
+
| [Write](https://stevie-ray.github.io/hangtime-grip-connect/api/write.html) | ✅ | ✅ | | | | | |
|
|
124
140
|
|
|
125
141
|
## Development
|
|
126
142
|
|
package/dist/battery.d.ts
CHANGED
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
import type { Device } from "./types/devices";
|
|
2
2
|
/**
|
|
3
3
|
* Retrieves battery or voltage information from the device.
|
|
4
|
-
*
|
|
5
|
-
*
|
|
4
|
+
* - For Motherboard devices, it reads the battery level.
|
|
5
|
+
* - For Progressor devices, it sends a command to retrieve battery voltage information.
|
|
6
|
+
*
|
|
7
|
+
* @param {Device} board - The device from which to retrieve battery information.
|
|
8
|
+
* @returns {Promise<string | undefined>} A Promise that resolves with the battery or voltage information,
|
|
9
|
+
* or rejects with an error if the device is not connected.
|
|
10
|
+
* @throws {Error} Throws an error if the device is not connected.
|
|
6
11
|
*/
|
|
7
|
-
export declare const battery: (board: Device) => Promise<
|
|
12
|
+
export declare const battery: (board: Device) => Promise<string | undefined>;
|
package/dist/battery.js
CHANGED
|
@@ -5,8 +5,13 @@ import { Motherboard, Progressor } from "./devices";
|
|
|
5
5
|
import { ProgressorCommands } from "./commands";
|
|
6
6
|
/**
|
|
7
7
|
* Retrieves battery or voltage information from the device.
|
|
8
|
-
*
|
|
9
|
-
*
|
|
8
|
+
* - For Motherboard devices, it reads the battery level.
|
|
9
|
+
* - For Progressor devices, it sends a command to retrieve battery voltage information.
|
|
10
|
+
*
|
|
11
|
+
* @param {Device} board - The device from which to retrieve battery information.
|
|
12
|
+
* @returns {Promise<string | undefined>} A Promise that resolves with the battery or voltage information,
|
|
13
|
+
* or rejects with an error if the device is not connected.
|
|
14
|
+
* @throws {Error} Throws an error if the device is not connected.
|
|
10
15
|
*/
|
|
11
16
|
export const battery = async (board) => {
|
|
12
17
|
// Check if the device is connected
|
|
@@ -14,12 +19,19 @@ export const battery = async (board) => {
|
|
|
14
19
|
// If the device is connected and it is a Motherboard device
|
|
15
20
|
if (board.filters.some((filter) => filter.name === "Motherboard")) {
|
|
16
21
|
// Read battery level information from the Motherboard
|
|
17
|
-
await read(Motherboard, "battery", "level", 250);
|
|
22
|
+
return await read(Motherboard, "battery", "level", 250);
|
|
18
23
|
}
|
|
19
24
|
// If the device is connected and its name starts with "Progressor"
|
|
20
25
|
if (board.filters.some((filter) => filter.namePrefix === "Progressor")) {
|
|
21
26
|
// Write command to get battery voltage information to the Progressor
|
|
22
|
-
|
|
27
|
+
let response = undefined;
|
|
28
|
+
await write(Progressor, "progressor", "tx", ProgressorCommands.GET_BATT_VLTG, 250, (data) => {
|
|
29
|
+
response = data;
|
|
30
|
+
});
|
|
31
|
+
return response;
|
|
23
32
|
}
|
|
33
|
+
// If device is not found, return undefined
|
|
34
|
+
return;
|
|
24
35
|
}
|
|
36
|
+
throw new Error("Not connected.");
|
|
25
37
|
};
|
package/dist/calibration.js
CHANGED
|
@@ -13,7 +13,9 @@ export const calibration = async (board) => {
|
|
|
13
13
|
// If the device is connected, and it is a Motherboard device
|
|
14
14
|
if (board.filters.some((filter) => filter.name === "Motherboard")) {
|
|
15
15
|
// Write the command to get calibration data to the device
|
|
16
|
-
await write(Motherboard, "uart", "tx", MotherboardCommands.GET_CALIBRATION, 2500)
|
|
16
|
+
await write(Motherboard, "uart", "tx", MotherboardCommands.GET_CALIBRATION, 2500, (data) => {
|
|
17
|
+
console.log(data);
|
|
18
|
+
});
|
|
17
19
|
}
|
|
18
20
|
}
|
|
19
21
|
};
|
package/dist/connect.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import type { Device } from "./types/devices";
|
|
|
2
2
|
/**
|
|
3
3
|
* Connects to a Bluetooth device.
|
|
4
4
|
* @param {Device} board - The device to connect to.
|
|
5
|
-
* @param {Function} onSuccess -
|
|
5
|
+
* @param {Function} [onSuccess] - Optional callback function to execute on successful connection. Default logs success.
|
|
6
|
+
* @param {Function} [onError] - Optional callback function to execute on error. Default logs the error.
|
|
6
7
|
*/
|
|
7
|
-
export declare const connect: (board: Device, onSuccess
|
|
8
|
+
export declare const connect: (board: Device, onSuccess?: () => void, onError?: (error: Error) => void) => Promise<void>;
|
package/dist/connect.js
CHANGED
|
@@ -9,7 +9,7 @@ const receiveBuffer = [];
|
|
|
9
9
|
const onDisconnected = (event, board) => {
|
|
10
10
|
board.device = undefined;
|
|
11
11
|
const device = event.target;
|
|
12
|
-
|
|
12
|
+
throw new Error(`Device ${device.name} is disconnected.`);
|
|
13
13
|
};
|
|
14
14
|
/**
|
|
15
15
|
* Handles notifications received from a characteristic.
|
|
@@ -61,46 +61,40 @@ const handleNotifications = (event, board) => {
|
|
|
61
61
|
* @param {Function} onSuccess - Callback function to execute on successful connection.
|
|
62
62
|
*/
|
|
63
63
|
const onConnected = async (board, onSuccess) => {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
const
|
|
77
|
-
|
|
78
|
-
const
|
|
79
|
-
if (
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
handleNotifications(event, board);
|
|
88
|
-
});
|
|
89
|
-
}
|
|
64
|
+
// Connect to GATT server and set up characteristics
|
|
65
|
+
const services = await server.getPrimaryServices();
|
|
66
|
+
if (!services || services.length === 0) {
|
|
67
|
+
throw new Error("No services found");
|
|
68
|
+
}
|
|
69
|
+
for (const service of services) {
|
|
70
|
+
const matchingService = board.services.find((boardService) => boardService.uuid === service.uuid);
|
|
71
|
+
if (matchingService) {
|
|
72
|
+
// Android bug: Introduce a delay before getting characteristics
|
|
73
|
+
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
74
|
+
const characteristics = await service.getCharacteristics();
|
|
75
|
+
for (const characteristic of matchingService.characteristics) {
|
|
76
|
+
const matchingCharacteristic = characteristics.find((char) => char.uuid === characteristic.uuid);
|
|
77
|
+
if (matchingCharacteristic) {
|
|
78
|
+
const element = matchingService.characteristics.find((char) => char.uuid === matchingCharacteristic.uuid);
|
|
79
|
+
if (element) {
|
|
80
|
+
element.characteristic = matchingCharacteristic;
|
|
81
|
+
// notify
|
|
82
|
+
if (element.id === "rx") {
|
|
83
|
+
matchingCharacteristic.startNotifications();
|
|
84
|
+
matchingCharacteristic.addEventListener("characteristicvaluechanged", (event) => {
|
|
85
|
+
handleNotifications(event, board);
|
|
86
|
+
});
|
|
90
87
|
}
|
|
91
88
|
}
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
}
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
throw new Error(`Characteristic ${characteristic.uuid} not found in service ${service.uuid}`);
|
|
95
92
|
}
|
|
96
93
|
}
|
|
97
94
|
}
|
|
98
|
-
// Call the onSuccess callback after successful connection and setup
|
|
99
|
-
onSuccess();
|
|
100
|
-
}
|
|
101
|
-
catch (error) {
|
|
102
|
-
console.error(error);
|
|
103
95
|
}
|
|
96
|
+
// Call the onSuccess callback after successful connection and setup
|
|
97
|
+
onSuccess();
|
|
104
98
|
};
|
|
105
99
|
/**
|
|
106
100
|
* Returns UUIDs of all services associated with the device.
|
|
@@ -113,9 +107,10 @@ const getAllServiceUUIDs = (device) => {
|
|
|
113
107
|
/**
|
|
114
108
|
* Connects to a Bluetooth device.
|
|
115
109
|
* @param {Device} board - The device to connect to.
|
|
116
|
-
* @param {Function} onSuccess -
|
|
110
|
+
* @param {Function} [onSuccess] - Optional callback function to execute on successful connection. Default logs success.
|
|
111
|
+
* @param {Function} [onError] - Optional callback function to execute on error. Default logs the error.
|
|
117
112
|
*/
|
|
118
|
-
export const connect = async (board, onSuccess) => {
|
|
113
|
+
export const connect = async (board, onSuccess = () => console.log("Connected successfully"), onError = (error) => console.error(error)) => {
|
|
119
114
|
try {
|
|
120
115
|
// Request device and set up connection
|
|
121
116
|
const deviceServices = getAllServiceUUIDs(board);
|
|
@@ -128,8 +123,7 @@ export const connect = async (board, onSuccess) => {
|
|
|
128
123
|
});
|
|
129
124
|
board.device = device;
|
|
130
125
|
if (!board.device.gatt) {
|
|
131
|
-
|
|
132
|
-
return;
|
|
126
|
+
throw new Error("GATT is not available on this device");
|
|
133
127
|
}
|
|
134
128
|
board.device.addEventListener("gattserverdisconnected", (event) => {
|
|
135
129
|
onDisconnected(event, board);
|
|
@@ -145,8 +139,17 @@ export const connect = async (board, onSuccess) => {
|
|
|
145
139
|
handleWHC06Data(manufacturerData);
|
|
146
140
|
}
|
|
147
141
|
});
|
|
142
|
+
// When the companyIdentifier is provided we want to get manufacturerData using watchAdvertisements.
|
|
148
143
|
if (optionalManufacturerData.length) {
|
|
149
|
-
|
|
144
|
+
// Receive events when the system receives an advertisement packet from a watched device.
|
|
145
|
+
// To use this function in Chrome: chrome://flags/#enable-experimental-web-platform-features has to be enabled.
|
|
146
|
+
// More info: https://chromestatus.com/feature/5180688812736512
|
|
147
|
+
if (typeof board.device.watchAdvertisements === "function") {
|
|
148
|
+
await board.device.watchAdvertisements();
|
|
149
|
+
}
|
|
150
|
+
else {
|
|
151
|
+
throw new Error("watchAdvertisements isn't supported. For Chrome, enable it at chrome://flags/#enable-experimental-web-platform-features.");
|
|
152
|
+
}
|
|
150
153
|
}
|
|
151
154
|
server = await board.device.gatt.connect();
|
|
152
155
|
if (server.connected) {
|
|
@@ -154,6 +157,6 @@ export const connect = async (board, onSuccess) => {
|
|
|
154
157
|
}
|
|
155
158
|
}
|
|
156
159
|
catch (error) {
|
|
157
|
-
|
|
160
|
+
onError(error);
|
|
158
161
|
}
|
|
159
162
|
};
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
export declare const CALIBRATION: never[][];
|
|
2
2
|
/**
|
|
3
|
-
* Handles data received from the Motherboard device.
|
|
4
|
-
*
|
|
3
|
+
* Handles data received from the Motherboard device. Processes hex-encoded streaming packets
|
|
4
|
+
* to extract samples, calibrate masses, and update running averages of mass data.
|
|
5
|
+
* If the received data is not a valid hex packet, it returns the unprocessed data.
|
|
6
|
+
*
|
|
7
|
+
* @param {string} receivedData - The raw data received from the Motherboard device.
|
|
8
|
+
* @returns {void}
|
|
5
9
|
*/
|
|
6
10
|
export declare const handleMotherboardData: (receivedData: string) => void;
|
package/dist/data/motherboard.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { notifyCallback } from "./../notify";
|
|
2
|
+
import { writeCallback } from "./../write";
|
|
2
3
|
import { applyTare } from "./../tare";
|
|
3
4
|
import { MotherboardCommands } from "./../commands";
|
|
4
5
|
import { checkActivity } from "./../is-active";
|
|
@@ -51,8 +52,12 @@ const applyCalibration = (sample, calibration) => {
|
|
|
51
52
|
return sign * final;
|
|
52
53
|
};
|
|
53
54
|
/**
|
|
54
|
-
* Handles data received from the Motherboard device.
|
|
55
|
-
*
|
|
55
|
+
* Handles data received from the Motherboard device. Processes hex-encoded streaming packets
|
|
56
|
+
* to extract samples, calibrate masses, and update running averages of mass data.
|
|
57
|
+
* If the received data is not a valid hex packet, it returns the unprocessed data.
|
|
58
|
+
*
|
|
59
|
+
* @param {string} receivedData - The raw data received from the Motherboard device.
|
|
60
|
+
* @returns {void}
|
|
56
61
|
*/
|
|
57
62
|
export const handleMotherboardData = (receivedData) => {
|
|
58
63
|
const receivedTime = Date.now();
|
|
@@ -131,6 +136,6 @@ export const handleMotherboardData = (receivedData) => {
|
|
|
131
136
|
}
|
|
132
137
|
else {
|
|
133
138
|
// unhandled data
|
|
134
|
-
|
|
139
|
+
writeCallback(receivedData);
|
|
135
140
|
}
|
|
136
141
|
};
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Handles data received from the Progressor device
|
|
3
|
-
*
|
|
2
|
+
* Handles data received from the Progressor device, processes weight measurements,
|
|
3
|
+
* and updates mass data including maximum and average values.
|
|
4
|
+
* It also handles command responses for retrieving device information.
|
|
5
|
+
*
|
|
6
|
+
* @param {DataView} data - The raw binary data received from the Progressor device.
|
|
7
|
+
* @returns {void}
|
|
4
8
|
*/
|
|
5
9
|
export declare const handleProgressorData: (data: DataView) => void;
|
package/dist/data/progressor.js
CHANGED
|
@@ -2,7 +2,7 @@ import { notifyCallback } from "./../notify";
|
|
|
2
2
|
import { applyTare } from "./../tare";
|
|
3
3
|
import { checkActivity } from "./../is-active";
|
|
4
4
|
import { ProgressorCommands, ProgressorResponses } from "./../commands/progressor";
|
|
5
|
-
import { lastWrite } from "./../write";
|
|
5
|
+
import { lastWrite, writeCallback } from "./../write";
|
|
6
6
|
import struct from "./../struct";
|
|
7
7
|
import { DownloadPackets } from "./../download";
|
|
8
8
|
// Constants
|
|
@@ -11,8 +11,12 @@ let MASS_AVERAGE = "0";
|
|
|
11
11
|
let MASS_TOTAL_SUM = 0;
|
|
12
12
|
let DATAPOINT_COUNT = 0;
|
|
13
13
|
/**
|
|
14
|
-
* Handles data received from the Progressor device
|
|
15
|
-
*
|
|
14
|
+
* Handles data received from the Progressor device, processes weight measurements,
|
|
15
|
+
* and updates mass data including maximum and average values.
|
|
16
|
+
* It also handles command responses for retrieving device information.
|
|
17
|
+
*
|
|
18
|
+
* @param {DataView} data - The raw binary data received from the Progressor device.
|
|
19
|
+
* @returns {void}
|
|
16
20
|
*/
|
|
17
21
|
export const handleProgressorData = (data) => {
|
|
18
22
|
const receivedTime = Date.now();
|
|
@@ -55,8 +59,7 @@ export const handleProgressorData = (data) => {
|
|
|
55
59
|
return;
|
|
56
60
|
let value = "";
|
|
57
61
|
if (lastWrite === ProgressorCommands.GET_BATT_VLTG) {
|
|
58
|
-
|
|
59
|
-
value = `ℹ️ Battery level: ${vdd} mV`;
|
|
62
|
+
value = new DataView(data.buffer, 2).getUint32(0, true).toString();
|
|
60
63
|
}
|
|
61
64
|
else if (lastWrite === ProgressorCommands.GET_FW_VERSION) {
|
|
62
65
|
value = new TextDecoder().decode(data.buffer.slice(2));
|
|
@@ -64,12 +67,12 @@ export const handleProgressorData = (data) => {
|
|
|
64
67
|
else if (lastWrite === ProgressorCommands.GET_ERR_INFO) {
|
|
65
68
|
value = new TextDecoder().decode(data.buffer.slice(2));
|
|
66
69
|
}
|
|
67
|
-
|
|
70
|
+
writeCallback(value);
|
|
68
71
|
}
|
|
69
72
|
else if (kind === ProgressorResponses.LOW_BATTERY_WARNING) {
|
|
70
73
|
console.warn("⚠️ Low power detected. Please consider connecting to a power source.");
|
|
71
74
|
}
|
|
72
75
|
else {
|
|
73
|
-
|
|
76
|
+
throw new Error(`Unknown message kind detected: ${kind}`);
|
|
74
77
|
}
|
|
75
78
|
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { Device } from "./types/devices";
|
|
2
|
+
/**
|
|
3
|
+
* Retrieves firmware version from the device.
|
|
4
|
+
* - For Motherboard devices, it reads the firmare version.
|
|
5
|
+
* - For Progressor devices, it sends a command to retrieve firware version.
|
|
6
|
+
*
|
|
7
|
+
* @param {Device} board - The device from which to retrieve firmware version.
|
|
8
|
+
* @returns {Promise<string>} A Promise that resolves with the firmware version,
|
|
9
|
+
* or rejects with an error if the device is not connected.
|
|
10
|
+
* @throws {Error} Throws an error if the device is not connected.
|
|
11
|
+
*/
|
|
12
|
+
export declare const firmware: (board: Device) => Promise<string | undefined>;
|
package/dist/firmware.js
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { write } from "./write";
|
|
2
|
+
import { read } from "./read";
|
|
3
|
+
import { isConnected } from "./is-connected";
|
|
4
|
+
import { Motherboard, Progressor } from "./devices";
|
|
5
|
+
import { ProgressorCommands } from "./commands";
|
|
6
|
+
/**
|
|
7
|
+
* Retrieves firmware version from the device.
|
|
8
|
+
* - For Motherboard devices, it reads the firmare version.
|
|
9
|
+
* - For Progressor devices, it sends a command to retrieve firware version.
|
|
10
|
+
*
|
|
11
|
+
* @param {Device} board - The device from which to retrieve firmware version.
|
|
12
|
+
* @returns {Promise<string>} A Promise that resolves with the firmware version,
|
|
13
|
+
* or rejects with an error if the device is not connected.
|
|
14
|
+
* @throws {Error} Throws an error if the device is not connected.
|
|
15
|
+
*/
|
|
16
|
+
export const firmware = async (board) => {
|
|
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 (board.filters.some((filter) => filter.name === "Motherboard")) {
|
|
21
|
+
// Read firmware version from the Motherboard
|
|
22
|
+
return await read(Motherboard, "device", "firmware", 250);
|
|
23
|
+
}
|
|
24
|
+
// If the device is connected and its name starts with "Progressor"
|
|
25
|
+
if (board.filters.some((filter) => filter.namePrefix === "Progressor")) {
|
|
26
|
+
// Write command to get firmware version information to the Progressor
|
|
27
|
+
let response = undefined;
|
|
28
|
+
await write(Progressor, "progressor", "tx", ProgressorCommands.GET_FW_VERSION, 250, (data) => {
|
|
29
|
+
response = data;
|
|
30
|
+
});
|
|
31
|
+
return response;
|
|
32
|
+
}
|
|
33
|
+
// If device is not found, return undefined
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
throw new Error("Not connected.");
|
|
37
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Device } from "./types/devices";
|
|
2
|
+
/**
|
|
3
|
+
* Retrieves hardware version from the device.
|
|
4
|
+
* - For Motherboard devices, it reads the hardware version.
|
|
5
|
+
*
|
|
6
|
+
* @param {Device} board - The device from which to retrieve hardware version.
|
|
7
|
+
* @returns {Promise<string>} A Promise that resolves with the hardware version,
|
|
8
|
+
* or rejects with an error if the device is not connected.
|
|
9
|
+
* @throws {Error} Throws an error if the device is not connected.
|
|
10
|
+
*/
|
|
11
|
+
export declare const hardware: (board: Device) => Promise<string | undefined>;
|
package/dist/hardware.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { read } from "./read";
|
|
2
|
+
import { isConnected } from "./is-connected";
|
|
3
|
+
import { Motherboard } from "./devices";
|
|
4
|
+
/**
|
|
5
|
+
* Retrieves hardware version from the device.
|
|
6
|
+
* - For Motherboard devices, it reads the hardware version.
|
|
7
|
+
*
|
|
8
|
+
* @param {Device} board - The device from which to retrieve hardware version.
|
|
9
|
+
* @returns {Promise<string>} A Promise that resolves with the hardware version,
|
|
10
|
+
* or rejects with an error if the device is not connected.
|
|
11
|
+
* @throws {Error} Throws an error if the device is not connected.
|
|
12
|
+
*/
|
|
13
|
+
export const hardware = async (board) => {
|
|
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 (board.filters.some((filter) => filter.name === "Motherboard")) {
|
|
18
|
+
// Read hardware version from the Motherboard
|
|
19
|
+
return await read(Motherboard, "device", "hardware", 250);
|
|
20
|
+
}
|
|
21
|
+
// If device is not found, return undefined
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
throw new Error("Not connected.");
|
|
25
|
+
};
|
package/dist/index.d.ts
CHANGED
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
export { Climbro, Entralpi, KilterBoard, Motherboard, mySmartBoard, WHC06, Progressor } from "./devices/index";
|
|
2
|
-
export { battery } from "./battery";
|
|
3
2
|
export { calibration } from "./calibration";
|
|
4
3
|
export { download } from "./download";
|
|
5
4
|
export { connect } from "./connect";
|
|
6
5
|
export { disconnect } from "./disconnect";
|
|
7
6
|
export { active, isActive } from "./is-active";
|
|
8
7
|
export { isConnected } from "./is-connected";
|
|
9
|
-
export {
|
|
8
|
+
export { battery } from "./battery";
|
|
9
|
+
export { firmware } from "./firmware";
|
|
10
|
+
export { hardware } from "./hardware";
|
|
11
|
+
export { manufacturer } from "./manufacturer";
|
|
12
|
+
export { text } from "./text";
|
|
13
|
+
export { serial } from "./serial";
|
|
10
14
|
export { led } from "./led";
|
|
11
15
|
export { notify } from "./notify";
|
|
12
16
|
export { stop } from "./stop";
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
// Export device types
|
|
2
2
|
export { Climbro, Entralpi, KilterBoard, Motherboard, mySmartBoard, WHC06, Progressor } from "./devices/index";
|
|
3
|
-
// Export battery related functions
|
|
4
|
-
export { battery } from "./battery";
|
|
5
3
|
// Export calibration function
|
|
6
4
|
export { calibration } from "./calibration";
|
|
7
5
|
// Export download function
|
|
@@ -11,8 +9,14 @@ export { connect } from "./connect";
|
|
|
11
9
|
export { disconnect } from "./disconnect";
|
|
12
10
|
export { active, isActive } from "./is-active";
|
|
13
11
|
export { isConnected } from "./is-connected";
|
|
14
|
-
// Export information retrieval
|
|
15
|
-
export {
|
|
12
|
+
// Export information retrieval functions
|
|
13
|
+
export { battery } from "./battery";
|
|
14
|
+
export { firmware } from "./firmware";
|
|
15
|
+
// Export "Motherboard exclusive" functions
|
|
16
|
+
export { hardware } from "./hardware";
|
|
17
|
+
export { manufacturer } from "./manufacturer";
|
|
18
|
+
export { text } from "./text";
|
|
19
|
+
export { serial } from "./serial";
|
|
16
20
|
// Export led retrieval function
|
|
17
21
|
export { led } from "./led";
|
|
18
22
|
// Export notification related function
|