@hangtime/grip-connect 0.5.6 → 0.5.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.
Files changed (44) hide show
  1. package/README.md +32 -35
  2. package/dist/index.d.ts +0 -4
  3. package/dist/index.js +0 -5
  4. package/dist/interfaces/callback.interface.d.ts +6 -0
  5. package/dist/interfaces/device/motherboard.interface.d.ts +0 -7
  6. package/dist/interfaces/device.interface.d.ts +32 -27
  7. package/dist/models/device/entralpi.model.js +8 -10
  8. package/dist/models/device/forceboard.model.js +35 -35
  9. package/dist/models/device/kilterboard.model.d.ts +10 -6
  10. package/dist/models/device/kilterboard.model.js +12 -8
  11. package/dist/models/device/motherboard.model.d.ts +12 -8
  12. package/dist/models/device/motherboard.model.js +22 -21
  13. package/dist/models/device/progressor.model.js +26 -20
  14. package/dist/models/device/wh-c06.model.d.ts +11 -6
  15. package/dist/models/device/wh-c06.model.js +30 -16
  16. package/dist/models/device.model.d.ts +161 -14
  17. package/dist/models/device.model.js +264 -9
  18. package/package.json +1 -1
  19. package/src/index.ts +0 -9
  20. package/src/interfaces/callback.interface.ts +7 -0
  21. package/src/interfaces/device/motherboard.interface.ts +0 -8
  22. package/src/interfaces/device.interface.ts +33 -31
  23. package/src/models/device/entralpi.model.ts +8 -10
  24. package/src/models/device/forceboard.model.ts +35 -36
  25. package/src/models/device/kilterboard.model.ts +23 -9
  26. package/src/models/device/motherboard.model.ts +23 -22
  27. package/src/models/device/progressor.model.ts +26 -20
  28. package/src/models/device/wh-c06.model.ts +38 -17
  29. package/src/models/device.model.ts +317 -19
  30. package/dist/helpers/download.d.ts +0 -16
  31. package/dist/helpers/download.js +0 -106
  32. package/dist/helpers/is-active.d.ts +0 -41
  33. package/dist/helpers/is-active.js +0 -59
  34. package/dist/helpers/is-device.d.ts +0 -37
  35. package/dist/helpers/is-device.js +0 -39
  36. package/dist/helpers/struct.d.ts +0 -9
  37. package/dist/helpers/struct.js +0 -203
  38. package/dist/helpers/tare.d.ts +0 -12
  39. package/dist/helpers/tare.js +0 -70
  40. package/src/helpers/download.ts +0 -123
  41. package/src/helpers/is-active.ts +0 -70
  42. package/src/helpers/is-device.ts +0 -50
  43. package/src/helpers/struct.ts +0 -239
  44. package/src/helpers/tare.ts +0 -76
