ble_manager.js 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765
  1. // 引入必要的微信小程序 API
  2. // const wx = require('wx');
  3. class bleManager {
  4. constructor() {
  5. var that = this;
  6. that.isAvailable = false;
  7. that.hasPermission = false;
  8. that.scanDevices = [];
  9. that.publicDevice = null;
  10. that.compareList = [];
  11. that.connectWillDevice = null;
  12. that.callBackConnect = null;
  13. that.requestBlueTime = 0;
  14. ///正在执行扫描中
  15. that.doStartScaning = false;
  16. that.dissmissDevice = [];
  17. }
  18. ///获取比较的数据
  19. getCompareList() {
  20. return this.compareList;
  21. }
  22. setCompareList(compareList) {
  23. this.compareList = compareList;
  24. }
  25. getDissmissDevice() {
  26. return this.dissmissDevice;
  27. }
  28. setConnectWillDevice(connectWillDevice) {
  29. this.connectWillDevice = connectWillDevice;
  30. }
  31. getCallBackConnect() {
  32. return this.callBackConnect;
  33. }
  34. setCallBackConnect(callBackConnect) {
  35. this.callBackConnect = callBackConnect;
  36. }
  37. /// 监控蓝牙打开状态
  38. initBluetoothAdapter() {
  39. var that = this;
  40. // wx.openBluetoothAdapter({
  41. // success: (res) => {
  42. // that.isAvailable = true;
  43. // },
  44. // fail: (err) => {
  45. // that.isAvailable = false;
  46. // }
  47. // });
  48. wx.onBluetoothAdapterStateChange(function (res) {
  49. that.isAvailable = res.available;
  50. })
  51. }
  52. ///监听搜索设备列表
  53. getBluetoothDevices() {
  54. var that = this;
  55. wx.onBluetoothDeviceFound(function (res) {
  56. ///第一种情况
  57. if (res.deviceId) {
  58. if (that.callBackConnect != null) {
  59. if (that.connectWillDevice != null && res.name == that.connectWillDevice.clientType) {
  60. res.mac = res.advertisData ? that.buf2hex(res.advertisData) : '';
  61. if (that.callBackConnect != null) {
  62. that.callBackConnect(res);
  63. }
  64. }
  65. } else {
  66. if (res.name != "") {
  67. if (that.compareList.length > 0) {
  68. var has = false;
  69. for (var i = 0; i < that.compareList.length; i++) {
  70. if (res.deviceId == that.compareList[i].deviceId) {
  71. has = true;
  72. break;
  73. }
  74. }
  75. if (!has) {
  76. that.compareList.push(res);
  77. }
  78. } else {
  79. that.compareList.push(res);
  80. }
  81. }
  82. }
  83. }
  84. ///第二种情况
  85. else if (res.devices) {
  86. if (that.callBackConnect != null) {
  87. for (var i = 0; i < res.devices.length; i++) {
  88. var temp = res.devices[i];
  89. // if (temp.name == "MW-SR1(4G_WIFI)") {
  90. // console.log("gadsfqewrqewrqwerqrqr==111==" + JSON.stringify(res.devices[i]));
  91. // }
  92. if (that.connectWillDevice != null && temp.name == that.connectWillDevice.clientType) {
  93. temp.mac = temp.advertisData ? that.buf2hex(temp.advertisData) : '';
  94. if (that.callBackConnect != null) {
  95. that.callBackConnect(temp);
  96. }
  97. break;
  98. }
  99. }
  100. } else {
  101. for (var i = 0; i < res.devices.length; i++) {
  102. if (that.compareList.length > 0) {
  103. var has = false;
  104. for (var j = 0; j < that.compareList.length; j++) {
  105. if (res.devices[i].name != "") {
  106. if (res.devices[i].deviceId == that.compareList[j].deviceId) {
  107. has = true;
  108. break;
  109. }
  110. }
  111. }
  112. if (!has) {
  113. that.compareList.push(res.devices[i]);
  114. }
  115. } else {
  116. that.compareList.push(res.devices[i]);
  117. }
  118. }
  119. }
  120. }
  121. ///第三种情况
  122. else if (res[0]) {
  123. if (that.callBackConnect != null) {
  124. if (that.connectWillDevice != null && res[0].name == that.connectWillDevice.clientType) {
  125. res[0].mac = res[0].advertisData ? that.buf2hex(res[0].advertisData) : '';
  126. if (that.callBackConnect != null) {
  127. that.callBackConnect(res[0]);
  128. }
  129. }
  130. } else {
  131. if (res[0].name != "") {
  132. if (that.compareList.length > 0) {
  133. var has = false;
  134. for (var i = 0; i < that.compareList.length; i++) {
  135. if (res[0].deviceId == that.compareList[i].deviceId) {
  136. has = true;
  137. break;
  138. }
  139. }
  140. if (!has) {
  141. that.compareList.push(res[0]);
  142. }
  143. } else {
  144. that.compareList.push(res[0]);
  145. }
  146. }
  147. }
  148. }
  149. });
  150. ///监听已连接或没有连接
  151. // {"deviceId":"E4:9F:80:09:40:EC","connected":false}
  152. wx.onBLEConnectionStateChange((result) => {
  153. if (result.connected) {
  154. for (var i = 0; i < that.dissmissDevice.length; i++) {
  155. if (result.deviceId == that.dissmissDevice[i].deviceId) {
  156. that.dissmissDevice.splice(i, 1);
  157. break;
  158. }
  159. }
  160. } else {
  161. var has = false;
  162. for (var i = 0; i < that.dissmissDevice.length; i++) {
  163. if (result.deviceId == that.dissmissDevice[i].deviceId) {
  164. has = true;
  165. break;
  166. }
  167. }
  168. if (!has) {
  169. that.dissmissDevice.push(result);
  170. }
  171. }
  172. // ///是否已配对
  173. // wx.isBluetoothDevicePaired({
  174. // deviceId: result.deviceId,
  175. // ///{"isPaired":false,"errno":0,"errMsg":"isBluetoothDevicePaired:ok"}
  176. // success: (res) => {
  177. // console.log("gasdfqwerqwerqr==00===" + JSON.stringify(res) + "===" + JSON.stringify(result));
  178. // },
  179. // fail: (err) => {
  180. // console.log("gasdfqwerqwerqr==111===" + JSON.stringify(err));
  181. // }
  182. // })
  183. });
  184. }
  185. ///获取 所有搜索到的蓝牙设备
  186. getConnectedDevices() {
  187. var that = this;
  188. wx.getBluetoothDevices({
  189. success: (res) => {
  190. if (that.callBackConnect != null) {
  191. for (var i = 0; i < res.devices.length; i++) {
  192. var temp = res.devices[i];
  193. if (that.connectWillDevice != null && temp.name == that.connectWillDevice.clientType) {
  194. temp.mac = temp.advertisData ? that.buf2hex(temp.advertisData) : '';
  195. if (that.callBackConnect != null) {
  196. that.callBackConnect(temp);
  197. }
  198. break;
  199. }
  200. }
  201. } else {
  202. for (var i = 0; i < res.devices.length; i++) {
  203. if (that.compareList.length > 0) {
  204. var has = false;
  205. for (var j = 0; j < that.compareList.length; j++) {
  206. if (res.devices[i].name != "") {
  207. // if (res.devices[i].name == "MW-SR1(4G_WIFI)") {
  208. // console.log("gadsfqewrqewrqwerqrqr==000==" + JSON.stringify(res.devices[i]));
  209. // }
  210. if (res.devices[i].deviceId == that.compareList[j].deviceId) {
  211. has = true;
  212. break;
  213. }
  214. }
  215. }
  216. if (!has) {
  217. that.compareList.push(res.devices[i]);
  218. }
  219. } else {
  220. that.compareList.push(res.devices[i]);
  221. }
  222. }
  223. }
  224. },
  225. fail: (err) => {
  226. console.error('获取蓝牙设备列表失败', err);
  227. }
  228. });
  229. }
  230. ///获取 已连接的蓝牙设备
  231. getConnectedBluetoothDevices() {
  232. // [{"deviceId":"E4:9F:80:09:40:EC","name":"MW-SR1(4G_WIFI)"}]
  233. // wx.getConnectedBluetoothDevices({
  234. // success: (res) => {
  235. // console.log("时代发生的法==33==" + JSON.stringify(res));
  236. // if (res.devices.length > 0) {
  237. // console.log("时代发生的法==22==" + JSON.stringify(res.devices));
  238. // for (var i = 0; i < res.devices.length; i++) {
  239. // console.log("时代发生的法==11==" + JSON.stringify(res.devices[i]));
  240. // if (res.devices[i].name == "MW-SR1(4G_WIFI)") {
  241. // console.log("gasdfqwerqwerqdfasdfr==11==" + JSON.stringify(res.devices[i]));
  242. // }
  243. // }
  244. // } else {
  245. // }
  246. // },
  247. // fail: (err) => {}
  248. // });
  249. }
  250. ///获取数据
  251. buf2hex(buffer) {
  252. return Array.prototype.map.call(new Uint8Array(buffer), x => ('00' + x.toString(16)).slice(-2)).join('');
  253. }
  254. ///获取毫秒
  255. getCurrentMills() {
  256. var currentDate = new Date();
  257. var currentTimeMillis = currentDate.getTime();
  258. // return Math.floor(currentTimeMillis / 1000);
  259. return currentTimeMillis;
  260. }
  261. // 等待多少秒
  262. delay(ms) {
  263. return new Promise(resolve => setTimeout(resolve, ms));
  264. }
  265. // 开始搜索蓝牙设备
  266. async startScan(connectWillDevice, boolean, callBackConnect) {
  267. var that = this;
  268. const route_util = require('../utils/route_util');
  269. const route_constant = require('../utils/route_constant');
  270. const indexRoot = route_constant.indexRoot;
  271. const connectBleRoot = route_constant.connectBleRoot;
  272. var lastPageRoute = route_util.getLastPageRoute();
  273. if (lastPageRoute != indexRoot && lastPageRoute != connectBleRoot) {
  274. return;
  275. }
  276. ///蓝牙连接 做限制
  277. if (lastPageRoute == indexRoot) {
  278. if (that.doStartScaning == true) {
  279. return;
  280. }
  281. }
  282. that.doStartScaning = true;
  283. var currentMill = that.getCurrentMills();
  284. var waitMills = 0;
  285. var reduce = currentMill - that.requestBlueTime;
  286. const delayMiliis = 6 * 1000;
  287. if (reduce > 0 && reduce < delayMiliis) {
  288. waitMills = delayMiliis - reduce;
  289. }
  290. if (waitMills > 0) {
  291. await that.delay(waitMills);
  292. }
  293. if (callBackConnect == null && lastPageRoute == connectBleRoot) {
  294. that.doStartScaning = false;
  295. return;
  296. }
  297. wx.openBluetoothAdapter({
  298. success: function (res) {
  299. wx.stopBluetoothDevicesDiscovery({
  300. success: (res) => {
  301. that.search(connectWillDevice, boolean, callBackConnect);
  302. },
  303. fail: (err) => {
  304. that.doStartScaning = false;
  305. that.requestBlueTime = that.getCurrentMills();
  306. if (boolean != null) {
  307. boolean(false);
  308. }
  309. }
  310. });
  311. },
  312. fail: function (res) {
  313. // wx.showModal({
  314. // title: '提示',
  315. // content: '请检查手机蓝牙是否打开',
  316. // showCancel: false,
  317. // success: function (res) {}
  318. // });
  319. that.doStartScaning = false;
  320. that.requestBlueTime = that.getCurrentMills();
  321. if (boolean != null) {
  322. boolean(false);
  323. }
  324. }
  325. })
  326. }
  327. search(connectWillDevice, boolean, callBackConnect) {
  328. var that = this;
  329. wx.startBluetoothDevicesDiscovery({
  330. allowDuplicatesKey: true,
  331. success: function (res) {
  332. that.getConnectedDevices();
  333. that.getConnectedBluetoothDevices();
  334. that.doStartScaning = false;
  335. that.requestBlueTime = that.getCurrentMills();
  336. if (boolean != null) {
  337. boolean(true);
  338. }
  339. that.setConnectWillDevice(connectWillDevice);
  340. that.setCallBackConnect(callBackConnect);
  341. that.compareList = [];
  342. },
  343. fail(err) {
  344. that.doStartScaning = false;
  345. that.requestBlueTime = that.getCurrentMills();
  346. if (boolean != null) {
  347. boolean(false);
  348. }
  349. },
  350. })
  351. }
  352. // 停止搜索
  353. stopSearch() {
  354. var that = this;
  355. that.setCallBackConnect(null);
  356. that.setConnectWillDevice(null);
  357. return new Promise((resolve, reject) => {
  358. wx.stopBluetoothDevicesDiscovery({
  359. success: (res) => {
  360. resolve(res);
  361. },
  362. fail: (err) => {
  363. reject('停止搜索失败');
  364. }
  365. });
  366. });
  367. }
  368. closeBle() {
  369. console.log('关闭蓝牙了')
  370. closeBluetoothAdapter();
  371. }
  372. // 断开与指定设备的连接
  373. disconnect(mDevice) {
  374. var that = this;
  375. const strings = require('../utils/strings');
  376. let device = that.publicDevice;
  377. if (mDevice != null) {
  378. device = mDevice;
  379. }
  380. if (strings.isEmpty(device)) {
  381. return;
  382. }
  383. let deviceId = device.deviceId
  384. if (strings.isEmpty(deviceId)) {
  385. return;
  386. }
  387. return new Promise((resolve, reject) => {
  388. wx.getConnectedBluetoothDevices({
  389. success: (res) => {
  390. if (res.devices.length > 0) {
  391. wx.closeBLEConnection({
  392. deviceId: deviceId,
  393. success: (res) => {
  394. that.publicDevice = null;
  395. resolve(res);
  396. },
  397. fail: (err) => {
  398. resolve(err);
  399. }
  400. });
  401. } else {
  402. resolve("暂无连接设备");
  403. }
  404. },
  405. fail: (err) => {
  406. resolve(err);
  407. }
  408. });
  409. });
  410. }
  411. // 连接到指定设备
  412. async connectToDevice(device) {
  413. var that = this;
  414. return new Promise((resolve, reject) => {
  415. console.log("开始连接蓝牙:", device.deviceId)
  416. wx.createBLEConnection({
  417. deviceId: device.deviceId,
  418. success: (res) => {
  419. that.publicDevice = device
  420. console.log('连接成功:', res);
  421. resolve(true);
  422. },
  423. fail: (err) => {
  424. that.publicDevice = null
  425. console.error('连接失败:', err);
  426. resolve(false);
  427. }
  428. });
  429. });
  430. }
  431. // 发送数据到指定设备
  432. async sendData(data, callback) {
  433. var that = this
  434. return new Promise((resolve, reject) => {
  435. var buffer = null;
  436. // todo 判断是否是buffer
  437. // if (Buffer.isBuffer(data)) {
  438. // buffer = data;
  439. // } else {
  440. buffer = new ArrayBuffer(data.length);
  441. // 下面是赋值,不能删
  442. const dataView = new DataView(buffer);
  443. data.forEach((value, index) => {
  444. dataView.setUint8(index, value); // 将每个16进制数值写入到 buffer 中
  445. });
  446. // }
  447. console.log('开始发送数据:', data, buffer);
  448. wx.writeBLECharacteristicValue({
  449. deviceId: that.publicDevice.deviceId,
  450. serviceId: that.publicDevice.serviceId,
  451. characteristicId: that.publicDevice.characteristicId,
  452. value: buffer,
  453. success: (res) => {
  454. // console.log('数据发送成功:');
  455. if (callback) {
  456. callback(true)
  457. }
  458. resolve(res);
  459. },
  460. fail: (err) => {
  461. if (callback) {
  462. callback(false)
  463. }
  464. console.error('数据发送失败:', err);
  465. reject(new Error('数据发送失败'));
  466. }
  467. });
  468. });
  469. }
  470. ab2hex(buffer) {
  471. var hexArr = Array.prototype.map.call(
  472. new Uint8Array(buffer),
  473. function (bit) {
  474. return ('00' + bit.toString(16)).slice(-2)
  475. }
  476. )
  477. return hexArr.join(':');
  478. }
  479. fiterDevice(res) {
  480. var that = this;
  481. var devices = res.devices.filter(device => {
  482. const name = device.name || '';
  483. const localName = device.localName || '';
  484. let isNot = that.isNotEmpty(name) || that.isNotEmpty(localName);
  485. if (isNot) {
  486. // console.log('是猫王设备名称:', device.advertisData, device.serviceData)
  487. let mac = that.ab2hex(device.advertisData)
  488. // console.log(mac)
  489. device.mac = mac
  490. }
  491. return isNot
  492. });
  493. let newDevices = devices.map((device) => {
  494. let uuid = device.advertisServiceUUIDs[0] ?? ""
  495. return {
  496. deviceId: device.deviceId,
  497. name: device.name,
  498. localName: device.localName,
  499. uuid: uuid,
  500. mac: device.mac,
  501. connectable: device.connectable
  502. }
  503. });
  504. return newDevices
  505. }
  506. isNotEmpty(name) {
  507. let isNot = (name !== '' &&
  508. (name.startsWith("MW_") ||
  509. name.startsWith("MW-") ||
  510. // name.startsWith("猫王") ||
  511. // name.startsWith("妙播") ||
  512. // name.startsWith("AirSmart") ||
  513. name === "le")
  514. )
  515. // if (!isNot && name !== '') {
  516. // console.log('不是猫王设备名称:', name)
  517. // }
  518. return isNot;
  519. }
  520. // 发现服务
  521. discoverServices(deviceId) {
  522. var that = this;
  523. console.log('发现服务:', deviceId);
  524. return new Promise((resolve, reject) => {
  525. wx.getBLEDeviceServices({
  526. deviceId: deviceId,
  527. success: (res) => {
  528. // that.publicDevice .services = res.services;
  529. let service_id = "";
  530. for (let i = 0; i < res.services.length; i++) {
  531. if (res.services[i].uuid.toUpperCase().indexOf("AB00") != -1 ||
  532. res.services[i].uuid.toUpperCase().indexOf("FFC0") != -1
  533. // res.services[i].uuid.toUpperCase().indexOf("ae800") != -1
  534. ) {
  535. service_id = res.services[i].uuid;
  536. break;
  537. }
  538. console.log('发现服务1:', service_id);
  539. service_id = res.services[i].uuid;
  540. }
  541. that.publicDevice.serviceId = service_id;
  542. console.log('发现服务2:', service_id);
  543. resolve(service_id);
  544. // resolve(res.services);
  545. },
  546. fail: (err) => {
  547. that.publicDevice.serviceId = null;
  548. console.error('发现服务失败:', err);
  549. reject([]);
  550. }
  551. });
  552. });
  553. }
  554. connect() { }
  555. // 发现特征值 read / write
  556. discoverCharacteristics(deviceId, serviceId) {
  557. var that = this;
  558. console.log('发现特征值:' + deviceId + " , " + serviceId);
  559. // if (deviceId !== that.publicDevice .deviceId) {
  560. // console.log('设备id不匹配')
  561. // return false
  562. // }
  563. return new Promise((resolve, reject) => {
  564. wx.getBLEDeviceCharacteristics({
  565. deviceId: deviceId,
  566. serviceId: serviceId,
  567. success: (res) => {
  568. // that.characteristics[serviceId] = res.characteristics;
  569. console.log('发现特征值2:', res);
  570. // that.publicDevice .characteristics = res.characteristics;
  571. resolve(res.characteristics);
  572. },
  573. fail: (err) => {
  574. that.publicDevice.characteristics = null;
  575. console.error('发现特征值失败:', err);
  576. reject("");
  577. }
  578. });
  579. });
  580. }
  581. // 读取特征值
  582. readCharacteristicValue(characteristicId) {
  583. var that = ths;
  584. console.log('开始读取特征值', characteristicId)
  585. return new Promise((resolve, reject) => {
  586. wx.readBLECharacteristicValue({
  587. deviceId: that.publicDevice.deviceId,
  588. serviceId: that.publicDevice.serviceId,
  589. characteristicId: characteristicId,
  590. success: (res) => {
  591. const name = that.parseBLEValue(res.value); // 解析读取到的值
  592. console.log('读取特征值成功:', name, res);
  593. resolve(res);
  594. },
  595. fail: (err) => {
  596. console.error('读取特征值失败:', err);
  597. reject("");
  598. }
  599. });
  600. });
  601. }
  602. // 解析读取到的设备名称
  603. parseBLEValue(buffer) {
  604. return String.fromCharCode.apply(null, new Uint8Array(buffer));
  605. }
  606. // 监听特征值变化
  607. notifyCharacteristicValueChange(characteristicId, callback) {
  608. var that = this;
  609. console.log('监听特征值变化:', characteristicId, that.publicDevice.deviceId, that.publicDevice.serviceId);
  610. wx.notifyBLECharacteristicValueChange({
  611. deviceId: that.publicDevice.deviceId, //设备mac IOS和安卓系统不一样
  612. serviceId: that.publicDevice.serviceId, //服务通道,这里主要是notify
  613. characteristicId: characteristicId, //notify uuid
  614. state: true,
  615. success: function (res) {
  616. console.log("开启notify 成功")
  617. //TODO onBLECharacteristicValueChange 监听特征值 设备的数据在这里获取到
  618. wx.onBLECharacteristicValueChange(function (characteristic) {
  619. let buffer = characteristic.value
  620. let dataView = new DataView(buffer)
  621. let dataResult = []
  622. for (let i = 0; i < dataView.byteLength; i++) {
  623. // console.log("0x" + dataView.getUint8(i).toString(16))
  624. // dataResult.push("0x" + dataView.getUint8(i).toString(16))
  625. dataResult.push(dataView.getUint8(i))
  626. }
  627. const result = dataResult
  628. console.log("拿到的数据:", result)
  629. if (callback) {
  630. callback(result)
  631. }
  632. })
  633. },
  634. fail: function (res) {
  635. console.log("订阅特征失败:", res)
  636. }
  637. })
  638. }
  639. setWrite(wirte, characteristicId) {
  640. var that = this;
  641. console.log('写入特征值:', characteristicId)
  642. // that.publicDevice .wirte = wirte
  643. that.publicDevice.characteristicId = characteristicId;
  644. }
  645. }
  646. // const ble = new bleManager();
  647. // 导出 bleManager 类
  648. module.exports = bleManager;
  649. // wx.getSetting({
  650. // success(res) {
  651. // if (res.authSetting["scope.userFuzzyLocation"]) {
  652. // // 成功
  653. // // that.getBluetoothStatus();
  654. // console.log("有定位权限")
  655. // resolve(true);
  656. // } else if (res.authSetting["scope.userFuzzyLocation"] === undefined) {
  657. // wx.authorize({
  658. // scope: "scope.userFuzzyLocation",
  659. // success() {
  660. // console.log("再次获取定位权限")
  661. // resolve(that.getSetting());
  662. // }
  663. // });
  664. // } else {
  665. // wx.showModal({
  666. // title: '请打开系统位置获取定位权限',
  667. // success(res) {
  668. // if (res.confirm) {
  669. // console.log('用户点击确定')
  670. // wx.openSetting({
  671. // complete() {
  672. // // that.getSetting();
  673. // // resolve(that.getSetting());
  674. // }
  675. // })
  676. // } else if (res.cancel) {
  677. // console.log('用户点击取消');
  678. // }
  679. // }
  680. // })
  681. // console.log("没有有定位权限")
  682. // reject(false);
  683. // }
  684. // }
  685. // })
  686. // // 获取已连接的蓝牙设备
  687. // getConnectedDevices() {
  688. // var that = this;
  689. // if (!that.isAvailable && !that.hasPermission) {
  690. // return [];
  691. // }
  692. // return new Promise((resolve, reject) => {
  693. // wx.getConnectedBluetoothDevices({
  694. // // services: ["FFC0", "ffc0", "FFC1", "FFC2", "ffc1", "ffc2", "AB00", "ab00", "AB01", "AB02", "FFF1", "fff1", "FFE2", "FFE5",],
  695. // // services: ["ab00", "ffe5", "1111", "FFC0", "FFC1", "FFF1", ],
  696. // // services: [],
  697. // // services: [
  698. // // "0000ab00-0000-1000-8000-00805f9b34fb",
  699. // // "0000ffc0-0000-1000-8000-00805f9b34fb",
  700. // // "0000FFF0-0000-1000-8000-00805F9B34FB",
  701. // // "0000FFF1-0000-1000-8000-00805F9B34FB",
  702. // // "0000FFE5-0000-1000-8000-00805F9B34FB",
  703. // // ],
  704. // success: (res) => {
  705. // console.log('已连接的蓝牙设备==11==:', newDevices);
  706. // let newDevices = that.fiterDevice(res)
  707. // console.log('已连接的蓝牙设备==22==:', newDevices);
  708. // resolve(newDevices);
  709. // },
  710. // fail: (err) => {
  711. // console.error('获取已连接的蓝牙设备失败:', err);
  712. // reject([]);
  713. // }
  714. // });
  715. // });
  716. // }