@hangtime/grip-connect 0.0.11 → 0.1.1

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 (52) hide show
  1. package/README.md +10 -9
  2. package/package.json +1 -1
  3. package/src/calibration.d.ts +6 -0
  4. package/src/calibration.js +16 -0
  5. package/src/calibration.ts +17 -0
  6. package/src/commands/climbro.d.ts +6 -0
  7. package/src/commands/climbro.js +5 -0
  8. package/src/commands/climbro.ts +6 -0
  9. package/src/commands/entralpi.d.ts +6 -0
  10. package/src/commands/entralpi.js +5 -0
  11. package/src/commands/entralpi.ts +6 -0
  12. package/src/commands/index.d.ts +5 -0
  13. package/src/commands/index.js +5 -0
  14. package/src/commands/index.ts +9 -0
  15. package/src/commands/motherboard.d.ts +6 -0
  16. package/src/commands/motherboard.js +13 -0
  17. package/src/commands/motherboard.ts +14 -0
  18. package/src/commands/smartboard.d.ts +6 -0
  19. package/src/commands/smartboard.js +5 -0
  20. package/src/commands/smartboard.ts +6 -0
  21. package/src/commands/tindeq.d.ts +11 -0
  22. package/src/commands/tindeq.js +23 -0
  23. package/src/commands/tindeq.ts +25 -0
  24. package/src/commands/types.d.ts +18 -0
  25. package/src/commands/types.js +1 -0
  26. package/src/commands/types.ts +21 -0
  27. package/src/connect.js +7 -3
  28. package/src/connect.ts +14 -10
  29. package/src/devices/climbro.d.ts +2 -0
  30. package/src/devices/climbro.js +4 -0
  31. package/src/devices/climbro.ts +6 -0
  32. package/src/devices/index.d.ts +3 -1
  33. package/src/devices/index.js +3 -1
  34. package/src/devices/index.ts +5 -1
  35. package/src/devices/{moterboard.ts → motherboard.ts} +2 -2
  36. package/src/devices/smartboard.d.ts +2 -0
  37. package/src/devices/smartboard.js +4 -0
  38. package/src/devices/smartboard.ts +6 -0
  39. package/src/devices/tindeq.d.ts +0 -15
  40. package/src/devices/tindeq.js +0 -15
  41. package/src/devices/tindeq.ts +0 -17
  42. package/src/index.d.ts +4 -2
  43. package/src/index.js +4 -2
  44. package/src/index.ts +6 -2
  45. package/src/stop.d.ts +6 -0
  46. package/src/stop.js +19 -0
  47. package/src/stop.ts +20 -0
  48. package/src/stream.d.ts +6 -0
  49. package/src/stream.js +31 -0
  50. package/src/stream.ts +32 -0
  51. /package/src/devices/{moterboard.d.ts → motherboard.d.ts} +0 -0
  52. /package/src/devices/{moterboard.js → motherboard.js} +0 -0
package/README.md CHANGED
@@ -63,7 +63,7 @@ Simply importing the utilities you need from `@hangtime/grip-connect`. Devices t
63
63
  ```
64
64
 
65
65
  ```js
66
- import { Motherboard, connect, disconnect, read, write, notify } from "@hangtime/grip-connect"
66
+ import { Motherboard, calibration, connect, disconnect, notify, read, stream } from "@hangtime/grip-connect"
67
67
 
68
68
  const motherboardButton = document.querySelector("#motherboard")
69
69
 
@@ -74,21 +74,22 @@ motherboardButton.addEventListener("click", () => {
74
74
  console.log(data)
75
75
  })
76
76
 
77
- // read battery + device info
77
+ // Read battery + device info
78
78
  await read(Motherboard, "battery", "level", 250)
79
79
  await read(Motherboard, "device", "manufacturer", 250)
80
80
  await read(Motherboard, "device", "hardware", 250)
81
81
  await read(Motherboard, "device", "firmware", 250)
82
82
 
