@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.
Files changed (88) hide show
  1. package/README.md +24 -14
  2. package/package.json +1 -1
  3. package/src/battery.d.ts +3 -2
  4. package/src/battery.js +8 -2
  5. package/src/battery.ts +8 -2
  6. package/src/calibration.d.ts +3 -2
  7. package/src/calibration.js +6 -2
  8. package/src/calibration.ts +6 -2
  9. package/src/characteristic.d.ts +5 -4
  10. package/src/characteristic.js +9 -4
  11. package/src/characteristic.ts +14 -5
  12. package/src/commands/index.d.ts +2 -1
  13. package/src/commands/index.js +2 -1
  14. package/src/commands/index.ts +3 -1
  15. package/src/commands/{smartboard.d.ts → musclemeter.d.ts} +1 -1
  16. package/src/commands/{smartboard.js → musclemeter.js} +1 -1
  17. package/src/commands/{smartboard.ts → musclemeter.ts} +1 -1
  18. package/src/commands/mysmartboard.d.ts +6 -0
  19. package/src/commands/mysmartboard.js +5 -0
  20. package/src/commands/mysmartboard.ts +6 -0
  21. package/src/commands/progressor.d.ts +2 -0
  22. package/src/commands/progressor.js +3 -1
  23. package/src/commands/progressor.ts +3 -1
  24. package/src/connect.d.ts +3 -3
  25. package/src/connect.js +23 -30
  26. package/src/connect.ts +23 -30
  27. package/src/data.d.ts +13 -6
  28. package/src/data.js +112 -49
  29. package/src/data.ts +128 -62
  30. package/src/devices/climbro.d.ts +4 -0
  31. package/src/devices/climbro.js +4 -0
  32. package/src/devices/climbro.ts +4 -0
  33. package/src/devices/entralpi.d.ts +3 -0
  34. package/src/devices/entralpi.js +3 -0
  35. package/src/devices/entralpi.ts +3 -0
  36. package/src/devices/index.d.ts +2 -1
  37. package/src/devices/index.js +2 -1
  38. package/src/devices/index.ts +3 -1
  39. package/src/devices/motherboard.d.ts +3 -0
  40. package/src/devices/motherboard.js +3 -0
  41. package/src/devices/motherboard.ts +3 -0
  42. package/src/devices/musclemeter.d.ts +6 -0
  43. package/src/devices/musclemeter.js +8 -0
  44. package/src/devices/musclemeter.ts +10 -0
  45. package/src/devices/mysmartboard.d.ts +6 -0
  46. package/src/devices/mysmartboard.js +8 -0
  47. package/src/devices/mysmartboard.ts +10 -0
  48. package/src/devices/progressor.d.ts +3 -0
  49. package/src/devices/progressor.js +4 -1
  50. package/src/devices/progressor.ts +4 -2
  51. package/src/devices/types.d.ts +9 -0
  52. package/src/devices/types.ts +21 -12
  53. package/src/disconnect.d.ts +2 -2
  54. package/src/disconnect.js +4 -2
  55. package/src/disconnect.ts +4 -2
  56. package/src/download.d.ts +19 -0
  57. package/src/download.js +50 -0
  58. package/src/download.ts +73 -0
  59. package/src/index.d.ts +3 -1
  60. package/src/index.js +11 -3
  61. package/src/index.ts +12 -8
  62. package/src/info.d.ts +3 -2
  63. package/src/info.js +9 -2
  64. package/src/info.ts +9 -2
  65. package/src/is-connected.d.ts +3 -3
  66. package/src/is-connected.js +7 -4
  67. package/src/is-connected.ts +8 -4
  68. package/src/notify.d.ts +19 -1
  69. package/src/notify.js +10 -2
  70. package/src/notify.ts +21 -6
  71. package/src/read.d.ts +6 -2
  72. package/src/read.js +10 -6
  73. package/src/read.ts +10 -6
  74. package/src/stop.d.ts +3 -2
  75. package/src/stop.js +5 -2
  76. package/src/stop.ts +5 -2
  77. package/src/stream.d.ts +4 -2
  78. package/src/stream.js +13 -7
  79. package/src/stream.ts +13 -7
  80. package/src/tare.d.ts +12 -0
  81. package/src/tare.js +70 -0
  82. package/src/tare.ts +76 -0
  83. package/src/write.d.ts +11 -3
  84. package/src/write.js +21 -6
  85. package/src/write.ts +23 -6
  86. package/src/devices/smartboard.d.ts +0 -2
  87. package/src/devices/smartboard.js +0 -4
  88. 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
