@hangtime/grip-connect 0.3.1 → 0.3.3

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 (102) hide show
  1. package/README.md +25 -7
  2. package/package.json +1 -1
  3. package/src/battery.ts +3 -3
  4. package/src/calibration.ts +2 -2
  5. package/src/characteristic.ts +1 -1
  6. package/src/commands/climbro.ts +1 -1
  7. package/src/commands/entralpi.ts +1 -1
  8. package/src/commands/motherboard.ts +1 -1
  9. package/src/commands/musclemeter.ts +1 -1
  10. package/src/commands/mysmartboard.ts +1 -1
  11. package/src/commands/progressor.ts +7 -7
  12. package/src/connect.ts +7 -23
  13. package/src/data.ts +2 -1
  14. package/src/devices/climbro.ts +2 -2
  15. package/src/devices/entralpi.ts +6 -2
  16. package/src/devices/index.ts +2 -0
  17. package/src/devices/kilterboard.ts +32 -0
  18. package/src/devices/motherboard.ts +2 -3
  19. package/src/devices/musclemeter.ts +2 -2
  20. package/src/devices/mysmartboard.ts +2 -2
  21. package/src/devices/progressor.ts +2 -2
  22. package/src/disconnect.ts +1 -1
  23. package/src/download.ts +1 -11
  24. package/src/index.ts +1 -1
  25. package/src/info.ts +3 -3
  26. package/src/is-connected.ts +1 -1
  27. package/src/notify.ts +3 -10
  28. package/src/read.ts +1 -1
  29. package/src/stop.ts +3 -3
  30. package/src/stream.ts +3 -3
  31. package/src/types/devices.ts +39 -0
  32. package/src/types/download.ts +15 -0
  33. package/src/types/notify.ts +14 -0
  34. package/src/write.ts +1 -4
  35. package/src/battery.d.ts +0 -7
  36. package/src/battery.js +0 -25
  37. package/src/calibration.d.ts +0 -7
  38. package/src/calibration.js +0 -19
  39. package/src/characteristic.d.ts +0 -10
  40. package/src/characteristic.js +0 -20
  41. package/src/commands/climbro.d.ts +0 -6
  42. package/src/commands/climbro.js +0 -5
  43. package/src/commands/entralpi.d.ts +0 -6
  44. package/src/commands/entralpi.js +0 -5
  45. package/src/commands/index.d.ts +0 -6
  46. package/src/commands/index.js +0 -6
  47. package/src/commands/motherboard.d.ts +0 -6
  48. package/src/commands/motherboard.js +0 -13
  49. package/src/commands/musclemeter.d.ts +0 -6
  50. package/src/commands/musclemeter.js +0 -5
  51. package/src/commands/mysmartboard.d.ts +0 -6
  52. package/src/commands/mysmartboard.js +0 -5
  53. package/src/commands/progressor.d.ts +0 -17
  54. package/src/commands/progressor.js +0 -29
  55. package/src/commands/types.d.ts +0 -18
  56. package/src/commands/types.js +0 -1
  57. package/src/connect.d.ts +0 -7
  58. package/src/connect.js +0 -152
  59. package/src/data.d.ts +0 -16
  60. package/src/data.js +0 -220
  61. package/src/devices/climbro.d.ts +0 -6
  62. package/src/devices/climbro.js +0 -8
  63. package/src/devices/entralpi.d.ts +0 -5
  64. package/src/devices/entralpi.js +0 -55
  65. package/src/devices/index.d.ts +0 -6
  66. package/src/devices/index.js +0 -6
  67. package/src/devices/motherboard.d.ts +0 -5
  68. package/src/devices/motherboard.js +0 -82
  69. package/src/devices/musclemeter.d.ts +0 -6
  70. package/src/devices/musclemeter.js +0 -8
  71. package/src/devices/mysmartboard.d.ts +0 -6
  72. package/src/devices/mysmartboard.js +0 -8
  73. package/src/devices/progressor.d.ts +0 -5
  74. package/src/devices/progressor.js +0 -37
  75. package/src/devices/types.d.ts +0 -29
  76. package/src/devices/types.js +0 -1
  77. package/src/devices/types.ts +0 -29
  78. package/src/disconnect.d.ts +0 -6
  79. package/src/disconnect.js +0 -12
  80. package/src/download.d.ts +0 -19
  81. package/src/download.js +0 -50
  82. package/src/index.d.ts +0 -12
  83. package/src/index.js +0 -20
  84. package/src/info.d.ts +0 -7
  85. package/src/info.js +0 -30
  86. package/src/is-connected.d.ts +0 -7
  87. package/src/is-connected.js +0 -13
  88. package/src/notify.d.ts +0 -22
  89. package/src/notify.js +0 -14
  90. package/src/read.d.ts +0 -10
  91. package/src/read.js +0 -49
  92. package/src/stop.d.ts +0 -7
  93. package/src/stop.js +0 -21
  94. package/src/stream.d.ts +0 -8
  95. package/src/stream.js +0 -41
  96. package/src/struct/index.d.ts +0 -9
  97. package/src/struct/index.js +0 -176
  98. package/src/tare.d.ts +0 -12
  99. package/src/tare.js +0 -70
  100. package/src/write.d.ts +0 -16
  101. package/src/write.js +0 -56
  102. /package/src/{commands/types.ts → types/commands.ts} +0 -0
