@hangtime/grip-connect 0.5.3 → 0.5.4
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 +1 -1
- package/dist/interfaces/device/forceboard.interface.d.ts +16 -0
- package/dist/interfaces/device.interface.d.ts +2 -2
- package/dist/models/device/entralpi.model.d.ts +1 -1
- package/dist/models/device/entralpi.model.js +10 -62
- package/dist/models/device/forceboard.model.d.ts +24 -0
- package/dist/models/device/forceboard.model.js +77 -19
- package/dist/models/device/motherboard.model.js +29 -73
- package/dist/models/device/progressor.model.d.ts +1 -1
- package/dist/models/device/progressor.model.js +19 -34
- package/dist/models/device.model.d.ts +2 -2
- package/dist/models/device.model.js +49 -57
- package/package.json +1 -1
- package/src/interfaces/device/forceboard.interface.ts +19 -0
- package/src/interfaces/device.interface.ts +2 -2
- package/src/models/device/entralpi.model.ts +10 -62
- package/src/models/device/forceboard.model.ts +89 -19
- package/src/models/device/motherboard.model.ts +29 -74
- package/src/models/device/progressor.model.ts +19 -34
- package/src/models/device.model.ts +51 -58
package/README.md
CHANGED
|
@@ -117,7 +117,7 @@ motherboardButton.addEventListener("click", () => {
|
|
|
117
117
|
enable it at `chrome://flags/#enable-experimental-web-platform-features`.
|
|
118
118
|
- ✅ [Kilter Board](https://stevie-ray.github.io/hangtime-grip-connect/devices/kilterboard.html)
|
|
119
119
|
- ✅ [Entralpi](https://stevie-ray.github.io/hangtime-grip-connect/devices/entralpi.html) / Lefu Scale
|
|
120
|
-
-
|
|
120
|
+
- ✅ [PitchSix Force Board](https://stevie-ray.github.io/hangtime-grip-connect/devices/forceboard.html)
|
|
121
121
|
- ➡️ [Climbro](https://stevie-ray.github.io/hangtime-grip-connect/devices/climbro.html)
|
|
122
122
|
- ➡️ [Smartboard Climbing - mySmartBoard](https://stevie-ray.github.io/hangtime-grip-connect/devices/mysmartboard.html)
|
|
123
123
|
|
|
@@ -18,4 +18,20 @@ export interface IForceBoard extends IDevice {
|
|
|
18
18
|
* @returns {Promise<string | undefined>} A Promise that resolves with the manufacturer information.
|
|
19
19
|
*/
|
|
20
20
|
manufacturer(): Promise<string | undefined>;
|
|
21
|
+
/**
|
|
22
|
+
* Stops the data stream on the specified device.
|
|
23
|
+
* @returns {Promise<void>} A promise that resolves when the stream is stopped.
|
|
24
|
+
*/
|
|
25
|
+
stop(): Promise<void>;
|
|
26
|
+
/**
|
|
27
|
+
* Starts streaming data from the specified device.
|
|
28
|
+
* @param {number} [duration=0] - The duration of the stream in milliseconds. If set to 0, stream will continue indefinitely.
|
|
29
|
+
* @returns {Promise<void>} A promise that resolves when the streaming operation is completed.
|
|
30
|
+
*/
|
|
31
|
+
stream(duration?: number): Promise<void>;
|
|
32
|
+
/**
|
|
33
|
+
* Retrieves temperature information from the device.
|
|
34
|
+
* @returns {Promise<string | undefined>} A Promise that resolves with the humidity level.
|
|
35
|
+
*/
|
|
36
|
+
temperature(): Promise<string | undefined>;
|
|
21
37
|
}
|
|
@@ -106,9 +106,9 @@ export interface IDevice extends IBase {
|
|
|
106
106
|
* @param {string} serviceId - The service ID where the characteristic belongs.
|
|
107
107
|
* @param {string} characteristicId - The characteristic ID to read from.
|
|
108
108
|
* @param {number} [duration=0] - The duration to wait before resolving the promise, in milliseconds.
|
|
109
|
-
* @returns {Promise<string>} A promise that resolves when the read operation is completed.
|
|
109
|
+
* @returns {Promise<string | undefined>} A promise that resolves when the read operation is completed.
|
|
110
110
|
*/
|
|
111
|
-
read(serviceId: string, characteristicId: string, duration?: number): Promise<string>;
|
|
111
|
+
read(serviceId: string, characteristicId: string, duration?: number): Promise<string | undefined>;
|
|
112
112
|
/**
|
|
113
113
|
* Writes a message to the specified characteristic of a Bluetooth device and optionally provides a callback to handle responses.
|
|
114
114
|
* @param {string} serviceId - The service UUID of the Bluetooth device containing the target characteristic.
|
|
@@ -18,7 +18,7 @@ export declare class Entralpi extends Device implements IEntralpi {
|
|
|
18
18
|
*/
|
|
19
19
|
firmware: () => Promise<string | undefined>;
|
|
20
20
|
/**
|
|
21
|
-
* Handles data received from the
|
|
21
|
+
* Handles data received from the device, processes weight measurements,
|
|
22
22
|
* and updates mass data including maximum and average values.
|
|
23
23
|
* It also handles command responses for retrieving device information.
|
|
24
24
|
*
|
|
@@ -128,40 +128,24 @@ export class Entralpi extends Device {
|
|
|
128
128
|
* @returns {Promise<string | undefined>} A Promise that resolves with the battery or voltage information.
|
|
129
129
|
*/
|
|
130
130
|
battery = async () => {
|
|
131
|
-
|
|
132
|
-
return await this.read("battery", "level", 250);
|
|
133
|
-
}
|
|
134
|
-
// If device is not found, return undefined
|
|
135
|
-
return undefined;
|
|
131
|
+
return await this.read("battery", "level", 250);
|
|
136
132
|
};
|
|
137
133
|
/**
|
|
138
134
|
* Retrieves IEEE 11073-20601 Regulatory Certification from the device.
|
|
139
135
|
* @returns {Promise<string>} A Promise that resolves with the certification.
|
|
140
136
|
*/
|
|
141
137
|
certification = async () => {
|
|
142
|
-
|
|
143
|
-
if (this.isConnected()) {
|
|
144
|
-
// Read certification from the device
|
|
145
|
-
return await this.read("device", "certification", 250);
|
|
146
|
-
}
|
|
147
|
-
// If device is not found, return undefined
|
|
148
|
-
return undefined;
|
|
138
|
+
return await this.read("device", "certification", 250);
|
|
149
139
|
};
|
|
150
140
|
/**
|
|
151
141
|
* Retrieves firmware version from the device.
|
|
152
142
|
* @returns {Promise<string>} A Promise that resolves with the firmware version.
|
|
153
143
|
*/
|
|
154
144
|
firmware = async () => {
|
|
155
|
-
|
|
156
|
-
if (this.isConnected()) {
|
|
157
|
-
// Read firmware version from the Motherboard
|
|
158
|
-
return await this.read("device", "firmware", 250);
|
|
159
|
-
}
|
|
160
|
-
// If device is not found, return undefined
|
|
161
|
-
return undefined;
|
|
145
|
+
return await this.read("device", "firmware", 250);
|
|
162
146
|
};
|
|
163
147
|
/**
|
|
164
|
-
* Handles data received from the
|
|
148
|
+
* Handles data received from the device, processes weight measurements,
|
|
165
149
|
* and updates mass data including maximum and average values.
|
|
166
150
|
* It also handles command responses for retrieving device information.
|
|
167
151
|
*
|
|
@@ -202,39 +186,21 @@ export class Entralpi extends Device {
|
|
|
202
186
|
* @returns {Promise<string>} A Promise that resolves with the hardware version.
|
|
203
187
|
*/
|
|
204
188
|
hardware = async () => {
|
|
205
|
-
|
|
206
|
-
if (this.isConnected()) {
|
|
207
|
-
// Read hardware version from the device
|
|
208
|
-
return await this.read("device", "hardware", 250);
|
|
209
|
-
}
|
|
210
|
-
// If device is not found, return undefined
|
|
211
|
-
return undefined;
|
|
189
|
+
return await this.read("device", "hardware", 250);
|
|
212
190
|
};
|
|
213
191
|
/**
|
|
214
192
|
* Retrieves manufacturer information from the device.
|
|
215
193
|
* @returns {Promise<string>} A Promise that resolves with the manufacturer information.
|
|
216
194
|
*/
|
|
217
195
|
manufacturer = async () => {
|
|
218
|
-
|
|
219
|
-
if (this.isConnected()) {
|
|
220
|
-
// Read manufacturer information from the device
|
|
221
|
-
return await this.read("device", "manufacturer", 250);
|
|
222
|
-
}
|
|
223
|
-
// If device is not found, return undefined
|
|
224
|
-
return undefined;
|
|
196
|
+
return await this.read("device", "manufacturer", 250);
|
|
225
197
|
};
|
|
226
198
|
/**
|
|
227
199
|
* Retrieves model number from the device.
|
|
228
200
|
* @returns {Promise<string>} A Promise that resolves with the model number.
|
|
229
201
|
*/
|
|
230
202
|
model = async () => {
|
|
231
|
-
|
|
232
|
-
if (this.isConnected()) {
|
|
233
|
-
// Read model number from the Entralpi
|
|
234
|
-
return await this.read("device", "model", 250);
|
|
235
|
-
}
|
|
236
|
-
// If device is not found, return undefined
|
|
237
|
-
return undefined;
|
|
203
|
+
return await this.read("device", "model", 250);
|
|
238
204
|
};
|
|
239
205
|
/**
|
|
240
206
|
* Retrieves PnP ID from the device, a set of values that used to create a device ID value that is unique for this device.
|
|
@@ -242,38 +208,20 @@ export class Entralpi extends Device {
|
|
|
242
208
|
* @returns {Promise<string>} A Promise that resolves with the PnP ID.
|
|
243
209
|
*/
|
|
244
210
|
pnp = async () => {
|
|
245
|
-
|
|
246
|
-
if (this.isConnected()) {
|
|
247
|
-
// Read software version from the Entralpi
|
|
248
|
-
return await this.read("device", "pnp", 250);
|
|
249
|
-
}
|
|
250
|
-
// If device is not found, return undefined
|
|
251
|
-
return undefined;
|
|
211
|
+
return await this.read("device", "pnp", 250);
|
|
252
212
|
};
|
|
253
213
|
/**
|
|
254
214
|
* Retrieves software version from the device.
|
|
255
215
|
* @returns {Promise<string>} A Promise that resolves with the software version.
|
|
256
216
|
*/
|
|
257
217
|
software = async () => {
|
|
258
|
-
|
|
259
|
-
if (this.isConnected()) {
|
|
260
|
-
// Read software version from the Entralpi
|
|
261
|
-
return await this.read("device", "software", 250);
|
|
262
|
-
}
|
|
263
|
-
// If device is not found, return undefined
|
|
264
|
-
return undefined;
|
|
218
|
+
return await this.read("device", "software", 250);
|
|
265
219
|
};
|
|
266
220
|
/**
|
|
267
221
|
* Retrieves system id from the device.
|
|
268
222
|
* @returns {Promise<string>} A Promise that resolves with the system id.
|
|
269
223
|
*/
|
|
270
224
|
system = async () => {
|
|
271
|
-
|
|
272
|
-
if (this.isConnected()) {
|
|
273
|
-
// Read system id from the device
|
|
274
|
-
return await this.read("device", "system", 250);
|
|
275
|
-
}
|
|
276
|
-
// If device is not found, return undefined
|
|
277
|
-
return undefined;
|
|
225
|
+
return await this.read("device", "system", 250);
|
|
278
226
|
};
|
|
279
227
|
}
|
|
@@ -10,6 +10,14 @@ export declare class ForceBoard extends Device implements IForceBoard {
|
|
|
10
10
|
* @returns {Promise<string | undefined>} A Promise that resolves with the battery or voltage information,
|
|
11
11
|
*/
|
|
12
12
|
battery: () => Promise<string | undefined>;
|
|
13
|
+
/**
|
|
14
|
+
* Handles data received from the 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 {Event} event - The notification event.
|
|
19
|
+
*/
|
|
20
|
+
handleNotifications: (event: Event) => void;
|
|
13
21
|
/**
|
|
14
22
|
* Retrieves humidity level from the device.
|
|
15
23
|
* @returns {Promise<string>} A Promise that resolves with the humidity level,
|
|
@@ -20,4 +28,20 @@ export declare class ForceBoard extends Device implements IForceBoard {
|
|
|
20
28
|
* @returns {Promise<string>} A Promise that resolves with the manufacturer information,
|
|
21
29
|
*/
|
|
22
30
|
manufacturer: () => Promise<string | undefined>;
|
|
31
|
+
/**
|
|
32
|
+
* Stops the data stream on the specified device.
|
|
33
|
+
* @returns {Promise<void>} A promise that resolves when the stream is stopped.
|
|
34
|
+
*/
|
|
35
|
+
stop: () => Promise<void>;
|
|
36
|
+
/**
|
|
37
|
+
* Starts streaming data from the specified device.
|
|
38
|
+
* @param {number} [duration=0] - The duration of the stream in milliseconds. If set to 0, stream will continue indefinitely.
|
|
39
|
+
* @returns {Promise<void>} A promise that resolves when the streaming operation is completed.
|
|
40
|
+
*/
|
|
41
|
+
stream: (duration?: number) => Promise<void>;
|
|
42
|
+
/**
|
|
43
|
+
* Retrieves temperature information from the device.
|
|
44
|
+
* @returns {Promise<string>} A Promise that resolves with the manufacturer information,
|
|
45
|
+
*/
|
|
46
|
+
temperature: () => Promise<string | undefined>;
|
|
23
47
|
}
|
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import { Device } from "../device.model";
|
|
2
|
+
import { emptyDownloadPackets } from "../../helpers/download";
|
|
3
|
+
import { checkActivity } from "../../helpers/is-active";
|
|
4
|
+
import { applyTare } from "../../helpers/tare";
|
|
2
5
|
/**
|
|
3
6
|
* Represents a PitchSix Force Board device
|
|
4
7
|
*/
|
|
@@ -142,13 +145,13 @@ export class ForceBoard extends Device {
|
|
|
142
145
|
],
|
|
143
146
|
},
|
|
144
147
|
{
|
|
145
|
-
name: "",
|
|
146
|
-
id: "",
|
|
148
|
+
name: "Weight Serivce",
|
|
149
|
+
id: "weight",
|
|
147
150
|
uuid: "467a8516-6e39-11eb-9439-0242ac130002",
|
|
148
151
|
characteristics: [
|
|
149
152
|
{
|
|
150
153
|
name: "Read + Write",
|
|
151
|
-
id: "",
|
|
154
|
+
id: "tx",
|
|
152
155
|
uuid: "467a8517-6e39-11eb-9439-0242ac130002",
|
|
153
156
|
},
|
|
154
157
|
{
|
|
@@ -159,6 +162,9 @@ export class ForceBoard extends Device {
|
|
|
159
162
|
],
|
|
160
163
|
},
|
|
161
164
|
],
|
|
165
|
+
commands: {
|
|
166
|
+
STOP_WEIGHT_MEAS: "",
|
|
167
|
+
},
|
|
162
168
|
});
|
|
163
169
|
}
|
|
164
170
|
/**
|
|
@@ -166,35 +172,87 @@ export class ForceBoard extends Device {
|
|
|
166
172
|
* @returns {Promise<string | undefined>} A Promise that resolves with the battery or voltage information,
|
|
167
173
|
*/
|
|
168
174
|
battery = async () => {
|
|
169
|
-
|
|
170
|
-
|
|
175
|
+
return await this.read("battery", "level", 250);
|
|
176
|
+
};
|
|
177
|
+
/**
|
|
178
|
+
* Handles data received from the device, processes weight measurements,
|
|
179
|
+
* and updates mass data including maximum and average values.
|
|
180
|
+
* It also handles command responses for retrieving device information.
|
|
181
|
+
*
|
|
182
|
+
* @param {Event} event - The notification event.
|
|
183
|
+
*/
|
|
184
|
+
handleNotifications = (event) => {
|
|
185
|
+
const characteristic = event.target;
|
|
186
|
+
const value = characteristic.value;
|
|
187
|
+
if (value) {
|
|
188
|
+
if (value.buffer) {
|
|
189
|
+
const buffer = value.buffer;
|
|
190
|
+
const rawData = new DataView(buffer);
|
|
191
|
+
const receivedData = rawData.getUint8(4); // Read the value at index 4
|
|
192
|
+
// Convert from LBS to KG
|
|
193
|
+
let numericData = receivedData * 0.453592;
|
|
194
|
+
// Tare correction
|
|
195
|
+
numericData -= applyTare(numericData);
|
|
196
|
+
// Update massMax
|
|
197
|
+
this.massMax = Math.max(Number(this.massMax), numericData).toFixed(1);
|
|
198
|
+
// Update running sum and count
|
|
199
|
+
const currentMassTotal = Math.max(-1000, numericData);
|
|
200
|
+
this.massTotalSum += currentMassTotal;
|
|
201
|
+
this.dataPointCount++;
|
|
202
|
+
// Calculate the average dynamically
|
|
203
|
+
this.massAverage = (this.massTotalSum / this.dataPointCount).toFixed(1);
|
|
204
|
+
// Check if device is being used
|
|
205
|
+
checkActivity(numericData);
|
|
206
|
+
// Notify with weight data
|
|
207
|
+
this.notifyCallback({
|
|
208
|
+
massMax: this.massMax,
|
|
209
|
+
massAverage: this.massAverage,
|
|
210
|
+
massTotal: Math.max(-1000, numericData).toFixed(1),
|
|
211
|
+
});
|
|
212
|
+
}
|
|
171
213
|
}
|
|
172
|
-
// If device is not found, return undefined
|
|
173
|
-
return undefined;
|
|
174
214
|
};
|
|
175
215
|
/**
|
|
176
216
|
* Retrieves humidity level from the device.
|
|
177
217
|
* @returns {Promise<string>} A Promise that resolves with the humidity level,
|
|
178
218
|
*/
|
|
179
219
|
humidity = async () => {
|
|
180
|
-
|
|
181
|
-
if (this.isConnected()) {
|
|
182
|
-
return await this.read("humidity", "level", 250);
|
|
183
|
-
}
|
|
184
|
-
// If device is not found, return undefined
|
|
185
|
-
return undefined;
|
|
220
|
+
return await this.read("humidity", "level", 250);
|
|
186
221
|
};
|
|
187
222
|
/**
|
|
188
223
|
* Retrieves manufacturer information from the device.
|
|
189
224
|
* @returns {Promise<string>} A Promise that resolves with the manufacturer information,
|
|
190
225
|
*/
|
|
191
226
|
manufacturer = async () => {
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
227
|
+
return await this.read("device", "manufacturer", 250);
|
|
228
|
+
};
|
|
229
|
+
/**
|
|
230
|
+
* Stops the data stream on the specified device.
|
|
231
|
+
* @returns {Promise<void>} A promise that resolves when the stream is stopped.
|
|
232
|
+
*/
|
|
233
|
+
stop = async () => {
|
|
234
|
+
await this.write("weight", "tx", this.commands.STOP_WEIGHT_MEAS, 0);
|
|
235
|
+
};
|
|
236
|
+
/**
|
|
237
|
+
* Starts streaming data from the specified device.
|
|
238
|
+
* @param {number} [duration=0] - The duration of the stream in milliseconds. If set to 0, stream will continue indefinitely.
|
|
239
|
+
* @returns {Promise<void>} A promise that resolves when the streaming operation is completed.
|
|
240
|
+
*/
|
|
241
|
+
stream = async (duration = 0) => {
|
|
242
|
+
// Reset download packets
|
|
243
|
+
emptyDownloadPackets();
|
|
244
|
+
// Start streaming data
|
|
245
|
+
await this.write("weight", "tx", new Uint8Array([0x04]), duration); // ASCII control character EOT (End of Transmission)
|
|
246
|
+
// Stop streaming if duration is set
|
|
247
|
+
if (duration !== 0) {
|
|
248
|
+
await this.stop();
|
|
196
249
|
}
|
|
197
|
-
|
|
198
|
-
|
|
250
|
+
};
|
|
251
|
+
/**
|
|
252
|
+
* Retrieves temperature information from the device.
|
|
253
|
+
* @returns {Promise<string>} A Promise that resolves with the manufacturer information,
|
|
254
|
+
*/
|
|
255
|
+
temperature = async () => {
|
|
256
|
+
return await this.read("temperature", "level", 250);
|
|
199
257
|
};
|
|
200
258
|
}
|
|
@@ -162,37 +162,23 @@ export class Motherboard extends Device {
|
|
|
162
162
|
* @returns {Promise<string | undefined>} A Promise that resolves with the battery or voltage information,
|
|
163
163
|
*/
|
|
164
164
|
battery = async () => {
|
|
165
|
-
|
|
166
|
-
return await this.read("battery", "level", 250);
|
|
167
|
-
}
|
|
168
|
-
// If device is not found, return undefined
|
|
169
|
-
return undefined;
|
|
165
|
+
return await this.read("battery", "level", 250);
|
|
170
166
|
};
|
|
171
167
|
/**
|
|
172
168
|
* Writes a command to get calibration data from the device.
|
|
173
169
|
* @returns {Promise<void>} A Promise that resolves when the command is successfully sent.
|
|
174
170
|
*/
|
|
175
171
|
calibration = async () => {
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
await this.write("uart", "tx", this.commands.GET_CALIBRATION, 2500, (data) => {
|
|
180
|
-
console.log(data);
|
|
181
|
-
});
|
|
182
|
-
}
|
|
172
|
+
await this.write("uart", "tx", this.commands.GET_CALIBRATION, 2500, (data) => {
|
|
173
|
+
console.log(data);
|
|
174
|
+
});
|
|
183
175
|
};
|
|
184
176
|
/**
|
|
185
177
|
* Retrieves firmware version from the device.
|
|
186
178
|
* @returns {Promise<string>} A Promise that resolves with the firmware version,
|
|
187
179
|
*/
|
|
188
180
|
firmware = async () => {
|
|
189
|
-
|
|
190
|
-
if (this.isConnected()) {
|
|
191
|
-
// Read firmware version from the Motherboard
|
|
192
|
-
return await this.read("device", "firmware", 250);
|
|
193
|
-
}
|
|
194
|
-
// If device is not found, return undefined
|
|
195
|
-
return undefined;
|
|
181
|
+
return await this.read("device", "firmware", 250);
|
|
196
182
|
};
|
|
197
183
|
/**
|
|
198
184
|
* Handles data received from the Motherboard device. Processes hex-encoded streaming packets
|
|
@@ -303,13 +289,7 @@ export class Motherboard extends Device {
|
|
|
303
289
|
* @returns {Promise<string>} A Promise that resolves with the hardware version,
|
|
304
290
|
*/
|
|
305
291
|
hardware = async () => {
|
|
306
|
-
|
|
307
|
-
if (this.isConnected()) {
|
|
308
|
-
// Read hardware version from the device
|
|
309
|
-
return await this.read("device", "hardware", 250);
|
|
310
|
-
}
|
|
311
|
-
// If device is not found, return undefined
|
|
312
|
-
return undefined;
|
|
292
|
+
return await this.read("device", "hardware", 250);
|
|
313
293
|
};
|
|
314
294
|
/**
|
|
315
295
|
* Sets the LED color based on a single color option. Defaults to turning the LEDs off if no configuration is provided.
|
|
@@ -337,40 +317,25 @@ export class Motherboard extends Device {
|
|
|
337
317
|
* @returns {Promise<string>} A Promise that resolves with the manufacturer information,
|
|
338
318
|
*/
|
|
339
319
|
manufacturer = async () => {
|
|
340
|
-
|
|
341
|
-
if (this.isConnected()) {
|
|
342
|
-
// Read manufacturer information from the device
|
|
343
|
-
return await this.read("device", "manufacturer", 250);
|
|
344
|
-
}
|
|
345
|
-
// If device is not found, return undefined
|
|
346
|
-
return undefined;
|
|
320
|
+
return await this.read("device", "manufacturer", 250);
|
|
347
321
|
};
|
|
348
322
|
/**
|
|
349
323
|
* Retrieves serial number from the device.
|
|
350
324
|
* @returns {Promise<string>} A Promise that resolves with the serial number,
|
|
351
325
|
*/
|
|
352
326
|
serial = async () => {
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
response = data;
|
|
359
|
-
});
|
|
360
|
-
return response;
|
|
361
|
-
}
|
|
362
|
-
// If device is not found, return undefined
|
|
363
|
-
return undefined;
|
|
327
|
+
let response = undefined;
|
|
328
|
+
await this.write("uart", "tx", this.commands.GET_SERIAL, 250, (data) => {
|
|
329
|
+
response = data;
|
|
330
|
+
});
|
|
331
|
+
return response;
|
|
364
332
|
};
|
|
365
333
|
/**
|
|
366
334
|
* Stops the data stream on the specified device.
|
|
367
335
|
* @returns {Promise<void>} A promise that resolves when the stream is stopped.
|
|
368
336
|
*/
|
|
369
337
|
stop = async () => {
|
|
370
|
-
|
|
371
|
-
// Stop stream of device
|
|
372
|
-
await this.write("uart", "tx", this.commands.STOP_WEIGHT_MEAS, 0);
|
|
373
|
-
}
|
|
338
|
+
await this.write("uart", "tx", this.commands.STOP_WEIGHT_MEAS, 0);
|
|
374
339
|
};
|
|
375
340
|
/**
|
|
376
341
|
* Starts streaming data from the specified device.
|
|
@@ -378,20 +343,17 @@ export class Motherboard extends Device {
|
|
|
378
343
|
* @returns {Promise<void>} A promise that resolves when the streaming operation is completed.
|
|
379
344
|
*/
|
|
380
345
|
stream = async (duration = 0) => {
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
if (duration !== 0) {
|
|
393
|
-
await this.stop();
|
|
394
|
-
}
|
|
346
|
+
// Reset download packets
|
|
347
|
+
emptyDownloadPackets();
|
|
348
|
+
// Read calibration data if not already available
|
|
349
|
+
if (!this.CALIBRATION[0].length) {
|
|
350
|
+
await this.calibration();
|
|
351
|
+
}
|
|
352
|
+
// Start streaming data
|
|
353
|
+
await this.write("uart", "tx", this.commands.START_WEIGHT_MEAS, duration);
|
|
354
|
+
// Stop streaming if duration is set
|
|
355
|
+
if (duration !== 0) {
|
|
356
|
+
await this.stop();
|
|
395
357
|
}
|
|
396
358
|
};
|
|
397
359
|
/**
|
|
@@ -404,16 +366,10 @@ export class Motherboard extends Device {
|
|
|
404
366
|
* @returns {Promise<string>} A Promise that resolves with the 320-byte memory content as a string,
|
|
405
367
|
*/
|
|
406
368
|
text = async () => {
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
response = data;
|
|
413
|
-
});
|
|
414
|
-
return response;
|
|
415
|
-
}
|
|
416
|
-
// If device is not found, return undefined
|
|
417
|
-
return undefined;
|
|
369
|
+
let response = undefined;
|
|
370
|
+
await this.write("uart", "tx", this.commands.GET_TEXT, 250, (data) => {
|
|
371
|
+
response = data;
|
|
372
|
+
});
|
|
373
|
+
return response;
|
|
418
374
|
};
|
|
419
375
|
}
|
|
@@ -16,7 +16,7 @@ export declare class Progressor extends Device implements IProgressor {
|
|
|
16
16
|
*/
|
|
17
17
|
firmware: () => Promise<string | undefined>;
|
|
18
18
|
/**
|
|
19
|
-
* Handles data received from the
|
|
19
|
+
* Handles data received from the device, processes weight measurements,
|
|
20
20
|
* and updates mass data including maximum and average values.
|
|
21
21
|
* It also handles command responses for retrieving device information.
|
|
22
22
|
*
|
|
@@ -93,35 +93,25 @@ export class Progressor extends Device {
|
|
|
93
93
|
* @returns {Promise<string | undefined>} A Promise that resolves with the battery or voltage information,
|
|
94
94
|
*/
|
|
95
95
|
battery = async () => {
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
return response;
|
|
102
|
-
}
|
|
103
|
-
// If device is not found, return undefined
|
|
104
|
-
return undefined;
|
|
96
|
+
let response = undefined;
|
|
97
|
+
await this.write("progressor", "tx", this.commands.GET_BATT_VLTG, 250, (data) => {
|
|
98
|
+
response = data;
|
|
99
|
+
});
|
|
100
|
+
return response;
|
|
105
101
|
};
|
|
106
102
|
/**
|
|
107
103
|
* Retrieves firmware version from the device.
|
|
108
104
|
* @returns {Promise<string>} A Promise that resolves with the firmware version,
|
|
109
105
|
*/
|
|
110
106
|
firmware = async () => {
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
response = data;
|
|
117
|
-
});
|
|
118
|
-
return response;
|
|
119
|
-
}
|
|
120
|
-
// If device is not found, return undefined
|
|
121
|
-
return undefined;
|
|
107
|
+
let response = undefined;
|
|
108
|
+
await this.write("progressor", "tx", this.commands.GET_FW_VERSION, 250, (data) => {
|
|
109
|
+
response = data;
|
|
110
|
+
});
|
|
111
|
+
return response;
|
|
122
112
|
};
|
|
123
113
|
/**
|
|
124
|
-
* Handles data received from the
|
|
114
|
+
* Handles data received from the device, processes weight measurements,
|
|
125
115
|
* and updates mass data including maximum and average values.
|
|
126
116
|
* It also handles command responses for retrieving device information.
|
|
127
117
|
*
|
|
@@ -198,10 +188,7 @@ export class Progressor extends Device {
|
|
|
198
188
|
* @returns {Promise<void>} A promise that resolves when the stream is stopped.
|
|
199
189
|
*/
|
|
200
190
|
stop = async () => {
|
|
201
|
-
|
|
202
|
-
// Stop stream of device
|
|
203
|
-
await this.write("progressor", "tx", this.commands.STOP_WEIGHT_MEAS, 0);
|
|
204
|
-
}
|
|
191
|
+
await this.write("progressor", "tx", this.commands.STOP_WEIGHT_MEAS, 0);
|
|
205
192
|
};
|
|
206
193
|
/**
|
|
207
194
|
* Starts streaming data from the specified device.
|
|
@@ -209,15 +196,13 @@ export class Progressor extends Device {
|
|
|
209
196
|
* @returns {Promise<void>} A promise that resolves when the streaming operation is completed.
|
|
210
197
|
*/
|
|
211
198
|
stream = async (duration = 0) => {
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
await this.stop();
|
|
220
|
-
}
|
|
199
|
+
// Reset download packets
|
|
200
|
+
emptyDownloadPackets();
|
|
201
|
+
// Start streaming data
|
|
202
|
+
await this.write("progressor", "tx", this.commands.START_WEIGHT_MEAS, duration);
|
|
203
|
+
// Stop streaming if duration is set
|
|
204
|
+
if (duration !== 0) {
|
|
205
|
+
await this.stop();
|
|
221
206
|
}
|
|
222
207
|
};
|
|
223
208
|
}
|
|
@@ -130,9 +130,9 @@ export declare abstract class Device extends BaseModel implements IDevice {
|
|
|
130
130
|
* @param {string} serviceId - The service ID where the characteristic belongs.
|
|
131
131
|
* @param {string} characteristicId - The characteristic ID to read from.
|
|
132
132
|
* @param {number} [duration=0] - The duration to wait before resolving the promise, in milliseconds.
|
|
133
|
-
* @returns {Promise<string>} A promise that resolves when the read operation is completed.
|
|
133
|
+
* @returns {Promise<string | undefined>} A promise that resolves when the read operation is completed.
|
|
134
134
|
*/
|
|
135
|
-
read: (serviceId: string, characteristicId: string, duration?: number) => Promise<string>;
|
|
135
|
+
read: (serviceId: string, characteristicId: string, duration?: number) => Promise<string | undefined>;
|
|
136
136
|
/**
|
|
137
137
|
* Writes a message to the specified characteristic of a Bluetooth device and optionally provides a callback to handle responses.
|
|
138
138
|
* @param {string} serviceId - The service UUID of the Bluetooth device containing the target characteristic.
|