@psdk/device-ble-taro 0.3.2 → 0.3.4
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/build/connected.js +69 -86
- package/build/provider.js +216 -247
- package/package.json +4 -4
package/build/connected.js
CHANGED
|
@@ -1,12 +1,3 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
1
|
import { ConnectionState } from "@psdk/frame-father";
|
|
11
2
|
import Timeout from 'await-timeout';
|
|
12
3
|
import Taro from "@tarojs/taro";
|
|
@@ -24,12 +15,12 @@ export class TaroBleConnectedDevice {
|
|
|
24
15
|
doListen() {
|
|
25
16
|
if (this.scpair.read == null)
|
|
26
17
|
return;
|
|
27
|
-
Taro.onBLECharacteristicValueChange((value) =>
|
|
18
|
+
Taro.onBLECharacteristicValueChange(async (value) => {
|
|
28
19
|
// this.dataOfRead.push(value)
|
|
29
20
|
if (this.notifyCallback) {
|
|
30
|
-
|
|
21
|
+
await this.notifyCallback(value);
|
|
31
22
|
}
|
|
32
|
-
})
|
|
23
|
+
});
|
|
33
24
|
Taro.onBLEConnectionStateChange(value => {
|
|
34
25
|
this._connectionState = value.connected ? ConnectionState.CONNECTED : ConnectionState.DISCONNECTED;
|
|
35
26
|
});
|
|
@@ -43,27 +34,25 @@ export class TaroBleConnectedDevice {
|
|
|
43
34
|
fail: (e) => console.error(e),
|
|
44
35
|
});
|
|
45
36
|
}
|
|
46
|
-
realRead() {
|
|
47
|
-
return
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
fail: (e) => reject(e),
|
|
66
|
-
});
|
|
37
|
+
async realRead() {
|
|
38
|
+
return new Promise((resolve, reject) => {
|
|
39
|
+
if (this.scpair.read == null) {
|
|
40
|
+
reject(`the connect device not support read operation: service id: [${this.scpair.service.uuid}]`);
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
Taro.readBLECharacteristicValue({
|
|
44
|
+
deviceId: this.device.deviceId,
|
|
45
|
+
serviceId: this.scpair.service.uuid,
|
|
46
|
+
characteristicId: this.scpair.read.uuid,
|
|
47
|
+
success: result => {
|
|
48
|
+
if (result.errMsg.indexOf('ok') == -1) {
|
|
49
|
+
reject(result.errMsg);
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
resolve();
|
|
53
|
+
},
|
|
54
|
+
// @ts-ignore
|
|
55
|
+
fail: (e) => reject(e),
|
|
67
56
|
});
|
|
68
57
|
});
|
|
69
58
|
}
|
|
@@ -76,68 +65,62 @@ export class TaroBleConnectedDevice {
|
|
|
76
65
|
deviceName() {
|
|
77
66
|
return this.device.localName || this.device.name || 'NONE';
|
|
78
67
|
}
|
|
79
|
-
disconnect() {
|
|
80
|
-
return
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
fail: (e) => reject(e),
|
|
91
|
-
});
|
|
68
|
+
async disconnect() {
|
|
69
|
+
return new Promise((resolve, reject) => {
|
|
70
|
+
Taro.closeBLEConnection({
|
|
71
|
+
deviceId: this.device.deviceId,
|
|
72
|
+
success: () => {
|
|
73
|
+
this.device = null;
|
|
74
|
+
this.scpair = null;
|
|
75
|
+
resolve();
|
|
76
|
+
},
|
|
77
|
+
// @ts-ignore
|
|
78
|
+
fail: (e) => reject(e),
|
|
92
79
|
});
|
|
93
80
|
});
|
|
94
81
|
}
|
|
95
82
|
canRead() {
|
|
96
83
|
return this.scpair.read != null;
|
|
97
84
|
}
|
|
98
|
-
read(options) {
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
85
|
+
async read(options) {
|
|
86
|
+
var _a;
|
|
87
|
+
if (this.dataOfRead.length > 0) {
|
|
88
|
+
this.dataOfRead.splice(0, this.dataOfRead.length);
|
|
89
|
+
}
|
|
90
|
+
await this.realRead();
|
|
91
|
+
const timeout = ((_a = options === null || options === void 0 ? void 0 : options.timeout) !== null && _a !== void 0 ? _a : 5000);
|
|
92
|
+
const startTime = +new Date();
|
|
93
|
+
while (true) {
|
|
94
|
+
const now = +new Date();
|
|
95
|
+
if (now - startTime > timeout) {
|
|
96
|
+
return new Uint8Array([]);
|
|
103
97
|
}
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
while (true) {
|
|
108
|
-
const now = +new Date();
|
|
109
|
-
if (now - startTime > timeout) {
|
|
110
|
-
return new Uint8Array([]);
|
|
111
|
-
}
|
|
112
|
-
if (this.dataOfRead.length == 0) {
|
|
113
|
-
yield Timeout.set(100);
|
|
114
|
-
continue;
|
|
115
|
-
}
|
|
116
|
-
const data = this.dataOfRead.pop();
|
|
117
|
-
const value = data.value;
|
|
118
|
-
return new Uint8Array(value);
|
|
98
|
+
if (this.dataOfRead.length == 0) {
|
|
99
|
+
await Timeout.set(100);
|
|
100
|
+
continue;
|
|
119
101
|
}
|
|
120
|
-
|
|
102
|
+
const data = this.dataOfRead.pop();
|
|
103
|
+
const value = data.value;
|
|
104
|
+
return new Uint8Array(value);
|
|
105
|
+
}
|
|
121
106
|
}
|
|
122
|
-
write(data) {
|
|
123
|
-
return
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
fail: (e) => reject(e)
|
|
140
|
-
});
|
|
107
|
+
async write(data) {
|
|
108
|
+
return new Promise((resolve, reject) => {
|
|
109
|
+
Taro.writeBLECharacteristicValue({
|
|
110
|
+
deviceId: this.device.deviceId,
|
|
111
|
+
serviceId: this.scpair.service.uuid,
|
|
112
|
+
characteristicId: this.scpair.write.uuid,
|
|
113
|
+
// @ts-ignore
|
|
114
|
+
value: data.buffer,
|
|
115
|
+
success: result => {
|
|
116
|
+
if (result.errMsg.indexOf('ok') == -1) {
|
|
117
|
+
reject(result.errMsg);
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
resolve();
|
|
121
|
+
},
|
|
122
|
+
// @ts-ignore
|
|
123
|
+
fail: (e) => reject(e)
|
|
141
124
|
});
|
|
142
125
|
});
|
|
143
126
|
}
|
package/build/provider.js
CHANGED
|
@@ -1,12 +1,3 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
1
|
import { Jluetooth, JluetoothDevice, TBluetoothHelpers, } from "@psdk/device-bluetooth-traits";
|
|
11
2
|
import { ConnectionState } from "@psdk/frame-father";
|
|
12
3
|
import Timeout from 'await-timeout';
|
|
@@ -23,123 +14,111 @@ export class TaroBleBluetooth extends Jluetooth {
|
|
|
23
14
|
return false;
|
|
24
15
|
return this.connectedDevice.connectionState() === ConnectionState.CONNECTED;
|
|
25
16
|
}
|
|
26
|
-
bluetoothAdapterState() {
|
|
27
|
-
return
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
fail: (e) => reject(e)
|
|
33
|
-
});
|
|
17
|
+
async bluetoothAdapterState() {
|
|
18
|
+
return new Promise((resolve, reject) => {
|
|
19
|
+
Taro.getBluetoothAdapterState({
|
|
20
|
+
success: (r) => resolve(r),
|
|
21
|
+
// @ts-ignore
|
|
22
|
+
fail: (e) => reject(e)
|
|
34
23
|
});
|
|
35
24
|
});
|
|
36
25
|
}
|
|
37
|
-
connect(device, options) {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
if (
|
|
41
|
-
|
|
42
|
-
return this.connectedDevice;
|
|
43
|
-
}
|
|
44
|
-
yield this.connectedDevice.disconnect();
|
|
45
|
-
}
|
|
46
|
-
const origin = device.origin;
|
|
47
|
-
yield this.createBLEConnection({ deviceId: origin.deviceId, timeout: options === null || options === void 0 ? void 0 : options.timeout, });
|
|
48
|
-
yield Timeout.set(500);
|
|
49
|
-
const services = yield this.getBLEDeviceServices({ deviceId: origin.deviceId });
|
|
50
|
-
const scpair = yield this.findSCPair({
|
|
51
|
-
deviceId: origin.deviceId,
|
|
52
|
-
services,
|
|
53
|
-
});
|
|
54
|
-
if (!scpair) {
|
|
55
|
-
return Promise.reject(`Can not get write characteristic by device: ${device.name}`);
|
|
26
|
+
async connect(device, options) {
|
|
27
|
+
var _a;
|
|
28
|
+
if (this.isConnected()) {
|
|
29
|
+
if (!((_a = options === null || options === void 0 ? void 0 : options.autoSwitchDevice) !== null && _a !== void 0 ? _a : false)) {
|
|
30
|
+
return this.connectedDevice;
|
|
56
31
|
}
|
|
57
|
-
this.connectedDevice
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
32
|
+
await this.connectedDevice.disconnect();
|
|
33
|
+
}
|
|
34
|
+
const origin = device.origin;
|
|
35
|
+
await this.createBLEConnection({ deviceId: origin.deviceId, timeout: options === null || options === void 0 ? void 0 : options.timeout, });
|
|
36
|
+
await Timeout.set(500);
|
|
37
|
+
const services = await this.getBLEDeviceServices({ deviceId: origin.deviceId });
|
|
38
|
+
const scpair = await this.findSCPair({
|
|
39
|
+
deviceId: origin.deviceId,
|
|
40
|
+
services,
|
|
63
41
|
});
|
|
42
|
+
if (!scpair) {
|
|
43
|
+
return Promise.reject(`Can not get write characteristic by device: ${device.name}`);
|
|
44
|
+
}
|
|
45
|
+
this.connectedDevice = new TaroBleConnectedDevice({
|
|
46
|
+
device: origin,
|
|
47
|
+
scpair,
|
|
48
|
+
});
|
|
49
|
+
await this.stopDiscovery();
|
|
50
|
+
return Promise.resolve(this.connectedDevice);
|
|
64
51
|
}
|
|
65
52
|
discovered(callback) {
|
|
66
53
|
this.discoveredCallback = callback;
|
|
67
54
|
}
|
|
68
|
-
startDiscovery() {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
// complete: () => resolve(),
|
|
91
|
-
});
|
|
55
|
+
async startDiscovery() {
|
|
56
|
+
await this.requestLocation();
|
|
57
|
+
await this.closeBluetoothAdapter();
|
|
58
|
+
await Timeout.set(300);
|
|
59
|
+
await this.openBluetoothAdapter();
|
|
60
|
+
const state = await this.bluetoothAdapterState();
|
|
61
|
+
if (!state.available) {
|
|
62
|
+
await Timeout.set(500);
|
|
63
|
+
}
|
|
64
|
+
if (state.discovering) {
|
|
65
|
+
await this.stopDiscovery();
|
|
66
|
+
await Timeout.set(500);
|
|
67
|
+
}
|
|
68
|
+
return new Promise((resolve, reject) => {
|
|
69
|
+
Taro.startBluetoothDevicesDiscovery({
|
|
70
|
+
// services: this.allowServices,
|
|
71
|
+
allowDuplicatesKey: false,
|
|
72
|
+
interval: 0,
|
|
73
|
+
success: () => resolve(),
|
|
74
|
+
// @ts-ignore
|
|
75
|
+
fail: (e) => reject(e),
|
|
76
|
+
// complete: () => resolve(),
|
|
92
77
|
});
|
|
93
78
|
});
|
|
94
79
|
}
|
|
95
|
-
stopDiscovery() {
|
|
96
|
-
return
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
fail: (e) => reject(e),
|
|
102
|
-
});
|
|
80
|
+
async stopDiscovery() {
|
|
81
|
+
return new Promise((resolve, reject) => {
|
|
82
|
+
Taro.stopBluetoothDevicesDiscovery({
|
|
83
|
+
success: (result) => resolve(result),
|
|
84
|
+
// @ts-ignore
|
|
85
|
+
fail: (e) => reject(e),
|
|
103
86
|
});
|
|
104
87
|
});
|
|
105
88
|
}
|
|
106
89
|
// ### inner function
|
|
107
|
-
openBluetoothAdapter() {
|
|
108
|
-
return
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
fail: (e) => reject(e)
|
|
120
|
-
});
|
|
90
|
+
async openBluetoothAdapter() {
|
|
91
|
+
return new Promise((resolve, reject) => {
|
|
92
|
+
Taro.openBluetoothAdapter({
|
|
93
|
+
success: (ret) => {
|
|
94
|
+
if (ret.errMsg && ret.errMsg.indexOf('ok') == -1) {
|
|
95
|
+
reject(ret);
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
resolve();
|
|
99
|
+
},
|
|
100
|
+
// @ts-ignore
|
|
101
|
+
fail: (e) => reject(e)
|
|
121
102
|
});
|
|
122
103
|
});
|
|
123
104
|
}
|
|
124
|
-
closeBluetoothAdapter() {
|
|
125
|
-
return
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
fail: (e) => reject(e)
|
|
137
|
-
});
|
|
105
|
+
async closeBluetoothAdapter() {
|
|
106
|
+
return new Promise((resolve, reject) => {
|
|
107
|
+
Taro.closeBluetoothAdapter({
|
|
108
|
+
success: (ret) => {
|
|
109
|
+
if (ret.errMsg && ret.errMsg.indexOf('ok') == -1) {
|
|
110
|
+
reject(ret);
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
resolve();
|
|
114
|
+
},
|
|
115
|
+
// @ts-ignore
|
|
116
|
+
fail: (e) => reject(e)
|
|
138
117
|
});
|
|
139
118
|
});
|
|
140
119
|
}
|
|
141
120
|
onBluetoothDeviceFound() {
|
|
142
|
-
Taro.onBluetoothDeviceFound((result) =>
|
|
121
|
+
Taro.onBluetoothDeviceFound(async (result) => {
|
|
143
122
|
const foundDevices = result.devices;
|
|
144
123
|
if (!foundDevices.length) {
|
|
145
124
|
return;
|
|
@@ -161,183 +140,173 @@ export class TaroBleBluetooth extends Jluetooth {
|
|
|
161
140
|
return;
|
|
162
141
|
}
|
|
163
142
|
if (this.discoveredCallback) {
|
|
164
|
-
|
|
143
|
+
await this.discoveredCallback(devices);
|
|
165
144
|
}
|
|
166
|
-
})
|
|
145
|
+
});
|
|
167
146
|
}
|
|
168
|
-
createBLEConnection(options) {
|
|
169
|
-
return
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
fail: (e) => reject(e),
|
|
177
|
-
});
|
|
147
|
+
async createBLEConnection(options) {
|
|
148
|
+
return new Promise((resolve, reject) => {
|
|
149
|
+
Taro.createBLEConnection({
|
|
150
|
+
deviceId: options.deviceId,
|
|
151
|
+
timeout: options.timeout,
|
|
152
|
+
success: () => resolve(),
|
|
153
|
+
// @ts-ignore
|
|
154
|
+
fail: (e) => reject(e),
|
|
178
155
|
});
|
|
179
156
|
});
|
|
180
157
|
}
|
|
181
|
-
getBLEDeviceServices(options) {
|
|
182
|
-
return
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
fail: (e) => reject(e),
|
|
195
|
-
});
|
|
158
|
+
async getBLEDeviceServices(options) {
|
|
159
|
+
return new Promise((resolve, reject) => {
|
|
160
|
+
Taro.getBLEDeviceServices({
|
|
161
|
+
deviceId: options.deviceId,
|
|
162
|
+
success: (result) => {
|
|
163
|
+
if (result.errMsg.indexOf('ok') == -1) {
|
|
164
|
+
reject(result.errMsg);
|
|
165
|
+
return;
|
|
166
|
+
}
|
|
167
|
+
resolve(result.services);
|
|
168
|
+
},
|
|
169
|
+
// @ts-ignore
|
|
170
|
+
fail: (e) => reject(e),
|
|
196
171
|
});
|
|
197
172
|
});
|
|
198
173
|
}
|
|
199
|
-
getBLEDeviceCharacteristics(options) {
|
|
200
|
-
return
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
fail: (e) => reject(e),
|
|
214
|
-
});
|
|
174
|
+
async getBLEDeviceCharacteristics(options) {
|
|
175
|
+
return new Promise((resolve, reject) => {
|
|
176
|
+
Taro.getBLEDeviceCharacteristics({
|
|
177
|
+
deviceId: options.deviceId,
|
|
178
|
+
serviceId: options.serviceId,
|
|
179
|
+
success: (result) => {
|
|
180
|
+
if (result.errMsg.indexOf('ok') == -1) {
|
|
181
|
+
reject(result.errMsg);
|
|
182
|
+
return;
|
|
183
|
+
}
|
|
184
|
+
resolve(result.characteristics);
|
|
185
|
+
},
|
|
186
|
+
// @ts-ignore
|
|
187
|
+
fail: (e) => reject(e),
|
|
215
188
|
});
|
|
216
189
|
});
|
|
217
190
|
}
|
|
218
|
-
requestLocation() {
|
|
219
|
-
return
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
fail: (e) => reject(e),
|
|
231
|
-
});
|
|
191
|
+
async requestLocation() {
|
|
192
|
+
return new Promise((resolve, reject) => {
|
|
193
|
+
// Taro.authorize({
|
|
194
|
+
// scope: 'scope.userLocation',
|
|
195
|
+
// success: () => resolve(),
|
|
196
|
+
// // @ts-ignore
|
|
197
|
+
// fail: (e) => reject(e),
|
|
198
|
+
// });
|
|
199
|
+
Taro.getLocation({
|
|
200
|
+
success: () => resolve(),
|
|
201
|
+
// @ts-ignore
|
|
202
|
+
fail: (e) => reject(e),
|
|
232
203
|
});
|
|
233
204
|
});
|
|
234
205
|
}
|
|
235
|
-
findSCPair(options) {
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
206
|
+
async findSCPair(options) {
|
|
207
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
|
|
208
|
+
// fill data
|
|
209
|
+
const _characteristicsMap = new Map();
|
|
210
|
+
for (const service of options.services) {
|
|
211
|
+
const characteristics = await this.getBLEDeviceCharacteristics({
|
|
212
|
+
deviceId: options.deviceId,
|
|
213
|
+
serviceId: service.uuid,
|
|
214
|
+
});
|
|
215
|
+
_characteristicsMap.set(service.uuid, characteristics);
|
|
216
|
+
}
|
|
217
|
+
// use special first
|
|
218
|
+
if (((_a = this.options) === null || _a === void 0 ? void 0 : _a.allowedWriteCharacteristic) && ((_b = this.options) === null || _b === void 0 ? void 0 : _b.allowedReadCharacteristic)) {
|
|
240
219
|
for (const service of options.services) {
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
if (!TBluetoothHelpers.isAllowServices(service.uuid, (_c = this.options) === null || _c === void 0 ? void 0 : _c.allowServices)) {
|
|
251
|
-
continue;
|
|
252
|
-
}
|
|
253
|
-
const characteristics = _characteristicsMap.get(service.uuid);
|
|
254
|
-
let writeCharacteristic = null;
|
|
255
|
-
let readCharacteristic = null;
|
|
256
|
-
for (const characteristic of characteristics) {
|
|
257
|
-
if (((_d = this.options) === null || _d === void 0 ? void 0 : _d.allowedWriteCharacteristic.toLowerCase()) == characteristic.uuid.toLowerCase()) {
|
|
258
|
-
writeCharacteristic = characteristic;
|
|
259
|
-
}
|
|
260
|
-
}
|
|
261
|
-
for (const characteristic of characteristics) {
|
|
262
|
-
if (((_e = this.options) === null || _e === void 0 ? void 0 : _e.allowedReadCharacteristic.toLowerCase()) == characteristic.uuid.toLowerCase()) {
|
|
263
|
-
readCharacteristic = characteristic;
|
|
264
|
-
}
|
|
220
|
+
if (!TBluetoothHelpers.isAllowServices(service.uuid, (_c = this.options) === null || _c === void 0 ? void 0 : _c.allowServices)) {
|
|
221
|
+
continue;
|
|
222
|
+
}
|
|
223
|
+
const characteristics = _characteristicsMap.get(service.uuid);
|
|
224
|
+
let writeCharacteristic = null;
|
|
225
|
+
let readCharacteristic = null;
|
|
226
|
+
for (const characteristic of characteristics) {
|
|
227
|
+
if (((_d = this.options) === null || _d === void 0 ? void 0 : _d.allowedWriteCharacteristic.toLowerCase()) == characteristic.uuid.toLowerCase()) {
|
|
228
|
+
writeCharacteristic = characteristic;
|
|
265
229
|
}
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
read: readCharacteristic,
|
|
271
|
-
};
|
|
230
|
+
}
|
|
231
|
+
for (const characteristic of characteristics) {
|
|
232
|
+
if (((_e = this.options) === null || _e === void 0 ? void 0 : _e.allowedReadCharacteristic.toLowerCase()) == characteristic.uuid.toLowerCase()) {
|
|
233
|
+
readCharacteristic = characteristic;
|
|
272
234
|
}
|
|
273
235
|
}
|
|
236
|
+
if (writeCharacteristic != null && readCharacteristic != null) {
|
|
237
|
+
return {
|
|
238
|
+
service,
|
|
239
|
+
write: writeCharacteristic,
|
|
240
|
+
read: readCharacteristic,
|
|
241
|
+
};
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
// choose best characteristic
|
|
246
|
+
for (const service of options.services) {
|
|
247
|
+
if (!TBluetoothHelpers.isAllowServices(service.uuid, (_f = this.options) === null || _f === void 0 ? void 0 : _f.allowServices)) {
|
|
248
|
+
continue;
|
|
274
249
|
}
|
|
275
|
-
|
|
250
|
+
const characteristics = _characteristicsMap.get(service.uuid);
|
|
251
|
+
// let readCharacteristic: GetBLEDeviceCharacteristicsSuccessData;
|
|
252
|
+
// let writeCharacteristic: GetBLEDeviceCharacteristicsSuccessData;
|
|
253
|
+
const pickedCharacteristic = characteristics.find(characteristic => {
|
|
254
|
+
const properties = characteristic.properties;
|
|
255
|
+
// @ts-ignore
|
|
256
|
+
return properties.write && (properties.notify);
|
|
257
|
+
});
|
|
258
|
+
if (pickedCharacteristic) {
|
|
259
|
+
return {
|
|
260
|
+
service,
|
|
261
|
+
write: pickedCharacteristic,
|
|
262
|
+
read: pickedCharacteristic,
|
|
263
|
+
};
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
if ((_h = (_g = this.options) === null || _g === void 0 ? void 0 : _g.allowDetectDifferentCharacteristic) !== null && _h !== void 0 ? _h : true) {
|
|
267
|
+
// choose different characteristic with write and read properties
|
|
276
268
|
for (const service of options.services) {
|
|
277
|
-
if (!TBluetoothHelpers.isAllowServices(service.uuid, (
|
|
269
|
+
if (!TBluetoothHelpers.isAllowServices(service.uuid, (_j = this.options) === null || _j === void 0 ? void 0 : _j.allowServices)) {
|
|
278
270
|
continue;
|
|
279
271
|
}
|
|
280
272
|
const characteristics = _characteristicsMap.get(service.uuid);
|
|
281
|
-
|
|
282
|
-
// let writeCharacteristic: GetBLEDeviceCharacteristicsSuccessData;
|
|
283
|
-
const pickedCharacteristic = characteristics.find(characteristic => {
|
|
273
|
+
const writeCharacteristic = characteristics.find(characteristic => {
|
|
284
274
|
const properties = characteristic.properties;
|
|
285
275
|
// @ts-ignore
|
|
286
|
-
return properties.write
|
|
276
|
+
return properties.write;
|
|
277
|
+
});
|
|
278
|
+
const readCharacteristic = characteristics.find(characteristic => {
|
|
279
|
+
const properties = characteristic.properties;
|
|
280
|
+
return (properties.notify);
|
|
287
281
|
});
|
|
288
|
-
if (
|
|
282
|
+
if (writeCharacteristic && readCharacteristic) {
|
|
289
283
|
return {
|
|
290
284
|
service,
|
|
291
|
-
write:
|
|
292
|
-
read:
|
|
285
|
+
write: writeCharacteristic,
|
|
286
|
+
read: readCharacteristic,
|
|
293
287
|
};
|
|
294
288
|
}
|
|
295
289
|
}
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
const characteristics = _characteristicsMap.get(service.uuid);
|
|
303
|
-
const writeCharacteristic = characteristics.find(characteristic => {
|
|
304
|
-
const properties = characteristic.properties;
|
|
305
|
-
// @ts-ignore
|
|
306
|
-
return properties.write;
|
|
307
|
-
});
|
|
308
|
-
const readCharacteristic = characteristics.find(characteristic => {
|
|
309
|
-
const properties = characteristic.properties;
|
|
310
|
-
return (properties.notify);
|
|
311
|
-
});
|
|
312
|
-
if (writeCharacteristic && readCharacteristic) {
|
|
313
|
-
return {
|
|
314
|
-
service,
|
|
315
|
-
write: writeCharacteristic,
|
|
316
|
-
read: readCharacteristic,
|
|
317
|
-
};
|
|
318
|
-
}
|
|
290
|
+
}
|
|
291
|
+
else {
|
|
292
|
+
// only write
|
|
293
|
+
for (const service of options.services) {
|
|
294
|
+
if (!TBluetoothHelpers.isAllowServices(service.uuid, (_k = this.options) === null || _k === void 0 ? void 0 : _k.allowServices)) {
|
|
295
|
+
continue;
|
|
319
296
|
}
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
return properties.write;
|
|
332
|
-
});
|
|
333
|
-
if (writeCharacteristic) {
|
|
334
|
-
return {
|
|
335
|
-
service,
|
|
336
|
-
write: writeCharacteristic,
|
|
337
|
-
};
|
|
338
|
-
}
|
|
297
|
+
const characteristics = _characteristicsMap.get(service.uuid);
|
|
298
|
+
const writeCharacteristic = characteristics.find(characteristic => {
|
|
299
|
+
const properties = characteristic.properties;
|
|
300
|
+
// @ts-ignore
|
|
301
|
+
return properties.write;
|
|
302
|
+
});
|
|
303
|
+
if (writeCharacteristic) {
|
|
304
|
+
return {
|
|
305
|
+
service,
|
|
306
|
+
write: writeCharacteristic,
|
|
307
|
+
};
|
|
339
308
|
}
|
|
340
309
|
}
|
|
341
|
-
}
|
|
310
|
+
}
|
|
342
311
|
}
|
|
343
312
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@psdk/device-ble-taro",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.4",
|
|
4
4
|
"description": "psdk",
|
|
5
5
|
"main": "build/index.js",
|
|
6
6
|
"types": "build/index.d.ts",
|
|
@@ -27,13 +27,13 @@
|
|
|
27
27
|
"typescript": "^5.4.5"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@psdk/device-bluetooth-traits": "0.3.
|
|
31
|
-
"@psdk/frame-father": "0.3.
|
|
30
|
+
"@psdk/device-bluetooth-traits": "0.3.4",
|
|
31
|
+
"@psdk/frame-father": "0.3.4",
|
|
32
32
|
"await-timeout": "^1.1.1"
|
|
33
33
|
},
|
|
34
34
|
"files": [
|
|
35
35
|
"build",
|
|
36
36
|
"!build/browser/psdk*"
|
|
37
37
|
],
|
|
38
|
-
"gitHead": "
|
|
38
|
+
"gitHead": "b8c2fdcb52f1bd3e9d75d004d37d717bd465b4c9"
|
|
39
39
|
}
|