@@ -1,59 +0,0 @@
1
- let activeCallback;
2
- /**
3
- * Indicates whether the device is currently active.
4
- * @type {boolean}
5
- */
6
- export let isActive = false;
7
- /**
8
- * Configuration for threshold and duration.
9
- */
10
- let config = { threshold: 2.5, duration: 1000 };
11
- /**
12
- * Sets the callback function to be called when the activity status changes,
13
- * and optionally sets the configuration for threshold and duration.
14
- *
15
- * This function allows you to specify a callback that will be invoked whenever
16
- * the activity status changes, indicating whether the device is currently active.
17
- * It also allows optionally configuring the threshold and duration used to determine activity.
18
- *
19
- * @param {IsActiveCallback} callback - The callback function to be set. This function
20
- * receives a boolean value indicating the new activity status.
21
- * @param {object} [options] - Optional configuration object containing the threshold and duration.
22
- * @param {number} [options.threshold=2.5] - The threshold value for determining activity.
23
- * @param {number} [options.duration=1000] - The duration (in milliseconds) to monitor the input for activity.
24
- * @returns {void}
25
- */
26
- export const active = (callback, options) => {
27
- activeCallback = callback;
28
- // Update the config values only if provided, otherwise use defaults
29
- config = {
30
- threshold: options?.threshold ?? config.threshold, // Use new threshold if provided, else use default
31
- duration: options?.duration ?? config.duration, // Use new duration if provided, else use default
32
- };
33
- };
34
- /**
35
- * Checks if a dynamic value is active based on a threshold and duration.
36
- *
37
- * This function assesses whether a given dynamic value surpasses a specified threshold
38
- * and remains active for a specified duration. If the activity status changes from
39
- * the previous state, the callback function is called with the updated activity status.
40
- *
41
- * @param {number} input - The dynamic value to check for activity status.
42
- * @returns {Promise<void>} A promise that resolves once the activity check is complete.
43
- */
44
- export const checkActivity = (input) => {
45
- return new Promise((resolve) => {
46
- // Check the activity status after the specified duration
47
- setTimeout(() => {
48
- // Determine the activity status based on the stored threshold in the config
49
- const activeNow = input > config.threshold;
50
- if (isActive !== activeNow) {
51
- isActive = activeNow;
52
- if (activeCallback) {
53
- activeCallback(activeNow);
54
- }
55
- }
56
- resolve();
57
- }, config.duration);
58
- });
59
- };
@@ -1,37 +0,0 @@
1
- import type { Device } from "./../models/device.model";
2
- /**
3
- * Checks if the given device is an Entralpi.
4
- * @param {Device} [device] - The device to check.
5
- * @returns {boolean} `true` if the device has a filter with the name "ENTRALPI", otherwise `false`.
6
- */
7
- export declare const isEntralpi: (device?: Device) => boolean;
8
- /**
9
- * Checks if the given device is a Force Board.
10
- * @param {Device} [device] - The device to check.
11
- * @returns {boolean} `true` if the device has a filter with the name "Force Board", otherwise `false`.
12
- */
13
- export declare const isForceBoard: (device?: Device) => boolean;
14
- /**
15
- * Checks if the given device is a Kilter Board.
16
- * @param {Device} [device] - The device to check.
17
- * @returns {boolean} `true` if the device has a service UUID matching the Kilter Board Aurora UUID, otherwise `false`.
18
- */
19
- export declare const isKilterBoard: (device?: Device) => boolean;
20
- /**
21
- * Checks if the given device is a Motherboard.
22
- * @param {Device} [device] - The device to check.
23
- * @returns {boolean} `true` if the device has a filter with the name "Motherdevice", otherwise `false`.
24
- */
25
- export declare const isMotherboard: (device?: Device) => boolean;
26
- /**
27
- * Checks if the given device is a Progressor.
28
- * @param {Device} [device] - The device to check.
29
- * @returns {boolean} `true` if the device has a filter with a namePrefix of "Progressor", otherwise `false`.
30
- */
31
- export declare const isProgressor: (device?: Device) => boolean;
32
- /**
33
- * Checks if the given device is a WH-C06.
34
- * @param {Device} [device] - The device to check.
35
- * @returns {boolean} `true` if the device has a filter with the company identifier 0x0100, otherwise `false`.
36
- */
37
- export declare const isWHC06: (device?: Device) => boolean;
@@ -1,39 +0,0 @@
1
- import { KilterBoard } from "../models";
2
- /**
3
- * Checks if the given device is an Entralpi.
4
- * @param {Device} [device] - The device to check.
5
- * @returns {boolean} `true` if the device has a filter with the name "ENTRALPI", otherwise `false`.
6
- */
7
- export const isEntralpi = (device) => device?.filters.some((filter) => filter.name === "ENTRALPI") ?? false;
8
- /**
9
- * Checks if the given device is a Force Board.
10
- * @param {Device} [device] - The device to check.
11
- * @returns {boolean} `true` if the device has a filter with the name "Force Board", otherwise `false`.
12
- */
13
- export const isForceBoard = (device) => device?.filters.some((filter) => filter.name === "Force Board") ?? false;
14
- /**
15
- * Checks if the given device is a Kilter Board.
16
- * @param {Device} [device] - The device to check.
17
- * @returns {boolean} `true` if the device has a service UUID matching the Kilter Board Aurora UUID, otherwise `false`.
18
- */
19
- export const isKilterBoard = (device) => {
20
- return device?.filters.some((filter) => filter.services?.includes(KilterBoard.AuroraUUID)) ?? false;
21
- };
22
- /**
23
- * Checks if the given device is a Motherboard.
24
- * @param {Device} [device] - The device to check.
25
- * @returns {boolean} `true` if the device has a filter with the name "Motherdevice", otherwise `false`.
26
- */
27
- export const isMotherboard = (device) => device?.filters.some((filter) => filter.name === "Motherdevice") ?? false;
28
- /**
29
- * Checks if the given device is a Progressor.
30
- * @param {Device} [device] - The device to check.
31
- * @returns {boolean} `true` if the device has a filter with a namePrefix of "Progressor", otherwise `false`.
32
- */
33
- export const isProgressor = (device) => device?.filters.some((filter) => filter.namePrefix === "Progressor") ?? false;
34
- /**
35
- * Checks if the given device is a WH-C06.
36
- * @param {Device} [device] - The device to check.
37
- * @returns {boolean} `true` if the device has a filter with the company identifier 0x0100, otherwise `false`.
38
- */
39
- export const isWHC06 = (device) => device?.filters.some((filter) => filter.manufacturerData?.some((data) => data.companyIdentifier === 0x0100)) ?? false;
@@ -1,9 +0,0 @@
1
- export default function struct(format: string): Readonly<{
2
- unpack: (arrb: ArrayBuffer) => unknown[];
3
- pack: (...values: unknown[]) => ArrayBuffer;
4
- unpack_from: (arrb: ArrayBuffer, offs: number) => unknown[];
5
- pack_into: (arrb: ArrayBuffer, offs: number, ...values: unknown[]) => void;
6
- iter_unpack: (arrb: ArrayBuffer) => IterableIterator<unknown[]>;
7
- format: string;
8
- size: number;
9
- }>;
@@ -1,203 +0,0 @@
1
- const rechk = /^([<>])?(([1-9]\d*)?([xcbB?hHiIfdsp]))*$/;
2
- const refmt = /([1-9]\d*)?([xcbB?hHiIfdsp])/g;
3
- const str = (v, o, c) => String.fromCharCode(...Array.from(new Uint8Array(v.buffer, v.byteOffset + o, c)));
4
- const rts = (v, o, c, s) => {
5
- new Uint8Array(v.buffer, v.byteOffset + o, c).set(s.split("").map((str) => str.charCodeAt(0)));
6
- };
7
- const pst = (v, o, c) => str(v, o + 1, Math.min(v.getUint8(o), c - 1));
8
- const tsp = (v, o, c, s) => {
9
- v.setUint8(o, s.length);
10
- rts(v, o + 1, c - 1, s);
11
- };
12
- const lut = (le) => ({
13
- x: (c) => [
14
- 1,
15
- c,
16
- () => ({
17
- u: () => undefined,
18
- p: () => undefined,
19
- }),
20
- ],
21
- c: (c) => [
22
- c,
23
- 1,
24
- (o) => ({
25
- u: (v) => str(v, o, 1),
26
- p: (v, s) => {
27
- rts(v, o, 1, s);
28
- },
29
- }),
30
- ],
31
- "?": (c) => [
32
- c,
33
- 1,
34
- (o) => ({
35
- u: (v) => Boolean(v.getUint8(o)),
36
- p: (v, B) => {
37
- v.setUint8(o, B ? 1 : 0);
38
- },
39
- }),
40
- ],
41
- b: (c) => [
42
- c,
43
- 1,
44
- (o) => ({
45
- u: (v) => v.getInt8(o),
46
- p: (v, b) => {
47
- v.setInt8(o, b);
48
- },
49
- }),
50
- ],
51
- B: (c) => [
52
- c,
53
- 1,
54
- (o) => ({
55
- u: (v) => v.getUint8(o),
56
- p: (v, B) => {
57
- v.setUint8(o, B);
58
- },
59
- }),
60
- ],
61
- h: (c) => [
62
- c,
63
- 2,
64
- (o) => ({
65
- u: (v) => v.getInt16(o, le),
66
- p: (v, h) => {
67
- v.setInt16(o, h, le);
68
- },
69
- }),
70
- ],
71
- H: (c) => [
72
- c,
73
- 2,
74
- (o) => ({
75
- u: (v) => v.getUint16(o, le),
76
- p: (v, H) => {
77
- v.setUint16(o, H, le);
78
- },
79
- }),
80
- ],
81
- i: (c) => [
82
- c,
83
- 4,
84
- (o) => ({
85
- u: (v) => v.getInt32(o, le),
86
- p: (v, i) => {
87
- v.setInt32(o, i, le);
88
- },
89
- }),
90
- ],
91
- I: (c) => [
92
- c,
93
- 4,
94
- (o) => ({
95
- u: (v) => v.getUint32(o, le),
96
- p: (v, I) => {
97
- v.setUint32(o, I, le);
98
- },
99
- }),
100
- ],
101
- f: (c) => [
102
- c,
103
- 4,
104
- (o) => ({
105
- u: (v) => v.getFloat32(o, le),
106
- p: (v, f) => {
107
- v.setFloat32(o, f, le);
108
- },
109
- }),
110
- ],
111
- d: (c) => [
112
- c,
113
- 8,
114
- (o) => ({
115
- u: (v) => v.getFloat64(o, le),
116
- p: (v, d) => {
117
- v.setFloat64(o, d, le);
118
- },
119
- }),
120
- ],
121
- s: (c) => [
122
- 1,
123
- c,
124
- (o) => ({
125
- u: (v) => str(v, o, c),
126
- p: (v, s) => {
127
- rts(v, o, c, s.slice(0, c));
128
- },
129
- }),
130
- ],
131
- p: (c) => [
132
- 1,
133
- c,
134
- (o) => ({
135
- u: (v) => pst(v, o, c),
136
- p: (v, s) => {
137
- tsp(v, o, c, s.slice(0, c - 1));
138
- },
139
- }),
140
- ],
141
- });
142
- const errbuf = new RangeError("Structure larger than remaining buffer");
143
- const errval = new RangeError("Not enough values for structure");
144
- export default function struct(format) {
145
- const fns = [];
146
- let size = 0;
147
- let m = rechk.exec(format);
148
- if (!m) {
149
- throw new RangeError("Invalid format string");
150
- }
151
- const t = lut("<" === m[1]);
152
- const lu = (n, c) => t[c](n ? parseInt(n, 10) : 1);
153
- while ((m = refmt.exec(format))) {
154
- ;
155
- ((r, s, f) => {
156
- for (let i = 0; i < r; ++i, size += s) {
157
- if (f) {
158
- fns.push(f(size));
159
- }
160
- }
161
- })(...lu(...m.slice(1)));
162
- }
163
- const unpack_from = (arrb, offs) => {
164
- if (arrb.byteLength < (offs | 0) + size) {
165
- throw errbuf;
166
- }
167
- const v = new DataView(arrb, offs | 0);
168
- return fns.map((f) => f.u(v));
169
- };
170
- const pack_into = (arrb, offs, ...values) => {
171
- if (values.length < fns.length) {
172
- throw errval;
173
- }
174
- if (arrb.byteLength < offs + size) {
175
- throw errbuf;
176
- }
177
- const v = new DataView(arrb, offs);
178
- new Uint8Array(arrb, offs, size).fill(0);
179
- fns.forEach((f, i) => {
180
- f.p(v, values[i]);
181
- });
182
- };
183
- const pack = (...values) => {
184
- const b = new ArrayBuffer(size);
185
- pack_into(b, 0, ...values);
186
- return b;
187
- };
188
- const unpack = (arrb) => unpack_from(arrb, 0);
189
- function* iter_unpack(arrb) {
190
- for (let offs = 0; offs + size <= arrb.byteLength; offs += size) {
191
- yield unpack_from(arrb, offs);
192
- }
193
- }
194
- return Object.freeze({
195
- unpack,
196
- pack,
197
- unpack_from,
198
- pack_into,
199
- iter_unpack,
200
- format,
201
- size,
202
- });
203
- }
@@ -1,12 +0,0 @@
1
- /**
2
- * Initiates the tare calibration process.
3
- * @param {number} time - The duration time for tare calibration process.
4
- * @returns {void} A Promise that resolves when tare calibration is initiated.
5
- */
6
- export declare const tare: (time?: number) => void;
7
- /**
8
- * Apply tare calibration to the provided sample.
9
- * @param {number} sample - The sample to calibrate.
10
- * @returns {number} The calibrated tare value.
11
- */
12
- export declare const applyTare: (sample: number) => number;
@@ -1,70 +0,0 @@
1
- /**
2
- * Represents the current tare value for calibration.
3
- * @type {number}
4
- */
5
- let currentTare = 0;
6
- /**
7
- * Represents the state of tare calibration.
8
- * - If `false`, tare calibration is not active.
9
- * - If `true`, tare calibration process is initiated.
10
- * - If `Date` object, tare calibration process is ongoing and started at this date.
11
- * @type {boolean | Date}
12
- */
13
- let runTare = false;
14
- /**
15
- * Array holding the samples collected during tare calibration.
16
- * @type {number[]}
17
- */
18
- let tareSamples = [];
19
- /**
20
- * Array holding the sum of samples collected during tare calibration.
21
- * @type {number}
22
- */
23
- let newTares = 0;
24
- /**
25
- * Duration time for tare calibration process.
26
- * @type {number}
27
- */
28
- let timeTare = 5000;
29
- /**
30
- * Initiates the tare calibration process.
31
- * @param {number} time - The duration time for tare calibration process.
32
- * @returns {void} A Promise that resolves when tare calibration is initiated.
33
- */
34
- export const tare = (time = 5000) => {
35
- runTare = true;
36
- timeTare = time;
37
- tareSamples = [];
38
- };
39
- /**
40
- * Apply tare calibration to the provided sample.
41
- * @param {number} sample - The sample to calibrate.
42
- * @returns {number} The calibrated tare value.
43
- */
44
- export const applyTare = (sample) => {
45
- if (runTare) {
46
- // If taring process is initiated
47
- if (typeof runTare === "boolean" && runTare) {
48
- // If tare flag is true (first time), set it to the current date
49
- runTare = new Date();
50
- // Initialize the sum of new tare values
51
- newTares = 0;
52
- }
53
- // Push current sample to tareSamples array
54
- tareSamples.push(sample);
55
- // Check if taring process duration has passed (defaults to 5 seconds)
56
- if (typeof runTare !== "boolean" && new Date().getTime() - runTare.getTime() > timeTare) {
57
- // Calculate the sum of tare samples
58
- for (const tareSample of tareSamples) {
59
- newTares += tareSample;
60
- }
61
- // Calculate the average by dividing the sum by the number of samples and update the tare value with the calculated average
62
- currentTare = newTares / tareSamples.length;
63
- // Reset tare related variables
64
- runTare = false;
65
- tareSamples = [];
66
- }
67
- }
68
- // Apply tare correction to the sample and return the calibrated value
69
- return currentTare;
70
- };
@@ -1,123 +0,0 @@
1
- import type { DownloadPacket } from "../interfaces/download.interface"
2
- /**
3
- * Array of DownloadPacket entries.
4
- */
5
- export const DownloadPackets: DownloadPacket[] = [] // Initialize an empty array of DownloadPacket entries
6
-
7
- // Function to empty DownloadPackets array
8
- export const emptyDownloadPackets = (): void => {
9
- DownloadPackets.length = 0 // Set the length of the array to 0 to empty it
10
- }
11
-
12
- /**
13
- * Converts an array of DownloadPacket objects to a CSV string.
14
- * @param data - Array of DownloadPacket objects.
15
- * @returns CSV string representation of the data.
16
- */
17
- const packetsToCSV = (data: DownloadPacket[]): string => {
18
- return data
19
- .map((packet) =>
20
- [
21
- packet.received.toString(),
22
- packet.sampleNum.toString(),
23
- packet.battRaw.toString(),
24
- ...packet.samples.map(String),
25
- ...packet.masses.map(String),
26
- ]
27
- .map((v) => v.replace(/"/g, '""'))
28
- .map((v) => `"${v}"`)
29
- .join(","),
30
- )
31
- .join("\r\n")
32
- }
33
-
34
- /**
35
- * Converts an array of DownloadPacket objects to a JSON string.
36
- * @param data - Array of DownloadPacket objects.
37
- * @returns JSON string representation of the data.
38
- */
39
- const packetsToJSON = (data: DownloadPacket[]): string => {
40
- return JSON.stringify(data, null, 2) // Pretty print JSON with 2-space indentation
41
- }
42
-
43
- /**
44
- * Converts an array of DownloadPacket objects to an XML string.
45
- * @param data - Array of DownloadPacket objects.
46
- * @returns XML string representation of the data.
47
- */
48
- const packetsToXML = (data: DownloadPacket[]): string => {
49
- const xmlPackets = data
50
- .map((packet) => {
51
- const samples = packet.samples.map((sample) => `<sample>${sample}</sample>`).join("")
52
- const masses = packet.masses.map((mass) => `<mass>${mass}</mass>`).join("")
53
- return `
54
- <packet>
55
- <received>${packet.received}</received>
56
- <sampleNum>${packet.sampleNum}</sampleNum>
57
- <battRaw>${packet.battRaw}</battRaw>
58
- <samples>${samples}</samples>
59
- <masses>${masses}</masses>
60
- </packet>
61
- `
62
- })
63
- .join("")
64
-
65
- return `<DownloadPackets>${xmlPackets}</DownloadPackets>`
66
- }
67
-
68
- /**
69
- * Exports the data in the specified format (CSV, JSON, XML) with a filename format:
70
- * 'data-export-YYYY-MM-DD-HH-MM-SS.{format}'.
71
- *
72
- * @param {('csv' | 'json' | 'xml')} [format='csv'] - The format in which to download the data.
73
- * Defaults to 'csv'. Accepted values are 'csv', 'json', and 'xml'.
74
- *
75
- * @returns {void} Initiates a download of the data in the specified format.
76
- */
77
- export const download = (format: "csv" | "json" | "xml" = "csv"): void => {
78
- let content = ""
79
- let mimeType = ""
80
- let fileName = ""
81
-
82
- if (format === "csv") {
83
- content = packetsToCSV(DownloadPackets)
84
- mimeType = "text/csv"
85
- } else if (format === "json") {
86
- content = packetsToJSON(DownloadPackets)
87
- mimeType = "application/json"
88
- } else if (format === "xml") {
89
- content = packetsToXML(DownloadPackets)
90
- mimeType = "application/xml"
91
- }
92
-
93
- const now = new Date()
94
- // YYYY-MM-DD
95
- const date = now.toISOString().split("T")[0]
96
- // HH-MM-SS
97
- const time = now.toTimeString().split(" ")[0].replace(/:/g, "-")
98
-
99
- fileName = `data-export-${date}-${time}.${format}`
100
-
101
- // Create a Blob object containing the data
102
- const blob = new Blob([content], { type: mimeType })
103
-
104
- // Create a URL for the Blob
105
- const url = window.URL.createObjectURL(blob)
106
-
107
- // Create a link element
108
- const link = document.createElement("a")
109
-
110
- // Set link attributes
111
- link.href = url
112
- link.setAttribute("download", fileName)
113
-
114
- // Append link to document body
115
- document.body.appendChild(link)
116
-
117
- // Programmatically click the link to trigger the download
118
- link.click()
119
-
120
- // Clean up: remove the link and revoke the URL
121
- document.body.removeChild(link)
122
- window.URL.revokeObjectURL(url)
123
- }
@@ -1,70 +0,0 @@
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
- * Configuration for threshold and duration.
17
- */
18
- let config = { threshold: 2.5, duration: 1000 }
19
-
20
- /**
21
- * Sets the callback function to be called when the activity status changes,
22
- * and optionally sets the configuration for threshold and duration.
23
- *
24
- * This function allows you to specify a callback that will be invoked whenever
25
- * the activity status changes, indicating whether the device is currently active.
26
- * It also allows optionally configuring the threshold and duration used to determine activity.
27
- *
28
- * @param {IsActiveCallback} callback - The callback function to be set. This function
29
- * receives a boolean value indicating the new activity status.
30
- * @param {object} [options] - Optional configuration object containing the threshold and duration.
31
- * @param {number} [options.threshold=2.5] - The threshold value for determining activity.
32
- * @param {number} [options.duration=1000] - The duration (in milliseconds) to monitor the input for activity.
33
- * @returns {void}
34
- */
35
- export const active = (callback: IsActiveCallback, options?: { threshold?: number; duration?: number }): void => {
36
- activeCallback = callback
37
-
38
- // Update the config values only if provided, otherwise use defaults
39
- config = {
40
- threshold: options?.threshold ?? config.threshold, // Use new threshold if provided, else use default
41
- duration: options?.duration ?? config.duration, // Use new duration if provided, else use default
42
- }
43
- }
44
-
45
- /**
46
- * Checks if a dynamic value is active based on a threshold and duration.
47
- *
48
- * This function assesses whether a given dynamic value surpasses a specified threshold
49
- * and remains active for a specified duration. If the activity status changes from
50
- * the previous state, the callback function is called with the updated activity status.
51
- *
52
- * @param {number} input - The dynamic value to check for activity status.
53
- * @returns {Promise<void>} A promise that resolves once the activity check is complete.
54
- */
55
- export const checkActivity = (input: number): Promise<void> => {
56
- return new Promise((resolve) => {
57
- // Check the activity status after the specified duration
58
- setTimeout(() => {
59
- // Determine the activity status based on the stored threshold in the config
60
- const activeNow = input > config.threshold
61
- if (isActive !== activeNow) {
62
- isActive = activeNow
63
- if (activeCallback) {
64
- activeCallback(activeNow)
65
- }
66
- }
67
- resolve()
68
- }, config.duration)
69
- })
70
- }
@@ -1,50 +0,0 @@
1
- import { KilterBoard } from "../models"
2
- import type { Device } from "./../models/device.model"
3
-
4
- /**
5
- * Checks if the given device is an Entralpi.
6
- * @param {Device} [device] - The device to check.
7
- * @returns {boolean} `true` if the device has a filter with the name "ENTRALPI", otherwise `false`.
8
- */
9
- export const isEntralpi = (device?: Device): boolean =>
10
- device?.filters.some((filter) => filter.name === "ENTRALPI") ?? false
11
- /**
12
- * Checks if the given device is a Force Board.
13
- * @param {Device} [device] - The device to check.
14
- * @returns {boolean} `true` if the device has a filter with the name "Force Board", otherwise `false`.
15
- */
16
- export const isForceBoard = (device?: Device): boolean =>
17
- device?.filters.some((filter) => filter.name === "Force Board") ?? false
18
- /**
19
- * Checks if the given device is a Kilter Board.
20
- * @param {Device} [device] - The device to check.
21
- * @returns {boolean} `true` if the device has a service UUID matching the Kilter Board Aurora UUID, otherwise `false`.
22
- */
23
- export const isKilterBoard = (device?: Device): boolean => {
24
- return device?.filters.some((filter) => filter.services?.includes(KilterBoard.AuroraUUID)) ?? false
25
- }
26
- /**
27
- * Checks if the given device is a Motherboard.
28
- * @param {Device} [device] - The device to check.
29
- * @returns {boolean} `true` if the device has a filter with the name "Motherdevice", otherwise `false`.
30
- */
31
- export const isMotherboard = (device?: Device): boolean =>
32
- device?.filters.some((filter) => filter.name === "Motherdevice") ?? false
33
- /**
34
- * Checks if the given device is a Progressor.
35
- * @param {Device} [device] - The device to check.
36
- * @returns {boolean} `true` if the device has a filter with a namePrefix of "Progressor", otherwise `false`.
37
- */
38
- export const isProgressor = (device?: Device): boolean =>
39
- device?.filters.some((filter) => filter.namePrefix === "Progressor") ?? false
40
- /**
41
- * Checks if the given device is a WH-C06.
42
- * @param {Device} [device] - The device to check.
43
- * @returns {boolean} `true` if the device has a filter with the company identifier 0x0100, otherwise `false`.
44
- */
45
- export const isWHC06 = (device?: Device): boolean =>
46
- device?.filters.some((filter) =>
47
- filter.manufacturerData?.some(
48
- (data) => data.companyIdentifier === 0x0100, // Company identifier for WH-C06, also used by 'TomTom International BV': https://www.bluetooth.com/specifications/assigned-numbers/
49
- ),
50
- ) ?? false