@hangtime/grip-connect 0.3.1 → 0.3.2
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/package.json +1 -1
- package/src/battery.ts +1 -1
- package/src/calibration.ts +1 -1
- package/src/characteristic.ts +1 -1
- package/src/commands/climbro.ts +1 -1
- package/src/commands/entralpi.ts +1 -1
- package/src/commands/motherboard.ts +1 -1
- package/src/commands/musclemeter.ts +1 -1
- package/src/commands/mysmartboard.ts +1 -1
- package/src/commands/progressor.ts +7 -7
- package/src/connect.ts +2 -2
- package/src/data.ts +2 -1
- package/src/devices/climbro.ts +1 -1
- package/src/devices/entralpi.ts +1 -1
- package/src/devices/motherboard.ts +1 -1
- package/src/devices/musclemeter.ts +1 -1
- package/src/devices/mysmartboard.ts +1 -1
- package/src/devices/progressor.ts +1 -1
- package/src/disconnect.ts +1 -1
- package/src/download.ts +1 -11
- package/src/info.ts +1 -1
- package/src/is-connected.ts +1 -1
- package/src/notify.ts +3 -10
- package/src/read.ts +1 -1
- package/src/stop.ts +1 -1
- package/src/stream.ts +1 -1
- package/src/types/devices.ts +41 -0
- package/src/types/download.ts +15 -0
- package/src/types/notify.ts +14 -0
- package/src/write.ts +1 -1
- package/src/battery.d.ts +0 -7
- package/src/battery.js +0 -25
- package/src/calibration.d.ts +0 -7
- package/src/calibration.js +0 -19
- package/src/characteristic.d.ts +0 -10
- package/src/characteristic.js +0 -20
- package/src/commands/climbro.d.ts +0 -6
- package/src/commands/climbro.js +0 -5
- package/src/commands/entralpi.d.ts +0 -6
- package/src/commands/entralpi.js +0 -5
- package/src/commands/index.d.ts +0 -6
- package/src/commands/index.js +0 -6
- package/src/commands/motherboard.d.ts +0 -6
- package/src/commands/motherboard.js +0 -13
- package/src/commands/musclemeter.d.ts +0 -6
- package/src/commands/musclemeter.js +0 -5
- package/src/commands/mysmartboard.d.ts +0 -6
- package/src/commands/mysmartboard.js +0 -5
- package/src/commands/progressor.d.ts +0 -17
- package/src/commands/progressor.js +0 -29
- package/src/commands/types.d.ts +0 -18
- package/src/commands/types.js +0 -1
- package/src/connect.d.ts +0 -7
- package/src/connect.js +0 -152
- package/src/data.d.ts +0 -16
- package/src/data.js +0 -220
- package/src/devices/climbro.d.ts +0 -6
- package/src/devices/climbro.js +0 -8
- package/src/devices/entralpi.d.ts +0 -5
- package/src/devices/entralpi.js +0 -55
- package/src/devices/index.d.ts +0 -6
- package/src/devices/index.js +0 -6
- package/src/devices/motherboard.d.ts +0 -5
- package/src/devices/motherboard.js +0 -82
- package/src/devices/musclemeter.d.ts +0 -6
- package/src/devices/musclemeter.js +0 -8
- package/src/devices/mysmartboard.d.ts +0 -6
- package/src/devices/mysmartboard.js +0 -8
- package/src/devices/progressor.d.ts +0 -5
- package/src/devices/progressor.js +0 -37
- package/src/devices/types.d.ts +0 -29
- package/src/devices/types.js +0 -1
- package/src/devices/types.ts +0 -29
- package/src/disconnect.d.ts +0 -6
- package/src/disconnect.js +0 -12
- package/src/download.d.ts +0 -19
- package/src/download.js +0 -50
- package/src/index.d.ts +0 -12
- package/src/index.js +0 -20
- package/src/info.d.ts +0 -7
- package/src/info.js +0 -30
- package/src/is-connected.d.ts +0 -7
- package/src/is-connected.js +0 -13
- package/src/notify.d.ts +0 -22
- package/src/notify.js +0 -14
- package/src/read.d.ts +0 -10
- package/src/read.js +0 -49
- package/src/stop.d.ts +0 -7
- package/src/stop.js +0 -21
- package/src/stream.d.ts +0 -8
- package/src/stream.js +0 -41
- package/src/struct/index.d.ts +0 -9
- package/src/struct/index.js +0 -176
- package/src/tare.d.ts +0 -12
- package/src/tare.js +0 -70
- package/src/write.d.ts +0 -16
- package/src/write.js +0 -56
- /package/src/{commands/types.ts → types/commands.ts} +0 -0
package/src/tare.js
DELETED
|
@@ -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 {Promise<void>} A Promise that resolves when tare calibration is initiated.
|
|
33
|
-
*/
|
|
34
|
-
export const tare = async (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 === true) {
|
|
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 (let i = 0; i < tareSamples.length; ++i) {
|
|
59
|
-
newTares += tareSamples[i];
|
|
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
|
-
};
|
package/src/write.d.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { Device } from "./devices/types";
|
|
2
|
-
/**
|
|
3
|
-
* The last message written to the device.
|
|
4
|
-
* @type {string | null}
|
|
5
|
-
*/
|
|
6
|
-
export declare let lastWrite: string | null;
|
|
7
|
-
/**
|
|
8
|
-
* Writes a message to the specified characteristic of the device.
|
|
9
|
-
* @param {Device} board - The device board to write to.
|
|
10
|
-
* @param {string} serviceId - The service ID where the characteristic belongs.
|
|
11
|
-
* @param {string} characteristicId - The characteristic ID to write to.
|
|
12
|
-
* @param {string | undefined} message - The message to write.
|
|
13
|
-
* @param {number} [duration=0] - The duration to wait before resolving the promise, in milliseconds.
|
|
14
|
-
* @returns {Promise<void>} A promise that resolves when the write operation is completed.
|
|
15
|
-
*/
|
|
16
|
-
export declare const write: (board: Device, serviceId: string, characteristicId: string, message: string | undefined, duration?: number) => Promise<void>;
|
package/src/write.js
DELETED
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
import { isConnected } from "./is-connected";
|
|
2
|
-
import { getCharacteristic } from "./characteristic";
|
|
3
|
-
/**
|
|
4
|
-
* The last message written to the device.
|
|
5
|
-
* @type {string | null}
|
|
6
|
-
*/
|
|
7
|
-
export let lastWrite = null;
|
|
8
|
-
/**
|
|
9
|
-
* Writes a message to the specified characteristic of the device.
|
|
10
|
-
* @param {Device} board - The device board to write to.
|
|
11
|
-
* @param {string} serviceId - The service ID where the characteristic belongs.
|
|
12
|
-
* @param {string} characteristicId - The characteristic ID to write to.
|
|
13
|
-
* @param {string | undefined} message - The message to write.
|
|
14
|
-
* @param {number} [duration=0] - The duration to wait before resolving the promise, in milliseconds.
|
|
15
|
-
* @returns {Promise<void>} A promise that resolves when the write operation is completed.
|
|
16
|
-
*/
|
|
17
|
-
export const write = (board, serviceId, characteristicId, message, duration = 0) => {
|
|
18
|
-
return new Promise((resolve, reject) => {
|
|
19
|
-
if (isConnected(board)) {
|
|
20
|
-
// Check if message is provided
|
|
21
|
-
if (message === undefined) {
|
|
22
|
-
// If not provided, return without performing write operation
|
|
23
|
-
return;
|
|
24
|
-
}
|
|
25
|
-
// Get the characteristic
|
|
26
|
-
const characteristic = getCharacteristic(board, serviceId, characteristicId);
|
|
27
|
-
if (characteristic) {
|
|
28
|
-
// Encode the message
|
|
29
|
-
const encoder = new TextEncoder();
|
|
30
|
-
characteristic
|
|
31
|
-
.writeValue(encoder.encode(message))
|
|
32
|
-
.then(() => {
|
|
33
|
-
// Update the last written message
|
|
34
|
-
lastWrite = message;
|
|
35
|
-
// Handle timeout
|
|
36
|
-
if (duration !== 0) {
|
|
37
|
-
setTimeout(() => {
|
|
38
|
-
resolve();
|
|
39
|
-
}, duration);
|
|
40
|
-
}
|
|
41
|
-
})
|
|
42
|
-
.catch((error) => {
|
|
43
|
-
reject(error);
|
|
44
|
-
});
|
|
45
|
-
}
|
|
46
|
-
else {
|
|
47
|
-
// Reject if characteristic is undefined
|
|
48
|
-
reject(new Error("Characteristics is undefined"));
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
else {
|
|
52
|
-
// Reject if device is not connected
|
|
53
|
-
reject(new Error("Device is not connected"));
|
|
54
|
-
}
|
|
55
|
-
});
|
|
56
|
-
};
|
|
File without changes
|