@hangtime/grip-connect 0.2.0 → 0.2.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.
- package/README.md +8 -5
- package/package.json +2 -2
- package/src/battery.ts +4 -4
- package/src/calibration.ts +1 -1
- package/src/commands/index.ts +2 -2
- package/src/commands/{tindeq.ts → progressor.ts} +7 -3
- package/src/commands/types.ts +5 -5
- package/src/connect.ts +64 -5
- package/src/devices/index.ts +1 -1
- package/src/devices/{tindeq.ts → progressor.ts} +17 -5
- package/src/index.ts +1 -1
- package/src/info.ts +6 -6
- package/src/stop.ts +5 -5
- package/src/stream.ts +6 -6
- package/src/write.ts +7 -4
- package/src/battery.d.ts +0 -6
- package/src/battery.js +0 -19
- package/src/calibration.d.ts +0 -6
- package/src/calibration.js +0 -15
- package/src/characteristic.d.ts +0 -9
- package/src/characteristic.js +0 -15
- 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 -5
- package/src/commands/index.js +0 -5
- package/src/commands/motherboard.d.ts +0 -6
- package/src/commands/motherboard.js +0 -13
- package/src/commands/smartboard.d.ts +0 -6
- package/src/commands/smartboard.js +0 -5
- package/src/commands/tindeq.d.ts +0 -11
- package/src/commands/tindeq.js +0 -23
- 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 -156
- package/src/data.d.ts +0 -8
- package/src/data.js +0 -109
- package/src/devices/climbro.d.ts +0 -2
- package/src/devices/climbro.js +0 -4
- package/src/devices/entralpi.d.ts +0 -2
- package/src/devices/entralpi.js +0 -52
- package/src/devices/index.d.ts +0 -5
- package/src/devices/index.js +0 -5
- package/src/devices/motherboard.d.ts +0 -2
- package/src/devices/motherboard.js +0 -79
- package/src/devices/smartboard.d.ts +0 -2
- package/src/devices/smartboard.js +0 -4
- package/src/devices/tindeq.d.ts +0 -2
- package/src/devices/tindeq.js +0 -22
- package/src/devices/types.d.ts +0 -20
- package/src/devices/types.js +0 -1
- package/src/disconnect.d.ts +0 -6
- package/src/disconnect.js +0 -10
- package/src/index.d.ts +0 -10
- package/src/index.js +0 -12
- package/src/info.d.ts +0 -6
- package/src/info.js +0 -23
- package/src/is-connected.d.ts +0 -7
- package/src/is-connected.js +0 -10
- package/src/notify.d.ts +0 -4
- package/src/notify.js +0 -6
- package/src/read.d.ts +0 -6
- package/src/read.js +0 -45
- package/src/stop.d.ts +0 -6
- package/src/stop.js +0 -18
- package/src/stream.d.ts +0 -6
- package/src/stream.js +0 -35
- package/src/write.d.ts +0 -7
- package/src/write.js +0 -35
package/src/connect.js
DELETED
|
@@ -1,156 +0,0 @@
|
|
|
1
|
-
import { notifyCallback } from "./notify";
|
|
2
|
-
import { handleMotherboardData } from "./data";
|
|
3
|
-
let server;
|
|
4
|
-
const receiveBuffer = [];
|
|
5
|
-
/**
|
|
6
|
-
* onDisconnected
|
|
7
|
-
* @param board
|
|
8
|
-
* @param event
|
|
9
|
-
*/
|
|
10
|
-
const onDisconnected = (event, board) => {
|
|
11
|
-
board.device = undefined;
|
|
12
|
-
const device = event.target;
|
|
13
|
-
console.log(`Device ${device.name} is disconnected.`);
|
|
14
|
-
};
|
|
15
|
-
/**
|
|
16
|
-
* handleNotifications
|
|
17
|
-
* @param event
|
|
18
|
-
* @param onNotify
|
|
19
|
-
*/
|
|
20
|
-
const handleNotifications = (event, board) => {
|
|
21
|
-
const characteristic = event.target;
|
|
22
|
-
const value = characteristic.value;
|
|
23
|
-
if (value) {
|
|
24
|
-
if (board.name === "Motherboard") {
|
|
25
|
-
for (let i = 0; i < value.byteLength; i++) {
|
|
26
|
-
receiveBuffer.push(value.getUint8(i));
|
|
27
|
-
}
|
|
28
|
-
let idx;
|
|
29
|
-
while ((idx = receiveBuffer.indexOf(10)) >= 0) {
|
|
30
|
-
const line = receiveBuffer.splice(0, idx + 1).slice(0, -1); // Combine and remove LF
|
|
31
|
-
if (line.length > 0 && line[line.length - 1] === 13)
|
|
32
|
-
line.pop(); // Remove CR
|
|
33
|
-
const decoder = new TextDecoder("utf-8");
|
|
34
|
-
const receivedData = decoder.decode(new Uint8Array(line));
|
|
35
|
-
handleMotherboardData(characteristic.uuid, receivedData);
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
else if (board.name === "ENTRALPI") {
|
|
39
|
-
if (value.buffer) {
|
|
40
|
-
const buffer = value.buffer;
|
|
41
|
-
const rawData = new DataView(buffer);
|
|
42
|
-
const receivedData = rawData.getUint16(0) / 100;
|
|
43
|
-
if (notifyCallback) {
|
|
44
|
-
notifyCallback({
|
|
45
|
-
uuid: characteristic.uuid,
|
|
46
|
-
value: {
|
|
47
|
-
massTotal: receivedData,
|
|
48
|
-
},
|
|
49
|
-
});
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
else if (board.name === "Tindeq") {
|
|
54
|
-
// TODO: handle Tindeq notify
|
|
55
|
-
}
|
|
56
|
-
else {
|
|
57
|
-
if (notifyCallback) {
|
|
58
|
-
notifyCallback({ uuid: characteristic.uuid, value: value });
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
};
|
|
63
|
-
/**
|
|
64
|
-
* onConnected
|
|
65
|
-
* @param event
|
|
66
|
-
* @param board
|
|
67
|
-
*/
|
|
68
|
-
const onConnected = async (board, onSuccess) => {
|
|
69
|
-
try {
|
|
70
|
-
const services = await server?.getPrimaryServices();
|
|
71
|
-
if (!services || services.length === 0) {
|
|
72
|
-
console.error("No services found");
|
|
73
|
-
return;
|
|
74
|
-
}
|
|
75
|
-
for (const service of services) {
|
|
76
|
-
const matchingService = board.services.find((boardService) => boardService.uuid === service.uuid);
|
|
77
|
-
if (matchingService) {
|
|
78
|
-
// Android bug: Introduce a delay before getting characteristics
|
|
79
|
-
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
80
|
-
const characteristics = await service.getCharacteristics();
|
|
81
|
-
for (const characteristic of matchingService.characteristics) {
|
|
82
|
-
const matchingCharacteristic = characteristics.find((char) => char.uuid === characteristic.uuid);
|
|
83
|
-
if (matchingCharacteristic) {
|
|
84
|
-
const element = matchingService.characteristics.find((char) => char.uuid === matchingCharacteristic.uuid);
|
|
85
|
-
if (element) {
|
|
86
|
-
element.characteristic = matchingCharacteristic;
|
|
87
|
-
// notify
|
|
88
|
-
if (element.id === "rx") {
|
|
89
|
-
matchingCharacteristic.startNotifications();
|
|
90
|
-
matchingCharacteristic.addEventListener("characteristicvaluechanged", (event) => handleNotifications(event, board));
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
else {
|
|
95
|
-
console.warn(`Characteristic ${characteristic.uuid} not found in service ${service.uuid}`);
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
// Call the onSuccess callback after successful connection and setup
|
|
101
|
-
onSuccess();
|
|
102
|
-
}
|
|
103
|
-
catch (error) {
|
|
104
|
-
console.error(error);
|
|
105
|
-
}
|
|
106
|
-
};
|
|
107
|
-
/**
|
|
108
|
-
* Return all service UUIDs
|
|
109
|
-
* @param device
|
|
110
|
-
*/
|
|
111
|
-
const getAllServiceUUIDs = (device) => {
|
|
112
|
-
return device.services.map((service) => service.uuid);
|
|
113
|
-
};
|
|
114
|
-
/**
|
|
115
|
-
* Connect to the BluetoothDevice
|
|
116
|
-
* @param device
|
|
117
|
-
* @param onSuccess
|
|
118
|
-
*/
|
|
119
|
-
export const connect = async (board, onSuccess) => {
|
|
120
|
-
try {
|
|
121
|
-
const deviceServices = getAllServiceUUIDs(board);
|
|
122
|
-
// setup filter list
|
|
123
|
-
const filters = [];
|
|
124
|
-
if (board.name) {
|
|
125
|
-
filters.push({
|
|
126
|
-
name: board.name,
|
|
127
|
-
});
|
|
128
|
-
}
|
|
129
|
-
if (board.companyId) {
|
|
130
|
-
filters.push({
|
|
131
|
-
manufacturerData: [
|
|
132
|
-
{
|
|
133
|
-
companyIdentifier: board.companyId,
|
|
134
|
-
},
|
|
135
|
-
],
|
|
136
|
-
});
|
|
137
|
-
}
|
|
138
|
-
const device = await navigator.bluetooth.requestDevice({
|
|
139
|
-
filters: filters,
|
|
140
|
-
optionalServices: deviceServices,
|
|
141
|
-
});
|
|
142
|
-
board.device = device;
|
|
143
|
-
if (!board.device.gatt) {
|
|
144
|
-
console.error("GATT is not available on this device");
|
|
145
|
-
return;
|
|
146
|
-
}
|
|
147
|
-
server = await board.device?.gatt?.connect();
|
|
148
|
-
board.device.addEventListener("gattserverdisconnected", (event) => onDisconnected(event, board));
|
|
149
|
-
if (server.connected) {
|
|
150
|
-
await onConnected(board, onSuccess);
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
catch (error) {
|
|
154
|
-
console.error(error);
|
|
155
|
-
}
|
|
156
|
-
};
|
package/src/data.d.ts
DELETED
package/src/data.js
DELETED
|
@@ -1,109 +0,0 @@
|
|
|
1
|
-
import { notifyCallback } from "./notify";
|
|
2
|
-
const PACKET_LENGTH = 32;
|
|
3
|
-
const NUM_SAMPLES = 3;
|
|
4
|
-
export const CALIBRATION = [[], [], [], []];
|
|
5
|
-
/**
|
|
6
|
-
* applyCalibration
|
|
7
|
-
* @param sample
|
|
8
|
-
* @param calibration
|
|
9
|
-
*/
|
|
10
|
-
const applyCalibration = (sample, calibration) => {
|
|
11
|
-
// Extract the calibrated value for the zero point
|
|
12
|
-
const zeroCalibration = calibration[0][2];
|
|
13
|
-
// Initialize sign as positive
|
|
14
|
-
let sign = 1;
|
|
15
|
-
// Initialize the final calibrated value
|
|
16
|
-
let final = 0;
|
|
17
|
-
// If the sample value is less than the zero calibration point
|
|
18
|
-
if (sample < zeroCalibration) {
|
|
19
|
-
// Change the sign to negative
|
|
20
|
-
sign = -1;
|
|
21
|
-
// Reflect the sample around the zero calibration point
|
|
22
|
-
sample = /* 2 * zeroCalibration */ -sample;
|
|
23
|
-
}
|
|
24
|
-
// Iterate through the calibration data
|
|
25
|
-
for (let i = 1; i < calibration.length; i++) {
|
|
26
|
-
// Extract the lower and upper bounds of the current calibration range
|
|
27
|
-
const calibrationStart = calibration[i - 1][2];
|
|
28
|
-
const calibrationEnd = calibration[i][2];
|
|
29
|
-
// If the sample value is within the current calibration range
|
|
30
|
-
if (sample < calibrationEnd) {
|
|
31
|
-
// Interpolate to get the calibrated value within the range
|
|
32
|
-
final =
|
|
33
|
-
calibration[i - 1][1] +
|
|
34
|
-
((sample - calibrationStart) / (calibrationEnd - calibrationStart)) *
|
|
35
|
-
(calibration[i][1] - calibration[i - 1][1]);
|
|
36
|
-
break;
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
// Return the calibrated value with the appropriate sign (positive/negative)
|
|
40
|
-
return sign * final;
|
|
41
|
-
};
|
|
42
|
-
/**
|
|
43
|
-
* handleMotherboardData
|
|
44
|
-
*
|
|
45
|
-
* @param uuid - Unique identifier
|
|
46
|
-
* @param receivedData - Received data string
|
|
47
|
-
*/
|
|
48
|
-
export const handleMotherboardData = (uuid, receivedData) => {
|
|
49
|
-
const receivedTime = Date.now();
|
|
50
|
-
// Check if the line is entirely hex characters
|
|
51
|
-
const isAllHex = /^[0-9A-Fa-f]+$/g.test(receivedData);
|
|
52
|
-
// Handle streaming packet
|
|
53
|
-
if (isAllHex && receivedData.length === PACKET_LENGTH) {
|
|
54
|
-
// Base-16 decode the string: convert hex pairs to byte values
|
|
55
|
-
const bytes = Array.from({ length: receivedData.length / 2 }, (_, i) => Number(`0x${receivedData.substring(i * 2, i * 2 + 2)}`));
|
|
56
|
-
// Translate header into packet, number of samples from the packet length
|
|
57
|
-
const packet = {
|
|
58
|
-
received: receivedTime,
|
|
59
|
-
sampleNum: new DataView(new Uint8Array(bytes).buffer).getUint16(0, true),
|
|
60
|
-
battRaw: new DataView(new Uint8Array(bytes).buffer).getUint16(2, true),
|
|
61
|
-
samples: [],
|
|
62
|
-
masses: [],
|
|
63
|
-
};
|
|
64
|
-
const dataView = new DataView(new Uint8Array(bytes).buffer);
|
|
65
|
-
for (let i = 0; i < NUM_SAMPLES; i++) {
|
|
66
|
-
const sampleStart = 4 + 3 * i;
|
|
67
|
-
// Use DataView to read the 24-bit unsigned integer
|
|
68
|
-
const rawValue = dataView.getUint8(sampleStart) |
|
|
69
|
-
(dataView.getUint8(sampleStart + 1) << 8) |
|
|
70
|
-
(dataView.getUint8(sampleStart + 2) << 16);
|
|
71
|
-
// Ensure unsigned 32-bit integer
|
|
72
|
-
packet.samples[i] = rawValue >>> 0;
|
|
73
|
-
if (packet.samples[i] >= 0x7fffff) {
|
|
74
|
-
packet.samples[i] -= 0x1000000;
|
|
75
|
-
}
|
|
76
|
-
// if (!CALIBRATION[0].length) return
|
|
77
|
-
packet.masses[i] = applyCalibration(packet.samples[i], CALIBRATION[i]);
|
|
78
|
-
}
|
|
79
|
-
// invert center and right values
|
|
80
|
-
packet.masses[1] *= -1;
|
|
81
|
-
packet.masses[2] *= -1;
|
|
82
|
-
// map to variables
|
|
83
|
-
const left = packet.masses[0];
|
|
84
|
-
const center = packet.masses[1];
|
|
85
|
-
const right = packet.masses[2];
|
|
86
|
-
if (notifyCallback) {
|
|
87
|
-
notifyCallback({
|
|
88
|
-
uuid,
|
|
89
|
-
value: {
|
|
90
|
-
massTotal: Math.max(-1000, left + right + center).toFixed(1),
|
|
91
|
-
massLeft: Math.max(-1000, left).toFixed(1),
|
|
92
|
-
massRight: Math.max(-1000, right).toFixed(1),
|
|
93
|
-
massCenter: Math.max(-1000, center).toFixed(1),
|
|
94
|
-
},
|
|
95
|
-
});
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
else if ((receivedData.match(/,/g) || []).length === 3) {
|
|
99
|
-
console.log(receivedData);
|
|
100
|
-
// if the returned notification is a calibration string add them to the array
|
|
101
|
-
const parts = receivedData.split(",");
|
|
102
|
-
const numericParts = parts.map((x) => parseFloat(x));
|
|
103
|
-
CALIBRATION[numericParts[0]].push(numericParts.slice(1));
|
|
104
|
-
}
|
|
105
|
-
else {
|
|
106
|
-
// unhanded data
|
|
107
|
-
console.log(receivedData);
|
|
108
|
-
}
|
|
109
|
-
};
|
package/src/devices/climbro.d.ts
DELETED
package/src/devices/climbro.js
DELETED
package/src/devices/entralpi.js
DELETED
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
export const Entralpi = {
|
|
2
|
-
name: "ENTRALPI",
|
|
3
|
-
services: [
|
|
4
|
-
{
|
|
5
|
-
name: "Device Information",
|
|
6
|
-
id: "device",
|
|
7
|
-
uuid: "0000180a-0000-1000-8000-00805f9b34fb",
|
|
8
|
-
characteristics: [],
|
|
9
|
-
},
|
|
10
|
-
{
|
|
11
|
-
name: "Battery Service",
|
|
12
|
-
id: "battery",
|
|
13
|
-
uuid: "0000180f-0000-1000-8000-00805f9b34fb",
|
|
14
|
-
characteristics: [],
|
|
15
|
-
},
|
|
16
|
-
{
|
|
17
|
-
name: "Generic Attribute",
|
|
18
|
-
id: "attribute",
|
|
19
|
-
uuid: "00001801-0000-1000-8000-00805f9b34fb",
|
|
20
|
-
characteristics: [],
|
|
21
|
-
},
|
|
22
|
-
{
|
|
23
|
-
name: "UART ISSC Transparent Service",
|
|
24
|
-
id: "uart",
|
|
25
|
-
uuid: "0000fff0-0000-1000-8000-00805f9b34fb",
|
|
26
|
-
characteristics: [
|
|
27
|
-
{
|
|
28
|
-
name: "TX",
|
|
29
|
-
id: "tx",
|
|
30
|
-
uuid: "0000fff5-0000-1000-8000-00805f9b34fb",
|
|
31
|
-
},
|
|
32
|
-
{
|
|
33
|
-
name: "RX",
|
|
34
|
-
id: "rx",
|
|
35
|
-
uuid: "0000fff4-0000-1000-8000-00805f9b34fb",
|
|
36
|
-
},
|
|
37
|
-
],
|
|
38
|
-
},
|
|
39
|
-
{
|
|
40
|
-
name: "Weight Scale",
|
|
41
|
-
id: "weight",
|
|
42
|
-
uuid: "0000181d-0000-1000-8000-00805f9b34fb",
|
|
43
|
-
characteristics: [],
|
|
44
|
-
},
|
|
45
|
-
{
|
|
46
|
-
name: "Generic Access",
|
|
47
|
-
id: "access",
|
|
48
|
-
uuid: "00001800-0000-1000-8000-00805f9b34fb",
|
|
49
|
-
characteristics: [],
|
|
50
|
-
},
|
|
51
|
-
],
|
|
52
|
-
};
|
package/src/devices/index.d.ts
DELETED
package/src/devices/index.js
DELETED
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
export const Motherboard = {
|
|
2
|
-
name: "Motherboard",
|
|
3
|
-
companyId: 0x2a29,
|
|
4
|
-
services: [
|
|
5
|
-
{
|
|
6
|
-
name: "Device Information",
|
|
7
|
-
id: "device",
|
|
8
|
-
uuid: "0000180a-0000-1000-8000-00805f9b34fb",
|
|
9
|
-
characteristics: [
|
|
10
|
-
// {
|
|
11
|
-
// name: 'Serial Number (Blocked)',
|
|
12
|
-
// id: 'serial'
|
|
13
|
-
// uuid: '00002a25-0000-1000-8000-00805f9b34fb'
|
|
14
|
-
// },
|
|
15
|
-
{
|
|
16
|
-
name: "Firmware Revision",
|
|
17
|
-
id: "firmware",
|
|
18
|
-
uuid: "00002a26-0000-1000-8000-00805f9b34fb",
|
|
19
|
-
},
|
|
20
|
-
{
|
|
21
|
-
name: "Hardware Revision",
|
|
22
|
-
id: "hardware",
|
|
23
|
-
uuid: "00002a27-0000-1000-8000-00805f9b34fb",
|
|
24
|
-
},
|
|
25
|
-
{
|
|
26
|
-
name: "Manufacturer Name",
|
|
27
|
-
id: "manufacturer",
|
|
28
|
-
uuid: "00002a29-0000-1000-8000-00805f9b34fb",
|
|
29
|
-
},
|
|
30
|
-
],
|
|
31
|
-
},
|
|
32
|
-
{
|
|
33
|
-
name: "Battery Service",
|
|
34
|
-
id: "battery",
|
|
35
|
-
uuid: "0000180f-0000-1000-8000-00805f9b34fb",
|
|
36
|
-
characteristics: [
|
|
37
|
-
{
|
|
38
|
-
name: "Battery Level",
|
|
39
|
-
id: "level",
|
|
40
|
-
uuid: "00002a19-0000-1000-8000-00805f9b34fb",
|
|
41
|
-
},
|
|
42
|
-
],
|
|
43
|
-
},
|
|
44
|
-
{
|
|
45
|
-
name: "Unknown Service",
|
|
46
|
-
id: "unknown",
|
|
47
|
-
uuid: "10ababcd-15e1-28ff-de13-725bea03b127",
|
|
48
|
-
characteristics: [
|
|
49
|
-
{
|
|
50
|
-
name: "Unknown 01",
|
|
51
|
-
id: "01",
|
|
52
|
-
uuid: "10ab1524-15e1-28ff-de13-725bea03b127",
|
|
53
|
-
},
|
|
54
|
-
{
|
|
55
|
-
name: "Unknown 02",
|
|
56
|
-
id: "02",
|
|
57
|
-
uuid: "10ab1525-15e1-28ff-de13-725bea03b127",
|
|
58
|
-
},
|
|
59
|
-
],
|
|
60
|
-
},
|
|
61
|
-
{
|
|
62
|
-
name: "UART Nordic Service",
|
|
63
|
-
id: "uart",
|
|
64
|
-
uuid: "6e400001-b5a3-f393-e0a9-e50e24dcca9e",
|
|
65
|
-
characteristics: [
|
|
66
|
-
{
|
|
67
|
-
name: "TX",
|
|
68
|
-
id: "tx",
|
|
69
|
-
uuid: "6e400002-b5a3-f393-e0a9-e50e24dcca9e",
|
|
70
|
-
},
|
|
71
|
-
{
|
|
72
|
-
name: "RX",
|
|
73
|
-
id: "rx",
|
|
74
|
-
uuid: "6e400003-b5a3-f393-e0a9-e50e24dcca9e",
|
|
75
|
-
},
|
|
76
|
-
],
|
|
77
|
-
},
|
|
78
|
-
],
|
|
79
|
-
};
|
package/src/devices/tindeq.d.ts
DELETED
package/src/devices/tindeq.js
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
export const Tindeq = {
|
|
2
|
-
name: "Tindeq",
|
|
3
|
-
services: [
|
|
4
|
-
{
|
|
5
|
-
name: "Progressor Service",
|
|
6
|
-
id: "progressor",
|
|
7
|
-
uuid: "7e4e1701-1ea6-40c9-9dcc-13d34ffead57",
|
|
8
|
-
characteristics: [
|
|
9
|
-
{
|
|
10
|
-
name: "Write",
|
|
11
|
-
id: "tx",
|
|
12
|
-
uuid: "7e4e1703-1ea6-40c9-9dcc-13d34ffead57",
|
|
13
|
-
},
|
|
14
|
-
{
|
|
15
|
-
name: "Notify",
|
|
16
|
-
id: "rx",
|
|
17
|
-
uuid: "7e4e1702-1ea6-40c9-9dcc-13d34ffead57",
|
|
18
|
-
},
|
|
19
|
-
],
|
|
20
|
-
},
|
|
21
|
-
],
|
|
22
|
-
};
|
package/src/devices/types.d.ts
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
/// <reference types="web-bluetooth" />
|
|
2
|
-
interface Characteristic {
|
|
3
|
-
name: string;
|
|
4
|
-
id: string;
|
|
5
|
-
uuid: string;
|
|
6
|
-
characteristic?: BluetoothRemoteGATTCharacteristic;
|
|
7
|
-
}
|
|
8
|
-
interface Service {
|
|
9
|
-
name: string;
|
|
10
|
-
id: string;
|
|
11
|
-
uuid: string;
|
|
12
|
-
characteristics: Characteristic[];
|
|
13
|
-
}
|
|
14
|
-
export interface Device {
|
|
15
|
-
name: string;
|
|
16
|
-
companyId?: number;
|
|
17
|
-
services: Service[];
|
|
18
|
-
device?: BluetoothDevice;
|
|
19
|
-
}
|
|
20
|
-
export {};
|
package/src/devices/types.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/src/disconnect.d.ts
DELETED
package/src/disconnect.js
DELETED
package/src/index.d.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
export { Climbro, Entralpi, Motherboard, SmartBoard, Tindeq } from "./devices/index";
|
|
2
|
-
export { battery } from "./battery";
|
|
3
|
-
export { calibration } from "./calibration";
|
|
4
|
-
export { connect } from "./connect";
|
|
5
|
-
export { disconnect } from "./disconnect";
|
|
6
|
-
export { isConnected } from "./is-connected";
|
|
7
|
-
export { info } from "./info";
|
|
8
|
-
export { notify } from "./notify";
|
|
9
|
-
export { stop } from "./stop";
|
|
10
|
-
export { stream } from "./stream";
|
package/src/index.js
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
export { Climbro, Entralpi, Motherboard, SmartBoard, Tindeq } from "./devices/index";
|
|
2
|
-
export { battery } from "./battery";
|
|
3
|
-
export { calibration } from "./calibration";
|
|
4
|
-
export { connect } from "./connect";
|
|
5
|
-
export { disconnect } from "./disconnect";
|
|
6
|
-
export { isConnected } from "./is-connected";
|
|
7
|
-
export { info } from "./info";
|
|
8
|
-
export { notify } from "./notify";
|
|
9
|
-
// export { read } from "./read"
|
|
10
|
-
export { stop } from "./stop";
|
|
11
|
-
export { stream } from "./stream";
|
|
12
|
-
// export { write } from "./write"
|
package/src/info.d.ts
DELETED
package/src/info.js
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { write } from "./write";
|
|
2
|
-
import { read } from "./read";
|
|
3
|
-
import { isConnected } from "./is-connected";
|
|
4
|
-
import { Motherboard, Tindeq } from "./devices";
|
|
5
|
-
import { MotherboardCommands, TindeqCommands } from "./commands";
|
|
6
|
-
/**
|
|
7
|
-
* Get device information
|
|
8
|
-
* @param board
|
|
9
|
-
*/
|
|
10
|
-
export const info = async (board) => {
|
|
11
|
-
if (isConnected(board)) {
|
|
12
|
-
if (board.name === "Motherboard") {
|
|
13
|
-
await read(Motherboard, "device", "manufacturer", 250);
|
|
14
|
-
await read(Motherboard, "device", "hardware", 250);
|
|
15
|
-
await read(Motherboard, "device", "firmware", 250);
|
|
16
|
-
await write(Motherboard, "uart", "tx", String(MotherboardCommands.GET_TEXT), 250);
|
|
17
|
-
await write(Motherboard, "uart", "tx", String(MotherboardCommands.GET_SERIAL), 250);
|
|
18
|
-
}
|
|
19
|
-
if (board.name === "Tindeq") {
|
|
20
|
-
await write(Tindeq, "progressor", "tx", String(TindeqCommands.GET_APP_VERSION), 250);
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
};
|
package/src/is-connected.d.ts
DELETED
package/src/is-connected.js
DELETED
package/src/notify.d.ts
DELETED
package/src/notify.js
DELETED
package/src/read.d.ts
DELETED
package/src/read.js
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import { notifyCallback } from "./notify";
|
|
2
|
-
import { getCharacteristic } from "./characteristic";
|
|
3
|
-
import { isConnected } from "./is-connected";
|
|
4
|
-
/**
|
|
5
|
-
* read
|
|
6
|
-
* @param characteristic
|
|
7
|
-
*/
|
|
8
|
-
export const read = (board, serviceId, characteristicId, duration = 0) => {
|
|
9
|
-
return new Promise((resolve, reject) => {
|
|
10
|
-
if (isConnected(board)) {
|
|
11
|
-
const characteristic = getCharacteristic(board, serviceId, characteristicId);
|
|
12
|
-
if (characteristic) {
|
|
13
|
-
characteristic
|
|
14
|
-
.readValue()
|
|
15
|
-
.then((value) => {
|
|
16
|
-
let decodedValue;
|
|
17
|
-
const decoder = new TextDecoder("utf-8");
|
|
18
|
-
switch (characteristicId) {
|
|
19
|
-
case "level":
|
|
20
|
-
decodedValue = value.getUint8(0);
|
|
21
|
-
break;
|
|
22
|
-
default:
|
|
23
|
-
decodedValue = decoder.decode(value);
|
|
24
|
-
break;
|
|
25
|
-
}
|
|
26
|
-
if (notifyCallback) {
|
|
27
|
-
notifyCallback({ uuid: characteristic.uuid, value: decodedValue });
|
|
28
|
-
}
|
|
29
|
-
setTimeout(() => {
|
|
30
|
-
resolve();
|
|
31
|
-
}, duration);
|
|
32
|
-
})
|
|
33
|
-
.catch((error) => {
|
|
34
|
-
reject(error);
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
|
-
else {
|
|
38
|
-
reject(new Error("Characteristic is undefined"));
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
else {
|
|
42
|
-
reject(new Error("Device is not connected"));
|
|
43
|
-
}
|
|
44
|
-
});
|
|
45
|
-
};
|