蓝牙墨水屏上位机学习(2)-ELink墨水屏电子纸社区-FPGA CPLD-ChipDebug

蓝牙墨水屏上位机学习(2)

 

界面如下 :图片[1]-蓝牙墨水屏上位机学习(2)-ELink墨水屏电子纸社区-FPGA CPLD-ChipDebug

第一节,蓝牙连接按键学习

 

<body>     <div class="main">         <h3>电子墨水屏蓝牙控制器</h3>         <fieldset>             <legend>蓝牙连接</legend>             <div class="flex-container">                 <div class="flex-group">                     <button id="connectbutton" type="button" class="primary" onclick="preConnect()">连接</button>                     <button id="reconnectbutton" type="button" class="secondary" onclick="reConnect()">重连</button> 					<button type="button" class="secondary" onclick="clearLog()">清空日志</button>                 </div>

preConnect()函数定义如下 :该函数定义在main.js中

async function preConnect() {   if (gattServer != null && gattServer.connected) {     if (bleDevice != null && bleDevice.gatt.connected) {       bleDevice.gatt.disconnect();     }   }   else {     resetVariables();     try {       bleDevice = await navigator.bluetooth.requestDevice({         optionalServices: ['62750001-d828-918d-fb46-b6c11c675aec'],         acceptAllDevices: true       });     } catch (e) {       console.error(e);       if (e.message) addLog("requestDevice: " + e.message);       addLog("请检查蓝牙是否已开启,且使用的浏览器支持蓝牙!建议使用以下浏览器:");       addLog("• 电脑: Chrome/Edge");       addLog("• Android: Chrome/Edge");       addLog("• iOS: Bluefy 浏览器");       return;     }      await bleDevice.addEventListener('gattserverdisconnected', disconnect);     setTimeout(async function () { await connect(); }, 300); 
请登录后发表评论

    没有回复内容