界面如下 :![图片[1]-蓝牙墨水屏上位机学习(2)-ELink墨水屏电子纸社区-FPGA CPLD-ChipDebug](http://chipdebug.com/wp-content/uploads/2025/11/20251112115201779-21762919521.png?v=1762919521)
第一节,蓝牙连接按键学习
<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);





没有回复内容