@hangtime/grip-connect 0.3.10 → 0.4.0

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/README.md CHANGED
@@ -46,7 +46,7 @@ Simply importing the utilities you need from `@hangtime/grip-connect`.
46
46
  ```
47
47
 
48
48
  ```js
49
- import { Motherboard, active, battery, connect, disconnect, info, notify, stream } from "@hangtime/grip-connect"
49
+ import { Motherboard, active, battery, connect, disconnect, firmware, notify, stream } from "@hangtime/grip-connect"
50
50
 
51
51
  const motherboardButton = document.querySelector("#motherboard")
52
52
 
@@ -65,12 +65,15 @@ motherboardButton.addEventListener("click", () => {
65
65
  console.log(value)
66
66
  })
67
67
 
68
- // Read battery + device info
69
- await battery(Motherboard)
70
- await info(Motherboard)
68
+ // Read info: battery + firmware
69
+ const batteryLevel = await battery(Motherboard)
70
+ console.log(batteryLevel)
71
+
72
+ const firmwareVersion = await firmware(Motherboard)
73
+ console.log(firmwareVersion)
71
74
 
72
75
  // trigger LEDs
73
- // await led(device)
76
+ // await led(Motherboard)
74
77
 
75
78
  // Start weight streaming (for a minute) remove parameter for a continues stream
76
79
  await stream(Motherboard, 60000)
