bluetooth.js 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642
  1. import game_store from "../store/game";
  2. import ble_store from "../store/bluetooth";
  3. import Notify from "../../static/vant/notify/notify";
  4. import {setDeviceInDb} from "../requests/game";
  5. var $ff = "ff";
  6. var $8f = "ffffffff"
  7. var control_close = false
  8. var connect_toy = false;
  9. var current_toy_id = "00";
  10. var current_toy_UUID = "";
  11. export default {
  12. //变量
  13. connect_toy, control_close, current_toy_id, current_toy_UUID,
  14. // 打开大包数据
  15. sendOpenBigData() {
  16. this.SendOrder('ff')
  17. },
  18. // 关闭大包数据
  19. sendCloseBigData() {
  20. this.SendOrder('00')
  21. },
  22. //获取当前连接的教具类型
  23. sendGetToyType() {
  24. this.SendOrder('06')
  25. },
  26. // 开启脑控
  27. sendControl() {
  28. this.SendOrder('07')
  29. },
  30. //暂停脑控
  31. sendControlPause() {
  32. //AA CC 03 00 00 00 09 F3
  33. this.SendOrder('08')
  34. },
  35. // 关闭脑控
  36. sendControlClose() {
  37. let that = this
  38. let $intv = setInterval(() => {
  39. if (!control_close) {
  40. that.SendOrder('09')
  41. } else {
  42. clearInterval($intv)
  43. //清空当前数据
  44. that.clearLocalDatas()
  45. }
  46. }, 1000)
  47. },
  48. //发送一对多连接
  49. sendConnectOneToMore(id) {
  50. this.WriteBufferInBle(`03 00 ${id} 00 0A`);
  51. },
  52. //发送一对一连接
  53. sendConnectOneToOne(id) {
  54. current_toy_id = id;
  55. this.WriteBufferInBle(`03 00 ${id} 01 0A`)
  56. },
  57. //获取教具电量
  58. sendToyPower_CheckReconected() {
  59. let that = this;
  60. let $connect_false_count = 0;
  61. let $game_status = game_store.getters.getGameStatus();
  62. if ($game_status == 1) {
  63. let toy_intv = setInterval(() => {
  64. if (connect_toy) {
  65. that.SendOrder('8a')
  66. connect_toy = false
  67. $connect_false_count = 0
  68. } else {
  69. $connect_false_count += 1;
  70. if ($connect_false_count == 3) {
  71. //调用重连教具
  72. that.ReconnectToy()
  73. clearInterval(toy_intv)
  74. }
  75. }
  76. console.log("循环数:" + $connect_false_count)
  77. }, 3000)
  78. }
  79. },
  80. // 获取大包数据 进行绘制图表
  81. get_big_data(hex) {
  82. if (hex.substr(0, 6) != "555520") {
  83. return false;
  84. }
  85. //当s1为 00时 数据有效
  86. let $s1 = hex.substr(8, 2);
  87. if ($s1 != "00") {
  88. return false;
  89. }
  90. //专注度数据
  91. let $att = parseInt("0x" + hex.substr(12, 2));
  92. //放松度数据
  93. let $med = parseInt("0x" + hex.substr(16, 2));
  94. //Delta数据
  95. let $delta_1 = hex.substr(hex.indexOf("0418") + 4, 2);
  96. let $delta_2 = hex.substr(hex.indexOf("0418") + 6, 2);
  97. let $delta_3 = hex.substr(hex.indexOf("0418") + 8, 2);
  98. let $delta = parseInt($delta_1 + $delta_2 + $delta_3, 16);
  99. //Theta数据
  100. let $theta_1 = hex.substr(hex.indexOf("0418") + 10, 2);
  101. let $theta_2 = hex.substr(hex.indexOf("0418") + 12, 2);
  102. let $theta_3 = hex.substr(hex.indexOf("0418") + 14, 2);
  103. let $theta = parseInt($theta_1 + $theta_2 + $theta_3, 16);
  104. //low_Alpha
  105. let $low_alpha_1 = hex.substr(hex.indexOf("0418") + 16, 2);
  106. let $low_alpha_2 = hex.substr(hex.indexOf("0418") + 18, 2);
  107. let $low_alpha_3 = hex.substr(hex.indexOf("0418") + 20, 2);
  108. let $low_alpha = parseInt($low_alpha_1 + $low_alpha_2 + $low_alpha_3, 16);
  109. //high_Alpha
  110. let $high_alpha_1 = hex.substr(hex.indexOf("0418") + 22, 2);
  111. let $high_alpha_2 = hex.substr(hex.indexOf("0418") + 24, 2);
  112. let $high_alpha_3 = hex.substr(hex.indexOf("0418") + 26, 2);
  113. let $high_alpha = parseInt($high_alpha_1 + $high_alpha_2 + $high_alpha_3, 16);
  114. //low_beta
  115. let $low_beta_1 = hex.substr(hex.indexOf("0418") + 28, 2);
  116. let $low_beta_2 = hex.substr(hex.indexOf("0418") + 30, 2);
  117. let $low_beta_3 = hex.substr(hex.indexOf("0418") + 32, 2);
  118. let $low_beta = parseInt($low_beta_1 + $low_beta_2 + $low_beta_3, 16);
  119. //high_beta
  120. let $high_beta_1 = hex.substr(hex.indexOf("0418") + 34, 2);
  121. let $high_beta_2 = hex.substr(hex.indexOf("0418") + 36, 2);
  122. let $high_beta_3 = hex.substr(hex.indexOf("0418") + 38, 2);
  123. let $high_beta = parseInt($high_beta_1 + $high_beta_2 + $high_beta_3, 16);
  124. let $max_num = 30000;
  125. return {
  126. att: $att,
  127. med: $med,
  128. delta: $delta >= $max_num ? $max_num : $delta,
  129. theta: $theta >= $max_num ? $max_num : $theta,
  130. low_alpha: $low_alpha >= $max_num ? $max_num : $low_alpha,
  131. high_alpha: $high_alpha >= $max_num ? $max_num : $high_alpha,
  132. low_beta: $low_beta >= $max_num ? $max_num : $low_beta,
  133. high_beta: $high_beta >= $max_num ? $max_num : $high_beta
  134. };
  135. },
  136. //获取设备电量
  137. get_device_elc(hex) {
  138. if (hex.substr(0, 8) != "55550203") {
  139. return false;
  140. }
  141. let $power = parseInt("0x" + hex.substr(8, 2));
  142. return $power;
  143. },
  144. // 监听蓝牙连接状态
  145. watch_bluetooth_status($this) {
  146. let that = this;
  147. // 微信自身监听低功耗蓝牙连接状态的改变事件
  148. wx.onBLEConnectionStateChange((res) => {
  149. // 该方法回调中可以用于处理连接意外断开等异常情况
  150. ble_store.setters.setBluetoothLinkStatus(res.connected);
  151. if (res.connected == false) {
  152. //判断游戏是否游戏中
  153. let $game_status = game_store.getters.getGameStatus();
  154. if ($game_status == 1) {
  155. // $that.game_finished();
  156. //清除状态 设置为默认初始状态 0 小乌龟
  157. Notify({
  158. type: 'danger',
  159. duration: 0,
  160. message: '智脑环已断开连接,正在尝试重新连接',
  161. onOpened() {
  162. that.reconnect(res.deviceId, $this)
  163. }
  164. });
  165. // game_store.setters.setGameStatus(0);
  166. // 结束状态更改为1
  167. }
  168. }
  169. });
  170. },
  171. //重新连接蓝牙
  172. reconnect($deviceId, $this) {
  173. let that = this;
  174. let $serviceId = game_store.getters.getServiceId();
  175. let $characteristicId = game_store.getters.getReadCharacterId();
  176. //重连的次数
  177. let $connect_count = 0;
  178. let $rec = setInterval(() => {
  179. $connect_count += 1;
  180. wx.createBLEConnection({
  181. deviceId: $deviceId,
  182. success(res) {
  183. Notify({type: 'success', message: `第${$connect_count}次重新连接成功`});
  184. wx.notifyBLECharacteristicValueChange({
  185. deviceId: $deviceId,
  186. serviceId: $serviceId,
  187. characteristicId: $characteristicId,
  188. state: true,
  189. success(res) {
  190. console.log("重新连接SUCCESS,log", res)
  191. that.watchingDevice($this)
  192. }, fail(res) {
  193. console.log("重新失败,log", res)
  194. }
  195. })
  196. that.watchingDevice($this)
  197. clearInterval($rec)
  198. },
  199. fail(res) {
  200. Notify({type: 'danger', message: `第${$connect_count}次重新连接失败`});
  201. game_store.setters.setGameCloseStatus(1);
  202. }
  203. })
  204. if ($connect_count == 3) {
  205. $this.game_finished();
  206. }
  207. }, 5000)
  208. },
  209. //获取蓝牙设备服务
  210. getBLEDeviceServices(deviceId) {
  211. const $this = this;
  212. wx.getBLEDeviceServices({
  213. deviceId,
  214. success: (res) => {
  215. for (let i = 0; i < res.services.length; i++) {
  216. console.log("serviceItem:" + res.services[i].uuid);
  217. if (res.services[i].uuid.indexOf('6E') != -1 || res.services[i].uuid.indexOf('0000FFF0') != -1) {
  218. console.log("SelectedServiceItem:" + res.services[i].uuid);
  219. $this.getBLEDeviceCharacteristics(deviceId, res.services[i].uuid);
  220. return;
  221. }
  222. }
  223. },
  224. fail(res) {
  225. console.log("连接蓝牙成功,获取服务失败");
  226. },
  227. });
  228. },
  229. //获取蓝牙设备某个服务中所有特征值
  230. getBLEDeviceCharacteristics(deviceId, serviceId) {
  231. console.log(deviceId, serviceId);
  232. const $this = this;
  233. wx.getBLEDeviceCharacteristics({
  234. deviceId,
  235. serviceId,
  236. success: (res) => {
  237. console.log("getBLEDeviceCharacteristics success", res.characteristics);
  238. for (let i = 0; i < res.characteristics.length; i++) {
  239. let item = res.characteristics[i];
  240. if (item.properties.read) {
  241. wx.readBLECharacteristicValue({
  242. deviceId,
  243. serviceId,
  244. characteristicId: item.uuid,
  245. });
  246. }
  247. if (item.properties.write) {
  248. $this.deviceId = deviceId;
  249. $this.serviceId = serviceId;
  250. $this.cid = item.uuid;
  251. game_store.setters.setDeviceId(deviceId);
  252. game_store.setters.setServiceId(serviceId);
  253. game_store.setters.setCid(item.uuid);
  254. //打开数据帧
  255. $this.sendOpenBigData();
  256. }
  257. if (item.properties.notify || item.properties.indicate) {
  258. wx.notifyBLECharacteristicValueChange({
  259. deviceId,
  260. serviceId,
  261. characteristicId: item.uuid,
  262. state: true,
  263. });
  264. game_store.setters.setReadCid(item.uuid);
  265. }
  266. }
  267. },
  268. fail(res) {
  269. console.error("getBLEDeviceCharacteristics", res);
  270. },
  271. });
  272. },
  273. // ArrayBuffer转16进度字符串示例
  274. ab2hex(buffer) {
  275. var hexArr = Array.prototype.map.call(
  276. new Uint8Array(buffer),
  277. function (bit) {
  278. return ("00" + bit.toString(16)).slice(-2);
  279. }
  280. );
  281. return hexArr.join("");
  282. },
  283. // 监听脑环数据
  284. watchingDevice($this) {
  285. const that = this;
  286. wx.onBLECharacteristicValueChange((characteristic) => {
  287. let hexStr = that.ab2hex(characteristic.value);
  288. if (hexStr.toUpperCase().indexOf("AADD") != -1) {
  289. console.log(hexStr);
  290. }
  291. let $data = that.get_big_data(hexStr);
  292. let $game_status = game_store.getters.getGameStatus();
  293. // 2021年10月20日17:18:13 判断教具 连接
  294. if (hexStr.toUpperCase().indexOf("AADD0A") != -1) {
  295. //没连接上教具
  296. if (hexStr.toUpperCase().indexOf("AADD0A0000") != -1) {
  297. $this.change_toy_connect_status(3);
  298. return false;
  299. }
  300. let $hexAry = $this.current_hex.split(" ")
  301. // 03 00 01 00 0a
  302. // [2] [3]
  303. // 连接上教具
  304. if (new RegExp("00").test($hexAry[2]) == false) {
  305. if (new RegExp("00").test($hexAry[3]) == true) {
  306. that.sendConnectOneToOne($hexAry[2])
  307. $this.current_hex = `03 00 $hexAry[2] 01 0A`
  308. console.log("一对多")
  309. } else {
  310. console.log("一对一")
  311. $this.current_hex = "";
  312. wx.showToast({
  313. title: "已连接到" + $this.toy_item.name
  314. });
  315. $this.toy_connected = true;
  316. $this.change_toy_connect_status(2);
  317. //连接成功后 获取一次教具电量信息
  318. that.SendOrder('8a')
  319. }
  320. }
  321. }
  322. //2021年10月21日16:30:07
  323. // 获取教具电量
  324. if (hexStr.toUpperCase().indexOf("AADD8A") != -1) {//接收教具电量状态
  325. let $_hexStr = hexStr.substr(6);
  326. let $power = parseInt($_hexStr.substr(0, 2), 16)
  327. let $voltage = parseInt($_hexStr.substr(2, 2), 16)
  328. console.log("电量:" + $power)
  329. console.log("电压:" + $voltage / 10)
  330. $this.toy_power = $power;
  331. //连接上教具的标识
  332. connect_toy = true;
  333. if (current_toy_UUID == "") {
  334. //获取教具UUID
  335. that.SendOrder('84')
  336. }
  337. }
  338. //监听佩戴正确
  339. if (hexStr.substr(0, 6) == "555520") {
  340. //当s1为 00时 数据有效
  341. let $s1 = hexStr.substr(8, 2);
  342. // console.log("监听脑环是否带正:", $s1 == '00')
  343. $this.device_bg = $s1 == "00";
  344. }
  345. // 2021年10月25日09:15:50
  346. // 收到一次UUID就发送一次获取教具的电量
  347. // 读取教具UUID
  348. if (hexStr.toUpperCase().indexOf("AADD84") != -1) {//接收UUID 5个字节
  349. let $_hexStr = hexStr.substr(6);
  350. let $datas = $_hexStr.substr(0, 10);
  351. if ($datas != "0000000000") {
  352. console.log("以获取UUID:" + $datas)
  353. current_toy_UUID = $datas;
  354. $this.toy_UUID = $datas;
  355. }
  356. }
  357. //2021年10月26日11:09:01
  358. // 量产结束读取数据
  359. if (hexStr.toUpperCase().indexOf("AADD02") != -1) {
  360. //脑环型号
  361. let $ring_type = hexStr.substr(10).substr(0, hexStr.substr(10).length - 2);
  362. for (let $i = 0; $i < $ring_type.length; $i += 2) {
  363. let $code = parseInt($ring_type.substr($i, 2), 16)
  364. $this.device_data.product_model += String.fromCharCode($code)
  365. }
  366. that.SendOrder("01")
  367. }
  368. if (hexStr.toUpperCase().indexOf("AADD01") != -1) {
  369. let _UUID = ""
  370. let $_str4 = hexStr.substr(6);
  371. let $UUID = $_str4.substr(0, $_str4.length - 2);
  372. for (let $i = 0; $i < $UUID.length; $i += 8) {
  373. let $code = $UUID.substr($i, 8);
  374. _UUID += `${$code}-`
  375. }
  376. _UUID = _UUID.substr(0, _UUID.length - 1)
  377. $this.device_data.UUID = _UUID
  378. that.SendOrder("03")
  379. }
  380. if (hexStr.toUpperCase().indexOf("AADD03") != -1) {
  381. let $_data = that.DoAnalysis(hexStr, 12);
  382. $this.device_data.software_version = $_data.substr(0, 4)
  383. // $this.device_data.software_date = $_data.substr(4)
  384. that.SendOrder("8d")
  385. }
  386. if (hexStr.toUpperCase().indexOf("AADD8D") != -1) {
  387. let $_str5 = hexStr.substr(10);
  388. let $version_date = $_str5.substr(0, $_str5.length - 2);
  389. let $_data = "";
  390. for (let $i = 0; $i < $version_date.length; $i += 2) {
  391. let $code = parseInt($version_date.substr($i, 2), 16)
  392. $_data += String.fromCharCode($code)
  393. }
  394. let $version_data = $_data.substr(0, 2).split('')
  395. $this.device_data.hardware_version = `${$version_data[0]}.${$version_data[1]}`
  396. setDeviceInDb($this, $this.device.deviceId)
  397. }
  398. if (hexStr.toUpperCase().indexOf("AADD09") != -1) {
  399. control_close = true;
  400. }
  401. //收到发送UUID的应答立马发送连接教具的指令
  402. if (hexStr.toUpperCase().indexOf("AADD8E") != -1) {
  403. //发送教具连接
  404. that.WriteBufferInBle(`03 00 ${current_toy_id} 02 0A`)
  405. }
  406. if (hexStr.toUpperCase().indexOf("AADD0A02") != -1) {
  407. //发送教具连接
  408. wx.showToast({
  409. title: "教具重连成功"
  410. })
  411. }
  412. // 监听脑环电量
  413. let $power = that.get_device_elc(hexStr);
  414. if ($power) {
  415. // console.log("当前脑环电量:", $power)
  416. $this.device_power = $power;
  417. }
  418. if ($power < 10 && $power > 0) {
  419. wx.showToast({
  420. title: "脑环电量不足",
  421. icon: "none",
  422. duration: 2000,
  423. success() {
  424. // $this.change_device_status(0);
  425. },
  426. });
  427. }
  428. //游戏中模块
  429. if ($game_status == 1 && $data) {
  430. try {
  431. if ($this.played_time > 0) {
  432. //自定义定时器
  433. $this.played_time -= 1;
  434. game_store.setters.setPlayedTime($this.played_time)
  435. $this.played_time_text = that.formatPlaySeconds($this.played_time);
  436. $this.do_datas($data);
  437. // if ($this.played_time % 10 == 0) {
  438. // //读取教具电量
  439. // that.sendToyPower_CheckReconected()
  440. // }
  441. }
  442. if ($this.played_time == 0) {
  443. $this.post_data();
  444. //判断是否隐藏 隐藏则不绘画
  445. that.sendControlClose();
  446. let $hide_status = game_store.getters.getHideStatus();
  447. if (!$hide_status) {
  448. $this.game_finished();
  449. }
  450. }
  451. } catch (e) {
  452. console.log("调用方法失败", e);
  453. }
  454. }
  455. });
  456. },
  457. // 游玩时间倒计时
  458. formatPlaySeconds(value) {
  459. // 字符串转数字
  460. var secondTime = parseInt(value); // 秒
  461. var minuteTime = 0; // 分
  462. if (secondTime > 60) {
  463. //如果秒数大于60,将秒数转换成整数
  464. //获取分钟,除以60取整数,得到整数分钟
  465. minuteTime = parseInt(secondTime / 60);
  466. //获取秒数,秒数取佘,得到整数秒数
  467. secondTime = parseInt(secondTime % 60);
  468. //如果分钟大于60,将分钟转换成小时
  469. }
  470. var result = "" + parseInt(secondTime);
  471. if (minuteTime > 0) {
  472. if (result.length == 1) {
  473. result = "0" + result;
  474. }
  475. if (parseInt(minuteTime).toString().length == 1) {
  476. minuteTime = "0" + parseInt(minuteTime);
  477. }
  478. result = "" + minuteTime + ":" + result;
  479. } else {
  480. result = "00:" + result;
  481. }
  482. return result;
  483. },
  484. //根据错误代码返回字符串信息
  485. GetopenBluetoothAdapterError(errCode) {
  486. let $errmsg = "";
  487. if (errCode == 10000) {
  488. $errmsg = "未初始化蓝牙适配器"
  489. }
  490. if (errCode == 10001) {
  491. $errmsg = "当前蓝牙适配器不可用"
  492. }
  493. if (errCode == 10002) {
  494. $errmsg = "没有找到指定设备"
  495. }
  496. if (errCode == 10003) {
  497. $errmsg = "连接失败"
  498. }
  499. if (errCode == 10006) {
  500. $errmsg = "当前连接已断开"
  501. }
  502. return $errmsg;
  503. },
  504. //写入buffer
  505. WriteBufferInBle($hex, $buffer_len = 8) {
  506. let $device_id = game_store.getters.getDeviceId();
  507. let $service_id = game_store.getters.getServiceId()
  508. let $charateristic = game_store.getters.getCharacterId();
  509. let $hex_header = "aa cc ";
  510. // let $hex = "03 00 01 00 0a";
  511. let $hex_sum = 0;
  512. let $hex_ary = $hex.split(" ");
  513. $hex_ary.forEach(($val, $index) => {
  514. $hex_sum += parseInt($val, 16);
  515. })
  516. let $checksum = ($hex_sum ^ parseInt($8f, 16)) & parseInt($ff, 16);
  517. $hex = $hex_header + $hex + " " + $checksum.toString(16);
  518. let buffer = new ArrayBuffer($buffer_len);
  519. let dataView = new DataView(buffer);
  520. $hex_ary = $hex.split(" ");
  521. $hex_ary.forEach(($val, $index) => {
  522. dataView.setUint8($index, parseInt($val, 16))
  523. })
  524. wx.writeBLECharacteristicValue({
  525. deviceId: $device_id,
  526. serviceId: $service_id,
  527. characteristicId: $charateristic,
  528. value: buffer,
  529. success: function (res) {
  530. console.log($hex + ',写入成功')
  531. },
  532. fail: function (err) {
  533. console.log($hex + "写入失败");
  534. console.log(err);
  535. },
  536. });
  537. },
  538. //写入指令
  539. SendOrder(id) {
  540. let $hexStr = `03 00 00 00 ${id}`;
  541. this.WriteBufferInBle($hexStr)
  542. },
  543. // 写入16个字节的指令
  544. Send16Order(val, id) {
  545. let $str = val;
  546. let $str_ary = $str.split('');
  547. $str = "";
  548. $str_ary.forEach(($val, $index) => {
  549. $str += $val.charCodeAt().toString(16) + " "
  550. });
  551. $str = $str.substr(0, $str.length - 1)
  552. let $hexStr = "03 ff " + $str + ` ${id}`;
  553. this.WriteBufferInBle($hexStr, 16)
  554. },
  555. //解析
  556. DoAnalysis(hexStr, byte_count, sublen = 6) {
  557. //byte_count
  558. let $_str5 = hexStr.substr(sublen);
  559. let $datas = $_str5.substr(0, byte_count * 2);
  560. let $_data = "";
  561. for (let $i = 0; $i < $datas.length; $i += 2) {
  562. let $code = parseInt($datas.substr($i, 2), 16)
  563. $_data += String.fromCharCode($code)
  564. }
  565. return $_data;
  566. },
  567. //重连教具
  568. ReconnectToy() {
  569. //发送UUID
  570. let $uuid_str = "";
  571. for (let $i = 0; $i < current_toy_UUID.length; $i + 2) {
  572. $uuid_str += current_toy_UUID.substr($i, 2) + " ";
  573. }
  574. console.log("uuid_str" + $uuid_str)
  575. $uuid_str = $uuid_str.substr(0, $uuid_str.length - 1)
  576. this.Send16Order($uuid_str, "8e")
  577. },
  578. //清空当前脚本的变量值
  579. clearLocalDatas() {
  580. control_close = false
  581. connect_toy = false;
  582. current_toy_id = "00";
  583. current_toy_UUID = "";
  584. }
  585. };