@hangtime/grip-connect 0.2.1 → 0.2.3

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 (61) hide show
  1. package/README.md +42 -35
  2. package/package.json +5 -3
  3. package/src/battery.d.ts +6 -0
  4. package/src/battery.js +19 -0
  5. package/src/calibration.d.ts +6 -0
  6. package/src/calibration.js +15 -0
  7. package/src/characteristic.d.ts +9 -0
  8. package/src/characteristic.js +15 -0
  9. package/src/commands/climbro.d.ts +6 -0
  10. package/src/commands/climbro.js +5 -0
  11. package/src/commands/entralpi.d.ts +6 -0
  12. package/src/commands/entralpi.js +5 -0
  13. package/src/commands/index.d.ts +5 -0
  14. package/src/commands/index.js +5 -0
  15. package/src/commands/motherboard.d.ts +6 -0
  16. package/src/commands/motherboard.js +13 -0
  17. package/src/commands/progressor.d.ts +15 -0
  18. package/src/commands/progressor.js +27 -0
  19. package/src/commands/smartboard.d.ts +6 -0
  20. package/src/commands/smartboard.js +5 -0
  21. package/src/commands/types.d.ts +18 -0
  22. package/src/commands/types.js +1 -0
  23. package/src/connect.d.ts +7 -0
  24. package/src/connect.js +159 -0
  25. package/src/connect.ts +3 -58
  26. package/src/data.d.ts +9 -0
  27. package/src/data.js +157 -0
  28. package/src/data.ts +45 -0
  29. package/src/declarations.d.ts +1 -0
  30. package/src/devices/climbro.d.ts +2 -0
  31. package/src/devices/climbro.js +4 -0
  32. package/src/devices/entralpi.d.ts +2 -0
  33. package/src/devices/entralpi.js +52 -0
  34. package/src/devices/index.d.ts +5 -0
  35. package/src/devices/index.js +5 -0
  36. package/src/devices/motherboard.d.ts +2 -0
  37. package/src/devices/motherboard.js +79 -0
  38. package/src/devices/progressor.d.ts +2 -0
  39. package/src/devices/progressor.js +34 -0
  40. package/src/devices/smartboard.d.ts +2 -0
  41. package/src/devices/smartboard.js +4 -0
  42. package/src/devices/types.d.ts +20 -0
  43. package/src/devices/types.js +1 -0
  44. package/src/disconnect.d.ts +6 -0
  45. package/src/disconnect.js +10 -0
  46. package/src/index.d.ts +10 -0
  47. package/src/index.js +12 -0
  48. package/src/info.d.ts +6 -0
  49. package/src/info.js +23 -0
  50. package/src/is-connected.d.ts +7 -0
  51. package/src/is-connected.js +10 -0
  52. package/src/notify.d.ts +4 -0
  53. package/src/notify.js +6 -0
  54. package/src/read.d.ts +6 -0
  55. package/src/read.js +45 -0
  56. package/src/stop.d.ts +6 -0
  57. package/src/stop.js +18 -0
  58. package/src/stream.d.ts +6 -0
  59. package/src/stream.js +35 -0
  60. package/src/write.d.ts +8 -0
  61. package/src/write.js +41 -0
package/src/stream.js ADDED
@@ -0,0 +1,35 @@
1
+ import { isConnected } from "./is-connected";
2
+ import { write } from "./write";
3
+ import { stop } from "./stop";
4
+ import { Motherboard, Progressor } from "./devices";
5
+ import { MotherboardCommands, ProgressorCommands } from "./commands";
6
+ import { CALIBRATION } from "./data";
7
+ import { calibration } from "./calibration";
8
+ /**
9
+ * stream output
10
+ * @param board
11
+ */
12
+ export const stream = async (board, duration = 0) => {
13
+ if (isConnected(board)) {
14
+ if (board.name === "Motherboard") {
15
+ // read calibration (required before reading data)
16
+ if (!CALIBRATION[0].length) {
17
+ await calibration(Motherboard);
18
+ }
19
+ // start stream
20
+ await write(Motherboard, "uart", "tx", MotherboardCommands.START_WEIGHT_MEAS, duration);
21
+ // end stream if duration is set
22
+ if (duration !== 0) {
23
+ await stop(Motherboard);
24
+ }
25
+ }
26
+ if (board.name && board.name.startsWith("Progressor")) {
27
+ // start stream
28
+ await write(Progressor, "progressor", "tx", ProgressorCommands.START_WEIGHT_MEAS, duration);
29
+ // end stream if duration is set
30
+ if (duration !== 0) {
31
+ await stop(Progressor);
32
+ }
33
+ }
34
+ }
35
+ };
package/src/write.d.ts ADDED
@@ -0,0 +1,8 @@
1
+ import { Device } from "./devices/types";
2
+ export declare let lastWrite: string | null;
3
+ /**
4
+ * write
5
+ * @param characteristic
6
+ * @param message
7
+ */
8
+ export declare const write: (board: Device, serviceId: string, characteristicId: string, message: string | undefined, duration?: number) => Promise<void>;
package/src/write.js ADDED
@@ -0,0 +1,41 @@
1
+ import { isConnected } from "./is-connected";
2
+ import { getCharacteristic } from "./characteristic";
3
+ export let lastWrite = null;
4
+ /**
5
+ * write
6
+ * @param characteristic
7
+ * @param message
8
+ */
9
+ export const write = (board, serviceId, characteristicId, message, duration = 0) => {
10
+ return new Promise((resolve, reject) => {
11
+ if (isConnected(board)) {
12
+ if (!message)
13
+ return;
14
+ const characteristic = getCharacteristic(board, serviceId, characteristicId);
15
+ if (characteristic) {
16
+ const encoder = new TextEncoder();
17
+ characteristic
18
+ .writeValue(encoder.encode(message))
19
+ .then(() => {
20
+ // update last written message
21
+ lastWrite = message;
22
+ // handle timeout
23
+ if (duration !== 0) {
24
+ setTimeout(() => {
25
+ resolve();
26
+ }, duration);
27
+ }
28
+ })
29
+ .catch((error) => {
30
+ reject(error);
31
+ });
32
+ }
33
+ else {
34
+ reject(new Error("Characteristics is undefined"));
35
+ }
36
+ }
37
+ else {
38
+ reject(new Error("Device is not connected"));
39
+ }
40
+ });
41
+ };