@hangtime/grip-connect 0.3.7 → 0.3.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +10 -1
- package/dist/data/entralpi.js +3 -0
- package/dist/data/motherboard.js +3 -0
- package/dist/data/progressor.js +3 -0
- package/dist/data/wh-c06.js +3 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/is-active.d.ts +37 -0
- package/dist/is-active.js +49 -0
- package/package.json +1 -1
- package/src/data/entralpi.ts +4 -0
- package/src/data/motherboard.ts +4 -0
- package/src/data/progressor.ts +4 -0
- package/src/data/wh-c06.ts +4 -0
- package/src/index.ts +1 -0
- package/src/is-active.ts +58 -0
package/README.md
CHANGED
|
@@ -47,7 +47,7 @@ Simply importing the utilities you need from `@hangtime/grip-connect`.
|
|
|
47
47
|
```
|
|
48
48
|
|
|
49
49
|
```js
|
|
50
|
-
import { Motherboard, battery, connect, disconnect, info, notify, stream } from "@hangtime/grip-connect"
|
|
50
|
+
import { Motherboard, active, battery, connect, disconnect, info, notify, stream } from "@hangtime/grip-connect"
|
|
51
51
|
|
|
52
52
|
const motherboardButton = document.querySelector("#motherboard")
|
|
53
53
|
|
|
@@ -59,10 +59,18 @@ motherboardButton.addEventListener("click", () => {
|
|
|
59
59
|
console.log(data)
|
|
60
60
|
})
|
|
61
61
|
|
|
62
|
+
// Check if device is being used
|
|
63
|
+
active((value) => {
|
|
64
|
+
console.log(value)
|
|
65
|
+
})
|
|
66
|
+
|
|
62
67
|
// Read battery + device info
|
|
63
68
|
await battery(Motherboard)
|
|
64
69
|
await info(Motherboard)
|
|
65
70
|
|
|
71
|
+
// trigger LEDs
|
|
72
|
+
// await led(device)
|
|
73
|
+
|
|
66
74
|
// Start weight streaming (for a minute) remove parameter for a continues stream
|
|
67
75
|
await stream(Motherboard, 60000)
|
|
68
76
|
|
|
@@ -106,6 +114,7 @@ available services with us.
|
|
|
106
114
|
- ✅ Read calibration
|
|
107
115
|
- ✅ Device info: firmware / serial etc.
|
|
108
116
|
- ✅ Check if device is connected
|
|
117
|
+
- ✅ Check if device is being used
|
|
109
118
|
- ✅ Peak / Average load
|
|
110
119
|
- ✅️ Tare / unladen weight
|
|
111
120
|
- ✅️ Download data to CVS
|
package/dist/data/entralpi.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { notifyCallback } from "./../notify";
|
|
2
|
+
import { checkActivity } from "./../is-active";
|
|
2
3
|
import { applyTare } from "./../tare";
|
|
3
4
|
// Constants
|
|
4
5
|
let MASS_MAX = "0";
|
|
@@ -21,6 +22,8 @@ export const handleEntralpiData = (receivedData) => {
|
|
|
21
22
|
DATAPOINT_COUNT++;
|
|
22
23
|
// Calculate the average dynamically
|
|
23
24
|
MASS_AVERAGE = (MASS_TOTAL_SUM / DATAPOINT_COUNT).toFixed(1);
|
|
25
|
+
// Check if device is being used
|
|
26
|
+
checkActivity(numericData);
|
|
24
27
|
// Notify with weight data
|
|
25
28
|
notifyCallback({
|
|
26
29
|
massMax: MASS_MAX,
|
package/dist/data/motherboard.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { notifyCallback } from "./../notify";
|
|
2
2
|
import { applyTare } from "./../tare";
|
|
3
3
|
import { MotherboardCommands } from "./../commands";
|
|
4
|
+
import { checkActivity } from "./../is-active";
|
|
4
5
|
import { lastWrite } from "./../write";
|
|
5
6
|
import { DownloadPackets } from "./../download";
|
|
6
7
|
// Constants
|
|
@@ -108,6 +109,8 @@ export const handleMotherboardData = (receivedData) => {
|
|
|
108
109
|
DATAPOINT_COUNT++;
|
|
109
110
|
// Calculate the average dynamically
|
|
110
111
|
MASS_AVERAGE = (MASS_TOTAL_SUM / DATAPOINT_COUNT).toFixed(1);
|
|
112
|
+
// Check if device is being used
|
|
113
|
+
checkActivity(center);
|
|
111
114
|
// Notify with weight data
|
|
112
115
|
notifyCallback({
|
|
113
116
|
massTotal: Math.max(-1000, left + center + right).toFixed(1),
|
package/dist/data/progressor.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { notifyCallback } from "./../notify";
|
|
2
2
|
import { applyTare } from "./../tare";
|
|
3
|
+
import { checkActivity } from "./../is-active";
|
|
3
4
|
import { ProgressorCommands, ProgressorResponses } from "./../commands/progressor";
|
|
4
5
|
import { lastWrite } from "./../write";
|
|
5
6
|
import struct from "./../struct";
|
|
@@ -39,6 +40,8 @@ export const handleProgressorData = (data) => {
|
|
|
39
40
|
DATAPOINT_COUNT++;
|
|
40
41
|
// Calculate the average dynamically
|
|
41
42
|
MASS_AVERAGE = (MASS_TOTAL_SUM / DATAPOINT_COUNT).toFixed(1);
|
|
43
|
+
// Check if device is being used
|
|
44
|
+
checkActivity(weight);
|
|
42
45
|
notifyCallback({
|
|
43
46
|
massMax: MASS_MAX,
|
|
44
47
|
massAverage: MASS_AVERAGE,
|
package/dist/data/wh-c06.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { checkActivity } from "./../is-active";
|
|
1
2
|
import { notifyCallback } from "./../notify";
|
|
2
3
|
import { applyTare } from "./../tare";
|
|
3
4
|
// Constants
|
|
@@ -26,6 +27,8 @@ export const handleWHC06Data = (data) => {
|
|
|
26
27
|
DATAPOINT_COUNT++;
|
|
27
28
|
// Calculate the average dynamically
|
|
28
29
|
MASS_AVERAGE = (MASS_TOTAL_SUM / DATAPOINT_COUNT).toFixed(1);
|
|
30
|
+
// Check if device is being used
|
|
31
|
+
checkActivity(numericData);
|
|
29
32
|
// Notify with weight data
|
|
30
33
|
notifyCallback({
|
|
31
34
|
massMax: MASS_MAX,
|
package/dist/index.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ export { calibration } from "./calibration";
|
|
|
4
4
|
export { download } from "./download";
|
|
5
5
|
export { connect } from "./connect";
|
|
6
6
|
export { disconnect } from "./disconnect";
|
|
7
|
+
export { active, isActive } from "./is-active";
|
|
7
8
|
export { isConnected } from "./is-connected";
|
|
8
9
|
export { info } from "./info";
|
|
9
10
|
export { led } from "./led";
|
package/dist/index.js
CHANGED
|
@@ -9,6 +9,7 @@ export { download } from "./download";
|
|
|
9
9
|
// Export connection related functions
|
|
10
10
|
export { connect } from "./connect";
|
|
11
11
|
export { disconnect } from "./disconnect";
|
|
12
|
+
export { active, isActive } from "./is-active";
|
|
12
13
|
export { isConnected } from "./is-connected";
|
|
13
14
|
// Export information retrieval function
|
|
14
15
|
export { info } from "./info";
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type definition for the callback function that is called when the activity status changes.
|
|
3
|
+
* @param {boolean} value - The new activity status (true if active, false if not).
|
|
4
|
+
*/
|
|
5
|
+
type IsActiveCallback = (value: boolean) => void;
|
|
6
|
+
/**
|
|
7
|
+
* Indicates whether the device is currently active.
|
|
8
|
+
* @type {boolean}
|
|
9
|
+
*/
|
|
10
|
+
export declare let isActive: boolean;
|
|
11
|
+
/**
|
|
12
|
+
* Sets the callback function to be called when the activity status changes.
|
|
13
|
+
*
|
|
14
|
+
* This function allows you to specify a callback that will be invoked whenever
|
|
15
|
+
* the activity status changes, indicating whether the device is currently active.
|
|
16
|
+
*
|
|
17
|
+
* @param {IsActiveCallback} callback - The callback function to be set. This function
|
|
18
|
+
* receives a boolean value indicating the new activity status.
|
|
19
|
+
* @returns {void}
|
|
20
|
+
*/
|
|
21
|
+
export declare const active: (callback: IsActiveCallback) => void;
|
|
22
|
+
/**
|
|
23
|
+
* Checks if a dynamic value is active based on a threshold and duration.
|
|
24
|
+
*
|
|
25
|
+
* This function assesses whether a given dynamic value surpasses a specified threshold
|
|
26
|
+
* and remains active for a specified duration. If the activity status changes from
|
|
27
|
+
* the previous state, the callback function is called with the updated activity status.
|
|
28
|
+
*
|
|
29
|
+
* @param {number} input - The dynamic value to check for activity status.
|
|
30
|
+
* @param {number} [threshold=2.5] - The threshold value to determine if the input is considered active.
|
|
31
|
+
* Defaults to 2.5 if not provided.
|
|
32
|
+
* @param {number} [duration=1000] - The duration (in milliseconds) to monitor the input for activity.
|
|
33
|
+
* Defaults to 1000 milliseconds if not provided.
|
|
34
|
+
* @returns {Promise<void>} A promise that resolves once the activity check is complete.
|
|
35
|
+
*/
|
|
36
|
+
export declare const checkActivity: (input: number, threshold?: number, duration?: number) => Promise<void>;
|
|
37
|
+
export {};
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
let activeCallback;
|
|
2
|
+
/**
|
|
3
|
+
* Indicates whether the device is currently active.
|
|
4
|
+
* @type {boolean}
|
|
5
|
+
*/
|
|
6
|
+
export let isActive = false;
|
|
7
|
+
/**
|
|
8
|
+
* Sets the callback function to be called when the activity status changes.
|
|
9
|
+
*
|
|
10
|
+
* This function allows you to specify a callback that will be invoked whenever
|
|
11
|
+
* the activity status changes, indicating whether the device is currently active.
|
|
12
|
+
*
|
|
13
|
+
* @param {IsActiveCallback} callback - The callback function to be set. This function
|
|
14
|
+
* receives a boolean value indicating the new activity status.
|
|
15
|
+
* @returns {void}
|
|
16
|
+
*/
|
|
17
|
+
export const active = (callback) => {
|
|
18
|
+
activeCallback = callback;
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* Checks if a dynamic value is active based on a threshold and duration.
|
|
22
|
+
*
|
|
23
|
+
* This function assesses whether a given dynamic value surpasses a specified threshold
|
|
24
|
+
* and remains active for a specified duration. If the activity status changes from
|
|
25
|
+
* the previous state, the callback function is called with the updated activity status.
|
|
26
|
+
*
|
|
27
|
+
* @param {number} input - The dynamic value to check for activity status.
|
|
28
|
+
* @param {number} [threshold=2.5] - The threshold value to determine if the input is considered active.
|
|
29
|
+
* Defaults to 2.5 if not provided.
|
|
30
|
+
* @param {number} [duration=1000] - The duration (in milliseconds) to monitor the input for activity.
|
|
31
|
+
* Defaults to 1000 milliseconds if not provided.
|
|
32
|
+
* @returns {Promise<void>} A promise that resolves once the activity check is complete.
|
|
33
|
+
*/
|
|
34
|
+
export const checkActivity = (input, threshold = 2.5, duration = 1000) => {
|
|
35
|
+
return new Promise((resolve) => {
|
|
36
|
+
// Check the activity status after the specified duration
|
|
37
|
+
setTimeout(() => {
|
|
38
|
+
// Determine the activity status based on the threshold
|
|
39
|
+
const activeNow = input > threshold;
|
|
40
|
+
if (isActive !== activeNow) {
|
|
41
|
+
isActive = activeNow;
|
|
42
|
+
if (activeCallback) {
|
|
43
|
+
activeCallback(activeNow);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
resolve();
|
|
47
|
+
}, duration);
|
|
48
|
+
});
|
|
49
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hangtime/grip-connect",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.8",
|
|
4
4
|
"description": "A client that can establish connections with various Force-Sensing Hangboards/Plates used by climbers for strength measurement. Examples of such hangboards include the Griptonite Motherboard, Climbro, SmartBoard, Entralpi or Tindeq Progressor",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
package/src/data/entralpi.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { notifyCallback } from "./../notify"
|
|
2
|
+
import { checkActivity } from "./../is-active"
|
|
2
3
|
import { applyTare } from "./../tare"
|
|
3
4
|
|
|
4
5
|
// Constants
|
|
@@ -28,6 +29,9 @@ export const handleEntralpiData = (receivedData: string): void => {
|
|
|
28
29
|
// Calculate the average dynamically
|
|
29
30
|
MASS_AVERAGE = (MASS_TOTAL_SUM / DATAPOINT_COUNT).toFixed(1)
|
|
30
31
|
|
|
32
|
+
// Check if device is being used
|
|
33
|
+
checkActivity(numericData)
|
|
34
|
+
|
|
31
35
|
// Notify with weight data
|
|
32
36
|
notifyCallback({
|
|
33
37
|
massMax: MASS_MAX,
|
package/src/data/motherboard.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { notifyCallback } from "./../notify"
|
|
2
2
|
import { applyTare } from "./../tare"
|
|
3
3
|
import { MotherboardCommands } from "./../commands"
|
|
4
|
+
import { checkActivity } from "./../is-active"
|
|
4
5
|
import { lastWrite } from "./../write"
|
|
5
6
|
import { DownloadPackets } from "./../download"
|
|
6
7
|
import type { DownloadPacket } from "./../types/download"
|
|
@@ -131,6 +132,9 @@ export const handleMotherboardData = (receivedData: string): void => {
|
|
|
131
132
|
// Calculate the average dynamically
|
|
132
133
|
MASS_AVERAGE = (MASS_TOTAL_SUM / DATAPOINT_COUNT).toFixed(1)
|
|
133
134
|
|
|
135
|
+
// Check if device is being used
|
|
136
|
+
checkActivity(center)
|
|
137
|
+
|
|
134
138
|
// Notify with weight data
|
|
135
139
|
notifyCallback({
|
|
136
140
|
massTotal: Math.max(-1000, left + center + right).toFixed(1),
|
package/src/data/progressor.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { notifyCallback } from "./../notify"
|
|
2
2
|
import { applyTare } from "./../tare"
|
|
3
|
+
import { checkActivity } from "./../is-active"
|
|
3
4
|
import { ProgressorCommands, ProgressorResponses } from "./../commands/progressor"
|
|
4
5
|
import { lastWrite } from "./../write"
|
|
5
6
|
import struct from "./../struct"
|
|
@@ -43,6 +44,9 @@ export const handleProgressorData = (data: DataView): void => {
|
|
|
43
44
|
// Calculate the average dynamically
|
|
44
45
|
MASS_AVERAGE = (MASS_TOTAL_SUM / DATAPOINT_COUNT).toFixed(1)
|
|
45
46
|
|
|
47
|
+
// Check if device is being used
|
|
48
|
+
checkActivity(weight)
|
|
49
|
+
|
|
46
50
|
notifyCallback({
|
|
47
51
|
massMax: MASS_MAX,
|
|
48
52
|
massAverage: MASS_AVERAGE,
|
package/src/data/wh-c06.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { checkActivity } from "./../is-active"
|
|
1
2
|
import { notifyCallback } from "./../notify"
|
|
2
3
|
import { applyTare } from "./../tare"
|
|
3
4
|
|
|
@@ -34,6 +35,9 @@ export const handleWHC06Data = (data: DataView): void => {
|
|
|
34
35
|
// Calculate the average dynamically
|
|
35
36
|
MASS_AVERAGE = (MASS_TOTAL_SUM / DATAPOINT_COUNT).toFixed(1)
|
|
36
37
|
|
|
38
|
+
// Check if device is being used
|
|
39
|
+
checkActivity(numericData)
|
|
40
|
+
|
|
37
41
|
// Notify with weight data
|
|
38
42
|
notifyCallback({
|
|
39
43
|
massMax: MASS_MAX,
|
package/src/index.ts
CHANGED
|
@@ -13,6 +13,7 @@ export { download } from "./download"
|
|
|
13
13
|
// Export connection related functions
|
|
14
14
|
export { connect } from "./connect"
|
|
15
15
|
export { disconnect } from "./disconnect"
|
|
16
|
+
export { active, isActive } from "./is-active"
|
|
16
17
|
export { isConnected } from "./is-connected"
|
|
17
18
|
|
|
18
19
|
// Export information retrieval function
|
package/src/is-active.ts
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type definition for the callback function that is called when the activity status changes.
|
|
3
|
+
* @param {boolean} value - The new activity status (true if active, false if not).
|
|
4
|
+
*/
|
|
5
|
+
type IsActiveCallback = (value: boolean) => void
|
|
6
|
+
|
|
7
|
+
let activeCallback: IsActiveCallback | undefined
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Indicates whether the device is currently active.
|
|
11
|
+
* @type {boolean}
|
|
12
|
+
*/
|
|
13
|
+
export let isActive = false
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Sets the callback function to be called when the activity status changes.
|
|
17
|
+
*
|
|
18
|
+
* This function allows you to specify a callback that will be invoked whenever
|
|
19
|
+
* the activity status changes, indicating whether the device is currently active.
|
|
20
|
+
*
|
|
21
|
+
* @param {IsActiveCallback} callback - The callback function to be set. This function
|
|
22
|
+
* receives a boolean value indicating the new activity status.
|
|
23
|
+
* @returns {void}
|
|
24
|
+
*/
|
|
25
|
+
export const active = (callback: IsActiveCallback): void => {
|
|
26
|
+
activeCallback = callback
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Checks if a dynamic value is active based on a threshold and duration.
|
|
31
|
+
*
|
|
32
|
+
* This function assesses whether a given dynamic value surpasses a specified threshold
|
|
33
|
+
* and remains active for a specified duration. If the activity status changes from
|
|
34
|
+
* the previous state, the callback function is called with the updated activity status.
|
|
35
|
+
*
|
|
36
|
+
* @param {number} input - The dynamic value to check for activity status.
|
|
37
|
+
* @param {number} [threshold=2.5] - The threshold value to determine if the input is considered active.
|
|
38
|
+
* Defaults to 2.5 if not provided.
|
|
39
|
+
* @param {number} [duration=1000] - The duration (in milliseconds) to monitor the input for activity.
|
|
40
|
+
* Defaults to 1000 milliseconds if not provided.
|
|
41
|
+
* @returns {Promise<void>} A promise that resolves once the activity check is complete.
|
|
42
|
+
*/
|
|
43
|
+
export const checkActivity = (input: number, threshold = 2.5, duration = 1000): Promise<void> => {
|
|
44
|
+
return new Promise((resolve) => {
|
|
45
|
+
// Check the activity status after the specified duration
|
|
46
|
+
setTimeout(() => {
|
|
47
|
+
// Determine the activity status based on the threshold
|
|
48
|
+
const activeNow = input > threshold
|
|
49
|
+
if (isActive !== activeNow) {
|
|
50
|
+
isActive = activeNow
|
|
51
|
+
if (activeCallback) {
|
|
52
|
+
activeCallback(activeNow)
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
resolve()
|
|
56
|
+
}, duration)
|
|
57
|
+
})
|
|
58
|
+
}
|