- * applyCalibration
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
- * handleMotherboardData
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 = (uuid, receivedData) => {
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
- // map to variables
86
- const left = packet.masses[0];
87
- const center = packet.masses[1];
88
- const right = packet.masses[2];
89
- if (notifyCallback) {
90
- notifyCallback({
91
- uuid,
92
- value: {
93
- massTotal: Math.max(-1000, left + right + center).toFixed(1),
94
- massLeft: Math.max(-1000, left).toFixed(1),
95
- massRight: Math.max(-1000, right).toFixed(1),
96
- massCenter: Math.max(-1000, center).toFixed(1),
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 ((receivedData.match(/,/g) || []).length === 3) {
102
- console.log(receivedData);
103
- // if the returned notification is a calibration string add them to the array
104
- const parts = receivedData.split(",");
105
- const numericParts = parts.map((x) => parseFloat(x));
106
- CALIBRATION[numericParts[0]].push(numericParts.slice(1));
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
- // unhanded data
132
+ // unhandled data
110
133
  console.log(receivedData);
111
134
  }
112
135
  };
113
- export const handleProgressorData = (uuid, data) => {
114
- const tare = 0; // todo: add tare
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
- for (const [weight] of iterable) {
119
- if (notifyCallback) {
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
- uuid: uuid,
122
- value: {
123
- massTotal: Math.max(-1000, Number(weight) - tare).toFixed(1),
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 = `Battery level = ${vdd} [mV]`;
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
- if (notifyCallback) {
144
- notifyCallback({ uuid: uuid, value: value });
145
- }
189
+ console.log(value);
146
190
  }
147
191
  else if (kind === ProgressorResponses.LOW_BATTERY_WARNING) {
148
- if (notifyCallback) {
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
- if (notifyCallback) {
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
- * applyCalibration
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
- * handleMotherboardData
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 = (uuid: string, receivedData: string): void => {
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: 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
- // map to variables
112
- const left: number = packet.masses[0]
113
- const center: number = packet.masses[1]
114
- const right: number = packet.masses[2]
115
- if (notifyCallback) {
116
- notifyCallback({
117
- uuid,
118
- value: {
119
- massTotal: Math.max(-1000, left + right + center).toFixed(1),
120
- massLeft: Math.max(-1000, left).toFixed(1),
121
- massRight: Math.max(-1000, right).toFixed(1),
122
- massCenter: Math.max(-1000, center).toFixed(1),
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
- // unhanded data
152
+ // unhandled data
134
153
  console.log(receivedData)
135
154
  }
136
155
  }
137
156
 
138
- export const handleProgressorData = (uuid: string, data: DataView): void => {
139
- const tare: number = 0 // todo: add tare
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
- for (const [weight] of iterable) {
144
- if (notifyCallback) {
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
- uuid: uuid,
147
- value: {
148
- massTotal: Math.max(-1000, Number(weight) - tare).toFixed(1),
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 = `Battery level = ${vdd} [mV]`
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
- if (notifyCallback) {
167
- notifyCallback({ uuid: uuid, value: value })
168
- }
210
+ console.log(value)
169
211
  } else if (kind === ProgressorResponses.LOW_BATTERY_WARNING) {
170
- if (notifyCallback) {
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
- if (notifyCallback) {
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
+ }
@@ -1,2 +1,6 @@
1
1
  import { Device } from "./types";
2
+ /**
3
+ * Represents a Climbro device
4
+ * TODO: Add services, do you own a Climbro? Help us!
5
+ */
2
6
  export declare const Climbro: Device;
@@ -1,3 +1,7 @@
1
+ /**
2
+ * Represents a Climbro device
3
+ * TODO: Add services, do you own a Climbro? Help us!
4
+ */
1
5
  export const Climbro = {
2
6
  name: "Climbro",
3
7
  services: [],
@@ -1,5 +1,9 @@
1
1
  import { Device } from "./types"
2
2
 
3
+ /**
4
+ * Represents a Climbro device
5
+ * TODO: Add services, do you own a Climbro? Help us!
6
+ */
3
7
  export const Climbro: Device = {
4
8
  name: "Climbro",
5
9
  services: [],
@@ -1,2 +1,5 @@
1
1
  import { Device } from "./types";
2
+ /**
3
+ * Represents a Entralpi device
4
+ */
2
5
  export declare const Entralpi: Device;
@@ -1,3 +1,6 @@
1
+ /**
2
+ * Represents a Entralpi device
3
+ */
1
4
  export const Entralpi = {
2
5
  name: "ENTRALPI",
3
6
  services: [
@@ -1,5 +1,8 @@
1
1
  import { Device } from "./types"
2
2
 
3
+ /**
4
+ * Represents a Entralpi device
5
+ */
3
6
  export const Entralpi: Device = {
4
7
  name: "ENTRALPI",
5
8
  services: [
@@ -1,5 +1,6 @@
1
1
  export { Climbro } from "./climbro";
2
2
  export { Entralpi } from "./entralpi";
3
3
  export { Motherboard } from "./motherboard";
4
- export { SmartBoard } from "./smartboard";
4
+ export { mySmartBoard } from "./mysmartboard";
5
+ export { MuscleMeter } from "./musclemeter";
5
6
  export { Progressor } from "./progressor";
@@ -1,5 +1,6 @@
1
1
  export { Climbro } from "./climbro";
2
2
  export { Entralpi } from "./entralpi";
3
3
  export { Motherboard } from "./motherboard";
4
- export { SmartBoard } from "./smartboard";
4
+ export { mySmartBoard } from "./mysmartboard";
5
+ export { MuscleMeter } from "./musclemeter";
5
6
  export { Progressor } from "./progressor";
@@ -4,6 +4,8 @@ export { Entralpi } from "./entralpi"
4
4
 
5
5
  export { Motherboard } from "./motherboard"
6
6
 
7
- export { SmartBoard } from "./smartboard"
7
+ export { mySmartBoard } from "./mysmartboard"
8
+
9
+ export { MuscleMeter } from "./musclemeter"
8
10
 
9
11
  export { Progressor } from "./progressor"
@@ -1,2 +1,5 @@
1
1
  import { Device } from "./types";
2
+ /**
3
+ * Represents a Griptonite Motherboard device
4
+ */
2
5
  export declare const Motherboard: Device;
@@ -1,3 +1,6 @@
1
+ /**
2
+ * Represents a Griptonite Motherboard device
3
+ */
1
4
  export const Motherboard = {
2
5
  name: "Motherboard",
3
6
  companyId: 0x2a29,
@@ -1,5 +1,8 @@
1
1
  import { Device } from "./types"
2
2
 
3
+ /**
4
+ * Represents a Griptonite Motherboard device
5
+ */
3
6
  export const Motherboard: Device = {
4
7
  name: "Motherboard",
5
8
  companyId: 0x2a29,
@@ -0,0 +1,6 @@
1
+ import { Device } from "./types";
2
+ /**
3
+ * Represents a MAT Muscle Meter device
4
+ * TODO: Add services, do you own a MAT Muscle Meter? Help us!
5
+ */
6
+ export declare const MuscleMeter: Device;
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Represents a MAT Muscle Meter device
3
+ * TODO: Add services, do you own a MAT Muscle Meter? Help us!
4
+ */
5
+ export const MuscleMeter = {
6
+ name: "MAT",
7
+ services: [],
8
+ };
@@ -0,0 +1,10 @@
1
+ import { Device } from "./types"
2
+
3
+ /**
4
+ * Represents a MAT Muscle Meter device
5
+ * TODO: Add services, do you own a MAT Muscle Meter? Help us!
6
+ */
7
+ export const MuscleMeter: Device = {
8
+ name: "MAT",
9
+ services: [],
10
+ }
@@ -0,0 +1,6 @@
1
+ import { Device } from "./types";
2
+ /**
3
+ * Represents a mySmartBoard device
4
+ * TODO: Add services, do you own a mySmartBoard? Help us!
5
+ */
6
+ export declare const mySmartBoard: Device;
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Represents a mySmartBoard device
3
+ * TODO: Add services, do you own a mySmartBoard? Help us!
4
+ */
5
+ export const mySmartBoard = {
6
+ name: "mySmartBoard",
7
+ services: [],
8
+ };
@@ -0,0 +1,10 @@
1
+ import { Device } from "./types"
2
+
3
+ /**
4
+ * Represents a mySmartBoard device
5
+ * TODO: Add services, do you own a mySmartBoard? Help us!
6
+ */
7
+ export const mySmartBoard: Device = {
8
+ name: "mySmartBoard",
9
+ services: [],
10
+ }
@@ -1,2 +1,5 @@
1
1
  import { Device } from "./types";
2
+ /**
3
+ * Represents a Tindeq Progressor device
4
+ */
2
5
  export declare const Progressor: Device;