@@ -113,23 +116,27 @@ motherboardButton.addEventListener("click", () => {
113
116
  `chrome://bluetooth-internals/#devices` and press `Start Scan` to look for your device, click on `Inspect` and share all
114
117
  available services with us.
115
118
 
116
- | | Motherboard | Progressor | WH-C06 | Entralpi | Kilter Board | Climbro | mySmartBoard |
117
- | --------------------------------------------------------------------------------------- | ----------- | ---------- | ------ | -------- | ------------ | ------- | ------------ |
118
- | [Battery](https://stevie-ray.github.io/hangtime-grip-connect/api/battery.html) | ✅ | ✅ | | | | | |
119
- | [Calibration](https://stevie-ray.github.io/hangtime-grip-connect/api/calibration.html) | ✅ | | | | | | |
120
- | [Connect](https://stevie-ray.github.io/hangtime-grip-connect/api/connect.html) | ✅ | ✅ | ✅ | ✅ | ✅ | | |
121
- | [Disconnect](https://stevie-ray.github.io/hangtime-grip-connect/api/disconnect.html) | ✅ | ✅ | ✅ | ✅ | ✅ | | |
122
- | [Download](https://stevie-ray.github.io/hangtime-grip-connect/api/download.html) | ✅ | ✅ | | | | | |
123
- | [Info](https://stevie-ray.github.io/hangtime-grip-connect/api/info.html) | ✅ | ✅ | | | | | |
124
- | [isActive](https://stevie-ray.github.io/hangtime-grip-connect/api/is-active.html) | ✅ |||| | | |
125
- | [isConnected](https://stevie-ray.github.io/hangtime-grip-connect/api/is-connected.html) | ✅ | ✅ | ✅ | ✅ || | |
126
- | [Led](https://stevie-ray.github.io/hangtime-grip-connect/api/led.html) | ✅ | | | | ✅ | | |
127
- | [Notify](https://stevie-ray.github.io/hangtime-grip-connect/api/notify.html) | ✅ ||| ✅ | | | |
128
- | [Read](https://stevie-ray.github.io/hangtime-grip-connect/api/read.html) | ✅ | | | | | | |
129
- | [Stop](https://stevie-ray.github.io/hangtime-grip-connect/api/stop.html) | ✅ | ✅ | | | | | |
130
- | [Stream](https://stevie-ray.github.io/hangtime-grip-connect/api/stream.html) | ✅ || | | | | |
131
- | [Tare](https://stevie-ray.github.io/hangtime-grip-connect/api/tare.html) | ✅ |||| | | |
132
- | [Write](https://stevie-ray.github.io/hangtime-grip-connect/api/write.html) | ✅ | ✅ | | | | | |
119
+ | | Motherboard | Progressor | WH-C06 | Entralpi | Kilter Board | Climbro | mySmartBoard |
120
+ | ---------------------------------------------------------------------------------------- | ----------- | ---------- | ------ | -------- | ------------ | ------- | ------------ |
121
+ | [Battery](https://stevie-ray.github.io/hangtime-grip-connect/api/battery.html) | ✅ | ✅ | | | | | |
122
+ | [Calibration](https://stevie-ray.github.io/hangtime-grip-connect/api/calibration.html) | ✅ | | | | | | |
123
+ | [Connect](https://stevie-ray.github.io/hangtime-grip-connect/api/connect.html) | ✅ | ✅ | ✅ | ✅ | ✅ | | |
124
+ | [Disconnect](https://stevie-ray.github.io/hangtime-grip-connect/api/disconnect.html) | ✅ | ✅ | ✅ | ✅ | ✅ | | |
125
+ | [Download](https://stevie-ray.github.io/hangtime-grip-connect/api/download.html) | ✅ | ✅ | | | | | |
126
+ | [Firmware](https://stevie-ray.github.io/hangtime-grip-connect/api/firmware.html) | ✅ | ✅ | | | | | |
127
+ | [Hardware](https://stevie-ray.github.io/hangtime-grip-connect/api/hardware.html) | ✅ | | | | | | |
128
+ | [isActive](https://stevie-ray.github.io/hangtime-grip-connect/api/is-active.html) | ✅ | ✅ | ✅ | ✅ | | | |
129
+ | [isConnected](https://stevie-ray.github.io/hangtime-grip-connect/api/is-connected.html) | ✅ |||| ✅ | | |
130
+ | [Led](https://stevie-ray.github.io/hangtime-grip-connect/api/led.html) | ✅ | | | | | | |
131
+ | [Manufacturer](https://stevie-ray.github.io/hangtime-grip-connect/api/manufacturer.html) | ✅ | | | | | | |
132
+ | [Notify](https://stevie-ray.github.io/hangtime-grip-connect/api/notify.html) | ✅ | ✅ ||| | | |
133
+ | [Read](https://stevie-ray.github.io/hangtime-grip-connect/api/read.html) | ✅ | | | | | | |
134
+ | [Serial](https://stevie-ray.github.io/hangtime-grip-connect/api/serial.html) | ✅ | | | | | | |
135
+ | [Stop](https://stevie-ray.github.io/hangtime-grip-connect/api/stop.html) | ✅ | ✅ | | | | | |
136
+ | [Stream](https://stevie-ray.github.io/hangtime-grip-connect/api/stream.html) | ✅ | ✅ | | | | | |
137
+ | [Tare](https://stevie-ray.github.io/hangtime-grip-connect/api/tare.html) | ✅ | ✅ | ✅ | ✅ | | | |
138
+ | [Text](https://stevie-ray.github.io/hangtime-grip-connect/api/text.html) | ✅ | | | | | | |
139
+ | [Write](https://stevie-ray.github.io/hangtime-grip-connect/api/write.html) | ✅ | ✅ | | | | | |
133
140
 
134
141
  ## Development
135
142
 
package/dist/battery.d.ts CHANGED
@@ -1,7 +1,12 @@
1
1
  import type { Device } from "./types/devices";
2
2
  /**
3
3
  * Retrieves battery or voltage information from the device.
4
- * @param {Device} board - The device.
5
- * @returns {Promise<void>} A Promise that resolves when the information is successfully retrieved.
4
+ * - For Motherboard devices, it reads the battery level.
5
+ * - For Progressor devices, it sends a command to retrieve battery voltage information.
6
+ *
7
+ * @param {Device} board - The device from which to retrieve battery information.
8
+ * @returns {Promise<string | undefined>} A Promise that resolves with the battery or voltage information,
9
+ * or rejects with an error if the device is not connected.
10
+ * @throws {Error} Throws an error if the device is not connected.
6
11
  */
7
- export declare const battery: (board: Device) => Promise<void>;
12
+ export declare const battery: (board: Device) => Promise<string | undefined>;
package/dist/battery.js CHANGED
@@ -5,8 +5,13 @@ import { Motherboard, Progressor } from "./devices";
5
5
  import { ProgressorCommands } from "./commands";
6
6
  /**
7
7
  * Retrieves battery or voltage information from the device.
8
- * @param {Device} board - The device.
9
- * @returns {Promise<void>} A Promise that resolves when the information is successfully retrieved.
8
+ * - For Motherboard devices, it reads the battery level.
9
+ * - For Progressor devices, it sends a command to retrieve battery voltage information.
10
+ *
11
+ * @param {Device} board - The device from which to retrieve battery information.
12
+ * @returns {Promise<string | undefined>} A Promise that resolves with the battery or voltage information,
13
+ * or rejects with an error if the device is not connected.
14
+ * @throws {Error} Throws an error if the device is not connected.
10
15
  */
11
16
  export const battery = async (board) => {
12
17
  // Check if the device is connected
@@ -14,12 +19,19 @@ export const battery = async (board) => {
14
19
  // If the device is connected and it is a Motherboard device
15
20
  if (board.filters.some((filter) => filter.name === "Motherboard")) {
16
21
  // Read battery level information from the Motherboard
17
- await read(Motherboard, "battery", "level", 250);
22
+ return await read(Motherboard, "battery", "level", 250);
18
23
  }
19
24
  // If the device is connected and its name starts with "Progressor"
20
25
  if (board.filters.some((filter) => filter.namePrefix === "Progressor")) {
21
26
  // Write command to get battery voltage information to the Progressor
22
- await write(Progressor, "progressor", "tx", ProgressorCommands.GET_BATT_VLTG, 250);
27
+ let response = undefined;
28
+ await write(Progressor, "progressor", "tx", ProgressorCommands.GET_BATT_VLTG, 250, (data) => {
29
+ response = data;
30
+ });
31
+ return response;
23
32
  }
33
+ // If device is not found, return undefined
34
+ return;
24
35
  }
36
+ throw new Error("Not connected.");
25
37
  };
@@ -13,7 +13,9 @@ export const calibration = async (board) => {
13
13
  // If the device is connected, and it is a Motherboard device
14
14
  if (board.filters.some((filter) => filter.name === "Motherboard")) {
15
15
  // Write the command to get calibration data to the device
16
- await write(Motherboard, "uart", "tx", MotherboardCommands.GET_CALIBRATION, 2500);
16
+ await write(Motherboard, "uart", "tx", MotherboardCommands.GET_CALIBRATION, 2500, (data) => {
17
+ console.log(data);
18
+ });
17
19
  }
18
20
  }
19
21
  };
@@ -59,7 +59,7 @@ export const KilterBoardPlacementRoles = [
59
59
  position: 4,
60
60
  name: "foot",
61
61
  full_name: "Foot Only",
62
- led_color: "FFA500",
62
+ led_color: "FFB600",
63
63
  screen_color: "FFA500",
64
64
  },
65
65
  ];
@@ -1,6 +1,10 @@
1
1
  export declare const CALIBRATION: never[][];
2
2
  /**
3
- * Handles data received from the Motherboard device.
4
- * @param {string} receivedData - The received data string.
3
+ * Handles data received from the Motherboard device. Processes hex-encoded streaming packets
4
+ * to extract samples, calibrate masses, and update running averages of mass data.
5
+ * If the received data is not a valid hex packet, it returns the unprocessed data.
6
+ *
7
+ * @param {string} receivedData - The raw data received from the Motherboard device.
8
+ * @returns {void}
5
9
  */
6
10
  export declare const handleMotherboardData: (receivedData: string) => void;
@@ -1,4 +1,5 @@
1
1
  import { notifyCallback } from "./../notify";
2
+ import { writeCallback } from "./../write";
2
3
  import { applyTare } from "./../tare";
3
4
  import { MotherboardCommands } from "./../commands";
4
5
  import { checkActivity } from "./../is-active";
@@ -51,8 +52,12 @@ const applyCalibration = (sample, calibration) => {
51
52
  return sign * final;
52
53
  };
53
54
  /**
54
- * Handles data received from the Motherboard device.
55
- * @param {string} receivedData - The received data string.
55
+ * Handles data received from the Motherboard device. Processes hex-encoded streaming packets
56
+ * to extract samples, calibrate masses, and update running averages of mass data.
57
+ * If the received data is not a valid hex packet, it returns the unprocessed data.
58
+ *
59
+ * @param {string} receivedData - The raw data received from the Motherboard device.
60
+ * @returns {void}
56
61
  */
57
62
  export const handleMotherboardData = (receivedData) => {
58
63
  const receivedTime = Date.now();
@@ -131,6 +136,6 @@ export const handleMotherboardData = (receivedData) => {
131
136
  }
132
137
  else {
133
138
  // unhandled data
134
- console.log(receivedData);
139
+ writeCallback(receivedData);
135
140
  }
136
141
  };
@@ -1,5 +1,9 @@
1
1
  /**
2
- * Handles data received from the Progressor device.
3
- * @param {DataView} data - The received data.
2
+ * Handles data received from the Progressor device, processes weight measurements,
3
+ * and updates mass data including maximum and average values.
4
+ * It also handles command responses for retrieving device information.
5
+ *
6
+ * @param {DataView} data - The raw binary data received from the Progressor device.
7
+ * @returns {void}
4
8
  */
5
9
  export declare const handleProgressorData: (data: DataView) => void;
@@ -2,7 +2,7 @@ import { notifyCallback } from "./../notify";
2
2
  import { applyTare } from "./../tare";
3
3
  import { checkActivity } from "./../is-active";
4
4
  import { ProgressorCommands, ProgressorResponses } from "./../commands/progressor";
5
- import { lastWrite } from "./../write";
5
+ import { lastWrite, writeCallback } from "./../write";
6
6
  import struct from "./../struct";
7
7
  import { DownloadPackets } from "./../download";
8
8
  // Constants
@@ -11,8 +11,12 @@ let MASS_AVERAGE = "0";
11
11
  let MASS_TOTAL_SUM = 0;
12
12
  let DATAPOINT_COUNT = 0;
13
13
  /**
14
- * Handles data received from the Progressor device.
15
- * @param {DataView} data - The received data.
14
+ * Handles data received from the Progressor device, processes weight measurements,
15
+ * and updates mass data including maximum and average values.
16
+ * It also handles command responses for retrieving device information.
17
+ *
18
+ * @param {DataView} data - The raw binary data received from the Progressor device.
19
+ * @returns {void}
16
20
  */
17
21
  export const handleProgressorData = (data) => {
18
22
  const receivedTime = Date.now();
@@ -55,8 +59,7 @@ export const handleProgressorData = (data) => {
55
59
  return;
56
60
  let value = "";
57
61
  if (lastWrite === ProgressorCommands.GET_BATT_VLTG) {
58
- const vdd = new DataView(data.buffer, 2).getUint32(0, true);
59
- value = `ℹ️ Battery level: ${vdd} mV`;
62
+ value = new DataView(data.buffer, 2).getUint32(0, true).toString();
60
63
  }
61
64
  else if (lastWrite === ProgressorCommands.GET_FW_VERSION) {
62
65
  value = new TextDecoder().decode(data.buffer.slice(2));
@@ -64,12 +67,12 @@ export const handleProgressorData = (data) => {
64
67
  else if (lastWrite === ProgressorCommands.GET_ERR_INFO) {
65
68
  value = new TextDecoder().decode(data.buffer.slice(2));
66
69
  }
67
- console.log(value);
70
+ writeCallback(value);
68
71
  }
69
72
  else if (kind === ProgressorResponses.LOW_BATTERY_WARNING) {
70
73
  console.warn("⚠️ Low power detected. Please consider connecting to a power source.");
71
74
  }
72
75
  else {
73
- console.error(`❌ Error: Unknown message kind detected: ${kind}`);
76
+ throw new Error(`Unknown message kind detected: ${kind}`);
74
77
  }
75
78
  };
@@ -0,0 +1,12 @@
1
+ import type { Device } from "./types/devices";
2
+ /**
3
+ * Retrieves firmware version from the device.
4
+ * - For Motherboard devices, it reads the firmare version.
5
+ * - For Progressor devices, it sends a command to retrieve firware version.
6
+ *
7
+ * @param {Device} board - The device from which to retrieve firmware version.
8
+ * @returns {Promise<string>} A Promise that resolves with the firmware version,
9
+ * or rejects with an error if the device is not connected.
10
+ * @throws {Error} Throws an error if the device is not connected.
11
+ */
12
+ export declare const firmware: (board: Device) => Promise<string | undefined>;
@@ -0,0 +1,37 @@
1
+ import { write } from "./write";
2
+ import { read } from "./read";
3
+ import { isConnected } from "./is-connected";
4
+ import { Motherboard, Progressor } from "./devices";
5
+ import { ProgressorCommands } from "./commands";
6
+ /**
7
+ * Retrieves firmware version from the device.
8
+ * - For Motherboard devices, it reads the firmare version.
9
+ * - For Progressor devices, it sends a command to retrieve firware version.
10
+ *
11
+ * @param {Device} board - The device from which to retrieve firmware version.
12
+ * @returns {Promise<string>} A Promise that resolves with the firmware version,
13
+ * or rejects with an error if the device is not connected.
14
+ * @throws {Error} Throws an error if the device is not connected.
15
+ */
16
+ export const firmware = async (board) => {
17
+ // Check if the device is connected
18
+ if (isConnected(board)) {
19
+ // If the device is connected and it is a Motherboard device
20
+ if (board.filters.some((filter) => filter.name === "Motherboard")) {
21
+ // Read firmware version from the Motherboard
22
+ return await read(Motherboard, "device", "firmware", 250);
23
+ }
24
+ // If the device is connected and its name starts with "Progressor"
25
+ if (board.filters.some((filter) => filter.namePrefix === "Progressor")) {
26
+ // Write command to get firmware version information to the Progressor
27
+ let response = undefined;
28
+ await write(Progressor, "progressor", "tx", ProgressorCommands.GET_FW_VERSION, 250, (data) => {
29
+ response = data;
30
+ });
31
+ return response;
32
+ }
33
+ // If device is not found, return undefined
34
+ return;
35
+ }
36
+ throw new Error("Not connected.");
37
+ };
@@ -0,0 +1,11 @@
1
+ import type { Device } from "./types/devices";
2
+ /**
3
+ * Retrieves hardware version from the device.
4
+ * - For Motherboard devices, it reads the hardware version.
5
+ *
6
+ * @param {Device} board - The device from which to retrieve hardware version.
7
+ * @returns {Promise<string>} A Promise that resolves with the hardware version,
8
+ * or rejects with an error if the device is not connected.
9
+ * @throws {Error} Throws an error if the device is not connected.
10
+ */
11
+ export declare const hardware: (board: Device) => Promise<string | undefined>;
@@ -0,0 +1,25 @@
1
+ import { read } from "./read";
2
+ import { isConnected } from "./is-connected";
3
+ import { Motherboard } from "./devices";
4
+ /**
5
+ * Retrieves hardware version from the device.
6
+ * - For Motherboard devices, it reads the hardware version.
7
+ *
8
+ * @param {Device} board - The device from which to retrieve hardware version.
9
+ * @returns {Promise<string>} A Promise that resolves with the hardware version,
10
+ * or rejects with an error if the device is not connected.
11
+ * @throws {Error} Throws an error if the device is not connected.
12
+ */
13
+ export const hardware = async (board) => {
14
+ // Check if the device is connected
15
+ if (isConnected(board)) {
16
+ // If the device is connected and it is a Motherboard device
17
+ if (board.filters.some((filter) => filter.name === "Motherboard")) {
18
+ // Read hardware version from the Motherboard
19
+ return await read(Motherboard, "device", "hardware", 250);
20
+ }
21
+ // If device is not found, return undefined
22
+ return;
23
+ }
24
+ throw new Error("Not connected.");
25
+ };
package/dist/index.d.ts CHANGED
@@ -1,12 +1,16 @@
1
1
  export { Climbro, Entralpi, KilterBoard, Motherboard, mySmartBoard, WHC06, Progressor } from "./devices/index";
2
- export { battery } from "./battery";
3
2
  export { calibration } from "./calibration";
4
3
  export { download } from "./download";
5
4
  export { connect } from "./connect";
6
5
  export { disconnect } from "./disconnect";
7
6
  export { active, isActive } from "./is-active";
8
7
  export { isConnected } from "./is-connected";
9
- export { info } from "./info";
8
+ export { battery } from "./battery";
9
+ export { firmware } from "./firmware";
10
+ export { hardware } from "./hardware";
11
+ export { manufacturer } from "./manufacturer";
12
+ export { text } from "./text";
13
+ export { serial } from "./serial";
10
14
  export { led } from "./led";
11
15
  export { notify } from "./notify";
12
16
  export { stop } from "./stop";
package/dist/index.js CHANGED
@@ -1,7 +1,5 @@
1
1
  // Export device types
2
2
  export { Climbro, Entralpi, KilterBoard, Motherboard, mySmartBoard, WHC06, Progressor } from "./devices/index";
3
- // Export battery related functions
4
- export { battery } from "./battery";
5
3
  // Export calibration function
6
4
  export { calibration } from "./calibration";
7
5
  // Export download function
@@ -11,8 +9,14 @@ export { connect } from "./connect";
11
9
  export { disconnect } from "./disconnect";
12
10
  export { active, isActive } from "./is-active";
13
11
  export { isConnected } from "./is-connected";
14
- // Export information retrieval function
15
- export { info } from "./info";
12
+ // Export information retrieval functions
13
+ export { battery } from "./battery";
14
+ export { firmware } from "./firmware";
15
+ // Export "Motherboard exclusive" functions
16
+ export { hardware } from "./hardware";
17
+ export { manufacturer } from "./manufacturer";
18
+ export { text } from "./text";
19
+ export { serial } from "./serial";
16
20
  // Export led retrieval function
17
21
  export { led } from "./led";
18
22
  // Export notification related function
package/dist/led.js CHANGED
@@ -181,15 +181,15 @@ export const led = async (board, placement) => {
181
181
  if (board.filters.some((filter) => filter.name === "Motherboard")) {
182
182
  console.log("Green");
183
183
  await write(Motherboard, "led", "red", new Uint8Array([0x00]));
184
- await write(Motherboard, "led", "green", new Uint8Array([0x01]), 2500);
184
+ await write(Motherboard, "led", "green", new Uint8Array([0x01]), 1250);
185
185
  console.log("Red");
186
186
  await write(Motherboard, "led", "red", new Uint8Array([0x01]));
187
- await write(Motherboard, "led", "green", new Uint8Array([0x00]), 2500);
187
+ await write(Motherboard, "led", "green", new Uint8Array([0x00]), 1250);
188
188
  console.log("Orage");
189
189
  await write(Motherboard, "led", "red", new Uint8Array([0x01]));
190
- await write(Motherboard, "led", "green", new Uint8Array([0x01]), 2500);
190
+ await write(Motherboard, "led", "green", new Uint8Array([0x01]), 1250);
191
191
  console.log("Off");
192
192
  await write(Motherboard, "led", "red", new Uint8Array([0x00]));
193
- await write(Motherboard, "led", "green", new Uint8Array([0x00]), 2500);
193
+ await write(Motherboard, "led", "green", new Uint8Array([0x00]), 1250);
194
194
  }
195
195
  };
@@ -0,0 +1,11 @@
1
+ import type { Device } from "./types/devices";
2
+ /**
3
+ * Retrieves manufacturer information from the device.
4
+ * - For Motherboard devices, it reads the manufacturer information.
5
+ *
6
+ * @param {Device} board - The device from which to retrieve manufacturer information.
7
+ * @returns {Promise<string>} A Promise that resolves with the manufacturer information,
8
+ * or rejects with an error if the device is not connected.
9
+ * @throws {Error} Throws an error if the device is not connected.
10
+ */
11
+ export declare const manufacturer: (board: Device) => Promise<string | undefined>;
@@ -0,0 +1,25 @@
1
+ import { read } from "./read";
2
+ import { isConnected } from "./is-connected";
3
+ import { Motherboard } from "./devices";
4
+ /**
5
+ * Retrieves manufacturer information from the device.
6
+ * - For Motherboard devices, it reads the manufacturer information.
7
+ *
8
+ * @param {Device} board - The device from which to retrieve manufacturer information.
9
+ * @returns {Promise<string>} A Promise that resolves with the manufacturer information,
10
+ * or rejects with an error if the device is not connected.
11
+ * @throws {Error} Throws an error if the device is not connected.
12
+ */
13
+ export const manufacturer = async (board) => {
14
+ // Check if the device is connected
15
+ if (isConnected(board)) {
16
+ // If the device is connected and it is a Motherboard device
17
+ if (board.filters.some((filter) => filter.name === "Motherboard")) {
18
+ // Read manufacturer information from the Motherboard
19
+ return await read(Motherboard, "device", "manufacturer", 250);
20
+ }
21
+ // If device is not found, return undefined
22
+ return;
23
+ }
24
+ throw new Error("Not connected.");
25
+ };
package/dist/read.d.ts CHANGED
@@ -5,6 +5,6 @@ import type { Device } from "./types/devices";
5
5
  * @param {string} serviceId - The service ID where the characteristic belongs.
6
6
  * @param {string} characteristicId - The characteristic ID to read from.
7
7
  * @param {number} [duration=0] - The duration to wait before resolving the promise, in milliseconds.
8
- * @returns {Promise<void>} A promise that resolves when the read operation is completed.
8
+ * @returns {Promise<string>} A promise that resolves when the read operation is completed.
9
9
  */
10
- export declare const read: (board: Device, serviceId: string, characteristicId: string, duration?: number) => Promise<void>;
10
+ export declare const read: (board: Device, serviceId: string, characteristicId: string, duration?: number) => Promise<string>;
package/dist/read.js CHANGED
@@ -6,7 +6,7 @@ import { isConnected } from "./is-connected";
6
6
  * @param {string} serviceId - The service ID where the characteristic belongs.
7
7
  * @param {string} characteristicId - The characteristic ID to read from.
8
8
  * @param {number} [duration=0] - The duration to wait before resolving the promise, in milliseconds.
9
- * @returns {Promise<void>} A promise that resolves when the read operation is completed.
9
+ * @returns {Promise<string>} A promise that resolves when the read operation is completed.
10
10
  */
11
11
  export const read = (board, serviceId, characteristicId, duration = 0) => {
12
12
  return new Promise((resolve, reject) => {
@@ -21,17 +21,15 @@ export const read = (board, serviceId, characteristicId, duration = 0) => {
21
21
  switch (characteristicId) {
22
22
  case "level":
23
23
  // TODO: This is Motherboard specific.
24
- decodedValue = value.getUint8(0);
24
+ decodedValue = value.getUint8(0).toString();
25
25
  break;
26
26
  default:
27
27
  decodedValue = decoder.decode(value);
28
28
  break;
29
29
  }
30
- // TODO: Create Read callback
31
- console.log(decodedValue);
32
30
  // Resolve after specified duration
33
31
  setTimeout(() => {
34
- resolve();
32
+ return resolve(decodedValue);
35
33
  }, duration);
36
34
  })
37
35
  .catch((error) => {
@@ -0,0 +1,11 @@
1
+ import type { Device } from "./types/devices";
2
+ /**
3
+ * Retrieves serial number from the device.
4
+ * - For Motherboard devices, it reads the serial number.
5
+ *
6
+ * @param {Device} board - The device from which to retrieve serial number.
7
+ * @returns {Promise<string>} A Promise that resolves with the serial number,
8
+ * or rejects with an error if the device is not connected.
9
+ * @throws {Error} Throws an error if the device is not connected.
10
+ */
11
+ export declare const serial: (board: Device) => Promise<string | undefined>;
package/dist/serial.js ADDED
@@ -0,0 +1,30 @@
1
+ import { write } from "./write";
2
+ import { isConnected } from "./is-connected";
3
+ import { Motherboard } from "./devices";
4
+ import { MotherboardCommands } from "./commands";
5
+ /**
6
+ * Retrieves serial number from the device.
7
+ * - For Motherboard devices, it reads the serial number.
8
+ *
9
+ * @param {Device} board - The device from which to retrieve serial number.
10
+ * @returns {Promise<string>} A Promise that resolves with the serial number,
11
+ * or rejects with an error if the device is not connected.
12
+ * @throws {Error} Throws an error if the device is not connected.
13
+ */
14
+ export const serial = async (board) => {
15
+ // Check if the device is connected
16
+ if (isConnected(board)) {
17
+ // If the device is connected and it is a Motherboard device
18
+ if (board.filters.some((filter) => filter.name === "Motherboard")) {
19
+ // Write serial number command to the Motherboard and read output
20
+ let response = undefined;
21
+ await write(Motherboard, "uart", "tx", MotherboardCommands.GET_SERIAL, 250, (data) => {
22
+ response = data;
23
+ });
24
+ return response;
25
+ }
26
+ // If device is not found, return undefined
27
+ return;
28
+ }
29
+ throw new Error("Not connected.");
30
+ };
package/dist/text.d.ts ADDED
@@ -0,0 +1,14 @@
1
+ import type { Device } from "./types/devices";
2
+ /**
3
+ * Retrieves the entire 320 bytes of non-volatile memory from the device.
4
+ *
5
+ * The memory consists of 10 segments, each 32 bytes long. If any segment was previously written,
6
+ * the corresponding data will appear in the response. Unused portions of the memory are
7
+ * padded with whitespace.
8
+ *
9
+ * @param {Device} board - The device from which to retrieve text information.
10
+ * @returns {Promise<string>} A Promise that resolves with the 320-byte memory content as a string,
11
+ * which includes both the written data and any unused, whitespace-padded segments.
12
+ * @throws {Error} Throws an error if the device is not connected.
13
+ */
14
+ export declare const text: (board: Device) => Promise<string | undefined>;
package/dist/text.js ADDED
@@ -0,0 +1,33 @@
1
+ import { write } from "./write";
2
+ import { isConnected } from "./is-connected";
3
+ import { Motherboard } from "./devices";
4
+ import { MotherboardCommands } from "./commands";
5
+ /**
6
+ * Retrieves the entire 320 bytes of non-volatile memory from the device.
7
+ *
8
+ * The memory consists of 10 segments, each 32 bytes long. If any segment was previously written,
9
+ * the corresponding data will appear in the response. Unused portions of the memory are
10
+ * padded with whitespace.
11
+ *
12
+ * @param {Device} board - The device from which to retrieve text information.
13
+ * @returns {Promise<string>} A Promise that resolves with the 320-byte memory content as a string,
14
+ * which includes both the written data and any unused, whitespace-padded segments.
15
+ * @throws {Error} Throws an error if the device is not connected.
16
+ */
17
+ export const text = async (board) => {
18
+ // Check if the device is connected
19
+ if (isConnected(board)) {
20
+ // If the device is connected and it is a Motherboard device
21
+ if (board.filters.some((filter) => filter.name === "Motherboard")) {
22
+ // Write text information command to the Motherboard and read output
23
+ let response = undefined;
24
+ await write(Motherboard, "uart", "tx", MotherboardCommands.GET_TEXT, 250, (data) => {
25
+ response = data;
26
+ });
27
+ return response;
28
+ }
29
+ // If device is not found, return undefined
30
+ return;
31
+ }
32
+ throw new Error("Not connected.");
33
+ };