@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.
Files changed (98) hide show
  1. package/package.json +1 -1
  2. package/src/battery.ts +1 -1
  3. package/src/calibration.ts +1 -1
  4. package/src/characteristic.ts +1 -1
  5. package/src/commands/climbro.ts +1 -1
  6. package/src/commands/entralpi.ts +1 -1
  7. package/src/commands/motherboard.ts +1 -1
  8. package/src/commands/musclemeter.ts +1 -1
  9. package/src/commands/mysmartboard.ts +1 -1
  10. package/src/commands/progressor.ts +7 -7
  11. package/src/connect.ts +2 -2
  12. package/src/data.ts +2 -1
  13. package/src/devices/climbro.ts +1 -1
  14. package/src/devices/entralpi.ts +1 -1
  15. package/src/devices/motherboard.ts +1 -1
  16. package/src/devices/musclemeter.ts +1 -1
  17. package/src/devices/mysmartboard.ts +1 -1
  18. package/src/devices/progressor.ts +1 -1
  19. package/src/disconnect.ts +1 -1
  20. package/src/download.ts +1 -11
  21. package/src/info.ts +1 -1
  22. package/src/is-connected.ts +1 -1
  23. package/src/notify.ts +3 -10
  24. package/src/read.ts +1 -1
  25. package/src/stop.ts +1 -1
  26. package/src/stream.ts +1 -1
  27. package/src/types/devices.ts +41 -0
  28. package/src/types/download.ts +15 -0
  29. package/src/types/notify.ts +14 -0
  30. package/src/write.ts +1 -1
  31. package/src/battery.d.ts +0 -7
  32. package/src/battery.js +0 -25
  33. package/src/calibration.d.ts +0 -7
  34. package/src/calibration.js +0 -19
  35. package/src/characteristic.d.ts +0 -10
  36. package/src/characteristic.js +0 -20
  37. package/src/commands/climbro.d.ts +0 -6
  38. package/src/commands/climbro.js +0 -5
  39. package/src/commands/entralpi.d.ts +0 -6
  40. package/src/commands/entralpi.js +0 -5
  41. package/src/commands/index.d.ts +0 -6
  42. package/src/commands/index.js +0 -6
  43. package/src/commands/motherboard.d.ts +0 -6
  44. package/src/commands/motherboard.js +0 -13
  45. package/src/commands/musclemeter.d.ts +0 -6
  46. package/src/commands/musclemeter.js +0 -5
  47. package/src/commands/mysmartboard.d.ts +0 -6
  48. package/src/commands/mysmartboard.js +0 -5
  49. package/src/commands/progressor.d.ts +0 -17
  50. package/src/commands/progressor.js +0 -29
  51. package/src/commands/types.d.ts +0 -18
  52. package/src/commands/types.js +0 -1
  53. package/src/connect.d.ts +0 -7
  54. package/src/connect.js +0 -152
  55. package/src/data.d.ts +0 -16
  56. package/src/data.js +0 -220
  57. package/src/devices/climbro.d.ts +0 -6
  58. package/src/devices/climbro.js +0 -8
  59. package/src/devices/entralpi.d.ts +0 -5
  60. package/src/devices/entralpi.js +0 -55
  61. package/src/devices/index.d.ts +0 -6
  62. package/src/devices/index.js +0 -6
  63. package/src/devices/motherboard.d.ts +0 -5
  64. package/src/devices/motherboard.js +0 -82
  65. package/src/devices/musclemeter.d.ts +0 -6
  66. package/src/devices/musclemeter.js +0 -8
  67. package/src/devices/mysmartboard.d.ts +0 -6
  68. package/src/devices/mysmartboard.js +0 -8
  69. package/src/devices/progressor.d.ts +0 -5
  70. package/src/devices/progressor.js +0 -37
  71. package/src/devices/types.d.ts +0 -29
  72. package/src/devices/types.js +0 -1
  73. package/src/devices/types.ts +0 -29
  74. package/src/disconnect.d.ts +0 -6
  75. package/src/disconnect.js +0 -12
  76. package/src/download.d.ts +0 -19
  77. package/src/download.js +0 -50
  78. package/src/index.d.ts +0 -12
  79. package/src/index.js +0 -20
  80. package/src/info.d.ts +0 -7
  81. package/src/info.js +0 -30
  82. package/src/is-connected.d.ts +0 -7
  83. package/src/is-connected.js +0 -13
  84. package/src/notify.d.ts +0 -22
  85. package/src/notify.js +0 -14
  86. package/src/read.d.ts +0 -10
  87. package/src/read.js +0 -49
  88. package/src/stop.d.ts +0 -7
  89. package/src/stop.js +0 -21
  90. package/src/stream.d.ts +0 -8
  91. package/src/stream.js +0 -41
  92. package/src/struct/index.d.ts +0 -9
  93. package/src/struct/index.js +0 -176
  94. package/src/tare.d.ts +0 -12
  95. package/src/tare.js +0 -70
  96. package/src/write.d.ts +0 -16
  97. package/src/write.js +0 -56
  98. /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