@hangtime/grip-connect 0.1.2 → 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 +22 -25
- package/package.json +2 -2
- package/src/battery.ts +21 -0
- package/src/calibration.ts +4 -4
- 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 +74 -9
- package/src/data.ts +133 -0
- package/src/devices/entralpi.ts +0 -17
- package/src/devices/index.ts +1 -1
- package/src/devices/motherboard.ts +0 -134
- package/src/devices/{tindeq.ts → progressor.ts} +17 -5
- package/src/disconnect.ts +3 -3
- package/src/index.ts +10 -2
- package/src/info.ts +25 -0
- package/src/is-connected.ts +11 -0
- package/src/notify.ts +2 -2
- package/src/read.ts +2 -1
- package/src/stop.ts +7 -7
- package/src/stream.ts +16 -11
- package/src/write.ts +10 -5
- package/tsconfig.json +2 -2
- package/src/calibration.d.ts +0 -6
- package/src/calibration.js +0 -16
- 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 -150
- package/src/devices/climbro.d.ts +0 -2
- package/src/devices/climbro.js +0 -4
- package/src/devices/entralpi.d.ts +0 -8
- package/src/devices/entralpi.js +0 -68
- package/src/devices/index.d.ts +0 -5
- package/src/devices/index.js +0 -5
- package/src/devices/motherboard.d.ts +0 -8
- package/src/devices/motherboard.js +0 -189
- 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 -11
- package/src/index.d.ts +0 -8
- package/src/index.js +0 -8
- 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 -44
- package/src/stop.d.ts +0 -6
- package/src/stop.js +0 -19
- package/src/stream.d.ts +0 -6
- package/src/stream.js +0 -31
- package/src/write.d.ts +0 -7
- package/src/write.js +0 -34
package/src/devices/entralpi.js
DELETED
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
import { notifyCallback } from "../notify";
|
|
2
|
-
export const Entralpi = {
|
|
3
|
-
name: "ENTRALPI",
|
|
4
|
-
services: [
|
|
5
|
-
{
|
|
6
|
-
name: "Device Information",
|
|
7
|
-
id: "device",
|
|
8
|
-
uuid: "0000180a-0000-1000-8000-00805f9b34fb",
|
|
9
|
-
characteristics: [],
|
|
10
|
-
},
|
|
11
|
-
{
|
|
12
|
-
name: "Battery Service",
|
|
13
|
-
id: "battery",
|
|
14
|
-
uuid: "0000180f-0000-1000-8000-00805f9b34fb",
|
|
15
|
-
characteristics: [],
|
|
16
|
-
},
|
|
17
|
-
{
|
|
18
|
-
name: "Generic Attribute",
|
|
19
|
-
id: "attribute",
|
|
20
|
-
uuid: "00001801-0000-1000-8000-00805f9b34fb",
|
|
21
|
-
characteristics: [],
|
|
22
|
-
},
|
|
23
|
-
{
|
|
24
|
-
name: "UART ISSC Transparent Service",
|
|
25
|
-
id: "uart",
|
|
26
|
-
uuid: "0000fff0-0000-1000-8000-00805f9b34fb",
|
|
27
|
-
characteristics: [
|
|
28
|
-
{
|
|
29
|
-
name: "TX",
|
|
30
|
-
id: "tx",
|
|
31
|
-
uuid: "0000fff5-0000-1000-8000-00805f9b34fb",
|
|
32
|
-
},
|
|
33
|
-
{
|
|
34
|
-
name: "RX",
|
|
35
|
-
id: "rx",
|
|
36
|
-
uuid: "0000fff4-0000-1000-8000-00805f9b34fb",
|
|
37
|
-
},
|
|
38
|
-
],
|
|
39
|
-
},
|
|
40
|
-
{
|
|
41
|
-
name: "Weight Scale",
|
|
42
|
-
id: "weight",
|
|
43
|
-
uuid: "0000181d-0000-1000-8000-00805f9b34fb",
|
|
44
|
-
characteristics: [],
|
|
45
|
-
},
|
|
46
|
-
{
|
|
47
|
-
name: "Generic Access",
|
|
48
|
-
id: "access",
|
|
49
|
-
uuid: "00001800-0000-1000-8000-00805f9b34fb",
|
|
50
|
-
characteristics: [],
|
|
51
|
-
},
|
|
52
|
-
],
|
|
53
|
-
};
|
|
54
|
-
/**
|
|
55
|
-
* handleEntralpiData
|
|
56
|
-
* @param uuid - Unique identifier
|
|
57
|
-
* @param receivedData - Received data string
|
|
58
|
-
*/
|
|
59
|
-
export function handleEntralpiData(uuid, receivedData) {
|
|
60
|
-
if (notifyCallback) {
|
|
61
|
-
notifyCallback({
|
|
62
|
-
uuid,
|
|
63
|
-
value: {
|
|
64
|
-
massTotal: receivedData,
|
|
65
|
-
},
|
|
66
|
-
});
|
|
67
|
-
}
|
|
68
|
-
}
|
package/src/devices/index.d.ts
DELETED
package/src/devices/index.js
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { Device } from "./types";
|
|
2
|
-
export declare const Motherboard: Device;
|
|
3
|
-
/**
|
|
4
|
-
* handleMotherboardData
|
|
5
|
-
* @param uuid - Unique identifier
|
|
6
|
-
* @param receivedData - Received data string
|
|
7
|
-
*/
|
|
8
|
-
export declare function handleMotherboardData(uuid: string, receivedData: string): void;
|
|
@@ -1,189 +0,0 @@
|
|
|
1
|
-
import { notifyCallback } from "../notify";
|
|
2
|
-
const PACKET_LENGTH = 32;
|
|
3
|
-
const NUM_SAMPLES = 3;
|
|
4
|
-
const CALIBRATION = [[], [], [], []];
|
|
5
|
-
export const Motherboard = {
|
|
6
|
-
name: "Motherboard",
|
|
7
|
-
companyId: 0x2a29,
|
|
8
|
-
services: [
|
|
9
|
-
{
|
|
10
|
-
name: "Device Information",
|
|
11
|
-
id: "device",
|
|
12
|
-
uuid: "0000180a-0000-1000-8000-00805f9b34fb",
|
|
13
|
-
characteristics: [
|
|
14
|
-
// {
|
|
15
|
-
// name: 'Serial Number (Blocked)',
|
|
16
|
-
// id: 'serial'
|
|
17
|
-
// uuid: '00002a25-0000-1000-8000-00805f9b34fb'
|
|
18
|
-
// },
|
|
19
|
-
{
|
|
20
|
-
name: "Firmware Revision",
|
|
21
|
-
id: "firmware",
|
|
22
|
-
uuid: "00002a26-0000-1000-8000-00805f9b34fb",
|
|
23
|
-
},
|
|
24
|
-
{
|
|
25
|
-
name: "Hardware Revision",
|
|
26
|
-
id: "hardware",
|
|
27
|
-
uuid: "00002a27-0000-1000-8000-00805f9b34fb",
|
|
28
|
-
},
|
|
29
|
-
{
|
|
30
|
-
name: "Manufacturer Name",
|
|
31
|
-
id: "manufacturer",
|
|
32
|
-
uuid: "00002a29-0000-1000-8000-00805f9b34fb",
|
|
33
|
-
},
|
|
34
|
-
],
|
|
35
|
-
},
|
|
36
|
-
{
|
|
37
|
-
name: "Battery Service",
|
|
38
|
-
id: "battery",
|
|
39
|
-
uuid: "0000180f-0000-1000-8000-00805f9b34fb",
|
|
40
|
-
characteristics: [
|
|
41
|
-
{
|
|
42
|
-
name: "Battery Level",
|
|
43
|
-
id: "level",
|
|
44
|
-
uuid: "00002a19-0000-1000-8000-00805f9b34fb",
|
|
45
|
-
},
|
|
46
|
-
],
|
|
47
|
-
},
|
|
48
|
-
{
|
|
49
|
-
name: "Unknown Service",
|
|
50
|
-
id: "unknown",
|
|
51
|
-
uuid: "10ababcd-15e1-28ff-de13-725bea03b127",
|
|
52
|
-
characteristics: [
|
|
53
|
-
{
|
|
54
|
-
name: "Unknown 01",
|
|
55
|
-
id: "01",
|
|
56
|
-
uuid: "10ab1524-15e1-28ff-de13-725bea03b127",
|
|
57
|
-
},
|
|
58
|
-
{
|
|
59
|
-
name: "Unknown 02",
|
|
60
|
-
id: "02",
|
|
61
|
-
uuid: "10ab1525-15e1-28ff-de13-725bea03b127",
|
|
62
|
-
},
|
|
63
|
-
],
|
|
64
|
-
},
|
|
65
|
-
{
|
|
66
|
-
name: "UART Nordic Service",
|
|
67
|
-
id: "uart",
|
|
68
|
-
uuid: "6e400001-b5a3-f393-e0a9-e50e24dcca9e",
|
|
69
|
-
characteristics: [
|
|
70
|
-
{
|
|
71
|
-
name: "TX",
|
|
72
|
-
id: "tx",
|
|
73
|
-
uuid: "6e400002-b5a3-f393-e0a9-e50e24dcca9e",
|
|
74
|
-
},
|
|
75
|
-
{
|
|
76
|
-
name: "RX",
|
|
77
|
-
id: "rx",
|
|
78
|
-
uuid: "6e400003-b5a3-f393-e0a9-e50e24dcca9e",
|
|
79
|
-
},
|
|
80
|
-
],
|
|
81
|
-
},
|
|
82
|
-
],
|
|
83
|
-
};
|
|
84
|
-
/**
|
|
85
|
-
* applyCalibration
|
|
86
|
-
* @param sample
|
|
87
|
-
* @param calibration
|
|
88
|
-
*/
|
|
89
|
-
const applyCalibration = (sample, calibration) => {
|
|
90
|
-
// Extract the calibrated value for the zero point
|
|
91
|
-
const zeroCalibration = calibration[0][2];
|
|
92
|
-
// Initialize sign as positive
|
|
93
|
-
let sign = 1;
|
|
94
|
-
// Initialize the final calibrated value
|
|
95
|
-
let final = 0;
|
|
96
|
-
// If the sample value is less than the zero calibration point
|
|
97
|
-
if (sample < zeroCalibration) {
|
|
98
|
-
// Change the sign to negative
|
|
99
|
-
sign = -1;
|
|
100
|
-
// Reflect the sample around the zero calibration point
|
|
101
|
-
sample = /* 2 * zeroCalibration */ -sample;
|
|
102
|
-
}
|
|
103
|
-
// Iterate through the calibration data
|
|
104
|
-
for (let i = 1; i < calibration.length; i++) {
|
|
105
|
-
// Extract the lower and upper bounds of the current calibration range
|
|
106
|
-
const calibrationStart = calibration[i - 1][2];
|
|
107
|
-
const calibrationEnd = calibration[i][2];
|
|
108
|
-
// If the sample value is within the current calibration range
|
|
109
|
-
if (sample < calibrationEnd) {
|
|
110
|
-
// Interpolate to get the calibrated value within the range
|
|
111
|
-
final =
|
|
112
|
-
calibration[i - 1][1] +
|
|
113
|
-
((sample - calibrationStart) / (calibrationEnd - calibrationStart)) *
|
|
114
|
-
(calibration[i][1] - calibration[i - 1][1]);
|
|
115
|
-
break;
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
// Return the calibrated value with the appropriate sign (positive/negative)
|
|
119
|
-
return sign * final;
|
|
120
|
-
};
|
|
121
|
-
/**
|
|
122
|
-
* handleMotherboardData
|
|
123
|
-
* @param uuid - Unique identifier
|
|
124
|
-
* @param receivedData - Received data string
|
|
125
|
-
*/
|
|
126
|
-
export function handleMotherboardData(uuid, receivedData) {
|
|
127
|
-
const receivedTime = Date.now();
|
|
128
|
-
// Check if the line is entirely hex characters
|
|
129
|
-
const isAllHex = /^[0-9A-Fa-f]+$/g.test(receivedData);
|
|
130
|
-
// Handle streaming packet
|
|
131
|
-
if (isAllHex && receivedData.length === PACKET_LENGTH) {
|
|
132
|
-
// Base-16 decode the string: convert hex pairs to byte values
|
|
133
|
-
const bytes = Array.from({ length: receivedData.length / 2 }, (_, i) => Number(`0x${receivedData.substring(i * 2, i * 2 + 2)}`));
|
|
134
|
-
// Translate header into packet, number of samples from the packet length
|
|
135
|
-
const packet = {
|
|
136
|
-
received: receivedTime,
|
|
137
|
-
sampleNum: new DataView(new Uint8Array(bytes).buffer).getUint16(0, true),
|
|
138
|
-
battRaw: new DataView(new Uint8Array(bytes).buffer).getUint16(2, true),
|
|
139
|
-
samples: [],
|
|
140
|
-
masses: [],
|
|
141
|
-
};
|
|
142
|
-
const dataView = new DataView(new Uint8Array(bytes).buffer);
|
|
143
|
-
for (let i = 0; i < NUM_SAMPLES; i++) {
|
|
144
|
-
const sampleStart = 4 + 3 * i;
|
|
145
|
-
// Use DataView to read the 24-bit unsigned integer
|
|
146
|
-
const rawValue = dataView.getUint8(sampleStart) |
|
|
147
|
-
(dataView.getUint8(sampleStart + 1) << 8) |
|
|
148
|
-
(dataView.getUint8(sampleStart + 2) << 16);
|
|
149
|
-
// Ensure unsigned 32-bit integer
|
|
150
|
-
packet.samples[i] = rawValue >>> 0;
|
|
151
|
-
if (packet.samples[i] >= 0x7fffff) {
|
|
152
|
-
packet.samples[i] -= 0x1000000;
|
|
153
|
-
}
|
|
154
|
-
// TODO: make sure device is calibrated
|
|
155
|
-
if (!CALIBRATION[0].length)
|
|
156
|
-
return;
|
|
157
|
-
packet.masses[i] = applyCalibration(packet.samples[i], CALIBRATION[i]);
|
|
158
|
-
}
|
|
159
|
-
// invert center and right values
|
|
160
|
-
packet.masses[1] *= -1;
|
|
161
|
-
packet.masses[2] *= -1;
|
|
162
|
-
// map to variables
|
|
163
|
-
const left = packet.masses[0];
|
|
164
|
-
const center = packet.masses[1];
|
|
165
|
-
const right = packet.masses[2];
|
|
166
|
-
if (notifyCallback) {
|
|
167
|
-
notifyCallback({
|
|
168
|
-
uuid,
|
|
169
|
-
value: {
|
|
170
|
-
massTotal: Math.max(-1000, left + right + center).toFixed(1),
|
|
171
|
-
massLeft: Math.max(-1000, left).toFixed(1),
|
|
172
|
-
massRight: Math.max(-1000, right).toFixed(1),
|
|
173
|
-
massCenter: Math.max(-1000, center).toFixed(1),
|
|
174
|
-
},
|
|
175
|
-
});
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
else if ((receivedData.match(/,/g) || []).length === 3) {
|
|
179
|
-
console.log(receivedData);
|
|
180
|
-
// if the returned notification is a calibration string add them to the array
|
|
181
|
-
const parts = receivedData.split(",");
|
|
182
|
-
const numericParts = parts.map((x) => parseFloat(x));
|
|
183
|
-
CALIBRATION[numericParts[0]].push(numericParts.slice(1));
|
|
184
|
-
}
|
|
185
|
-
else {
|
|
186
|
-
// unhanded data
|
|
187
|
-
console.log(receivedData);
|
|
188
|
-
}
|
|
189
|
-
}
|
package/src/devices/tindeq.d.ts
DELETED
package/src/devices/tindeq.js
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
export const Tindeq = {
|
|
2
|
-
name: "Tindeq",
|
|
3
|
-
services: [
|
|
4
|
-
{
|
|
5
|
-
name: "Progressor Service",
|
|
6
|
-
id: "progressor",
|
|
7
|
-
uuid: "7e4e1701-1ea6-40c9-9dcc-13d34ffead57",
|
|
8
|
-
characteristics: [
|
|
9
|
-
{
|
|
10
|
-
name: "Write",
|
|
11
|
-
id: "tx",
|
|
12
|
-
uuid: "7e4e1703-1ea6-40c9-9dcc-13d34ffead57",
|
|
13
|
-
},
|
|
14
|
-
{
|
|
15
|
-
name: "Notify",
|
|
16
|
-
id: "rx",
|
|
17
|
-
uuid: "7e4e1702-1ea6-40c9-9dcc-13d34ffead57",
|
|
18
|
-
},
|
|
19
|
-
],
|
|
20
|
-
},
|
|
21
|
-
],
|
|
22
|
-
};
|
package/src/devices/types.d.ts
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
/// <reference types="web-bluetooth" />
|
|
2
|
-
interface Characteristic {
|
|
3
|
-
name: string;
|
|
4
|
-
id: string;
|
|
5
|
-
uuid: string;
|
|
6
|
-
characteristic?: BluetoothRemoteGATTCharacteristic;
|
|
7
|
-
}
|
|
8
|
-
interface Service {
|
|
9
|
-
name: string;
|
|
10
|
-
id: string;
|
|
11
|
-
uuid: string;
|
|
12
|
-
characteristics: Characteristic[];
|
|
13
|
-
}
|
|
14
|
-
export interface Device {
|
|
15
|
-
name: string;
|
|
16
|
-
companyId?: number;
|
|
17
|
-
services: Service[];
|
|
18
|
-
device?: BluetoothDevice;
|
|
19
|
-
}
|
|
20
|
-
export {};
|
package/src/devices/types.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/src/disconnect.d.ts
DELETED
package/src/disconnect.js
DELETED
package/src/index.d.ts
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
export { Climbro, Entralpi, Motherboard, SmartBoard, Tindeq } from "./devices/index";
|
|
2
|
-
export { calibration } from "./calibration";
|
|
3
|
-
export { connect } from "./connect";
|
|
4
|
-
export { disconnect } from "./disconnect";
|
|
5
|
-
export { notify } from "./notify";
|
|
6
|
-
export { read } from "./read";
|
|
7
|
-
export { stop } from "./stop";
|
|
8
|
-
export { stream } from "./stream";
|
package/src/index.js
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
export { Climbro, Entralpi, Motherboard, SmartBoard, Tindeq } from "./devices/index";
|
|
2
|
-
export { calibration } from "./calibration";
|
|
3
|
-
export { connect } from "./connect";
|
|
4
|
-
export { disconnect } from "./disconnect";
|
|
5
|
-
export { notify } from "./notify";
|
|
6
|
-
export { read } from "./read";
|
|
7
|
-
export { stop } from "./stop";
|
|
8
|
-
export { stream } from "./stream";
|
package/src/notify.d.ts
DELETED
package/src/notify.js
DELETED
package/src/read.d.ts
DELETED
package/src/read.js
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import { notifyCallback } from "./notify";
|
|
2
|
-
import { getCharacteristic } from "./characteristic";
|
|
3
|
-
/**
|
|
4
|
-
* read
|
|
5
|
-
* @param characteristic
|
|
6
|
-
*/
|
|
7
|
-
export const read = (board, serviceId, characteristicId, duration = 0) => {
|
|
8
|
-
return new Promise((resolve, reject) => {
|
|
9
|
-
if (board.device?.gatt?.connected) {
|
|
10
|
-
const characteristic = getCharacteristic(board, serviceId, characteristicId);
|
|
11
|
-
if (characteristic) {
|
|
12
|
-
characteristic
|
|
13
|
-
.readValue()
|
|
14
|
-
.then((value) => {
|
|
15
|
-
let decodedValue;
|
|
16
|
-
const decoder = new TextDecoder("utf-8");
|
|
17
|
-
switch (characteristicId) {
|
|
18
|
-
case "level":
|
|
19
|
-
decodedValue = value.getUint8(0);
|
|
20
|
-
break;
|
|
21
|
-
default:
|
|
22
|
-
decodedValue = decoder.decode(value);
|
|
23
|
-
break;
|
|
24
|
-
}
|
|
25
|
-
if (notifyCallback) {
|
|
26
|
-
notifyCallback({ uuid: characteristic.uuid, value: decodedValue });
|
|
27
|
-
}
|
|
28
|
-
setTimeout(() => {
|
|
29
|
-
resolve();
|
|
30
|
-
}, duration);
|
|
31
|
-
})
|
|
32
|
-
.catch((error) => {
|
|
33
|
-
reject(error);
|
|
34
|
-
});
|
|
35
|
-
}
|
|
36
|
-
else {
|
|
37
|
-
reject(new Error("Characteristic is undefined"));
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
else {
|
|
41
|
-
reject(new Error("Device is not connected"));
|
|
42
|
-
}
|
|
43
|
-
});
|
|
44
|
-
};
|
package/src/stop.d.ts
DELETED
package/src/stop.js
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { Motherboard, Tindeq } from "./devices";
|
|
2
|
-
import { MotherboardCommands, TindeqCommands } from "./commands";
|
|
3
|
-
import { write } from "./write";
|
|
4
|
-
/**
|
|
5
|
-
* read calibration
|
|
6
|
-
* @param board
|
|
7
|
-
*/
|
|
8
|
-
export const stop = async (board) => {
|
|
9
|
-
if (!board.device)
|
|
10
|
-
return;
|
|
11
|
-
if (board.device.gatt?.connected) {
|
|
12
|
-
if (board.name === "Motherboard") {
|
|
13
|
-
await write(Motherboard, "uart", "tx", String(MotherboardCommands.STOP_WEIGHT_MEAS), 0);
|
|
14
|
-
}
|
|
15
|
-
if (board.name === "Tindeq") {
|
|
16
|
-
await write(Tindeq, "progressor", "tx", String(TindeqCommands.STOP_WEIGHT_MEAS), 0);
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
};
|
package/src/stream.d.ts
DELETED
package/src/stream.js
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { Motherboard, Tindeq } from "./devices";
|
|
2
|
-
import { MotherboardCommands, TindeqCommands } from "./commands";
|
|
3
|
-
import { write } from "./write";
|
|
4
|
-
import { stop } from "./stop";
|
|
5
|
-
/**
|
|
6
|
-
* stream output
|
|
7
|
-
* @param board
|
|
8
|
-
*/
|
|
9
|
-
export const stream = async (board, duration = 0) => {
|
|
10
|
-
if (!board.device)
|
|
11
|
-
return;
|
|
12
|
-
if (board.device.gatt?.connected) {
|
|
13
|
-
if (board.name === "Motherboard") {
|
|
14
|
-
// TODO: add check if device is recalibrated
|
|
15
|
-
// start stream
|
|
16
|
-
await write(Motherboard, "uart", "tx", String(MotherboardCommands.START_WEIGHT_MEAS), duration);
|
|
17
|
-
// end stream
|
|
18
|
-
if (duration !== 0) {
|
|
19
|
-
await stop(Motherboard);
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
if (board.name === "Tindeq") {
|
|
23
|
-
// start stream
|
|
24
|
-
await write(Tindeq, "progressor", "tx", String(TindeqCommands.START_WEIGHT_MEAS), duration);
|
|
25
|
-
// end stream
|
|
26
|
-
if (duration !== 0) {
|
|
27
|
-
await stop(Tindeq);
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
};
|
package/src/write.d.ts
DELETED
package/src/write.js
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { getCharacteristic } from "./characteristic";
|
|
2
|
-
/**
|
|
3
|
-
* write
|
|
4
|
-
* @param characteristic
|
|
5
|
-
* @param message
|
|
6
|
-
*/
|
|
7
|
-
export const write = (board, serviceId, characteristicId, message, duration = 0) => {
|
|
8
|
-
return new Promise((resolve, reject) => {
|
|
9
|
-
if (board.device?.gatt?.connected) {
|
|
10
|
-
const encoder = new TextEncoder();
|
|
11
|
-
const characteristic = getCharacteristic(board, serviceId, characteristicId);
|
|
12
|
-
if (characteristic) {
|
|
13
|
-
characteristic
|
|
14
|
-
.writeValue(encoder.encode(message))
|
|
15
|
-
.then(() => {
|
|
16
|
-
if (duration !== 0) {
|
|
17
|
-
setTimeout(() => {
|
|
18
|
-
resolve();
|
|
19
|
-
}, duration);
|
|
20
|
-
}
|
|
21
|
-
})
|
|
22
|
-
.catch((error) => {
|
|
23
|
-
reject(error);
|
|
24
|
-
});
|
|
25
|
-
}
|
|
26
|
-
else {
|
|
27
|
-
reject(new Error("Characteristics is undefined"));
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
else {
|
|
31
|
-
reject(new Error("Device is not connected"));
|
|
32
|
-
}
|
|
33
|
-
});
|
|
34
|
-
};
|