@@ -1,7 +0,0 @@
1
- import { Device } from "./devices/types";
2
- /**
3
- * Writes a command to get calibration data from the device.
4
- * @param {Device} board - The device.
5
- * @returns {Promise<void>} A Promise that resolves when the command is successfully sent.
6
- */
7
- export declare const calibration: (board: Device) => Promise<void>;
@@ -1,19 +0,0 @@
1
- import { isConnected } from "./is-connected";
2
- import { write } from "./write";
3
- import { Motherboard } from "./devices";
4
- import { MotherboardCommands } from "./commands";
5
- /**
6
- * Writes a command to get calibration data from the device.
7
- * @param {Device} board - The device.
8
- * @returns {Promise<void>} A Promise that resolves when the command is successfully sent.
9
- */
10
- export const calibration = async (board) => {
11
- // Check if the device is connected
12
- if (isConnected(board)) {
13
- // If the device is connected, and it is a Motherboard device
14
- if (board.name === "Motherboard") {
15
- // Write the command to get calibration data to the device
16
- await write(Motherboard, "uart", "tx", MotherboardCommands.GET_CALIBRATION, 2500);
17
- }
18
- }
19
- };
@@ -1,10 +0,0 @@
1
- /// <reference types="web-bluetooth" />
2
- import { Device } from "./devices/types";
3
- /**
4
- * Retrieves the characteristic from the device's service.
5
- * @param {Device} board - The device.
6
- * @param {string} serviceId - The UUID of the service.
7
- * @param {string} characteristicId - The UUID of the characteristic.
8
- * @returns {BluetoothRemoteGATTCharacteristic | undefined} The characteristic, if found.
9
- */
10
- export declare const getCharacteristic: (board: Device, serviceId: string, characteristicId: string) => BluetoothRemoteGATTCharacteristic | undefined;
@@ -1,20 +0,0 @@
1
- /**
2
- * Retrieves the characteristic from the device's service.
3
- * @param {Device} board - The device.
4
- * @param {string} serviceId - The UUID of the service.
5
- * @param {string} characteristicId - The UUID of the characteristic.
6
- * @returns {BluetoothRemoteGATTCharacteristic | undefined} The characteristic, if found.
7
- */
8
- export const getCharacteristic = (board, serviceId, characteristicId) => {
9
- // Find the service with the specified serviceId
10
- const boardService = board.services.find((service) => service.id === serviceId);
11
- if (boardService) {
12
- // If the service is found, find the characteristic with the specified characteristicId
13
- const boardCharacteristic = boardService.characteristics.find((characteristic) => characteristic.id === characteristicId);
14
- if (boardCharacteristic) {
15
- // If the characteristic is found, return it
16
- return boardCharacteristic.characteristic;
17
- }
18
- }
19
- // Return undefined if the service or characteristic is not found
20
- };
@@ -1,6 +0,0 @@
1
- import { Commands } from "../commands/types";
2
- /**
3
- * Warning:
4
- * Using other commands can seriously harm your device
5
- */
6
- export declare const ClimbroCommands: Commands;
@@ -1,5 +0,0 @@
1
- /**
2
- * Warning:
3
- * Using other commands can seriously harm your device
4
- */
5
- export const ClimbroCommands = {};
@@ -1,6 +0,0 @@
1
- import { Commands } from "../commands/types";
2
- /**
3
- * Warning:
4
- * Using other commands can seriously harm your device
5
- */
6
- export declare const EntralpiCommands: Commands;
@@ -1,5 +0,0 @@
1
- /**
2
- * Warning:
3
- * Using other commands can seriously harm your device
4
- */
5
- export const EntralpiCommands = {};
@@ -1,6 +0,0 @@
1
- export { ClimbroCommands } from "./climbro";
2
- export { EntralpiCommands } from "./entralpi";
3
- export { MotherboardCommands } from "./motherboard";
4
- export { MuscleMeterCommands } from "./musclemeter";
5
- export { ProgressorCommands } from "./progressor";
6
- export { mySmartBoardCommands } from "./mysmartboard";
@@ -1,6 +0,0 @@
1
- export { ClimbroCommands } from "./climbro";
2
- export { EntralpiCommands } from "./entralpi";
3
- export { MotherboardCommands } from "./motherboard";
4
- export { MuscleMeterCommands } from "./musclemeter";
5
- export { ProgressorCommands } from "./progressor";
6
- export { mySmartBoardCommands } from "./mysmartboard";
@@ -1,6 +0,0 @@
1
- import { Commands } from "../commands/types";
2
- /**
3
- * Warning:
4
- * Using other commands can seriously harm your device
5
- */
6
- export declare const MotherboardCommands: Commands;
@@ -1,13 +0,0 @@
1
- /**
2
- * Warning:
3
- * Using other commands can seriously harm your device
4
- */
5
- export const MotherboardCommands = {
6
- GET_SERIAL: "#",
7
- START_WEIGHT_MEAS: "S30",
8
- STOP_WEIGHT_MEAS: "", // All commands will stop the data stream.
9
- GET_CALIBRATION: "C",
10
- SLEEP: 0,
11
- GET_TEXT: "T",
12
- DEBUG_STREAM: "D",
13
- };
@@ -1,6 +0,0 @@
1
- import { Commands } from "../commands/types";
2
- /**
3
- * Warning:
4
- * Using other commands can seriously harm your device
5
- */
6
- export declare const MuscleMeterCommands: Commands;
@@ -1,5 +0,0 @@
1
- /**
2
- * Warning:
3
- * Using other commands can seriously harm your device
4
- */
5
- export const MuscleMeterCommands = {};
@@ -1,6 +0,0 @@
1
- import { Commands } from "../commands/types";
2
- /**
3
- * Warning:
4
- * Using other commands can seriously harm your device
5
- */
6
- export declare const mySmartBoardCommands: Commands;
@@ -1,5 +0,0 @@
1
- /**
2
- * Warning:
3
- * Using other commands can seriously harm your device
4
- */
5
- export const mySmartBoardCommands = {};
@@ -1,17 +0,0 @@
1
- import { Commands } from "../commands/types";
2
- /**
3
- * Warning:
4
- * Using other commands can seriously harm your device
5
- */
6
- export declare const ProgressorCommands: Commands;
7
- /**
8
- * The Progressor returns a Uint8Array.
9
- * The first item [0] is the type of response it returns
10
- */
11
- export declare const ProgressorResponses: {
12
- COMMAND_RESPONSE: number;
13
- WEIGHT_MEASURE: number;
14
- PEAK_RFD_MEAS: number;
15
- PEAK_RFD_MEAS_SERIES: number;
16
- LOW_BATTERY_WARNING: number;
17
- };
@@ -1,29 +0,0 @@
1
- /**
2
- * Warning:
3
- * Using other commands can seriously harm your device
4
- */
5
- export const ProgressorCommands = {
6
- TARE_SCALE: "d", // 0x64,
7
- START_WEIGHT_MEAS: "e", // 0x65,
8
- STOP_WEIGHT_MEAS: "f", // 0x66,
9
- START_PEAK_RFD_MEAS: "g", // 0x67,
10
- START_PEAK_RFD_MEAS_SERIES: "h", // 0x68,
11
- ADD_CALIB_POINT: "i", // 0x69,
12
- SAVE_CALIB: "j", // 0x6a,
13
- GET_FW_VERSION: "k", // 0x6b,
14
- GET_ERR_INFO: "l", // 0x6c,
15
- CLR_ERR_INFO: "m", // 0x6d,
16
- SLEEP: "n", // 0x6e,
17
- GET_BATT_VLTG: "o", // 0x6f,
18
- };
19
- /**
20
- * The Progressor returns a Uint8Array.
21
- * The first item [0] is the type of response it returns
22
- */
23
- export const ProgressorResponses = {
24
- COMMAND_RESPONSE: 0,
25
- WEIGHT_MEASURE: 1,
26
- PEAK_RFD_MEAS: 2,
27
- PEAK_RFD_MEAS_SERIES: 3,
28
- LOW_BATTERY_WARNING: 4,
29
- };
@@ -1,18 +0,0 @@
1
- export interface Commands {
2
- START_WEIGHT_MEAS?: string;
3
- STOP_WEIGHT_MEAS?: string;
4
- SLEEP?: number | string;
5
- GET_SERIAL?: string;
6
- GET_TEXT?: string;
7
- DEBUG_STREAM?: string;
8
- GET_CALIBRATION?: string;
9
- TARE_SCALE?: string;
10
- START_PEAK_RFD_MEAS?: string;
11
- START_PEAK_RFD_MEAS_SERIES?: string;
12
- ADD_CALIB_POINT?: string;
13
- SAVE_CALIB?: string;
14
- GET_FW_VERSION?: string;
15
- GET_ERR_INFO?: string;
16
- CLR_ERR_INFO?: string;
17
- GET_BATT_VLTG?: string;
18
- }
@@ -1 +0,0 @@
1
- export {};
package/src/connect.d.ts DELETED
@@ -1,7 +0,0 @@
1
- import { Device } from "./devices/types";
2
- /**
3
- * Connects to a Bluetooth device.
4
- * @param {Device} board - The device to connect to.
5
- * @param {Function} onSuccess - Callback function to execute on successful connection.
6
- */
7
- export declare const connect: (board: Device, onSuccess: () => void) => Promise<void>;
package/src/connect.js DELETED
@@ -1,152 +0,0 @@
1
- import { handleEntralpiData, handleMotherboardData, handleProgressorData } from "./data";
2
- let server;
3
- const receiveBuffer = [];
4
- /**
5
- * Handles the 'disconnected' event.
6
- * @param {Event} event - The 'disconnected' event.
7
- * @param {Device} board - The device that is disconnected.
8
- */
9
- const onDisconnected = (event, board) => {
10
- board.device = undefined;
11
- const device = event.target;
12
- console.log(`Device ${device.name} is disconnected.`);
13
- };
14
- /**
15
- * Handles notifications received from a characteristic.
16
- * @param {Event} event - The notification event.
17
- * @param {Device} board - The device associated with the characteristic.
18
- */
19
- const handleNotifications = (event, board) => {
20
- const characteristic = event.target;
21
- const value = characteristic.value;
22
- if (value) {
23
- if (board.name === "Motherboard") {
24
- for (let i = 0; i < value.byteLength; i++) {
25
- receiveBuffer.push(value.getUint8(i));
26
- }
27
- let idx;
28
- while ((idx = receiveBuffer.indexOf(10)) >= 0) {
29
- const line = receiveBuffer.splice(0, idx + 1).slice(0, -1); // Combine and remove LF
30
- if (line.length > 0 && line[line.length - 1] === 13)
31
- line.pop(); // Remove CR
32
- const decoder = new TextDecoder("utf-8");
33
- const receivedData = decoder.decode(new Uint8Array(line));
34
- handleMotherboardData(receivedData);
35
- }
36
- }
37
- else if (board.name === "ENTRALPI") {
38
- if (value.buffer) {
39
- const buffer = value.buffer;
40
- const rawData = new DataView(buffer);
41
- const receivedData = (rawData.getUint16(0) / 100).toFixed(1);
42
- handleEntralpiData(receivedData);
43
- }
44
- }
45
- else if (board.name && board.name.startsWith("Progressor")) {
46
- if (value.buffer) {
47
- const buffer = value.buffer;
48
- const rawData = new DataView(buffer);
49
- handleProgressorData(rawData);
50
- }
51
- }
52
- else {
53
- console.log(value);
54
- }
55
- }
56
- };
57
- /**
58
- * Handles the 'connected' event.
59
- * @param {Device} board - The connected device.
60
- * @param {Function} onSuccess - Callback function to execute on successful connection.
61
- */
62
- const onConnected = async (board, onSuccess) => {
63
- try {
64
- // Connect to GATT server and set up characteristics
65
- const services = await server?.getPrimaryServices();
66
- if (!services || services.length === 0) {
67
- console.error("No services found");
68
- return;
69
- }
70
- for (const service of services) {
71
- const matchingService = board.services.find((boardService) => boardService.uuid === service.uuid);
72
- if (matchingService) {
73
- // Android bug: Introduce a delay before getting characteristics
74
- await new Promise((resolve) => setTimeout(resolve, 100));
75
- const characteristics = await service.getCharacteristics();
76
- for (const characteristic of matchingService.characteristics) {
77
- const matchingCharacteristic = characteristics.find((char) => char.uuid === characteristic.uuid);
78
- if (matchingCharacteristic) {
79
- const element = matchingService.characteristics.find((char) => char.uuid === matchingCharacteristic.uuid);
80
- if (element) {
81
- element.characteristic = matchingCharacteristic;
82
- // notify
83
- if (element.id === "rx") {
84
- matchingCharacteristic.startNotifications();
85
- matchingCharacteristic.addEventListener("characteristicvaluechanged", (event) => handleNotifications(event, board));
86
- }
87
- }
88
- }
89
- else {
90
- console.warn(`Characteristic ${characteristic.uuid} not found in service ${service.uuid}`);
91
- }
92
- }
93
- }
94
- }
95
- // Call the onSuccess callback after successful connection and setup
96
- onSuccess();
97
- }
98
- catch (error) {
99
- console.error(error);
100
- }
101
- };
102
- /**
103
- * Returns UUIDs of all services associated with the device.
104
- * @param {Device} device - The device.
105
- * @returns {string[]} Array of service UUIDs.
106
- */
107
- const getAllServiceUUIDs = (device) => {
108
- return device.services.map((service) => service.uuid);
109
- };
110
- /**
111
- * Connects to a Bluetooth device.
112
- * @param {Device} board - The device to connect to.
113
- * @param {Function} onSuccess - Callback function to execute on successful connection.
114
- */
115
- export const connect = async (board, onSuccess) => {
116
- try {
117
- // Request device and set up connection
118
- const deviceServices = getAllServiceUUIDs(board);
119
- // setup filter list
120
- const filters = [];
121
- if (board.name) {
122
- const filterName = board.name === "Progressor" ? { namePrefix: board.name } : { name: board.name };
123
- filters.push(filterName);
124
- }
125
- if (board.companyId) {
126
- filters.push({
127
- manufacturerData: [
128
- {
129
- companyIdentifier: board.companyId,
130
- },
131
- ],
132
- });
133
- }
134
- const device = await navigator.bluetooth.requestDevice({
135
- filters: filters,
136
- optionalServices: deviceServices,
137
- });
138
- board.device = device;
139
- if (!board.device.gatt) {
140
- console.error("GATT is not available on this device");
141
- return;
142
- }
143
- server = await board.device?.gatt?.connect();
144
- board.device.addEventListener("gattserverdisconnected", (event) => onDisconnected(event, board));
145
- if (server.connected) {
146
- await onConnected(board, onSuccess);
147
- }
148
- }
149
- catch (error) {
150
- console.error(error);
151
- }
152
- };
package/src/data.d.ts DELETED
@@ -1,16 +0,0 @@
1
- export declare const CALIBRATION: never[][];
2
- /**
3
- * Handles data received from the Motherboard device.
4
- * @param {string} receivedData - The received data string.
5
- */
6
- export declare const handleMotherboardData: (receivedData: string) => void;
7
- /**
8
- * Handles data received from the Progressor device.
9
- * @param {DataView} data - The received data.
10
- */
11
- export declare const handleProgressorData: (data: DataView) => void;
12
- /**
13
- * Handles data received from the Entralpi device.
14
- * @param {string} receivedData - The received data string.
15
- */
16
- export declare const handleEntralpiData: (receivedData: string) => void;
package/src/data.js DELETED
@@ -1,220 +0,0 @@
1
- import { notifyCallback } from "./notify";
2
- import { applyTare } from "./tare";
3
- import { ProgressorCommands, ProgressorResponses } from "./commands/progressor";
4
- import { MotherboardCommands } from "./commands";
5
- import { lastWrite } from "./write";
6
- import { DownloadPackets } from "./download";
7
- import struct from "./struct";
8
- // Constants
9
- const PACKET_LENGTH = 32;
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;
15
- export const CALIBRATION = [[], [], [], []];
16
- /**
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.
21
- */
22
- const applyCalibration = (sample, calibration) => {
23
- // Extract the calibrated value for the zero point
24
- const zeroCalibration = calibration[0][2];
25
- // Initialize sign as positive
26
- let sign = 1;
27
- // Initialize the final calibrated value
28
- let final = 0;
29
- // If the sample value is less than the zero calibration point
30
- if (sample < zeroCalibration) {
31
- // Change the sign to negative
32
- sign = -1;
33
- // Reflect the sample around the zero calibration point
34
- sample = /* 2 * zeroCalibration */ -sample;
35
- }
36
- // Iterate through the calibration data
37
- for (let i = 1; i < calibration.length; i++) {
38
- // Extract the lower and upper bounds of the current calibration range
39
- const calibrationStart = calibration[i - 1][2];
40
- const calibrationEnd = calibration[i][2];
41
- // If the sample value is within the current calibration range
42
- if (sample < calibrationEnd) {
43
- // Interpolate to get the calibrated value within the range
44
- final =
45
- calibration[i - 1][1] +
46
- ((sample - calibrationStart) / (calibrationEnd - calibrationStart)) *
47
- (calibration[i][1] - calibration[i - 1][1]);
48
- break;
49
- }
50
- }
51
- // Return the calibrated value with the appropriate sign (positive/negative)
52
- return sign * final;
53
- };
54
- /**
55
- * Handles data received from the Motherboard device.
56
- * @param {string} receivedData - The received data string.
57
- */
58
- export const handleMotherboardData = (receivedData) => {
59
- const receivedTime = Date.now();
60
- // Check if the line is entirely hex characters
61
- const isAllHex = /^[0-9A-Fa-f]+$/g.test(receivedData);
62
- // Handle streaming packet
63
- if (isAllHex && receivedData.length === PACKET_LENGTH) {
64
- // Base-16 decode the string: convert hex pairs to byte values
65
- const bytes = Array.from({ length: receivedData.length / 2 }, (_, i) => Number(`0x${receivedData.substring(i * 2, i * 2 + 2)}`));
66
- // Translate header into packet, number of samples from the packet length
67
- const packet = {
68
- received: receivedTime,
69
- sampleNum: new DataView(new Uint8Array(bytes).buffer).getUint16(0, true),
70
- battRaw: new DataView(new Uint8Array(bytes).buffer).getUint16(2, true),
71
- samples: [],
72
- masses: [],
73
- };
74
- const dataView = new DataView(new Uint8Array(bytes).buffer);
75
- for (let i = 0; i < NUM_SAMPLES; i++) {
76
- const sampleStart = 4 + 3 * i;
77
- // Use DataView to read the 24-bit unsigned integer
78
- const rawValue = dataView.getUint8(sampleStart) |
79
- (dataView.getUint8(sampleStart + 1) << 8) |
80
- (dataView.getUint8(sampleStart + 2) << 16);
81
- // Ensure unsigned 32-bit integer
82
- packet.samples[i] = rawValue >>> 0;
83
- if (packet.samples[i] >= 0x7fffff) {
84
- packet.samples[i] -= 0x1000000;
85
- }
86
- packet.masses[i] = applyCalibration(packet.samples[i], CALIBRATION[i]);
87
- }
88
- // invert center and right values
89
- packet.masses[1] *= -1;
90
- packet.masses[2] *= -1;
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
- });
122
- }
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
- }
130
- }
131
- else {
132
- // unhandled data
133
- console.log(receivedData);
134
- }
135
- };
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();
142
- const [kind] = struct("<bb").unpack(data.buffer.slice(0, 2));
143
- if (kind === ProgressorResponses.WEIGHT_MEASURE) {
144
- const iterable = struct("<fi").iter_unpack(data.buffer.slice(2));
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);
167
- notifyCallback({
168
- massMax: MASS_MAX,
169
- massAverage: MASS_AVERAGE,
170
- massTotal: Math.max(-1000, weight).toFixed(1),
171
- });
172
- }
173
- }
174
- }
175
- else if (kind === ProgressorResponses.COMMAND_RESPONSE) {
176
- if (!lastWrite)
177
- return;
178
- let value = "";
179
- if (lastWrite === ProgressorCommands.GET_BATT_VLTG) {
180
- const vdd = new DataView(data.buffer, 2).getUint32(0, true);
181
- value = `ℹ️ Battery level: ${vdd} mV`;
182
- }
183
- else if (lastWrite === ProgressorCommands.GET_FW_VERSION) {
184
- value = new TextDecoder().decode(data.buffer.slice(2));
185
- }
186
- else if (lastWrite === ProgressorCommands.GET_ERR_INFO) {
187
- value = new TextDecoder().decode(data.buffer.slice(2));
188
- }
189
- console.log(value);
190
- }
191
- else if (kind === ProgressorResponses.LOW_BATTERY_WARNING) {
192
- console.warn("⚠️ Low power detected. Please consider connecting to a power source.");
193
- }
194
- else {
195
- console.error(`❌ Error: Unknown message kind detected: ${kind}`);
196
- }
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
- };
@@ -1,6 +0,0 @@
1
- import { Device } from "./types";
2
- /**
3
- * Represents a Climbro device
4
- * TODO: Add services, do you own a Climbro? Help us!
5
- */
6
- export declare const Climbro: Device;
@@ -1,8 +0,0 @@
1
- /**
2
- * Represents a Climbro device
3
- * TODO: Add services, do you own a Climbro? Help us!
4
- */
5
- export const Climbro = {
6
- name: "Climbro",
7
- services: [],
8
- };
@@ -1,5 +0,0 @@
1
- import { Device } from "./types";
2
- /**
3
- * Represents a Entralpi device
4
- */
5
- export declare const Entralpi: Device;