@hangtime/grip-connect 0.2.0 → 0.2.1
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 +8 -5
- package/package.json +2 -2
- package/src/battery.ts +4 -4
- package/src/calibration.ts +1 -1
- package/src/commands/index.ts +2 -2
- package/src/commands/{tindeq.ts → progressor.ts} +7 -3
- package/src/commands/types.ts +5 -5
- package/src/connect.ts +64 -5
- package/src/devices/index.ts +1 -1
- package/src/devices/{tindeq.ts → progressor.ts} +17 -5
- package/src/index.ts +1 -1
- package/src/info.ts +6 -6
- package/src/stop.ts +5 -5
- package/src/stream.ts +6 -6
- package/src/write.ts +7 -4
- package/src/battery.d.ts +0 -6
- package/src/battery.js +0 -19
- package/src/calibration.d.ts +0 -6
- package/src/calibration.js +0 -15
- package/src/characteristic.d.ts +0 -9
- package/src/characteristic.js +0 -15
- package/src/commands/climbro.d.ts +0 -6
- package/src/commands/climbro.js +0 -5
- package/src/commands/entralpi.d.ts +0 -6
- package/src/commands/entralpi.js +0 -5
- package/src/commands/index.d.ts +0 -5
- package/src/commands/index.js +0 -5
- package/src/commands/motherboard.d.ts +0 -6
- package/src/commands/motherboard.js +0 -13
- package/src/commands/smartboard.d.ts +0 -6
- package/src/commands/smartboard.js +0 -5
- package/src/commands/tindeq.d.ts +0 -11
- package/src/commands/tindeq.js +0 -23
- package/src/commands/types.d.ts +0 -18
- package/src/commands/types.js +0 -1
- package/src/connect.d.ts +0 -7
- package/src/connect.js +0 -156
- package/src/data.d.ts +0 -8
- package/src/data.js +0 -109
- package/src/devices/climbro.d.ts +0 -2
- package/src/devices/climbro.js +0 -4
- package/src/devices/entralpi.d.ts +0 -2
- package/src/devices/entralpi.js +0 -52
- package/src/devices/index.d.ts +0 -5
- package/src/devices/index.js +0 -5
- package/src/devices/motherboard.d.ts +0 -2
- package/src/devices/motherboard.js +0 -79
- package/src/devices/smartboard.d.ts +0 -2
- package/src/devices/smartboard.js +0 -4
- package/src/devices/tindeq.d.ts +0 -2
- package/src/devices/tindeq.js +0 -22
- package/src/devices/types.d.ts +0 -20
- package/src/devices/types.js +0 -1
- package/src/disconnect.d.ts +0 -6
- package/src/disconnect.js +0 -10
- package/src/index.d.ts +0 -10
- package/src/index.js +0 -12
- package/src/info.d.ts +0 -6
- package/src/info.js +0 -23
- package/src/is-connected.d.ts +0 -7
- package/src/is-connected.js +0 -10
- package/src/notify.d.ts +0 -4
- package/src/notify.js +0 -6
- package/src/read.d.ts +0 -6
- package/src/read.js +0 -45
- package/src/stop.d.ts +0 -6
- package/src/stop.js +0 -18
- package/src/stream.d.ts +0 -6
- package/src/stream.js +0 -35
- package/src/write.d.ts +0 -7
- package/src/write.js +0 -35
package/README.md
CHANGED
|
@@ -94,13 +94,16 @@ motherboardButton.addEventListener("click", () => {
|
|
|
94
94
|
A special thank you to:
|
|
95
95
|
|
|
96
96
|
- [@CassimLadha](https://github.com/CassimLadha) for sharing insights on reading the Motherboards data.
|
|
97
|
-
- [@donaldharvey](https://github.com/donaldharvey) for a valuable example on connecting to the
|
|
98
|
-
- [@ecstrema](https://github.com/ecstrema) for providing
|
|
97
|
+
- [@donaldharvey](https://github.com/donaldharvey) for a valuable example on connecting to the Motherboard.
|
|
98
|
+
- [@ecstrema](https://github.com/ecstrema) for providing [examples](https://github.com/ecstrema/entralpi-games) on how
|
|
99
|
+
to play games with the Entralpi.
|
|
100
|
+
- [@StuartLittlefair](https://github.com/StuartLittlefair) for his
|
|
101
|
+
[PyTindeq](https://github.com/StuartLittlefair/PyTindeq) implementation.
|
|
99
102
|
|
|
100
|
-
##
|
|
103
|
+
## Disclaimer
|
|
101
104
|
|
|
102
|
-
THIS SOFTWARE IS NOT
|
|
103
|
-
ARE
|
|
105
|
+
THIS SOFTWARE IS NOT OFFICIALLY SUPPORTED, SUPPLIED OR MAINTAINED BY THE DEVICE MANUFACTURER. BY USING THE SOFTWARE YOU
|
|
106
|
+
ARE ACKNOWLEDGING THIS AND UNDERSTAND THAT USING THIS SOFTWARE WILL INVALIDATE THE MANUFACTURERS WARRANTY.
|
|
104
107
|
|
|
105
108
|
## License
|
|
106
109
|
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hangtime/grip-connect",
|
|
3
|
-
"version": "0.2.
|
|
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",
|
|
3
|
+
"version": "0.2.1",
|
|
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": {
|
|
7
7
|
"build": "tsc --build"
|
package/src/battery.ts
CHANGED
|
@@ -2,8 +2,8 @@ import { Device } from "./devices/types"
|
|
|
2
2
|
import { write } from "./write"
|
|
3
3
|
import { read } from "./read"
|
|
4
4
|
import { isConnected } from "./is-connected"
|
|
5
|
-
import { Motherboard,
|
|
6
|
-
import {
|
|
5
|
+
import { Motherboard, Progressor } from "./devices"
|
|
6
|
+
import { ProgressorCommands } from "./commands"
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* Get Battery / Voltage information
|
|
@@ -14,8 +14,8 @@ export const battery = async (board: Device): Promise<void> => {
|
|
|
14
14
|
if (board.name === "Motherboard") {
|
|
15
15
|
await read(Motherboard, "battery", "level", 250)
|
|
16
16
|
}
|
|
17
|
-
if (board.name
|
|
18
|
-
await write(
|
|
17
|
+
if (board.name && board.name.startsWith("Progressor")) {
|
|
18
|
+
await write(Progressor, "progressor", "tx", ProgressorCommands.GET_BATT_VLTG, 250)
|
|
19
19
|
}
|
|
20
20
|
}
|
|
21
21
|
}
|
package/src/calibration.ts
CHANGED
|
@@ -11,7 +11,7 @@ import { MotherboardCommands } from "./commands"
|
|
|
11
11
|
export const calibration = async (board: Device): Promise<void> => {
|
|
12
12
|
if (isConnected(board)) {
|
|
13
13
|
if (board.name === "Motherboard") {
|
|
14
|
-
await write(Motherboard, "uart", "tx",
|
|
14
|
+
await write(Motherboard, "uart", "tx", MotherboardCommands.GET_CALIBRATION, 2500)
|
|
15
15
|
}
|
|
16
16
|
}
|
|
17
17
|
}
|
package/src/commands/index.ts
CHANGED
|
@@ -4,6 +4,6 @@ export { EntralpiCommands } from "./entralpi"
|
|
|
4
4
|
|
|
5
5
|
export { MotherboardCommands } from "./motherboard"
|
|
6
6
|
|
|
7
|
-
export {
|
|
7
|
+
export { ProgressorCommands } from "./progressor"
|
|
8
8
|
|
|
9
|
-
export {
|
|
9
|
+
export { SmartBoardCommands } from "./smartboard"
|
|
@@ -3,7 +3,7 @@ import { Commands } from "../commands/types"
|
|
|
3
3
|
* Warning:
|
|
4
4
|
* Using other commands can seriously harm your device
|
|
5
5
|
*/
|
|
6
|
-
export const
|
|
6
|
+
export const ProgressorCommands: Commands = {
|
|
7
7
|
TARE_SCALE: "d", // 0x64,
|
|
8
8
|
START_WEIGHT_MEAS: "e", // 0x65,
|
|
9
9
|
STOP_WEIGHT_MEAS: "f", // 0x66,
|
|
@@ -11,14 +11,18 @@ export const TindeqCommands: Commands = {
|
|
|
11
11
|
START_PEAK_RFD_MEAS_SERIES: "h", // 0x68,
|
|
12
12
|
ADD_CALIB_POINT: "i", // 0x69,
|
|
13
13
|
SAVE_CALIB: "j", // 0x6a,
|
|
14
|
-
|
|
14
|
+
GET_FW_VERSION: "k", // 0x6b,
|
|
15
15
|
GET_ERR_INFO: "l", // 0x6c,
|
|
16
16
|
CLR_ERR_INFO: "m", // 0x6d,
|
|
17
17
|
SLEEP: "n", // 0x6e,
|
|
18
18
|
GET_BATT_VLTG: "o", // 0x6f,
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
|
|
21
|
+
/**
|
|
22
|
+
* The Progressor returns a Uint8Array.
|
|
23
|
+
* The first item [0] is the type of response it returns
|
|
24
|
+
*/
|
|
25
|
+
export const ProgressorResponses = {
|
|
22
26
|
COMMAND_RESPONSE: 0,
|
|
23
27
|
WEIGHT_MEASURE: 1,
|
|
24
28
|
LOW_BATTERY_WARNING: 2,
|
package/src/commands/types.ts
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
export interface Commands {
|
|
2
|
-
// Motherboard,
|
|
2
|
+
// Motherboard, Progressor
|
|
3
3
|
START_WEIGHT_MEAS?: string
|
|
4
4
|
STOP_WEIGHT_MEAS?: string
|
|
5
5
|
SLEEP?: number | string
|
|
6
|
-
// Motherboard
|
|
7
|
-
GET_TEXT?: string
|
|
8
6
|
GET_SERIAL?: string
|
|
7
|
+
// Griptonite Motherboard
|
|
8
|
+
GET_TEXT?: string
|
|
9
9
|
DEBUG_STREAM?: string
|
|
10
10
|
GET_CALIBRATION?: string
|
|
11
|
-
// Tindeq
|
|
11
|
+
// Tindeq Progressor
|
|
12
12
|
TARE_SCALE?: string
|
|
13
13
|
START_PEAK_RFD_MEAS?: string
|
|
14
14
|
START_PEAK_RFD_MEAS_SERIES?: string
|
|
15
15
|
ADD_CALIB_POINT?: string
|
|
16
16
|
SAVE_CALIB?: string
|
|
17
|
-
|
|
17
|
+
GET_FW_VERSION?: string
|
|
18
18
|
GET_ERR_INFO?: string
|
|
19
19
|
CLR_ERR_INFO?: string
|
|
20
20
|
GET_BATT_VLTG?: string
|
package/src/connect.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { Device } from "./devices/types"
|
|
2
|
+
import { ProgressorCommands, ProgressorResponses } from "./commands/progressor"
|
|
2
3
|
import { notifyCallback } from "./notify"
|
|
3
4
|
import { handleMotherboardData } from "./data"
|
|
5
|
+
import { lastWrite } from "./write"
|
|
4
6
|
|
|
5
7
|
let server: BluetoothRemoteGATTServer
|
|
6
8
|
const receiveBuffer: number[] = []
|
|
@@ -23,6 +25,19 @@ const onDisconnected = (event: Event, board: Device): void => {
|
|
|
23
25
|
const handleNotifications = (event: Event, board: Device): void => {
|
|
24
26
|
const characteristic: BluetoothRemoteGATTCharacteristic = event.target as BluetoothRemoteGATTCharacteristic
|
|
25
27
|
const value: DataView | undefined = characteristic.value
|
|
28
|
+
|
|
29
|
+
function _unpackFloat(bytes: Uint8Array) {
|
|
30
|
+
const view = new DataView(new ArrayBuffer(4))
|
|
31
|
+
for (let i = 0; i < 4; i++) {
|
|
32
|
+
view.setUint8(i, bytes[i])
|
|
33
|
+
}
|
|
34
|
+
return view.getFloat32(0, true)
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// function _unpackInt(bytes: Uint8Array) {
|
|
38
|
+
// return (bytes[1] << 8) + bytes[0];
|
|
39
|
+
// }
|
|
40
|
+
|
|
26
41
|
if (value) {
|
|
27
42
|
if (board.name === "Motherboard") {
|
|
28
43
|
for (let i: number = 0; i < value.byteLength; i++) {
|
|
@@ -51,8 +66,53 @@ const handleNotifications = (event: Event, board: Device): void => {
|
|
|
51
66
|
})
|
|
52
67
|
}
|
|
53
68
|
}
|
|
54
|
-
} else if (board.name
|
|
55
|
-
|
|
69
|
+
} else if (board.name && board.name.startsWith("Progressor")) {
|
|
70
|
+
if (value.buffer) {
|
|
71
|
+
const buffer: ArrayBuffer = value.buffer
|
|
72
|
+
const rawData: Uint8Array = new Uint8Array(buffer)
|
|
73
|
+
const kind: number = rawData[0]
|
|
74
|
+
const tare: number = 0 // todo: add tare
|
|
75
|
+
if (kind === ProgressorResponses.WEIGHT_MEASURE) {
|
|
76
|
+
for (let i = 2; i < rawData.length; i += 6) {
|
|
77
|
+
const weight = _unpackFloat(rawData.slice(i, i + 4))
|
|
78
|
+
// let useconds = _unpackInt(rawData.slice(i + 4, i + 6));
|
|
79
|
+
// let now = useconds / 1.0e6;
|
|
80
|
+
|
|
81
|
+
if (notifyCallback) {
|
|
82
|
+
notifyCallback({
|
|
83
|
+
uuid: characteristic.uuid,
|
|
84
|
+
value: {
|
|
85
|
+
massTotal: weight - tare,
|
|
86
|
+
},
|
|
87
|
+
})
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
} else if (kind === ProgressorResponses.COMMAND_RESPONSE) {
|
|
91
|
+
if (!lastWrite) return
|
|
92
|
+
|
|
93
|
+
let value: string = ""
|
|
94
|
+
|
|
95
|
+
if (lastWrite === ProgressorCommands.GET_BATT_VLTG) {
|
|
96
|
+
const vdd = new DataView(rawData.buffer, 2).getUint32(0, true)
|
|
97
|
+
value = `Battery level = ${vdd} [mV]`
|
|
98
|
+
} else if (lastWrite === ProgressorCommands.GET_FW_VERSION) {
|
|
99
|
+
value = new TextDecoder().decode(rawData.slice(2))
|
|
100
|
+
} else if (lastWrite === ProgressorCommands.GET_ERR_INFO) {
|
|
101
|
+
value = new TextDecoder().decode(rawData.slice(2))
|
|
102
|
+
}
|
|
103
|
+
if (notifyCallback) {
|
|
104
|
+
notifyCallback({ uuid: characteristic.uuid, value: value })
|
|
105
|
+
}
|
|
106
|
+
} else if (kind === ProgressorResponses.LOW_BATTERY_WARNING) {
|
|
107
|
+
if (notifyCallback) {
|
|
108
|
+
notifyCallback({ uuid: characteristic.uuid, value: "low power warning" })
|
|
109
|
+
}
|
|
110
|
+
} else {
|
|
111
|
+
if (notifyCallback) {
|
|
112
|
+
notifyCallback({ uuid: characteristic.uuid, value: `unknown message kind ${kind}` })
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
56
116
|
} else {
|
|
57
117
|
if (notifyCallback) {
|
|
58
118
|
notifyCallback({ uuid: characteristic.uuid, value: value })
|
|
@@ -132,9 +192,8 @@ export const connect = async (board: Device, onSuccess: () => void): Promise<voi
|
|
|
132
192
|
const filters = []
|
|
133
193
|
|
|
134
194
|
if (board.name) {
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
})
|
|
195
|
+
const filterName = board.name === "Progressor" ? { namePrefix: board.name } : { name: board.name }
|
|
196
|
+
filters.push(filterName)
|
|
138
197
|
}
|
|
139
198
|
if (board.companyId) {
|
|
140
199
|
filters.push({
|
package/src/devices/index.ts
CHANGED
|
@@ -1,22 +1,34 @@
|
|
|
1
1
|
import { Device } from "./types"
|
|
2
2
|
|
|
3
|
-
export const
|
|
4
|
-
name: "
|
|
3
|
+
export const Progressor: Device = {
|
|
4
|
+
name: "Progressor",
|
|
5
5
|
services: [
|
|
6
6
|
{
|
|
7
7
|
name: "Progressor Service",
|
|
8
8
|
id: "progressor",
|
|
9
9
|
uuid: "7e4e1701-1ea6-40c9-9dcc-13d34ffead57",
|
|
10
10
|
characteristics: [
|
|
11
|
+
{
|
|
12
|
+
name: "Notify",
|
|
13
|
+
id: "rx",
|
|
14
|
+
uuid: "7e4e1702-1ea6-40c9-9dcc-13d34ffead57",
|
|
15
|
+
},
|
|
11
16
|
{
|
|
12
17
|
name: "Write",
|
|
13
18
|
id: "tx",
|
|
14
19
|
uuid: "7e4e1703-1ea6-40c9-9dcc-13d34ffead57",
|
|
15
20
|
},
|
|
21
|
+
],
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
name: "Secure DFU Service",
|
|
25
|
+
id: "dfu",
|
|
26
|
+
uuid: "0000fe59-0000-1000-8000-00805f9b34fb",
|
|
27
|
+
characteristics: [
|
|
16
28
|
{
|
|
17
|
-
name: "
|
|
18
|
-
id: "
|
|
19
|
-
uuid: "
|
|
29
|
+
name: "Buttonless DFU",
|
|
30
|
+
id: "dfu",
|
|
31
|
+
uuid: "8ec90003-f315-4f60-9fb8-838830daea50",
|
|
20
32
|
},
|
|
21
33
|
],
|
|
22
34
|
},
|
package/src/index.ts
CHANGED
package/src/info.ts
CHANGED
|
@@ -2,8 +2,8 @@ import { Device } from "./devices/types"
|
|
|
2
2
|
import { write } from "./write"
|
|
3
3
|
import { read } from "./read"
|
|
4
4
|
import { isConnected } from "./is-connected"
|
|
5
|
-
import { Motherboard,
|
|
6
|
-
import { MotherboardCommands,
|
|
5
|
+
import { Motherboard, Progressor } from "./devices"
|
|
6
|
+
import { MotherboardCommands, ProgressorCommands } from "./commands"
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* Get device information
|
|
@@ -15,11 +15,11 @@ export const info = async (board: Device): Promise<void> => {
|
|
|
15
15
|
await read(Motherboard, "device", "manufacturer", 250)
|
|
16
16
|
await read(Motherboard, "device", "hardware", 250)
|
|
17
17
|
await read(Motherboard, "device", "firmware", 250)
|
|
18
|
-
await write(Motherboard, "uart", "tx",
|
|
19
|
-
await write(Motherboard, "uart", "tx",
|
|
18
|
+
await write(Motherboard, "uart", "tx", MotherboardCommands.GET_TEXT, 250)
|
|
19
|
+
await write(Motherboard, "uart", "tx", MotherboardCommands.GET_SERIAL, 250)
|
|
20
20
|
}
|
|
21
|
-
if (board.name
|
|
22
|
-
await write(
|
|
21
|
+
if (board.name && board.name.startsWith("Progressor")) {
|
|
22
|
+
await write(Progressor, "progressor", "tx", ProgressorCommands.GET_FW_VERSION, 250)
|
|
23
23
|
}
|
|
24
24
|
}
|
|
25
25
|
}
|
package/src/stop.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Device } from "./devices/types"
|
|
2
2
|
import { write } from "./write"
|
|
3
3
|
import { isConnected } from "./is-connected"
|
|
4
|
-
import { Motherboard,
|
|
5
|
-
import { MotherboardCommands,
|
|
4
|
+
import { Motherboard, Progressor } from "./devices"
|
|
5
|
+
import { MotherboardCommands, ProgressorCommands } from "./commands"
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* read calibration
|
|
@@ -11,10 +11,10 @@ import { MotherboardCommands, TindeqCommands } from "./commands"
|
|
|
11
11
|
export const stop = async (board: Device): Promise<void> => {
|
|
12
12
|
if (isConnected(board)) {
|
|
13
13
|
if (board.name === "Motherboard") {
|
|
14
|
-
await write(Motherboard, "uart", "tx",
|
|
14
|
+
await write(Motherboard, "uart", "tx", MotherboardCommands.STOP_WEIGHT_MEAS, 0)
|
|
15
15
|
}
|
|
16
|
-
if (board.name
|
|
17
|
-
await write(
|
|
16
|
+
if (board.name && board.name.startsWith("Progressor")) {
|
|
17
|
+
await write(Progressor, "progressor", "tx", ProgressorCommands.STOP_WEIGHT_MEAS, 0)
|
|
18
18
|
}
|
|
19
19
|
}
|
|
20
20
|
}
|
package/src/stream.ts
CHANGED
|
@@ -2,8 +2,8 @@ import { Device } from "./devices/types"
|
|
|
2
2
|
import { isConnected } from "./is-connected"
|
|
3
3
|
import { write } from "./write"
|
|
4
4
|
import { stop } from "./stop"
|
|
5
|
-
import { Motherboard,
|
|
6
|
-
import { MotherboardCommands,
|
|
5
|
+
import { Motherboard, Progressor } from "./devices"
|
|
6
|
+
import { MotherboardCommands, ProgressorCommands } from "./commands"
|
|
7
7
|
import { CALIBRATION } from "./data"
|
|
8
8
|
import { calibration } from "./calibration"
|
|
9
9
|
|
|
@@ -19,18 +19,18 @@ export const stream = async (board: Device, duration: number = 0): Promise<void>
|
|
|
19
19
|
await calibration(Motherboard)
|
|
20
20
|
}
|
|
21
21
|
// start stream
|
|
22
|
-
await write(Motherboard, "uart", "tx",
|
|
22
|
+
await write(Motherboard, "uart", "tx", MotherboardCommands.START_WEIGHT_MEAS, duration)
|
|
23
23
|
// end stream if duration is set
|
|
24
24
|
if (duration !== 0) {
|
|
25
25
|
await stop(Motherboard)
|
|
26
26
|
}
|
|
27
27
|
}
|
|
28
|
-
if (board.name
|
|
28
|
+
if (board.name && board.name.startsWith("Progressor")) {
|
|
29
29
|
// start stream
|
|
30
|
-
await write(
|
|
30
|
+
await write(Progressor, "progressor", "tx", ProgressorCommands.START_WEIGHT_MEAS, duration)
|
|
31
31
|
// end stream if duration is set
|
|
32
32
|
if (duration !== 0) {
|
|
33
|
-
await stop(
|
|
33
|
+
await stop(Progressor)
|
|
34
34
|
}
|
|
35
35
|
}
|
|
36
36
|
}
|
package/src/write.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { Device } from "./devices/types"
|
|
|
2
2
|
import { isConnected } from "./is-connected"
|
|
3
3
|
import { getCharacteristic } from "./characteristic"
|
|
4
4
|
|
|
5
|
+
export let lastWrite: string | null = null
|
|
5
6
|
/**
|
|
6
7
|
* write
|
|
7
8
|
* @param characteristic
|
|
@@ -11,19 +12,21 @@ export const write = (
|
|
|
11
12
|
board: Device,
|
|
12
13
|
serviceId: string,
|
|
13
14
|
characteristicId: string,
|
|
14
|
-
message: string,
|
|
15
|
+
message: string | undefined,
|
|
15
16
|
duration: number = 0,
|
|
16
17
|
): Promise<void> => {
|
|
17
18
|
return new Promise((resolve, reject) => {
|
|
18
19
|
if (isConnected(board)) {
|
|
19
|
-
|
|
20
|
-
|
|
20
|
+
if (!message) return
|
|
21
21
|
const characteristic = getCharacteristic(board, serviceId, characteristicId)
|
|
22
|
-
|
|
23
22
|
if (characteristic) {
|
|
23
|
+
const encoder = new TextEncoder()
|
|
24
24
|
characteristic
|
|
25
25
|
.writeValue(encoder.encode(message))
|
|
26
26
|
.then(() => {
|
|
27
|
+
// update last written message
|
|
28
|
+
lastWrite = message
|
|
29
|
+
// handle timeout
|
|
27
30
|
if (duration !== 0) {
|
|
28
31
|
setTimeout(() => {
|
|
29
32
|
resolve()
|
package/src/battery.d.ts
DELETED
package/src/battery.js
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { write } from "./write";
|
|
2
|
-
import { read } from "./read";
|
|
3
|
-
import { isConnected } from "./is-connected";
|
|
4
|
-
import { Motherboard, Tindeq } from "./devices";
|
|
5
|
-
import { TindeqCommands } from "./commands";
|
|
6
|
-
/**
|
|
7
|
-
* Get Battery / Voltage information
|
|
8
|
-
* @param board
|
|
9
|
-
*/
|
|
10
|
-
export const battery = async (board) => {
|
|
11
|
-
if (isConnected(board)) {
|
|
12
|
-
if (board.name === "Motherboard") {
|
|
13
|
-
await read(Motherboard, "battery", "level", 250);
|
|
14
|
-
}
|
|
15
|
-
if (board.name === "Tindeq") {
|
|
16
|
-
await write(Tindeq, "progressor", "tx", String(TindeqCommands.GET_BATT_VLTG), 250);
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
};
|
package/src/calibration.d.ts
DELETED
package/src/calibration.js
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { isConnected } from "./is-connected";
|
|
2
|
-
import { write } from "./write";
|
|
3
|
-
import { Motherboard } from "./devices";
|
|
4
|
-
import { MotherboardCommands } from "./commands";
|
|
5
|
-
/**
|
|
6
|
-
* write command to get calibration
|
|
7
|
-
* @param board
|
|
8
|
-
*/
|
|
9
|
-
export const calibration = async (board) => {
|
|
10
|
-
if (isConnected(board)) {
|
|
11
|
-
if (board.name === "Motherboard") {
|
|
12
|
-
await write(Motherboard, "uart", "tx", String(MotherboardCommands.GET_CALIBRATION), 2500);
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
};
|
package/src/characteristic.d.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
/// <reference types="web-bluetooth" />
|
|
2
|
-
import { Device } from "./devices/types";
|
|
3
|
-
/**
|
|
4
|
-
* getCharacteristic
|
|
5
|
-
* @param board
|
|
6
|
-
* @param serviceId
|
|
7
|
-
* @param characteristicId
|
|
8
|
-
*/
|
|
9
|
-
export declare const getCharacteristic: (board: Device, serviceId: string, characteristicId: string) => BluetoothRemoteGATTCharacteristic | undefined;
|
package/src/characteristic.js
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* getCharacteristic
|
|
3
|
-
* @param board
|
|
4
|
-
* @param serviceId
|
|
5
|
-
* @param characteristicId
|
|
6
|
-
*/
|
|
7
|
-
export const getCharacteristic = (board, serviceId, characteristicId) => {
|
|
8
|
-
const boardService = board.services.find((service) => service.id === serviceId);
|
|
9
|
-
if (boardService) {
|
|
10
|
-
const boardCharacteristic = boardService.characteristics.find((characteristic) => characteristic.id === characteristicId);
|
|
11
|
-
if (boardCharacteristic) {
|
|
12
|
-
return boardCharacteristic.characteristic;
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
};
|
package/src/commands/climbro.js
DELETED
package/src/commands/entralpi.js
DELETED
package/src/commands/index.d.ts
DELETED
package/src/commands/index.js
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Warning:
|
|
3
|
-
* Using other commands can seriously harm your device
|
|
4
|
-
*/
|
|
5
|
-
export const MotherboardCommands = {
|
|
6
|
-
GET_SERIAL: "#",
|
|
7
|
-
START_WEIGHT_MEAS: "S30",
|
|
8
|
-
STOP_WEIGHT_MEAS: "", // All commands will stop the data stream.
|
|
9
|
-
GET_CALIBRATION: "C",
|
|
10
|
-
SLEEP: 0,
|
|
11
|
-
GET_TEXT: "T",
|
|
12
|
-
DEBUG_STREAM: "D",
|
|
13
|
-
};
|
package/src/commands/tindeq.d.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { Commands } from "../commands/types";
|
|
2
|
-
/**
|
|
3
|
-
* Warning:
|
|
4
|
-
* Using other commands can seriously harm your device
|
|
5
|
-
*/
|
|
6
|
-
export declare const TindeqCommands: Commands;
|
|
7
|
-
export declare const NotificationTypes: {
|
|
8
|
-
COMMAND_RESPONSE: number;
|
|
9
|
-
WEIGHT_MEASURE: number;
|
|
10
|
-
LOW_BATTERY_WARNING: number;
|
|
11
|
-
};
|
package/src/commands/tindeq.js
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Warning:
|
|
3
|
-
* Using other commands can seriously harm your device
|
|
4
|
-
*/
|
|
5
|
-
export const TindeqCommands = {
|
|
6
|
-
TARE_SCALE: "d", // 0x64,
|
|
7
|
-
START_WEIGHT_MEAS: "e", // 0x65,
|
|
8
|
-
STOP_WEIGHT_MEAS: "f", // 0x66,
|
|
9
|
-
START_PEAK_RFD_MEAS: "g", // 0x67,
|
|
10
|
-
START_PEAK_RFD_MEAS_SERIES: "h", // 0x68,
|
|
11
|
-
ADD_CALIB_POINT: "i", // 0x69,
|
|
12
|
-
SAVE_CALIB: "j", // 0x6a,
|
|
13
|
-
GET_APP_VERSION: "k", // 0x6b,
|
|
14
|
-
GET_ERR_INFO: "l", // 0x6c,
|
|
15
|
-
CLR_ERR_INFO: "m", // 0x6d,
|
|
16
|
-
SLEEP: "n", // 0x6e,
|
|
17
|
-
GET_BATT_VLTG: "o", // 0x6f,
|
|
18
|
-
};
|
|
19
|
-
export const NotificationTypes = {
|
|
20
|
-
COMMAND_RESPONSE: 0,
|
|
21
|
-
WEIGHT_MEASURE: 1,
|
|
22
|
-
LOW_BATTERY_WARNING: 2,
|
|
23
|
-
};
|
package/src/commands/types.d.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
export interface Commands {
|
|
2
|
-
START_WEIGHT_MEAS?: string;
|
|
3
|
-
STOP_WEIGHT_MEAS?: string;
|
|
4
|
-
SLEEP?: number | string;
|
|
5
|
-
GET_TEXT?: string;
|
|
6
|
-
GET_SERIAL?: string;
|
|
7
|
-
DEBUG_STREAM?: string;
|
|
8
|
-
GET_CALIBRATION?: string;
|
|
9
|
-
TARE_SCALE?: string;
|
|
10
|
-
START_PEAK_RFD_MEAS?: string;
|
|
11
|
-
START_PEAK_RFD_MEAS_SERIES?: string;
|
|
12
|
-
ADD_CALIB_POINT?: string;
|
|
13
|
-
SAVE_CALIB?: string;
|
|
14
|
-
GET_APP_VERSION?: string;
|
|
15
|
-
GET_ERR_INFO?: string;
|
|
16
|
-
CLR_ERR_INFO?: string;
|
|
17
|
-
GET_BATT_VLTG?: string;
|
|
18
|
-
}
|
package/src/commands/types.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|