@hangtime/grip-connect 0.5.4 → 0.5.5

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.
@@ -1,6 +1,7 @@
1
1
  import { Device } from "../device.model";
2
2
  import { applyTare } from "../../helpers/tare";
3
3
  import { checkActivity } from "../../helpers/is-active";
4
+ import { DownloadPackets } from "../../helpers/download";
4
5
  export class Entralpi extends Device {
5
6
  constructor() {
6
7
  super({
@@ -158,10 +159,19 @@ export class Entralpi extends Device {
158
159
  if (value.buffer) {
159
160
  const buffer = value.buffer;
160
161
  const rawData = new DataView(buffer);
162
+ const receivedTime = Date.now();
161
163
  const receivedData = (rawData.getUint16(0) / 100).toFixed(1);
162
- let numericData = Number(receivedData);
164
+ const convertedData = Number(receivedData);
163
165
  // Tare correction
164
- numericData -= applyTare(numericData);
166
+ const numericData = convertedData - applyTare(convertedData);
167
+ // Add data to downloadable Array
168
+ DownloadPackets.push({
169
+ received: receivedTime,
170
+ sampleNum: this.dataPointCount,
171
+ battRaw: 0,
172
+ samples: [convertedData],
173
+ masses: [numericData],
174
+ });
165
175
  // Update massMax
166
176
  this.massMax = Math.max(Number(this.massMax), numericData).toFixed(1);
167
177
  // Update running sum and count
@@ -1,5 +1,5 @@
1
1
  import { Device } from "../device.model";
2
- import { emptyDownloadPackets } from "../../helpers/download";
2
+ import { DownloadPackets, emptyDownloadPackets } from "../../helpers/download";
3
3
  import { checkActivity } from "../../helpers/is-active";
4
4
  import { applyTare } from "../../helpers/tare";
5
5
  /**
@@ -188,11 +188,20 @@ export class ForceBoard extends Device {
188
188
  if (value.buffer) {
189
189
  const buffer = value.buffer;
190
190
  const rawData = new DataView(buffer);
191
+ const receivedTime = Date.now();
191
192
  const receivedData = rawData.getUint8(4); // Read the value at index 4
192
193
  // Convert from LBS to KG
193
- let numericData = receivedData * 0.453592;
194
+ const convertedReceivedData = receivedData * 0.453592;
194
195
  // Tare correction
195
- numericData -= applyTare(numericData);
196
+ const numericData = convertedReceivedData - applyTare(convertedReceivedData);
197
+ // Add data to downloadable Array
198
+ DownloadPackets.push({
199
+ received: receivedTime,
200
+ sampleNum: this.dataPointCount,
201
+ battRaw: 0,
202
+ samples: [convertedReceivedData],
203
+ masses: [numericData],
204
+ });
196
205
  // Update massMax
197
206
  this.massMax = Math.max(Number(this.massMax), numericData).toFixed(1);
198
207
  // Update running sum and count
@@ -123,38 +123,38 @@ export class Progressor extends Device {
123
123
  if (value) {
124
124
  if (value.buffer) {
125
125
  const buffer = value.buffer;
126
- const data = new DataView(buffer);
126
+ const rawData = new DataView(buffer);
127
127
  const receivedTime = Date.now();
128
- const [kind] = struct("<bb").unpack(data.buffer.slice(0, 2));
128
+ const [kind] = struct("<bb").unpack(rawData.buffer.slice(0, 2));
129
129
  if (kind === ProgressorResponses.WEIGHT_MEASURE) {
130
- const iterable = struct("<fi").iter_unpack(data.buffer.slice(2));
130
+ const iterable = struct("<fi").iter_unpack(rawData.buffer.slice(2));
131
131
  // eslint-disable-next-line prefer-const
132
132
  for (let [weight, seconds] of iterable) {
133
133
  if (typeof weight === "number" && !isNaN(weight) && typeof seconds === "number" && !isNaN(seconds)) {
134
- // Add data to downloadable Array: sample and mass are the same
134
+ // Tare correction
135
+ const numericData = weight - applyTare(weight);
136
+ // Add data to downloadable Array
135
137
  DownloadPackets.push({
136
138
  received: receivedTime,
137
139
  sampleNum: seconds,
138
140
  battRaw: 0,
139
141
  samples: [weight],
140
- masses: [weight],
142
+ masses: [numericData],
141
143
  });
142
- // Tare correction
143
- weight -= applyTare(weight);
144
144
  // Check for max weight
145
- this.massMax = Math.max(Number(this.massMax), Number(weight)).toFixed(1);
145
+ this.massMax = Math.max(Number(this.massMax), Number(numericData)).toFixed(1);
146
146
  // Update running sum and count
147
- const currentMassTotal = Math.max(-1000, Number(weight));
147
+ const currentMassTotal = Math.max(-1000, Number(numericData));
148
148
  this.massTotalSum += currentMassTotal;
149
149
  this.dataPointCount++;
150
150
  // Calculate the average dynamically
151
151
  this.massAverage = (this.massTotalSum / this.dataPointCount).toFixed(1);
152
152
  // Check if device is being used
153
- checkActivity(weight);
153
+ checkActivity(numericData);
154
154
  this.notifyCallback({
155
155
  massMax: this.massMax,
156
156
  massAverage: this.massAverage,
157
- massTotal: Math.max(-1000, weight).toFixed(1),
157
+ massTotal: Math.max(-1000, numericData).toFixed(1),
158
158
  });
159
159
  }
160
160
  }
@@ -164,13 +164,13 @@ export class Progressor extends Device {
164
164
  return;
165
165
  let value = "";
166
166
  if (this.writeLast === this.commands.GET_BATT_VLTG) {
167
- value = new DataView(data.buffer, 2).getUint32(0, true).toString();
167
+ value = new DataView(rawData.buffer, 2).getUint32(0, true).toString();
168
168
  }
169
169
  else if (this.writeLast === this.commands.GET_FW_VERSION) {
170
- value = new TextDecoder().decode(data.buffer.slice(2));
170
+ value = new TextDecoder().decode(rawData.buffer.slice(2));
171
171
  }
172
172
  else if (this.writeLast === this.commands.GET_ERR_INFO) {
173
- value = new TextDecoder().decode(data.buffer.slice(2));
173
+ value = new TextDecoder().decode(rawData.buffer.slice(2));
174
174
  }
175
175
  this.writeCallback(value);
176
176
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hangtime/grip-connect",
3
- "version": "0.5.4",
3
+ "version": "0.5.5",
4
4
  "description": "Griptonite Motherboard, Tindeq Progressor, PitchSix Force Board, WHC-06, Entralpi, Climbro, mySmartBoard: Web Bluetooth API Force-Sensing strength analysis for climbers",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -2,6 +2,7 @@ import { Device } from "../device.model"
2
2
  import type { IEntralpi } from "../../interfaces/device/entralpi.interface"
3
3
  import { applyTare } from "../../helpers/tare"
4
4
  import { checkActivity } from "../../helpers/is-active"
5
+ import { DownloadPackets } from "../../helpers/download"
5
6
 
6
7
  export class Entralpi extends Device implements IEntralpi {
7
8
  constructor() {
@@ -165,12 +166,20 @@ export class Entralpi extends Device implements IEntralpi {
165
166
  if (value.buffer) {
166
167
  const buffer: ArrayBuffer = value.buffer
167
168
  const rawData: DataView = new DataView(buffer)
169
+ const receivedTime: number = Date.now()
168
170
  const receivedData: string = (rawData.getUint16(0) / 100).toFixed(1)
169
171
 
170
- let numericData = Number(receivedData)
171
-
172
+ const convertedData = Number(receivedData)
172
173
  // Tare correction
173
- numericData -= applyTare(numericData)
174
+ const numericData = convertedData - applyTare(convertedData)
175
+ // Add data to downloadable Array
176
+ DownloadPackets.push({
177
+ received: receivedTime,
178
+ sampleNum: this.dataPointCount,
179
+ battRaw: 0,
180
+ samples: [convertedData],
181
+ masses: [numericData],
182
+ })
174
183
 
175
184
  // Update massMax
176
185
  this.massMax = Math.max(Number(this.massMax), numericData).toFixed(1)
@@ -1,6 +1,6 @@
1
1
  import { Device } from "../device.model"
2
2
  import type { IForceBoard } from "../../interfaces/device/forceboard.interface"
3
- import { emptyDownloadPackets } from "../../helpers/download"
3
+ import { DownloadPackets, emptyDownloadPackets } from "../../helpers/download"
4
4
  import { checkActivity } from "../../helpers/is-active"
5
5
  import { applyTare } from "../../helpers/tare"
6
6
 
@@ -192,14 +192,21 @@ export class ForceBoard extends Device implements IForceBoard {
192
192
  if (value.buffer) {
193
193
  const buffer: ArrayBuffer = value.buffer
194
194
  const rawData: DataView = new DataView(buffer)
195
+ const receivedTime: number = Date.now()
195
196
 
196
197
  const receivedData = rawData.getUint8(4) // Read the value at index 4
197
-
198
198
  // Convert from LBS to KG
199
- let numericData = receivedData * 0.453592
200
-
199
+ const convertedReceivedData = receivedData * 0.453592
201
200
  // Tare correction
202
- numericData -= applyTare(numericData)
201
+ const numericData = convertedReceivedData - applyTare(convertedReceivedData)
202
+ // Add data to downloadable Array
203
+ DownloadPackets.push({
204
+ received: receivedTime,
205
+ sampleNum: this.dataPointCount,
206
+ battRaw: 0,
207
+ samples: [convertedReceivedData],
208
+ masses: [numericData],
209
+ })
203
210
 
204
211
  // Update massMax
205
212
  this.massMax = Math.max(Number(this.massMax), numericData).toFixed(1)
@@ -133,28 +133,28 @@ export class Progressor extends Device implements IProgressor {
133
133
  if (value) {
134
134
  if (value.buffer) {
135
135
  const buffer: ArrayBuffer = value.buffer
136
- const data: DataView = new DataView(buffer)
136
+ const rawData: DataView = new DataView(buffer)
137
137
  const receivedTime: number = Date.now()
138
- const [kind] = struct("<bb").unpack(data.buffer.slice(0, 2))
138
+ const [kind] = struct("<bb").unpack(rawData.buffer.slice(0, 2))
139
139
  if (kind === ProgressorResponses.WEIGHT_MEASURE) {
140
- const iterable: IterableIterator<unknown[]> = struct("<fi").iter_unpack(data.buffer.slice(2))
140
+ const iterable: IterableIterator<unknown[]> = struct("<fi").iter_unpack(rawData.buffer.slice(2))
141
141
  // eslint-disable-next-line prefer-const
142
142
  for (let [weight, seconds] of iterable) {
143
143
  if (typeof weight === "number" && !isNaN(weight) && typeof seconds === "number" && !isNaN(seconds)) {
144
- // Add data to downloadable Array: sample and mass are the same
144
+ // Tare correction
145
+ const numericData = weight - applyTare(weight)
146
+ // Add data to downloadable Array
145
147
  DownloadPackets.push({
146
148
  received: receivedTime,
147
149
  sampleNum: seconds,
148
150
  battRaw: 0,
149
151
  samples: [weight],
150
- masses: [weight],
152
+ masses: [numericData],
151
153
  })
152
- // Tare correction
153
- weight -= applyTare(weight)
154
154
  // Check for max weight
155
- this.massMax = Math.max(Number(this.massMax), Number(weight)).toFixed(1)
155
+ this.massMax = Math.max(Number(this.massMax), Number(numericData)).toFixed(1)
156
156
  // Update running sum and count
157
- const currentMassTotal = Math.max(-1000, Number(weight))
157
+ const currentMassTotal = Math.max(-1000, Number(numericData))
158
158
  this.massTotalSum += currentMassTotal
159
159
  this.dataPointCount++
160
160
 
@@ -162,12 +162,12 @@ export class Progressor extends Device implements IProgressor {
162
162
  this.massAverage = (this.massTotalSum / this.dataPointCount).toFixed(1)
163
163
 
164
164
  // Check if device is being used
165
- checkActivity(weight)
165
+ checkActivity(numericData)
166
166
 
167
167
  this.notifyCallback({
168
168
  massMax: this.massMax,
169
169
  massAverage: this.massAverage,
170
- massTotal: Math.max(-1000, weight).toFixed(1),
170
+ massTotal: Math.max(-1000, numericData).toFixed(1),
171
171
  })
172
172
  }
173
173
  }
@@ -177,11 +177,11 @@ export class Progressor extends Device implements IProgressor {
177
177
  let value = ""
178
178
 
179
179
  if (this.writeLast === this.commands.GET_BATT_VLTG) {
180
- value = new DataView(data.buffer, 2).getUint32(0, true).toString()
180
+ value = new DataView(rawData.buffer, 2).getUint32(0, true).toString()
181
181
  } else if (this.writeLast === this.commands.GET_FW_VERSION) {
182
- value = new TextDecoder().decode(data.buffer.slice(2))
182
+ value = new TextDecoder().decode(rawData.buffer.slice(2))
183
183
  } else if (this.writeLast === this.commands.GET_ERR_INFO) {
184
- value = new TextDecoder().decode(data.buffer.slice(2))
184
+ value = new TextDecoder().decode(rawData.buffer.slice(2))
185
185
  }
186
186
  this.writeCallback(value)
187
187
  } else if (kind === ProgressorResponses.LOW_BATTERY_WARNING) {