@hangtime/grip-connect 0.3.5 → 0.3.7
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/dist/battery.d.ts +7 -0
- package/dist/battery.js +25 -0
- package/dist/calibration.d.ts +7 -0
- package/dist/calibration.js +19 -0
- package/dist/characteristic.d.ts +9 -0
- package/dist/characteristic.js +20 -0
- package/dist/commands/climbro.d.ts +6 -0
- package/dist/commands/climbro.js +5 -0
- package/dist/commands/entralpi.d.ts +6 -0
- package/dist/commands/entralpi.js +5 -0
- package/dist/commands/index.d.ts +6 -0
- package/dist/commands/index.js +6 -0
- package/dist/commands/kilterboard.d.ts +23 -0
- package/dist/commands/kilterboard.js +24 -0
- package/dist/commands/motherboard.d.ts +6 -0
- package/dist/commands/motherboard.js +13 -0
- package/dist/commands/mysmartboard.d.ts +6 -0
- package/dist/commands/mysmartboard.js +5 -0
- package/dist/commands/progressor.d.ts +17 -0
- package/dist/commands/progressor.js +30 -0
- package/dist/commands/wh-c06.d.ts +6 -0
- package/dist/commands/wh-c06.js +5 -0
- package/dist/connect.d.ts +7 -0
- package/dist/connect.js +159 -0
- package/dist/data/entralpi.d.ts +5 -0
- package/dist/data/entralpi.js +30 -0
- package/dist/data/index.d.ts +4 -0
- package/dist/data/index.js +4 -0
- package/dist/data/motherboard.d.ts +6 -0
- package/dist/data/motherboard.js +133 -0
- package/dist/data/progressor.d.ts +5 -0
- package/dist/data/progressor.js +72 -0
- package/dist/data/wh-c06.d.ts +5 -0
- package/dist/data/wh-c06.js +35 -0
- package/dist/devices/climbro.d.ts +6 -0
- package/dist/devices/climbro.js +8 -0
- package/dist/devices/entralpi.d.ts +5 -0
- package/dist/devices/entralpi.js +59 -0
- package/dist/devices/index.d.ts +7 -0
- package/dist/devices/index.js +7 -0
- package/dist/devices/kilterboard.d.ts +6 -0
- package/dist/devices/kilterboard.js +30 -0
- package/dist/devices/motherboard.d.ts +5 -0
- package/dist/devices/motherboard.js +81 -0
- package/dist/devices/mysmartboard.d.ts +6 -0
- package/dist/devices/mysmartboard.js +8 -0
- package/dist/devices/progressor.d.ts +5 -0
- package/dist/devices/progressor.js +37 -0
- package/dist/devices/wh-c06.d.ts +6 -0
- package/dist/devices/wh-c06.js +17 -0
- package/dist/disconnect.d.ts +6 -0
- package/dist/disconnect.js +12 -0
- package/dist/download.d.ts +10 -0
- package/dist/download.js +50 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.js +22 -0
- package/dist/info.d.ts +7 -0
- package/dist/info.js +30 -0
- package/dist/is-connected.d.ts +7 -0
- package/dist/is-connected.js +13 -0
- package/dist/led.d.ts +20 -0
- package/dist/led.js +192 -0
- package/dist/notify.d.ts +16 -0
- package/dist/notify.js +14 -0
- package/dist/read.d.ts +10 -0
- package/dist/read.js +49 -0
- package/dist/stop.d.ts +7 -0
- package/dist/stop.js +21 -0
- package/dist/stream.d.ts +8 -0
- package/dist/stream.js +41 -0
- package/dist/struct/index.d.ts +9 -0
- package/dist/struct/index.js +203 -0
- package/dist/tare.d.ts +12 -0
- package/dist/tare.js +70 -0
- package/dist/types/commands.d.ts +18 -0
- package/dist/types/commands.js +1 -0
- package/dist/types/devices.d.ts +38 -0
- package/dist/types/devices.js +1 -0
- package/dist/types/download.d.ts +15 -0
- package/dist/types/download.js +1 -0
- package/dist/types/notify.d.ts +14 -0
- package/dist/types/notify.js +1 -0
- package/dist/write.d.ts +16 -0
- package/dist/write.js +57 -0
- package/package.json +3 -2
- package/src/connect.ts +1 -4
- package/src/data/index.ts +7 -0
- package/src/devices/motherboard.ts +6 -6
- package/src/is-connected.ts +1 -1
- package/src/led.ts +29 -11
- package/tsconfig.json +3 -1
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { notifyCallback } from "./../notify";
|
|
2
|
+
import { applyTare } from "./../tare";
|
|
3
|
+
import { ProgressorCommands, ProgressorResponses } from "./../commands/progressor";
|
|
4
|
+
import { lastWrite } from "./../write";
|
|
5
|
+
import struct from "./../struct";
|
|
6
|
+
import { DownloadPackets } from "./../download";
|
|
7
|
+
// Constants
|
|
8
|
+
let MASS_MAX = "0";
|
|
9
|
+
let MASS_AVERAGE = "0";
|
|
10
|
+
let MASS_TOTAL_SUM = 0;
|
|
11
|
+
let DATAPOINT_COUNT = 0;
|
|
12
|
+
/**
|
|
13
|
+
* Handles data received from the Progressor device.
|
|
14
|
+
* @param {DataView} data - The received data.
|
|
15
|
+
*/
|
|
16
|
+
export const handleProgressorData = (data) => {
|
|
17
|
+
const receivedTime = Date.now();
|
|
18
|
+
const [kind] = struct("<bb").unpack(data.buffer.slice(0, 2));
|
|
19
|
+
if (kind === ProgressorResponses.WEIGHT_MEASURE) {
|
|
20
|
+
const iterable = struct("<fi").iter_unpack(data.buffer.slice(2));
|
|
21
|
+
// eslint-disable-next-line prefer-const
|
|
22
|
+
for (let [weight, seconds] of iterable) {
|
|
23
|
+
if (typeof weight === "number" && !isNaN(weight) && typeof seconds === "number" && !isNaN(seconds)) {
|
|
24
|
+
// Add data to downloadable Array: sample and mass are the same
|
|
25
|
+
DownloadPackets.push({
|
|
26
|
+
received: receivedTime,
|
|
27
|
+
sampleNum: seconds,
|
|
28
|
+
battRaw: 0,
|
|
29
|
+
samples: [weight],
|
|
30
|
+
masses: [weight],
|
|
31
|
+
});
|
|
32
|
+
// Tare correction
|
|
33
|
+
weight -= applyTare(weight);
|
|
34
|
+
// Check for max weight
|
|
35
|
+
MASS_MAX = Math.max(Number(MASS_MAX), Number(weight)).toFixed(1);
|
|
36
|
+
// Update running sum and count
|
|
37
|
+
const currentMassTotal = Math.max(-1000, Number(weight));
|
|
38
|
+
MASS_TOTAL_SUM += currentMassTotal;
|
|
39
|
+
DATAPOINT_COUNT++;
|
|
40
|
+
// Calculate the average dynamically
|
|
41
|
+
MASS_AVERAGE = (MASS_TOTAL_SUM / DATAPOINT_COUNT).toFixed(1);
|
|
42
|
+
notifyCallback({
|
|
43
|
+
massMax: MASS_MAX,
|
|
44
|
+
massAverage: MASS_AVERAGE,
|
|
45
|
+
massTotal: Math.max(-1000, weight).toFixed(1),
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
else if (kind === ProgressorResponses.COMMAND_RESPONSE) {
|
|
51
|
+
if (!lastWrite)
|
|
52
|
+
return;
|
|
53
|
+
let value = "";
|
|
54
|
+
if (lastWrite === ProgressorCommands.GET_BATT_VLTG) {
|
|
55
|
+
const vdd = new DataView(data.buffer, 2).getUint32(0, true);
|
|
56
|
+
value = `ℹ️ Battery level: ${vdd} mV`;
|
|
57
|
+
}
|
|
58
|
+
else if (lastWrite === ProgressorCommands.GET_FW_VERSION) {
|
|
59
|
+
value = new TextDecoder().decode(data.buffer.slice(2));
|
|
60
|
+
}
|
|
61
|
+
else if (lastWrite === ProgressorCommands.GET_ERR_INFO) {
|
|
62
|
+
value = new TextDecoder().decode(data.buffer.slice(2));
|
|
63
|
+
}
|
|
64
|
+
console.log(value);
|
|
65
|
+
}
|
|
66
|
+
else if (kind === ProgressorResponses.LOW_BATTERY_WARNING) {
|
|
67
|
+
console.warn("⚠️ Low power detected. Please consider connecting to a power source.");
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
console.error(`❌ Error: Unknown message kind detected: ${kind}`);
|
|
71
|
+
}
|
|
72
|
+
};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { notifyCallback } from "./../notify";
|
|
2
|
+
import { applyTare } from "./../tare";
|
|
3
|
+
// Constants
|
|
4
|
+
let MASS_MAX = "0";
|
|
5
|
+
let MASS_AVERAGE = "0";
|
|
6
|
+
let MASS_TOTAL_SUM = 0;
|
|
7
|
+
let DATAPOINT_COUNT = 0;
|
|
8
|
+
const WEIGHT_OFFSET = 10;
|
|
9
|
+
// const STABLE_OFFSET = 14
|
|
10
|
+
/**
|
|
11
|
+
* Handles data received from the WH-C06 device.
|
|
12
|
+
* @param {DataView} data - The received data.
|
|
13
|
+
*/
|
|
14
|
+
export const handleWHC06Data = (data) => {
|
|
15
|
+
const weight = (data.getUint8(WEIGHT_OFFSET) << 8) | data.getUint8(WEIGHT_OFFSET + 1);
|
|
16
|
+
// const stable = (data.getUint8(STABLE_OFFSET) & 0xf0) >> 4
|
|
17
|
+
// const unit = data.getUint8(STABLE_OFFSET) & 0x0f
|
|
18
|
+
let numericData = weight / 100;
|
|
19
|
+
// Tare correction
|
|
20
|
+
numericData -= applyTare(numericData);
|
|
21
|
+
// Update MASS_MAX
|
|
22
|
+
MASS_MAX = Math.max(Number(MASS_MAX), numericData).toFixed(1);
|
|
23
|
+
// Update running sum and count
|
|
24
|
+
const currentMassTotal = Math.max(-1000, numericData);
|
|
25
|
+
MASS_TOTAL_SUM += currentMassTotal;
|
|
26
|
+
DATAPOINT_COUNT++;
|
|
27
|
+
// Calculate the average dynamically
|
|
28
|
+
MASS_AVERAGE = (MASS_TOTAL_SUM / DATAPOINT_COUNT).toFixed(1);
|
|
29
|
+
// Notify with weight data
|
|
30
|
+
notifyCallback({
|
|
31
|
+
massMax: MASS_MAX,
|
|
32
|
+
massAverage: MASS_AVERAGE,
|
|
33
|
+
massTotal: Math.max(-1000, numericData).toFixed(1),
|
|
34
|
+
});
|
|
35
|
+
};
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Represents a Entralpi device
|
|
3
|
+
*/
|
|
4
|
+
export const Entralpi = {
|
|
5
|
+
filters: [
|
|
6
|
+
{
|
|
7
|
+
name: "ENTRALPI",
|
|
8
|
+
},
|
|
9
|
+
],
|
|
10
|
+
services: [
|
|
11
|
+
{
|
|
12
|
+
name: "Device Information",
|
|
13
|
+
id: "device",
|
|
14
|
+
uuid: "0000180a-0000-1000-8000-00805f9b34fb",
|
|
15
|
+
characteristics: [],
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
name: "Battery Service",
|
|
19
|
+
id: "battery",
|
|
20
|
+
uuid: "0000180f-0000-1000-8000-00805f9b34fb",
|
|
21
|
+
characteristics: [],
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
name: "Generic Attribute",
|
|
25
|
+
id: "attribute",
|
|
26
|
+
uuid: "00001801-0000-1000-8000-00805f9b34fb",
|
|
27
|
+
characteristics: [],
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
name: "UART ISSC Transparent Service",
|
|
31
|
+
id: "uart",
|
|
32
|
+
uuid: "0000fff0-0000-1000-8000-00805f9b34fb",
|
|
33
|
+
characteristics: [
|
|
34
|
+
{
|
|
35
|
+
name: "TX",
|
|
36
|
+
id: "tx",
|
|
37
|
+
uuid: "0000fff5-0000-1000-8000-00805f9b34fb",
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
name: "RX",
|
|
41
|
+
id: "rx",
|
|
42
|
+
uuid: "0000fff4-0000-1000-8000-00805f9b34fb",
|
|
43
|
+
},
|
|
44
|
+
],
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
name: "Weight Scale",
|
|
48
|
+
id: "weight",
|
|
49
|
+
uuid: "0000181d-0000-1000-8000-00805f9b34fb",
|
|
50
|
+
characteristics: [],
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
name: "Generic Access",
|
|
54
|
+
id: "access",
|
|
55
|
+
uuid: "00001800-0000-1000-8000-00805f9b34fb",
|
|
56
|
+
characteristics: [],
|
|
57
|
+
},
|
|
58
|
+
],
|
|
59
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { Climbro } from "./climbro";
|
|
2
|
+
export { Entralpi } from "./entralpi";
|
|
3
|
+
export { KilterBoard } from "./kilterboard";
|
|
4
|
+
export { Motherboard } from "./motherboard";
|
|
5
|
+
export { mySmartBoard } from "./mysmartboard";
|
|
6
|
+
export { WHC06 } from "./wh-c06";
|
|
7
|
+
export { Progressor } from "./progressor";
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { Climbro } from "./climbro";
|
|
2
|
+
export { Entralpi } from "./entralpi";
|
|
3
|
+
export { KilterBoard } from "./kilterboard";
|
|
4
|
+
export { Motherboard } from "./motherboard";
|
|
5
|
+
export { mySmartBoard } from "./mysmartboard";
|
|
6
|
+
export { WHC06 } from "./wh-c06";
|
|
7
|
+
export { Progressor } from "./progressor";
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Represents a Aurora Climbing device
|
|
3
|
+
* Kilter Board, Tension Board, Decoy Board, Touchstone Board, Grasshopper Board, Aurora Board, So iLL Board
|
|
4
|
+
*/
|
|
5
|
+
export const KilterBoard = {
|
|
6
|
+
filters: [
|
|
7
|
+
{
|
|
8
|
+
services: ["4488b571-7806-4df6-bcff-a2897e4953ff"], // Aurora Climbing Advertising service
|
|
9
|
+
},
|
|
10
|
+
],
|
|
11
|
+
services: [
|
|
12
|
+
{
|
|
13
|
+
name: "UART Nordic Service",
|
|
14
|
+
id: "uart",
|
|
15
|
+
uuid: "6e400001-b5a3-f393-e0a9-e50e24dcca9e",
|
|
16
|
+
characteristics: [
|
|
17
|
+
{
|
|
18
|
+
name: "TX",
|
|
19
|
+
id: "tx",
|
|
20
|
+
uuid: "6e400002-b5a3-f393-e0a9-e50e24dcca9e",
|
|
21
|
+
},
|
|
22
|
+
// {
|
|
23
|
+
// name: "RX",
|
|
24
|
+
// id: "rx",
|
|
25
|
+
// uuid: "6e400003-b5a3-f393-e0a9-e50e24dcca9e",
|
|
26
|
+
// },
|
|
27
|
+
],
|
|
28
|
+
},
|
|
29
|
+
],
|
|
30
|
+
};
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Represents a Griptonite Motherboard device
|
|
3
|
+
*/
|
|
4
|
+
export const Motherboard = {
|
|
5
|
+
filters: [{ name: "Motherboard" }],
|
|
6
|
+
services: [
|
|
7
|
+
{
|
|
8
|
+
name: "Device Information",
|
|
9
|
+
id: "device",
|
|
10
|
+
uuid: "0000180a-0000-1000-8000-00805f9b34fb",
|
|
11
|
+
characteristics: [
|
|
12
|
+
// {
|
|
13
|
+
// name: 'Serial Number (Blocked)',
|
|
14
|
+
// id: 'serial'
|
|
15
|
+
// uuid: '00002a25-0000-1000-8000-00805f9b34fb'
|
|
16
|
+
// },
|
|
17
|
+
{
|
|
18
|
+
name: "Firmware Revision",
|
|
19
|
+
id: "firmware",
|
|
20
|
+
uuid: "00002a26-0000-1000-8000-00805f9b34fb",
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
name: "Hardware Revision",
|
|
24
|
+
id: "hardware",
|
|
25
|
+
uuid: "00002a27-0000-1000-8000-00805f9b34fb",
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
name: "Manufacturer Name",
|
|
29
|
+
id: "manufacturer",
|
|
30
|
+
uuid: "00002a29-0000-1000-8000-00805f9b34fb",
|
|
31
|
+
},
|
|
32
|
+
],
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
name: "Battery Service",
|
|
36
|
+
id: "battery",
|
|
37
|
+
uuid: "0000180f-0000-1000-8000-00805f9b34fb",
|
|
38
|
+
characteristics: [
|
|
39
|
+
{
|
|
40
|
+
name: "Battery Level",
|
|
41
|
+
id: "level",
|
|
42
|
+
uuid: "00002a19-0000-1000-8000-00805f9b34fb",
|
|
43
|
+
},
|
|
44
|
+
],
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
name: "LED Service",
|
|
48
|
+
id: "led",
|
|
49
|
+
uuid: "10ababcd-15e1-28ff-de13-725bea03b127",
|
|
50
|
+
characteristics: [
|
|
51
|
+
{
|
|
52
|
+
name: "Red LED",
|
|
53
|
+
id: "red",
|
|
54
|
+
uuid: "10ab1524-15e1-28ff-de13-725bea03b127",
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
name: "Green LED",
|
|
58
|
+
id: "green",
|
|
59
|
+
uuid: "10ab1525-15e1-28ff-de13-725bea03b127",
|
|
60
|
+
},
|
|
61
|
+
],
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
name: "UART Nordic Service",
|
|
65
|
+
id: "uart",
|
|
66
|
+
uuid: "6e400001-b5a3-f393-e0a9-e50e24dcca9e",
|
|
67
|
+
characteristics: [
|
|
68
|
+
{
|
|
69
|
+
name: "TX",
|
|
70
|
+
id: "tx",
|
|
71
|
+
uuid: "6e400002-b5a3-f393-e0a9-e50e24dcca9e",
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
name: "RX",
|
|
75
|
+
id: "rx",
|
|
76
|
+
uuid: "6e400003-b5a3-f393-e0a9-e50e24dcca9e",
|
|
77
|
+
},
|
|
78
|
+
],
|
|
79
|
+
},
|
|
80
|
+
],
|
|
81
|
+
};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Represents a Tindeq Progressor device
|
|
3
|
+
*/
|
|
4
|
+
export const Progressor = {
|
|
5
|
+
filters: [{ namePrefix: "Progressor" }],
|
|
6
|
+
services: [
|
|
7
|
+
{
|
|
8
|
+
name: "Progressor Service",
|
|
9
|
+
id: "progressor",
|
|
10
|
+
uuid: "7e4e1701-1ea6-40c9-9dcc-13d34ffead57",
|
|
11
|
+
characteristics: [
|
|
12
|
+
{
|
|
13
|
+
name: "Notify",
|
|
14
|
+
id: "rx",
|
|
15
|
+
uuid: "7e4e1702-1ea6-40c9-9dcc-13d34ffead57",
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
name: "Write",
|
|
19
|
+
id: "tx",
|
|
20
|
+
uuid: "7e4e1703-1ea6-40c9-9dcc-13d34ffead57",
|
|
21
|
+
},
|
|
22
|
+
],
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
name: "Nordic Device Firmware Update (DFU) Service",
|
|
26
|
+
id: "dfu",
|
|
27
|
+
uuid: "0000fe59-0000-1000-8000-00805f9b34fb",
|
|
28
|
+
characteristics: [
|
|
29
|
+
{
|
|
30
|
+
name: "Buttonless DFU",
|
|
31
|
+
id: "dfu",
|
|
32
|
+
uuid: "8ec90003-f315-4f60-9fb8-838830daea50",
|
|
33
|
+
},
|
|
34
|
+
],
|
|
35
|
+
},
|
|
36
|
+
],
|
|
37
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Represents a Weiheng - WH-C06 (or MAT Muscle Meter) device
|
|
3
|
+
* Enable 'Experimental Web Platform features' Chrome Flags.
|
|
4
|
+
*/
|
|
5
|
+
export const WHC06 = {
|
|
6
|
+
filters: [
|
|
7
|
+
{
|
|
8
|
+
// namePrefix: "IF_B7",
|
|
9
|
+
manufacturerData: [
|
|
10
|
+
{
|
|
11
|
+
companyIdentifier: 0x0100, // 256
|
|
12
|
+
},
|
|
13
|
+
],
|
|
14
|
+
},
|
|
15
|
+
],
|
|
16
|
+
services: [],
|
|
17
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { isConnected } from "./is-connected";
|
|
2
|
+
/**
|
|
3
|
+
* Disconnects the device if it is connected.
|
|
4
|
+
* @param {Device} board - The device to disconnect.
|
|
5
|
+
*/
|
|
6
|
+
export const disconnect = (board) => {
|
|
7
|
+
// Check if the device is connected
|
|
8
|
+
if (isConnected(board)) {
|
|
9
|
+
// Disconnect the device using optional chaining
|
|
10
|
+
board.device?.gatt?.disconnect();
|
|
11
|
+
}
|
|
12
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { DownloadPacket } from "./types/download";
|
|
2
|
+
/**
|
|
3
|
+
* Array of DownloadPacket entries.
|
|
4
|
+
*/
|
|
5
|
+
export declare const DownloadPackets: DownloadPacket[];
|
|
6
|
+
export declare const emptyDownloadPackets: () => void;
|
|
7
|
+
/**
|
|
8
|
+
* Exports the data as a CSV file.
|
|
9
|
+
*/
|
|
10
|
+
export declare const download: () => void;
|
package/dist/download.js
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Array of DownloadPacket entries.
|
|
3
|
+
*/
|
|
4
|
+
export const DownloadPackets = []; // Initialize an empty array of DownloadPacket entries
|
|
5
|
+
// Function to empty DownloadPackets array
|
|
6
|
+
export const emptyDownloadPackets = () => {
|
|
7
|
+
DownloadPackets.length = 0; // Set the length of the array to 0 to empty it
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* Converts an array of DownloadPacket objects to a CSV string.
|
|
11
|
+
* @param data - Array of DownloadPacket objects.
|
|
12
|
+
* @returns CSV string representation of the data.
|
|
13
|
+
*/
|
|
14
|
+
const packetsToCSV = (data) => {
|
|
15
|
+
return data
|
|
16
|
+
.map((packet) => [
|
|
17
|
+
packet.received.toString(),
|
|
18
|
+
packet.sampleNum.toString(),
|
|
19
|
+
packet.battRaw.toString(),
|
|
20
|
+
...packet.samples.map(String),
|
|
21
|
+
...packet.masses.map(String),
|
|
22
|
+
]
|
|
23
|
+
.map((v) => v.replace(/"/g, '""'))
|
|
24
|
+
.map((v) => `"${v}"`)
|
|
25
|
+
.join(","))
|
|
26
|
+
.join("\r\n");
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* Exports the data as a CSV file.
|
|
30
|
+
*/
|
|
31
|
+
export const download = () => {
|
|
32
|
+
// Generate CSV string from DownloadPackets array
|
|
33
|
+
const csvContent = packetsToCSV(DownloadPackets);
|
|
34
|
+
// Create a Blob object containing the CSV data
|
|
35
|
+
const blob = new Blob([csvContent], { type: "text/csv" });
|
|
36
|
+
// Create a URL for the Blob
|
|
37
|
+
const url = window.URL.createObjectURL(blob);
|
|
38
|
+
// Create a link element
|
|
39
|
+
const link = document.createElement("a");
|
|
40
|
+
// Set link attributes
|
|
41
|
+
link.href = url;
|
|
42
|
+
link.setAttribute("download", "data.csv");
|
|
43
|
+
// Append link to document body
|
|
44
|
+
document.body.appendChild(link);
|
|
45
|
+
// Programmatically click the link to trigger the download
|
|
46
|
+
link.click();
|
|
47
|
+
// Clean up: remove the link and revoke the URL
|
|
48
|
+
document.body.removeChild(link);
|
|
49
|
+
window.URL.revokeObjectURL(url);
|
|
50
|
+
};
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export { Climbro, Entralpi, KilterBoard, Motherboard, mySmartBoard, WHC06, Progressor } from "./devices/index";
|
|
2
|
+
export { battery } from "./battery";
|
|
3
|
+
export { calibration } from "./calibration";
|
|
4
|
+
export { download } from "./download";
|
|
5
|
+
export { connect } from "./connect";
|
|
6
|
+
export { disconnect } from "./disconnect";
|
|
7
|
+
export { isConnected } from "./is-connected";
|
|
8
|
+
export { info } from "./info";
|
|
9
|
+
export { led } from "./led";
|
|
10
|
+
export { notify } from "./notify";
|
|
11
|
+
export { stop } from "./stop";
|
|
12
|
+
export { stream } from "./stream";
|
|
13
|
+
export { tare } from "./tare";
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
// Export device types
|
|
2
|
+
export { Climbro, Entralpi, KilterBoard, Motherboard, mySmartBoard, WHC06, Progressor } from "./devices/index";
|
|
3
|
+
// Export battery related functions
|
|
4
|
+
export { battery } from "./battery";
|
|
5
|
+
// Export calibration function
|
|
6
|
+
export { calibration } from "./calibration";
|
|
7
|
+
// Export download function
|
|
8
|
+
export { download } from "./download";
|
|
9
|
+
// Export connection related functions
|
|
10
|
+
export { connect } from "./connect";
|
|
11
|
+
export { disconnect } from "./disconnect";
|
|
12
|
+
export { isConnected } from "./is-connected";
|
|
13
|
+
// Export information retrieval function
|
|
14
|
+
export { info } from "./info";
|
|
15
|
+
// Export led retrieval function
|
|
16
|
+
export { led } from "./led";
|
|
17
|
+
// Export notification related function
|
|
18
|
+
export { notify } from "./notify";
|
|
19
|
+
// Export stream related functions
|
|
20
|
+
export { stop } from "./stop";
|
|
21
|
+
export { stream } from "./stream";
|
|
22
|
+
export { tare } from "./tare";
|
package/dist/info.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { Device } from "./types/devices";
|
|
2
|
+
/**
|
|
3
|
+
* Retrieves device information.
|
|
4
|
+
* @param {Device} board - The device to retrieve information from.
|
|
5
|
+
* @returns {Promise<void>} A promise that resolves when the information retrieval is completed.
|
|
6
|
+
*/
|
|
7
|
+
export declare const info: (board: Device) => Promise<void>;
|
package/dist/info.js
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { write } from "./write";
|
|
2
|
+
import { read } from "./read";
|
|
3
|
+
import { isConnected } from "./is-connected";
|
|
4
|
+
import { Motherboard, Progressor } from "./devices";
|
|
5
|
+
import { MotherboardCommands, ProgressorCommands } from "./commands";
|
|
6
|
+
/**
|
|
7
|
+
* Retrieves device information.
|
|
8
|
+
* @param {Device} board - The device to retrieve information from.
|
|
9
|
+
* @returns {Promise<void>} A promise that resolves when the information retrieval is completed.
|
|
10
|
+
*/
|
|
11
|
+
export const info = async (board) => {
|
|
12
|
+
if (isConnected(board)) {
|
|
13
|
+
if (board.filters.some((filter) => filter.name === "Motherboard")) {
|
|
14
|
+
// Read manufacturer information
|
|
15
|
+
await read(Motherboard, "device", "manufacturer", 250);
|
|
16
|
+
// Read hardware version
|
|
17
|
+
await read(Motherboard, "device", "hardware", 250);
|
|
18
|
+
// Read firmware version
|
|
19
|
+
await read(Motherboard, "device", "firmware", 250);
|
|
20
|
+
// Get text from Motherboard
|
|
21
|
+
await write(Motherboard, "uart", "tx", MotherboardCommands.GET_TEXT, 250);
|
|
22
|
+
// Get serial number from Motherboard
|
|
23
|
+
await write(Motherboard, "uart", "tx", MotherboardCommands.GET_SERIAL, 250);
|
|
24
|
+
}
|
|
25
|
+
if (board.filters.some((filter) => filter.namePrefix === "Progressor")) {
|
|
26
|
+
// Get firmware version from Progressor
|
|
27
|
+
await write(Progressor, "progressor", "tx", ProgressorCommands.GET_FW_VERSION, 250);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { Device } from "./types/devices";
|
|
2
|
+
/**
|
|
3
|
+
* Checks if a Bluetooth device is connected.
|
|
4
|
+
* @param {Device} board - The device to check for connection.
|
|
5
|
+
* @returns {boolean} A boolean indicating whether the device is connected.
|
|
6
|
+
*/
|
|
7
|
+
export declare const isConnected: (board?: Device) => boolean;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Checks if a Bluetooth device is connected.
|
|
3
|
+
* @param {Device} board - The device to check for connection.
|
|
4
|
+
* @returns {boolean} A boolean indicating whether the device is connected.
|
|
5
|
+
*/
|
|
6
|
+
export const isConnected = (board) => {
|
|
7
|
+
// Check if the device is defined and available
|
|
8
|
+
if (!board?.device) {
|
|
9
|
+
return false;
|
|
10
|
+
}
|
|
11
|
+
// Check if the device is connected
|
|
12
|
+
return !!board.device.gatt?.connected;
|
|
13
|
+
};
|
package/dist/led.d.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { Device } from "./types/devices";
|
|
2
|
+
declare class ClimbPlacement {
|
|
3
|
+
position: number;
|
|
4
|
+
role_id: string;
|
|
5
|
+
constructor(position: number, role_id: string);
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Prepares byte arrays for transmission based on a list of climb placements.
|
|
9
|
+
* @param climbPlacementList - The list of climb placements containing position and role ID.
|
|
10
|
+
* @returns The final byte array ready for transmission.
|
|
11
|
+
*/
|
|
12
|
+
export declare function prepBytesV3(climbPlacementList: ClimbPlacement[]): number[];
|
|
13
|
+
/**
|
|
14
|
+
* Sets the LEDs on the specified device.
|
|
15
|
+
* @param {Device} board - The device on which to set the LEDs.
|
|
16
|
+
* @param {ClimbPlacement[]} [placement] - An optional array of climb placements for LED positioning.
|
|
17
|
+
* @returns {Promise<number[] | undefined>} A promise that resolves with the payload array if LED settings were applied, or `undefined` if no action was taken.
|
|
18
|
+
*/
|
|
19
|
+
export declare const led: (board: Device, placement?: ClimbPlacement[]) => Promise<number[] | undefined>;
|
|
20
|
+
export {};
|