83
- // read calibration (required before reading data)
84
- await write(Motherboard, "uart", "tx", "C", 2500)
83
+ // Read calibration (required before reading data)
84
+ await calibration(Motherboard)
85
85
 
86
- // start streaming for a minute
87
- await write(Motherboard, "uart", "tx", "S30", 60000)
86
+ // Start streaming (for a minute) remove parameter for a continues stream
87
+ await stream(Motherboard, 60000)
88
88
 
89
- // end stream
90
- await write(Motherboard, "uart", "tx", "", 0)
91
- // disconnect from device after we are done
89
+ // Manually call stop method if stream is continues
90
+ // await stop(Motherboard)
91
+
92
+ // Disconnect from device after we are done
92
93
  disconnect(Motherboard)
93
94
  })
94
95
  })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hangtime/grip-connect",
3
- "version": "0.0.11",
3
+ "version": "0.1.1",
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 Motherboard, Climbro, SmartBoard, Entralpi or Tindeq Progressor",
5
5
  "main": "src/index.ts",
6
6
  "scripts": {
@@ -0,0 +1,6 @@
1
+ import { Device } from "./devices/types";
2
+ /**
3
+ * write command to get calibration
4
+ * @param board
5
+ */
6
+ export declare const calibration: (board: Device) => Promise<void>;
@@ -0,0 +1,16 @@
1
+ import { Motherboard } from "./devices";
2
+ import { MotherboardCommands } from "./commands";
3
+ import { write } from "./write";
4
+ /**
5
+ * write command to get calibration
6
+ * @param board
7
+ */
8
+ export const calibration = async (board) => {
9
+ if (!board.device)
10
+ return;
11
+ if (board.device.gatt?.connected) {
12
+ if (board.name === "Motherboard") {
13
+ await write(Motherboard, "uart", "tx", String(MotherboardCommands.GET_CALIBRATION), 2500);
14
+ }
15
+ }
16
+ };
@@ -0,0 +1,17 @@
1
+ import { Device } from "./devices/types"
2
+ import { Motherboard } from "./devices"
3
+ import { MotherboardCommands } from "./commands"
4
+ import { write } from "./write"
5
+
6
+ /**
7
+ * write command to get calibration
8
+ * @param board
9
+ */
10
+ export const calibration = async (board: Device): Promise<void> => {
11
+ if (!board.device) return
12
+ if (board.device.gatt?.connected) {
13
+ if (board.name === "Motherboard") {
14
+ await write(Motherboard, "uart", "tx", String(MotherboardCommands.GET_CALIBRATION), 2500)
15
+ }
16
+ }
17
+ }
@@ -0,0 +1,6 @@
1
+ import { Commands } from "../commands/types";
2
+ /**
3
+ * Warning:
4
+ * Using other commands can seriously harm your device
5
+ */
6
+ export declare const ClimbroCommands: Commands;
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Warning:
3
+ * Using other commands can seriously harm your device
4
+ */
5
+ export const ClimbroCommands = {};
@@ -0,0 +1,6 @@
1
+ import { Commands } from "../commands/types"
2
+ /**
3
+ * Warning:
4
+ * Using other commands can seriously harm your device
5
+ */
6
+ export const ClimbroCommands: Commands = {}
@@ -0,0 +1,6 @@
1
+ import { Commands } from "../commands/types";
2
+ /**
3
+ * Warning:
4
+ * Using other commands can seriously harm your device
5
+ */
6
+ export declare const EntralpiCommands: Commands;
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Warning:
3
+ * Using other commands can seriously harm your device
4
+ */
5
+ export const EntralpiCommands = {};
@@ -0,0 +1,6 @@
1
+ import { Commands } from "../commands/types"
2
+ /**
3
+ * Warning:
4
+ * Using other commands can seriously harm your device
5
+ */
6
+ export const EntralpiCommands: Commands = {}
@@ -0,0 +1,5 @@
1
+ export { ClimbroCommands } from "./climbro";
2
+ export { EntralpiCommands } from "./entralpi";
3
+ export { MotherboardCommands } from "./motherboard";
4
+ export { SmartBoardCommands } from "./smartboard";
5
+ export { TindeqCommands } from "./tindeq";
@@ -0,0 +1,5 @@
1
+ export { ClimbroCommands } from "./climbro";
2
+ export { EntralpiCommands } from "./entralpi";
3
+ export { MotherboardCommands } from "./motherboard";
4
+ export { SmartBoardCommands } from "./smartboard";
5
+ export { TindeqCommands } from "./tindeq";
@@ -0,0 +1,9 @@
1
+ export { ClimbroCommands } from "./climbro"
2
+
3
+ export { EntralpiCommands } from "./entralpi"
4
+
5
+ export { MotherboardCommands } from "./motherboard"
6
+
7
+ export { SmartBoardCommands } from "./smartboard"
8
+
9
+ export { TindeqCommands } from "./tindeq"
@@ -0,0 +1,6 @@
1
+ import { Commands } from "../commands/types";
2
+ /**
3
+ * Warning:
4
+ * Using other commands can seriously harm your device
5
+ */
6
+ export declare const MotherboardCommands: Commands;
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Warning:
3
+ * Using other commands can seriously harm your device
4
+ */
5
+ export const MotherboardCommands = {
6
+ GET_SERIAL: "#",
7
+ START_WEIGHT_MEAS: "S30",
8
+ STOP_WEIGHT_MEAS: "", // All commands will stop the data stream.
9
+ GET_CALIBRATION: "C",
10
+ SLEEP: 0,
11
+ GET_TEXT: "T",
12
+ DEBUG_STREAM: "D",
13
+ };
@@ -0,0 +1,14 @@
1
+ import { Commands } from "../commands/types"
2
+ /**
3
+ * Warning:
4
+ * Using other commands can seriously harm your device
5
+ */
6
+ export const MotherboardCommands: Commands = {
7
+ GET_SERIAL: "#",
8
+ START_WEIGHT_MEAS: "S30",
9
+ STOP_WEIGHT_MEAS: "", // All commands will stop the data stream.
10
+ GET_CALIBRATION: "C",
11
+ SLEEP: 0,
12
+ GET_TEXT: "T",
13
+ DEBUG_STREAM: "D",
14
+ }
@@ -0,0 +1,6 @@
1
+ import { Commands } from "../commands/types";
2
+ /**
3
+ * Warning:
4
+ * Using other commands can seriously harm your device
5
+ */
6
+ export declare const SmartBoardCommands: Commands;
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Warning:
3
+ * Using other commands can seriously harm your device
4
+ */
5
+ export const SmartBoardCommands = {};
@@ -0,0 +1,6 @@
1
+ import { Commands } from "../commands/types"
2
+ /**
3
+ * Warning:
4
+ * Using other commands can seriously harm your device
5
+ */
6
+ export const SmartBoardCommands: Commands = {}
@@ -0,0 +1,11 @@
1
+ import { Commands } from "../commands/types";
2
+ /**
3
+ * Warning:
4
+ * Using other commands can seriously harm your device
5
+ */
6
+ export declare const TindeqCommands: Commands;
7
+ export declare const NotificationTypes: {
8
+ COMMAND_RESPONSE: number;
9
+ WEIGHT_MEASURE: number;
10
+ LOW_BATTERY_WARNING: number;
11
+ };
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Warning:
3
+ * Using other commands can seriously harm your device
4
+ */
5
+ export const TindeqCommands = {
6
+ TARE_SCALE: 'd', // 0x64,
7
+ START_WEIGHT_MEAS: 'e', // 0x65,
8
+ STOP_WEIGHT_MEAS: 'f', // 0x66,
9
+ START_PEAK_RFD_MEAS: 'g', // 0x67,
10
+ START_PEAK_RFD_MEAS_SERIES: 'h', // 0x68,
11
+ ADD_CALIB_POINT: 'i', // 0x69,
12
+ SAVE_CALIB: 'j', // 0x6a,
13
+ GET_APP_VERSION: 'k', // 0x6b,
14
+ GET_ERR_INFO: 'l', // 0x6c,
15
+ CLR_ERR_INFO: 'm', // 0x6d,
16
+ SLEEP: 'n', // 0x6e,
17
+ GET_BATT_VLTG: 'o' // 0x6f,
18
+ };
19
+ export const NotificationTypes = {
20
+ COMMAND_RESPONSE: 0,
21
+ WEIGHT_MEASURE: 1,
22
+ LOW_BATTERY_WARNING: 2,
23
+ };
@@ -0,0 +1,25 @@
1
+ import { Commands } from "../commands/types"
2
+ /**
3
+ * Warning:
4
+ * Using other commands can seriously harm your device
5
+ */
6
+ export const TindeqCommands: Commands = {
7
+ TARE_SCALE: "d", // 0x64,
8
+ START_WEIGHT_MEAS: "e", // 0x65,
9
+ STOP_WEIGHT_MEAS: "f", // 0x66,
10
+ START_PEAK_RFD_MEAS: "g", // 0x67,
11
+ START_PEAK_RFD_MEAS_SERIES: "h", // 0x68,
12
+ ADD_CALIB_POINT: "i", // 0x69,
13
+ SAVE_CALIB: "j", // 0x6a,
14
+ GET_APP_VERSION: "k", // 0x6b,
15
+ GET_ERR_INFO: "l", // 0x6c,
16
+ CLR_ERR_INFO: "m", // 0x6d,
17
+ SLEEP: "n", // 0x6e,
18
+ GET_BATT_VLTG: "o", // 0x6f,
19
+ }
20
+
21
+ export const NotificationTypes = {
22
+ COMMAND_RESPONSE: 0,
23
+ WEIGHT_MEASURE: 1,
24
+ LOW_BATTERY_WARNING: 2,
25
+ }
@@ -0,0 +1,18 @@
1
+ export interface Commands {
2
+ START_WEIGHT_MEAS?: string;
3
+ STOP_WEIGHT_MEAS?: string;
4
+ SLEEP?: number | string;
5
+ GET_TEXT?: string;
6
+ GET_SERIAL?: string;
7
+ DEBUG_STREAM?: string;
8
+ GET_CALIBRATION?: string;
9
+ TARE_SCALE?: string;
10
+ START_PEAK_RFD_MEAS?: string;
11
+ START_PEAK_RFD_MEAS_SERIES?: string;
12
+ ADD_CALIB_POINT?: string;
13
+ SAVE_CALIB?: string;
14
+ GET_APP_VERSION?: string;
15
+ GET_ERR_INFO?: string;
16
+ CLR_ERR_INFO?: string;
17
+ GET_BATT_VLTG?: string;
18
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,21 @@
1
+ export interface Commands {
2
+ // Motherboard, Tindeq
3
+ START_WEIGHT_MEAS?: string
4
+ STOP_WEIGHT_MEAS?: string
5
+ SLEEP?: number | string
6
+ // Motherboard
7
+ GET_TEXT?: string
8
+ GET_SERIAL?: string
9
+ DEBUG_STREAM?: string
10
+ GET_CALIBRATION?: string
11
+ // Tindeq
12
+ TARE_SCALE?: string
13
+ START_PEAK_RFD_MEAS?: string
14
+ START_PEAK_RFD_MEAS_SERIES?: string
15
+ ADD_CALIB_POINT?: string
16
+ SAVE_CALIB?: string
17
+ GET_APP_VERSION?: string
18
+ GET_ERR_INFO?: string
19
+ CLR_ERR_INFO?: string
20
+ GET_BATT_VLTG?: string
21
+ }
package/src/connect.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { notifyCallback } from "./notify";
2
- import { handleMotherboardData } from "./devices/moterboard";
2
+ import { handleMotherboardData } from "./devices/motherboard";
3
3
  import { handleEntralpiData } from "./devices/entralpi";
4
4
  let server;
5
5
  const receiveBuffer = [];
@@ -37,8 +37,12 @@ const handleNotifications = (event, board) => {
37
37
  }
38
38
  }
39
39
  else if (board.name === "ENTRALPI") {
40
- const receivedData = value.getInt16(0) / 100;
41
- handleEntralpiData(characteristic.uuid, receivedData);
40
+ if (value.buffer) {
41
+ const buffer = value.buffer;
42
+ const rawData = new DataView(buffer);
43
+ const receivedData = rawData.getUint16(0) / 100;
44
+ handleEntralpiData(characteristic.uuid, receivedData);
45
+ }
42
46
  }
43
47
  else if (board.name === "Tindeq") {
44
48
  // TODO: handle Tindeq notify
package/src/connect.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { Device } from "./devices/types"
2
2
  import { notifyCallback } from "./notify"
3
- import { handleMotherboardData } from "./devices/moterboard"
3
+ import { handleMotherboardData } from "./devices/motherboard"
4
4
  import { handleEntralpiData } from "./devices/entralpi"
5
5
 
6
6
  let server: BluetoothRemoteGATTServer
@@ -22,25 +22,29 @@ const onDisconnected = (event: Event, board: Device): void => {
22
22
  * @param onNotify
23
23
  */
24
24
  const handleNotifications = (event: Event, board: Device): void => {
25
- const characteristic = event.target as BluetoothRemoteGATTCharacteristic
26
- const value = characteristic.value
25
+ const characteristic: BluetoothRemoteGATTCharacteristic = event.target as BluetoothRemoteGATTCharacteristic
26
+ const value: DataView | undefined = characteristic.value
27
27
  if (value) {
28
28
  if (board.name === "Motherboard") {
29
- for (let i = 0; i < value.byteLength; i++) {
29
+ for (let i: number = 0; i < value.byteLength; i++) {
30
30
  receiveBuffer.push(value.getUint8(i))
31
31
  }
32
32
 
33
33
  let idx: number
34
34
  while ((idx = receiveBuffer.indexOf(10)) >= 0) {
35
- const line = receiveBuffer.splice(0, idx + 1).slice(0, -1) // Combine and remove LF
35
+ const line: number[] = receiveBuffer.splice(0, idx + 1).slice(0, -1) // Combine and remove LF
36
36
  if (line.length > 0 && line[line.length - 1] === 13) line.pop() // Remove CR
37
- const decoder = new TextDecoder("utf-8")
38
- const receivedData = decoder.decode(new Uint8Array(line))
37
+ const decoder: TextDecoder = new TextDecoder("utf-8")
38
+ const receivedData: string = decoder.decode(new Uint8Array(line))
39
39
  handleMotherboardData(characteristic.uuid, receivedData)
40
40
  }
41
41
  } else if (board.name === "ENTRALPI") {
42
- const receivedData: number = value.getInt16(0) / 100
43
- handleEntralpiData(characteristic.uuid, receivedData)
42
+ if (value.buffer) {
43
+ const buffer: ArrayBuffer = value.buffer
44
+ const rawData: DataView = new DataView(buffer)
45
+ const receivedData: number = rawData.getUint16(0) / 100
46
+ handleEntralpiData(characteristic.uuid, receivedData)
47
+ }
44
48
  } else if (board.name === "Tindeq") {
45
49
  // TODO: handle Tindeq notify
46
50
  } else {
@@ -57,7 +61,7 @@ const handleNotifications = (event: Event, board: Device): void => {
57
61
  */
58
62
  const onConnected = async (board: Device, onSuccess: () => void): Promise<void> => {
59
63
  try {
60
- const services = await server?.getPrimaryServices()
64
+ const services: BluetoothRemoteGATTService[] = await server?.getPrimaryServices()
61
65
 
62
66
  if (!services || services.length === 0) {
63
67
  console.error("No services found")
@@ -0,0 +1,2 @@
1
+ import { Device } from "./types";
2
+ export declare const Climbro: Device;
@@ -0,0 +1,4 @@
1
+ export const Climbro = {
2
+ name: "Climbro",
3
+ services: [],
4
+ };
@@ -0,0 +1,6 @@
1
+ import { Device } from "./types"
2
+
3
+ export const Climbro: Device = {
4
+ name: "Climbro",
5
+ services: [],
6
+ }
@@ -1,3 +1,5 @@
1
- export { Motherboard } from "./moterboard";
1
+ export { Climbro } from "./climbro";
2
2
  export { Entralpi } from "./entralpi";
3
+ export { Motherboard } from "./motherboard";
4
+ export { SmartBoard } from "./smartboard";
3
5
  export { Tindeq } from "./tindeq";
@@ -1,3 +1,5 @@
1
- export { Motherboard } from "./moterboard";
1
+ export { Climbro } from "./climbro";
2
2
  export { Entralpi } from "./entralpi";
3
+ export { Motherboard } from "./motherboard";
4
+ export { SmartBoard } from "./smartboard";
3
5
  export { Tindeq } from "./tindeq";
@@ -1,5 +1,9 @@
1
- export { Motherboard } from "./moterboard"
1
+ export { Climbro } from "./climbro"
2
2
 
3
3
  export { Entralpi } from "./entralpi"
4
4
 
5
+ export { Motherboard } from "./motherboard"
6
+
7
+ export { SmartBoard } from "./smartboard"
8
+
5
9
  export { Tindeq } from "./tindeq"
@@ -185,8 +185,8 @@ export function handleMotherboardData(uuid: string, receivedData: string): void
185
185
  packet.masses[i] = applyCalibration(packet.samples[i], CALIBRATION[i])
186
186
  }
187
187
  // invert center and right values
188
- packet.masses[1] *= -1;
189
- packet.masses[2] *= -1;
188
+ packet.masses[1] *= -1
189
+ packet.masses[2] *= -1
190
190
  // map to variables
191
191
  const left: number = packet.masses[0]
192
192
  const center: number = packet.masses[1]
@@ -0,0 +1,2 @@
1
+ import { Device } from "./types";
2
+ export declare const SmartBoard: Device;
@@ -0,0 +1,4 @@
1
+ export const SmartBoard = {
2
+ name: "SmartBoard",
3
+ services: [],
4
+ };
@@ -0,0 +1,6 @@
1
+ import { Device } from "./types"
2
+
3
+ export const SmartBoard: Device = {
4
+ name: "SmartBoard",
5
+ services: [],
6
+ }
@@ -1,17 +1,2 @@
1
1
  import { Device } from "./types";
2
2
  export declare const Tindeq: Device;
3
- export declare const Commands: {
4
- TARE_SCALE: number;
5
- START_MEASURING: number;
6
- STOP_MEASURING: number;
7
- GET_APP_VERSION: number;
8
- GET_ERROR_INFO: number;
9
- CLEAR_ERR_INFO: number;
10
- GET_BATTERY_LEVEL: number;
11
- SLEEP: number;
12
- };
13
- export declare const NotificationTypes: {
14
- COMMAND_RESPONSE: number;
15
- WEIGHT_MEASURE: number;
16
- LOW_BATTERY_WARNING: number;
17
- };
@@ -20,18 +20,3 @@ export const Tindeq = {
20
20
  },
21
21
  ],
22
22
  };
23
- export const Commands = {
24
- TARE_SCALE: 0x64,
25
- START_MEASURING: 0x65,
26
- STOP_MEASURING: 0x66,
27
- GET_APP_VERSION: 0x6b,
28
- GET_ERROR_INFO: 0x6c,
29
- CLEAR_ERR_INFO: 0x6d,
30
- GET_BATTERY_LEVEL: 0x6f,
31
- SLEEP: 0x6e,
32
- };
33
- export const NotificationTypes = {
34
- COMMAND_RESPONSE: 0,
35
- WEIGHT_MEASURE: 1,
36
- LOW_BATTERY_WARNING: 2,
37
- };
@@ -22,20 +22,3 @@ export const Tindeq: Device = {
22
22
  },
23
23
  ],
24
24
  }
25
-
26
- export const Commands = {
27
- TARE_SCALE: 0x64,
28
- START_MEASURING: 0x65,
29
- STOP_MEASURING: 0x66,
30
- GET_APP_VERSION: 0x6b,
31
- GET_ERROR_INFO: 0x6c,
32
- CLEAR_ERR_INFO: 0x6d,
33
- GET_BATTERY_LEVEL: 0x6f,
34
- SLEEP: 0x6e,
35
- }
36
-
37
- export const NotificationTypes = {
38
- COMMAND_RESPONSE: 0,
39
- WEIGHT_MEASURE: 1,
40
- LOW_BATTERY_WARNING: 2,
41
- }
package/src/index.d.ts CHANGED
@@ -1,6 +1,8 @@
1
- export { Motherboard, Entralpi, Tindeq } from "./devices/index";
1
+ export { Climbro, Entralpi, Motherboard, SmartBoard, Tindeq } from "./devices/index";
2
+ export { calibration } from "./calibration";
2
3
  export { connect } from "./connect";
3
4
  export { disconnect } from "./disconnect";
4
5
  export { notify } from "./notify";
5
6
  export { read } from "./read";
6
- export { write } from "./write";
7
+ export { stop } from "./stop";
8
+ export { stream } from "./stream";
package/src/index.js CHANGED
@@ -1,6 +1,8 @@
1
- export { Motherboard, Entralpi, Tindeq } from "./devices/index";
1
+ export { Climbro, Entralpi, Motherboard, SmartBoard, Tindeq } from "./devices/index";
2
+ export { calibration } from "./calibration";
2
3
  export { connect } from "./connect";
3
4
  export { disconnect } from "./disconnect";
4
5
  export { notify } from "./notify";
5
6
  export { read } from "./read";
6
- export { write } from "./write";
7
+ export { stop } from "./stop";
8
+ export { stream } from "./stream";
package/src/index.ts CHANGED
@@ -1,4 +1,6 @@
1
- export { Motherboard, Entralpi, Tindeq } from "./devices/index"
1
+ export { Climbro, Entralpi, Motherboard, SmartBoard, Tindeq } from "./devices/index"
2
+
3
+ export { calibration } from "./calibration"
2
4
 
3
5
  export { connect } from "./connect"
4
6
 
@@ -8,4 +10,6 @@ export { notify } from "./notify"
8
10
 
9
11
  export { read } from "./read"
10
12
 
11
- export { write } from "./write"
13
+ export { stop } from "./stop"
14
+
15
+ export { stream } from "./stream"
package/src/stop.d.ts ADDED
@@ -0,0 +1,6 @@
1
+ import { Device } from "./devices/types";
2
+ /**
3
+ * read calibration
4
+ * @param board
5
+ */
6
+ export declare const stop: (board: Device) => Promise<void>;
package/src/stop.js ADDED
@@ -0,0 +1,19 @@
1
+ import { Motherboard, Tindeq } from "./devices";
2
+ import { MotherboardCommands, TindeqCommands } from "./commands";
3
+ import { write } from "./write";
4
+ /**
5
+ * read calibration
6
+ * @param board
7
+ */
8
+ export const stop = async (board) => {
9
+ if (!board.device)
10
+ return;
11
+ if (board.device.gatt?.connected) {
12
+ if (board.name === "Motherboard") {
13
+ await write(Motherboard, "uart", "tx", String(MotherboardCommands.STOP_WEIGHT_MEAS), 0);
14
+ }
15
+ if (board.name === "Tindeq") {
16
+ await write(Tindeq, "progressor", "tx", String(TindeqCommands.STOP_WEIGHT_MEAS), 0);
17
+ }
18
+ }
19
+ };
package/src/stop.ts ADDED
@@ -0,0 +1,20 @@
1
+ import { Device } from "./devices/types"
2
+ import { Motherboard, Tindeq } from "./devices"
3
+ import { MotherboardCommands, TindeqCommands } from "./commands"
4
+ import { write } from "./write"
5
+
6
+ /**
7
+ * read calibration
8
+ * @param board
9
+ */
10
+ export const stop = async (board: Device): Promise<void> => {
11
+ if (!board.device) return
12
+ if (board.device.gatt?.connected) {
13
+ if (board.name === "Motherboard") {
14
+ await write(Motherboard, "uart", "tx", String(MotherboardCommands.STOP_WEIGHT_MEAS), 0)
15
+ }
16
+ if (board.name === "Tindeq") {
17
+ await write(Tindeq, "progressor", "tx", String(TindeqCommands.STOP_WEIGHT_MEAS), 0)
18
+ }
19
+ }
20
+ }
@@ -0,0 +1,6 @@
1
+ import { Device } from "./devices/types";
2
+ /**
3
+ * stream output
4
+ * @param board
5
+ */
6
+ export declare const stream: (board: Device, duration?: number) => Promise<void>;
package/src/stream.js ADDED
@@ -0,0 +1,31 @@
1
+ import { Motherboard, Tindeq } from "./devices";
2
+ import { MotherboardCommands, TindeqCommands } from "./commands";
3
+ import { write } from "./write";
4
+ import { stop } from "./stop";
5
+ /**
6
+ * stream output
7
+ * @param board
8
+ */
9
+ export const stream = async (board, duration = 0) => {
10
+ if (!board.device)
11
+ return;
12
+ if (board.device.gatt?.connected) {
13
+ if (board.name === "Motherboard") {
14
+ // TODO: add check if device is recalibrated
15
+ // start stream
16
+ await write(Motherboard, "uart", "tx", String(MotherboardCommands.START_WEIGHT_MEAS), duration);
17
+ // end stream
18
+ if (duration !== 0) {
19
+ await stop(Motherboard);
20
+ }
21
+ }
22
+ if (board.name === "Tindeq") {
23
+ // start stream
24
+ await write(Tindeq, "progressor", "tx", String(TindeqCommands.START_WEIGHT_MEAS), duration);
25
+ // end stream
26
+ if (duration !== 0) {
27
+ await stop(Tindeq);
28
+ }
29
+ }
30
+ }
31
+ };
package/src/stream.ts ADDED
@@ -0,0 +1,32 @@
1
+ import { Device } from "./devices/types"
2
+ import { Motherboard, Tindeq } from "./devices"
3
+ import { MotherboardCommands, TindeqCommands } from "./commands"
4
+ import { write } from "./write"
5
+ import { stop } from "./stop"
6
+
7
+ /**
8
+ * stream output
9
+ * @param board
10
+ */
11
+ export const stream = async (board: Device, duration: number = 0): Promise<void> => {
12
+ if (!board.device) return
13
+ if (board.device.gatt?.connected) {
14
+ if (board.name === "Motherboard") {
15
+ // TODO: add check if device is recalibrated
16
+ // start stream
17
+ await write(Motherboard, "uart", "tx", String(MotherboardCommands.START_WEIGHT_MEAS), duration)
18
+ // end stream
19
+ if (duration !== 0) {
20
+ await stop(Motherboard)
21
+ }
22
+ }
23
+ if (board.name === "Tindeq") {
24
+ // start stream
25
+ await write(Tindeq, "progressor", "tx", String(TindeqCommands.START_WEIGHT_MEAS), duration)
26
+ // end stream
27
+ if (duration !== 0) {
28
+ await stop(Tindeq)
29
+ }
30
+ }
31
+ }
32
+ }
File without changes