@hangtime/grip-connect 0.2.6 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +24 -14
- package/package.json +1 -1
- package/src/battery.d.ts +3 -2
- package/src/battery.js +8 -2
- package/src/battery.ts +8 -2
- package/src/calibration.d.ts +3 -2
- package/src/calibration.js +6 -2
- package/src/calibration.ts +6 -2
- package/src/characteristic.d.ts +5 -4
- package/src/characteristic.js +9 -4
- package/src/characteristic.ts +14 -5
- package/src/commands/index.d.ts +2 -1
- package/src/commands/index.js +2 -1
- package/src/commands/index.ts +3 -1
- package/src/commands/{smartboard.d.ts → musclemeter.d.ts} +1 -1
- package/src/commands/{smartboard.js → musclemeter.js} +1 -1
- package/src/commands/{smartboard.ts → musclemeter.ts} +1 -1
- package/src/commands/mysmartboard.d.ts +6 -0
- package/src/commands/mysmartboard.js +5 -0
- package/src/commands/mysmartboard.ts +6 -0
- package/src/commands/progressor.d.ts +2 -0
- package/src/commands/progressor.js +3 -1
- package/src/commands/progressor.ts +3 -1
- package/src/connect.d.ts +3 -3
- package/src/connect.js +23 -30
- package/src/connect.ts +23 -30
- package/src/data.d.ts +13 -6
- package/src/data.js +112 -49
- package/src/data.ts +128 -62
- package/src/devices/climbro.d.ts +4 -0
- package/src/devices/climbro.js +4 -0
- package/src/devices/climbro.ts +4 -0
- package/src/devices/entralpi.d.ts +3 -0
- package/src/devices/entralpi.js +3 -0
- package/src/devices/entralpi.ts +3 -0
- package/src/devices/index.d.ts +2 -1
- package/src/devices/index.js +2 -1
- package/src/devices/index.ts +3 -1
- package/src/devices/motherboard.d.ts +3 -0
- package/src/devices/motherboard.js +3 -0
- package/src/devices/motherboard.ts +3 -0
- package/src/devices/musclemeter.d.ts +6 -0
- package/src/devices/musclemeter.js +8 -0
- package/src/devices/musclemeter.ts +10 -0
- package/src/devices/mysmartboard.d.ts +6 -0
- package/src/devices/mysmartboard.js +8 -0
- package/src/devices/mysmartboard.ts +10 -0
- package/src/devices/progressor.d.ts +3 -0
- package/src/devices/progressor.js +4 -1
- package/src/devices/progressor.ts +4 -2
- package/src/devices/types.d.ts +9 -0
- package/src/devices/types.ts +21 -12
- package/src/disconnect.d.ts +2 -2
- package/src/disconnect.js +4 -2
- package/src/disconnect.ts +4 -2
- package/src/download.d.ts +19 -0
- package/src/download.js +50 -0
- package/src/download.ts +73 -0
- package/src/index.d.ts +3 -1
- package/src/index.js +11 -3
- package/src/index.ts +12 -8
- package/src/info.d.ts +3 -2
- package/src/info.js +9 -2
- package/src/info.ts +9 -2
- package/src/is-connected.d.ts +3 -3
- package/src/is-connected.js +7 -4
- package/src/is-connected.ts +8 -4
- package/src/notify.d.ts +19 -1
- package/src/notify.js +10 -2
- package/src/notify.ts +21 -6
- package/src/read.d.ts +6 -2
- package/src/read.js +10 -6
- package/src/read.ts +10 -6
- package/src/stop.d.ts +3 -2
- package/src/stop.js +5 -2
- package/src/stop.ts +5 -2
- package/src/stream.d.ts +4 -2
- package/src/stream.js +13 -7
- package/src/stream.ts +13 -7
- package/src/tare.d.ts +12 -0
- package/src/tare.js +70 -0
- package/src/tare.ts +76 -0
- package/src/write.d.ts +11 -3
- package/src/write.js +21 -6
- package/src/write.ts +23 -6
- package/src/devices/smartboard.d.ts +0 -2
- package/src/devices/smartboard.js +0 -4
- package/src/devices/smartboard.ts +0 -6
package/src/data.js
CHANGED
|
@@ -1,14 +1,23 @@
|
|
|
1
1
|
import { notifyCallback } from "./notify";
|
|
2
|
+
import { applyTare } from "./tare";
|
|
2
3
|
import { ProgressorCommands, ProgressorResponses } from "./commands/progressor";
|
|
4
|
+
import { MotherboardCommands } from "./commands";
|
|
3
5
|
import { lastWrite } from "./write";
|
|
6
|
+
import { DownloadPackets } from "./download";
|
|
4
7
|
import struct from "./struct";
|
|
8
|
+
// Constants
|
|
5
9
|
const PACKET_LENGTH = 32;
|
|
6
10
|
const NUM_SAMPLES = 3;
|
|
11
|
+
let MASS_MAX = "0";
|
|
12
|
+
let MASS_AVERAGE = "0";
|
|
13
|
+
let MASS_TOTAL_SUM = 0;
|
|
14
|
+
let DATAPOINT_COUNT = 0;
|
|
7
15
|
export const CALIBRATION = [[], [], [], []];
|
|
8
16
|
/**
|
|
9
|
-
*
|
|
10
|
-
* @param sample
|
|
11
|
-
* @param calibration
|
|
17
|
+
* Applies calibration to a sample value.
|
|
18
|
+
* @param {number} sample - The sample value to calibrate.
|
|
19
|
+
* @param {number[][]} calibration - The calibration data.
|
|
20
|
+
* @returns {number} The calibrated sample value.
|
|
12
21
|
*/
|
|
13
22
|
const applyCalibration = (sample, calibration) => {
|
|
14
23
|
// Extract the calibrated value for the zero point
|
|
@@ -43,12 +52,10 @@ const applyCalibration = (sample, calibration) => {
|
|
|
43
52
|
return sign * final;
|
|
44
53
|
};
|
|
45
54
|
/**
|
|
46
|
-
*
|
|
47
|
-
*
|
|
48
|
-
* @param uuid - Unique identifier
|
|
49
|
-
* @param receivedData - Received data string
|
|
55
|
+
* Handles data received from the Motherboard device.
|
|
56
|
+
* @param {string} receivedData - The received data string.
|
|
50
57
|
*/
|
|
51
|
-
export const handleMotherboardData = (
|
|
58
|
+
export const handleMotherboardData = (receivedData) => {
|
|
52
59
|
const receivedTime = Date.now();
|
|
53
60
|
// Check if the line is entirely hex characters
|
|
54
61
|
const isAllHex = /^[0-9A-Fa-f]+$/g.test(receivedData);
|
|
@@ -76,52 +83,91 @@ export const handleMotherboardData = (uuid, receivedData) => {
|
|
|
76
83
|
if (packet.samples[i] >= 0x7fffff) {
|
|
77
84
|
packet.samples[i] -= 0x1000000;
|
|
78
85
|
}
|
|
79
|
-
// if (!CALIBRATION[0].length) return
|
|
80
86
|
packet.masses[i] = applyCalibration(packet.samples[i], CALIBRATION[i]);
|
|
81
87
|
}
|
|
82
88
|
// invert center and right values
|
|
83
89
|
packet.masses[1] *= -1;
|
|
84
90
|
packet.masses[2] *= -1;
|
|
85
|
-
//
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
91
|
+
// Add data to downloadable Array
|
|
92
|
+
DownloadPackets.push({
|
|
93
|
+
received: packet.received,
|
|
94
|
+
sampleNum: packet.battRaw,
|
|
95
|
+
battRaw: packet.received,
|
|
96
|
+
samples: [...packet.samples],
|
|
97
|
+
masses: [...packet.masses],
|
|
98
|
+
});
|
|
99
|
+
let left = packet.masses[0];
|
|
100
|
+
let center = packet.masses[1];
|
|
101
|
+
let right = packet.masses[2];
|
|
102
|
+
// Tare correction
|
|
103
|
+
left -= applyTare(left);
|
|
104
|
+
center -= applyTare(center);
|
|
105
|
+
right -= applyTare(right);
|
|
106
|
+
MASS_MAX = Math.max(Number(MASS_MAX), Math.max(-1000, left + center + right)).toFixed(1);
|
|
107
|
+
// Update running sum and count
|
|
108
|
+
const currentMassTotal = Math.max(-1000, left + center + right);
|
|
109
|
+
MASS_TOTAL_SUM += currentMassTotal;
|
|
110
|
+
DATAPOINT_COUNT++;
|
|
111
|
+
// Calculate the average dynamically
|
|
112
|
+
MASS_AVERAGE = (MASS_TOTAL_SUM / DATAPOINT_COUNT).toFixed(1);
|
|
113
|
+
// Notify with weight data
|
|
114
|
+
notifyCallback({
|
|
115
|
+
massTotal: Math.max(-1000, left + center + right).toFixed(1),
|
|
116
|
+
massMax: MASS_MAX,
|
|
117
|
+
massAverage: MASS_AVERAGE,
|
|
118
|
+
massLeft: Math.max(-1000, packet.masses[0]).toFixed(1),
|
|
119
|
+
massCenter: Math.max(-1000, packet.masses[1]).toFixed(1),
|
|
120
|
+
massRight: Math.max(-1000, packet.masses[2]).toFixed(1),
|
|
121
|
+
});
|
|
100
122
|
}
|
|
101
|
-
else if (
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
123
|
+
else if (lastWrite === MotherboardCommands.GET_CALIBRATION) {
|
|
124
|
+
// check data integrity
|
|
125
|
+
if ((receivedData.match(/,/g) || []).length === 3) {
|
|
126
|
+
const parts = receivedData.split(",");
|
|
127
|
+
const numericParts = parts.map((x) => parseFloat(x));
|
|
128
|
+
CALIBRATION[numericParts[0]].push(numericParts.slice(1));
|
|
129
|
+
}
|
|
107
130
|
}
|
|
108
131
|
else {
|
|
109
|
-
//
|
|
132
|
+
// unhandled data
|
|
110
133
|
console.log(receivedData);
|
|
111
134
|
}
|
|
112
135
|
};
|
|
113
|
-
|
|
114
|
-
|
|
136
|
+
/**
|
|
137
|
+
* Handles data received from the Progressor device.
|
|
138
|
+
* @param {DataView} data - The received data.
|
|
139
|
+
*/
|
|
140
|
+
export const handleProgressorData = (data) => {
|
|
141
|
+
const receivedTime = Date.now();
|
|
115
142
|
const [kind] = struct("<bb").unpack(data.buffer.slice(0, 2));
|
|
116
143
|
if (kind === ProgressorResponses.WEIGHT_MEASURE) {
|
|
117
144
|
const iterable = struct("<fi").iter_unpack(data.buffer.slice(2));
|
|
118
|
-
|
|
119
|
-
|
|
145
|
+
console.log(iterable);
|
|
146
|
+
// eslint-disable-next-line prefer-const
|
|
147
|
+
for (let [weight, seconds] of iterable) {
|
|
148
|
+
if (typeof weight === "number" && !isNaN(weight) && typeof seconds === "number" && !isNaN(seconds)) {
|
|
149
|
+
// Add data to downloadable Array: sample and mass are the same
|
|
150
|
+
DownloadPackets.push({
|
|
151
|
+
received: receivedTime,
|
|
152
|
+
sampleNum: seconds,
|
|
153
|
+
battRaw: 0,
|
|
154
|
+
samples: [weight],
|
|
155
|
+
masses: [weight],
|
|
156
|
+
});
|
|
157
|
+
// Tare correction
|
|
158
|
+
weight -= applyTare(weight);
|
|
159
|
+
// Check for max weight
|
|
160
|
+
MASS_MAX = Math.max(Number(MASS_MAX), Number(weight)).toFixed(1);
|
|
161
|
+
// Update running sum and count
|
|
162
|
+
const currentMassTotal = Math.max(-1000, Number(weight));
|
|
163
|
+
MASS_TOTAL_SUM += currentMassTotal;
|
|
164
|
+
DATAPOINT_COUNT++;
|
|
165
|
+
// Calculate the average dynamically
|
|
166
|
+
MASS_AVERAGE = (MASS_TOTAL_SUM / DATAPOINT_COUNT).toFixed(1);
|
|
120
167
|
notifyCallback({
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
},
|
|
168
|
+
massMax: MASS_MAX,
|
|
169
|
+
massAverage: MASS_AVERAGE,
|
|
170
|
+
massTotal: Math.max(-1000, weight).toFixed(1),
|
|
125
171
|
});
|
|
126
172
|
}
|
|
127
173
|
}
|
|
@@ -132,7 +178,7 @@ export const handleProgressorData = (uuid, data) => {
|
|
|
132
178
|
let value = "";
|
|
133
179
|
if (lastWrite === ProgressorCommands.GET_BATT_VLTG) {
|
|
134
180
|
const vdd = new DataView(data.buffer, 2).getUint32(0, true);
|
|
135
|
-
value =
|
|
181
|
+
value = `ℹ️ Battery level: ${vdd} mV`;
|
|
136
182
|
}
|
|
137
183
|
else if (lastWrite === ProgressorCommands.GET_FW_VERSION) {
|
|
138
184
|
value = new TextDecoder().decode(data.buffer.slice(2));
|
|
@@ -140,18 +186,35 @@ export const handleProgressorData = (uuid, data) => {
|
|
|
140
186
|
else if (lastWrite === ProgressorCommands.GET_ERR_INFO) {
|
|
141
187
|
value = new TextDecoder().decode(data.buffer.slice(2));
|
|
142
188
|
}
|
|
143
|
-
|
|
144
|
-
notifyCallback({ uuid: uuid, value: value });
|
|
145
|
-
}
|
|
189
|
+
console.log(value);
|
|
146
190
|
}
|
|
147
191
|
else if (kind === ProgressorResponses.LOW_BATTERY_WARNING) {
|
|
148
|
-
|
|
149
|
-
notifyCallback({ uuid: uuid, value: "low power warning" });
|
|
150
|
-
}
|
|
192
|
+
console.warn("⚠️ Low power detected. Please consider connecting to a power source.");
|
|
151
193
|
}
|
|
152
194
|
else {
|
|
153
|
-
|
|
154
|
-
notifyCallback({ uuid: uuid, value: `unknown message kind ${kind}` });
|
|
155
|
-
}
|
|
195
|
+
console.error(`❌ Error: Unknown message kind detected: ${kind}`);
|
|
156
196
|
}
|
|
157
197
|
};
|
|
198
|
+
/**
|
|
199
|
+
* Handles data received from the Entralpi device.
|
|
200
|
+
* @param {string} receivedData - The received data string.
|
|
201
|
+
*/
|
|
202
|
+
export const handleEntralpiData = (receivedData) => {
|
|
203
|
+
let numericData = Number(receivedData);
|
|
204
|
+
// Tare correction
|
|
205
|
+
numericData -= applyTare(numericData);
|
|
206
|
+
// Update MASS_MAX
|
|
207
|
+
MASS_MAX = Math.max(Number(MASS_MAX), numericData).toFixed(1);
|
|
208
|
+
// Update running sum and count
|
|
209
|
+
const currentMassTotal = Math.max(-1000, numericData);
|
|
210
|
+
MASS_TOTAL_SUM += currentMassTotal;
|
|
211
|
+
DATAPOINT_COUNT++;
|
|
212
|
+
// Calculate the average dynamically
|
|
213
|
+
MASS_AVERAGE = (MASS_TOTAL_SUM / DATAPOINT_COUNT).toFixed(1);
|
|
214
|
+
// Notify with weight data
|
|
215
|
+
notifyCallback({
|
|
216
|
+
massMax: MASS_MAX,
|
|
217
|
+
massAverage: MASS_AVERAGE,
|
|
218
|
+
massTotal: Math.max(-1000, numericData).toFixed(1),
|
|
219
|
+
});
|
|
220
|
+
};
|
package/src/data.ts
CHANGED
|
@@ -1,23 +1,31 @@
|
|
|
1
1
|
import { notifyCallback } from "./notify"
|
|
2
|
+
import { applyTare } from "./tare"
|
|
2
3
|
import { ProgressorCommands, ProgressorResponses } from "./commands/progressor"
|
|
4
|
+
import { MotherboardCommands } from "./commands"
|
|
3
5
|
import { lastWrite } from "./write"
|
|
6
|
+
import { DownloadPacket, DownloadPackets } from "./download"
|
|
4
7
|
import struct from "./struct"
|
|
5
8
|
|
|
9
|
+
// Constants
|
|
6
10
|
const PACKET_LENGTH: number = 32
|
|
7
11
|
const NUM_SAMPLES: number = 3
|
|
12
|
+
let MASS_MAX: string = "0"
|
|
13
|
+
let MASS_AVERAGE: string = "0"
|
|
14
|
+
let MASS_TOTAL_SUM: number = 0
|
|
15
|
+
let DATAPOINT_COUNT: number = 0
|
|
8
16
|
export const CALIBRATION = [[], [], [], []]
|
|
17
|
+
|
|
9
18
|
/**
|
|
10
|
-
*
|
|
11
|
-
* @param sample
|
|
12
|
-
* @param calibration
|
|
19
|
+
* Applies calibration to a sample value.
|
|
20
|
+
* @param {number} sample - The sample value to calibrate.
|
|
21
|
+
* @param {number[][]} calibration - The calibration data.
|
|
22
|
+
* @returns {number} The calibrated sample value.
|
|
13
23
|
*/
|
|
14
24
|
const applyCalibration = (sample: number, calibration: number[][]): number => {
|
|
15
25
|
// Extract the calibrated value for the zero point
|
|
16
26
|
const zeroCalibration: number = calibration[0][2]
|
|
17
|
-
|
|
18
27
|
// Initialize sign as positive
|
|
19
28
|
let sign: number = 1
|
|
20
|
-
|
|
21
29
|
// Initialize the final calibrated value
|
|
22
30
|
let final: number = 0
|
|
23
31
|
|
|
@@ -25,7 +33,6 @@ const applyCalibration = (sample: number, calibration: number[][]): number => {
|
|
|
25
33
|
if (sample < zeroCalibration) {
|
|
26
34
|
// Change the sign to negative
|
|
27
35
|
sign = -1
|
|
28
|
-
|
|
29
36
|
// Reflect the sample around the zero calibration point
|
|
30
37
|
sample = /* 2 * zeroCalibration */ -sample
|
|
31
38
|
}
|
|
@@ -49,22 +56,11 @@ const applyCalibration = (sample: number, calibration: number[][]): number => {
|
|
|
49
56
|
// Return the calibrated value with the appropriate sign (positive/negative)
|
|
50
57
|
return sign * final
|
|
51
58
|
}
|
|
52
|
-
|
|
53
|
-
interface Packet {
|
|
54
|
-
received: number
|
|
55
|
-
sampleNum: number
|
|
56
|
-
battRaw: number
|
|
57
|
-
samples: number[]
|
|
58
|
-
masses: number[]
|
|
59
|
-
}
|
|
60
|
-
|
|
61
59
|
/**
|
|
62
|
-
*
|
|
63
|
-
*
|
|
64
|
-
* @param uuid - Unique identifier
|
|
65
|
-
* @param receivedData - Received data string
|
|
60
|
+
* Handles data received from the Motherboard device.
|
|
61
|
+
* @param {string} receivedData - The received data string.
|
|
66
62
|
*/
|
|
67
|
-
export const handleMotherboardData = (
|
|
63
|
+
export const handleMotherboardData = (receivedData: string): void => {
|
|
68
64
|
const receivedTime: number = Date.now()
|
|
69
65
|
|
|
70
66
|
// Check if the line is entirely hex characters
|
|
@@ -78,7 +74,7 @@ export const handleMotherboardData = (uuid: string, receivedData: string): void
|
|
|
78
74
|
)
|
|
79
75
|
|
|
80
76
|
// Translate header into packet, number of samples from the packet length
|
|
81
|
-
const packet:
|
|
77
|
+
const packet: DownloadPacket = {
|
|
82
78
|
received: receivedTime,
|
|
83
79
|
sampleNum: new DataView(new Uint8Array(bytes).buffer).getUint16(0, true),
|
|
84
80
|
battRaw: new DataView(new Uint8Array(bytes).buffer).getUint16(2, true),
|
|
@@ -102,51 +98,99 @@ export const handleMotherboardData = (uuid: string, receivedData: string): void
|
|
|
102
98
|
if (packet.samples[i] >= 0x7fffff) {
|
|
103
99
|
packet.samples[i] -= 0x1000000
|
|
104
100
|
}
|
|
105
|
-
// if (!CALIBRATION[0].length) return
|
|
106
101
|
packet.masses[i] = applyCalibration(packet.samples[i], CALIBRATION[i])
|
|
107
102
|
}
|
|
108
103
|
// invert center and right values
|
|
109
104
|
packet.masses[1] *= -1
|
|
110
105
|
packet.masses[2] *= -1
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
106
|
+
|
|
107
|
+
// Add data to downloadable Array
|
|
108
|
+
DownloadPackets.push({
|
|
109
|
+
received: packet.received,
|
|
110
|
+
sampleNum: packet.battRaw,
|
|
111
|
+
battRaw: packet.received,
|
|
112
|
+
samples: [...packet.samples],
|
|
113
|
+
masses: [...packet.masses],
|
|
114
|
+
})
|
|
115
|
+
|
|
116
|
+
let left: number = packet.masses[0]
|
|
117
|
+
let center: number = packet.masses[1]
|
|
118
|
+
let right: number = packet.masses[2]
|
|
119
|
+
|
|
120
|
+
// Tare correction
|
|
121
|
+
left -= applyTare(left)
|
|
122
|
+
center -= applyTare(center)
|
|
123
|
+
right -= applyTare(right)
|
|
124
|
+
|
|
125
|
+
MASS_MAX = Math.max(Number(MASS_MAX), Math.max(-1000, left + center + right)).toFixed(1)
|
|
126
|
+
|
|
127
|
+
// Update running sum and count
|
|
128
|
+
const currentMassTotal = Math.max(-1000, left + center + right)
|
|
129
|
+
MASS_TOTAL_SUM += currentMassTotal
|
|
130
|
+
DATAPOINT_COUNT++
|
|
131
|
+
|
|
132
|
+
// Calculate the average dynamically
|
|
133
|
+
MASS_AVERAGE = (MASS_TOTAL_SUM / DATAPOINT_COUNT).toFixed(1)
|
|
134
|
+
|
|
135
|
+
// Notify with weight data
|
|
136
|
+
notifyCallback({
|
|
137
|
+
massTotal: Math.max(-1000, left + center + right).toFixed(1),
|
|
138
|
+
massMax: MASS_MAX,
|
|
139
|
+
massAverage: MASS_AVERAGE,
|
|
140
|
+
massLeft: Math.max(-1000, packet.masses[0]).toFixed(1),
|
|
141
|
+
massCenter: Math.max(-1000, packet.masses[1]).toFixed(1),
|
|
142
|
+
massRight: Math.max(-1000, packet.masses[2]).toFixed(1),
|
|
143
|
+
})
|
|
144
|
+
} else if (lastWrite === MotherboardCommands.GET_CALIBRATION) {
|
|
145
|
+
// check data integrity
|
|
146
|
+
if ((receivedData.match(/,/g) || []).length === 3) {
|
|
147
|
+
const parts: string[] = receivedData.split(",")
|
|
148
|
+
const numericParts: number[] = parts.map((x) => parseFloat(x))
|
|
149
|
+
;(CALIBRATION[numericParts[0]] as number[][]).push(numericParts.slice(1))
|
|
125
150
|
}
|
|
126
|
-
} else if ((receivedData.match(/,/g) || []).length === 3) {
|
|
127
|
-
console.log(receivedData)
|
|
128
|
-
// if the returned notification is a calibration string add them to the array
|
|
129
|
-
const parts: string[] = receivedData.split(",")
|
|
130
|
-
const numericParts: number[] = parts.map((x) => parseFloat(x))
|
|
131
|
-
;(CALIBRATION[numericParts[0]] as number[][]).push(numericParts.slice(1))
|
|
132
151
|
} else {
|
|
133
|
-
//
|
|
152
|
+
// unhandled data
|
|
134
153
|
console.log(receivedData)
|
|
135
154
|
}
|
|
136
155
|
}
|
|
137
156
|
|
|
138
|
-
|
|
139
|
-
|
|
157
|
+
/**
|
|
158
|
+
* Handles data received from the Progressor device.
|
|
159
|
+
* @param {DataView} data - The received data.
|
|
160
|
+
*/
|
|
161
|
+
export const handleProgressorData = (data: DataView): void => {
|
|
162
|
+
const receivedTime: number = Date.now()
|
|
140
163
|
const [kind] = struct("<bb").unpack(data.buffer.slice(0, 2))
|
|
141
164
|
if (kind === ProgressorResponses.WEIGHT_MEASURE) {
|
|
142
|
-
const iterable = struct("<fi").iter_unpack(data.buffer.slice(2))
|
|
143
|
-
|
|
144
|
-
|
|
165
|
+
const iterable: IterableIterator<unknown[]> = struct("<fi").iter_unpack(data.buffer.slice(2))
|
|
166
|
+
console.log(iterable)
|
|
167
|
+
// eslint-disable-next-line prefer-const
|
|
168
|
+
for (let [weight, seconds] of iterable) {
|
|
169
|
+
if (typeof weight === "number" && !isNaN(weight) && typeof seconds === "number" && !isNaN(seconds)) {
|
|
170
|
+
// Add data to downloadable Array: sample and mass are the same
|
|
171
|
+
DownloadPackets.push({
|
|
172
|
+
received: receivedTime,
|
|
173
|
+
sampleNum: seconds,
|
|
174
|
+
battRaw: 0,
|
|
175
|
+
samples: [weight],
|
|
176
|
+
masses: [weight],
|
|
177
|
+
})
|
|
178
|
+
// Tare correction
|
|
179
|
+
weight -= applyTare(weight)
|
|
180
|
+
// Check for max weight
|
|
181
|
+
MASS_MAX = Math.max(Number(MASS_MAX), Number(weight)).toFixed(1)
|
|
182
|
+
// Update running sum and count
|
|
183
|
+
const currentMassTotal = Math.max(-1000, Number(weight))
|
|
184
|
+
MASS_TOTAL_SUM += currentMassTotal
|
|
185
|
+
DATAPOINT_COUNT++
|
|
186
|
+
|
|
187
|
+
// Calculate the average dynamically
|
|
188
|
+
MASS_AVERAGE = (MASS_TOTAL_SUM / DATAPOINT_COUNT).toFixed(1)
|
|
189
|
+
|
|
145
190
|
notifyCallback({
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
},
|
|
191
|
+
massMax: MASS_MAX,
|
|
192
|
+
massAverage: MASS_AVERAGE,
|
|
193
|
+
massTotal: Math.max(-1000, weight).toFixed(1),
|
|
150
194
|
})
|
|
151
195
|
}
|
|
152
196
|
}
|
|
@@ -157,22 +201,44 @@ export const handleProgressorData = (uuid: string, data: DataView): void => {
|
|
|
157
201
|
|
|
158
202
|
if (lastWrite === ProgressorCommands.GET_BATT_VLTG) {
|
|
159
203
|
const vdd = new DataView(data.buffer, 2).getUint32(0, true)
|
|
160
|
-
value =
|
|
204
|
+
value = `ℹ️ Battery level: ${vdd} mV`
|
|
161
205
|
} else if (lastWrite === ProgressorCommands.GET_FW_VERSION) {
|
|
162
206
|
value = new TextDecoder().decode(data.buffer.slice(2))
|
|
163
207
|
} else if (lastWrite === ProgressorCommands.GET_ERR_INFO) {
|
|
164
208
|
value = new TextDecoder().decode(data.buffer.slice(2))
|
|
165
209
|
}
|
|
166
|
-
|
|
167
|
-
notifyCallback({ uuid: uuid, value: value })
|
|
168
|
-
}
|
|
210
|
+
console.log(value)
|
|
169
211
|
} else if (kind === ProgressorResponses.LOW_BATTERY_WARNING) {
|
|
170
|
-
|
|
171
|
-
notifyCallback({ uuid: uuid, value: "low power warning" })
|
|
172
|
-
}
|
|
212
|
+
console.warn("⚠️ Low power detected. Please consider connecting to a power source.")
|
|
173
213
|
} else {
|
|
174
|
-
|
|
175
|
-
notifyCallback({ uuid: uuid, value: `unknown message kind ${kind}` })
|
|
176
|
-
}
|
|
214
|
+
console.error(`❌ Error: Unknown message kind detected: ${kind}`)
|
|
177
215
|
}
|
|
178
216
|
}
|
|
217
|
+
/**
|
|
218
|
+
* Handles data received from the Entralpi device.
|
|
219
|
+
* @param {string} receivedData - The received data string.
|
|
220
|
+
*/
|
|
221
|
+
export const handleEntralpiData = (receivedData: string): void => {
|
|
222
|
+
let numericData = Number(receivedData)
|
|
223
|
+
|
|
224
|
+
// Tare correction
|
|
225
|
+
numericData -= applyTare(numericData)
|
|
226
|
+
|
|
227
|
+
// Update MASS_MAX
|
|
228
|
+
MASS_MAX = Math.max(Number(MASS_MAX), numericData).toFixed(1)
|
|
229
|
+
|
|
230
|
+
// Update running sum and count
|
|
231
|
+
const currentMassTotal = Math.max(-1000, numericData)
|
|
232
|
+
MASS_TOTAL_SUM += currentMassTotal
|
|
233
|
+
DATAPOINT_COUNT++
|
|
234
|
+
|
|
235
|
+
// Calculate the average dynamically
|
|
236
|
+
MASS_AVERAGE = (MASS_TOTAL_SUM / DATAPOINT_COUNT).toFixed(1)
|
|
237
|
+
|
|
238
|
+
// Notify with weight data
|
|
239
|
+
notifyCallback({
|
|
240
|
+
massMax: MASS_MAX,
|
|
241
|
+
massAverage: MASS_AVERAGE,
|
|
242
|
+
massTotal: Math.max(-1000, numericData).toFixed(1),
|
|
243
|
+
})
|
|
244
|
+
}
|
package/src/devices/climbro.d.ts
CHANGED
package/src/devices/climbro.js
CHANGED
package/src/devices/climbro.ts
CHANGED
package/src/devices/entralpi.js
CHANGED
package/src/devices/entralpi.ts
CHANGED
package/src/devices/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export { Climbro } from "./climbro";
|
|
2
2
|
export { Entralpi } from "./entralpi";
|
|
3
3
|
export { Motherboard } from "./motherboard";
|
|
4
|
-
export {
|
|
4
|
+
export { mySmartBoard } from "./mysmartboard";
|
|
5
|
+
export { MuscleMeter } from "./musclemeter";
|
|
5
6
|
export { Progressor } from "./progressor";
|
package/src/devices/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export { Climbro } from "./climbro";
|
|
2
2
|
export { Entralpi } from "./entralpi";
|
|
3
3
|
export { Motherboard } from "./motherboard";
|
|
4
|
-
export {
|
|
4
|
+
export { mySmartBoard } from "./mysmartboard";
|
|
5
|
+
export { MuscleMeter } from "./musclemeter";
|
|
5
6
|
export { Progressor } from "./progressor";
|
package/src/devices/index.ts
CHANGED
|
@@ -4,6 +4,8 @@ export { Entralpi } from "./entralpi"
|
|
|
4
4
|
|
|
5
5
|
export { Motherboard } from "./motherboard"
|
|
6
6
|
|
|
7
|
-
export {
|
|
7
|
+
export { mySmartBoard } from "./mysmartboard"
|
|
8
|
+
|
|
9
|
+
export { MuscleMeter } from "./musclemeter"
|
|
8
10
|
|
|
9
11
|
export { Progressor } from "./progressor"
|