diff --git a/.github/workflows/static.yml b/.github/workflows/static.yml index e37018c..a08fa59 100644 --- a/.github/workflows/static.yml +++ b/.github/workflows/static.yml @@ -4,7 +4,7 @@ on: push: branches: ["main"] paths: - - "html/*" + - "html/**" workflow_dispatch: permissions: diff --git a/html/index.html b/html/index.html index 497f91c..941d9cc 100644 --- a/html/index.html +++ b/html/index.html @@ -36,7 +36,7 @@

4.2 寸电子墨水屏蓝牙控制器(nRF51)

- 蓝牙 + 蓝牙连接
@@ -57,16 +57,19 @@
- 传图 + 屏幕控制
- +
- + +
+
+
@@ -110,6 +113,7 @@
  • 驱动选择:黑白屏可尝试 EPD_4in2 / EPD_4in2_V2, 三色屏选择 EPD_4in2b_V2 (选错驱动可能会导致任何未知的异常,重启即可恢复)
  • 引脚配置:格式为十六进制,顺序:MOSI/SCLK/CS/DC/ST/BUSY/BS,必须按此顺序包含完整的 7 个引脚配置(没有用到的引脚可配置为 FF
  • 确认间隔: 这个间隔指的是数据包数量间隔,即发送此数量的不确认响应的数据包后才发送一次需确认响应的数据包。加大此值可优化传图速度,但是丢包风险也更大(你可能会发现图片有部分位置显示不正常,此时需调小这个值)。 +
  • 日历模式: 点击“日历模式”按钮将自动从浏览器同步时间到墨水屏,并切换到日历显示。
  • 指令列表(指令和参数全部要使用十六进制):
      @@ -124,6 +128,10 @@
    • 06: 屏幕睡眠
  • +
  • 日历模式: +
      +
    • 20+UNIX 时间戳: 同步时间并开启日历模式
    • +
  • 系统相关:
    • 90+配置: 写入配置信息(重启生效,格式参考源码 epd_config_t
    • diff --git a/html/js/main.js b/html/js/main.js index 2a58e49..3d03dad 100644 --- a/html/js/main.js +++ b/html/js/main.js @@ -17,6 +17,8 @@ const EpdCmd = { DISPLAY: 0x05, SLEEP: 0x06, + SET_TIME: 0x20, + SET_CONFIG: 0x90, SYS_RESET: 0x91, SYS_SLEEP: 0x92, @@ -31,7 +33,7 @@ function resetVariables() { } async function handleError(error) { - console.log(error); + console.error(error); resetVariables(); if (bleDevice == null) return; @@ -48,22 +50,30 @@ async function handleError(error) { async function write(cmd, data, withResponse=true) { if (!epdCharacteristic) { addLog("服务不可用,请检查蓝牙连接"); - return; + return false; } let payload = [cmd]; if (data) { if (typeof data == 'string') data = hex2bytes(data); if (data instanceof Uint8Array) data = Array.from(data); payload.push(...data) - }; + } if (payload.length > MAX_PACKET_SIZE) { - throw new Error("BLE packet too large!"); + addLog("BLE packet too large!"); + return false; } addLog(` ${bytes2hex(payload)}`); - if (withResponse) - await epdCharacteristic.writeValueWithResponse(Uint8Array.from(payload)); - else - await epdCharacteristic.writeValueWithoutResponse(Uint8Array.from(payload)); + try { + if (withResponse) + await epdCharacteristic.writeValueWithResponse(Uint8Array.from(payload)); + else + await epdCharacteristic.writeValueWithoutResponse(Uint8Array.from(payload)); + } catch (e) { + console.error(e); + if (e.message) addLog(e.message); + return false; + } + return true; } async function epdWrite(cmd, data) { @@ -95,7 +105,21 @@ async function setDriver() { await write(EpdCmd.INIT, document.getElementById("epddriver").value); } -async function clearscreen() { +async function syncTime() { + const timestamp = new Date().getTime() / 1000; + const data = new Uint8Array([ + (timestamp >> 24) & 0xFF, + (timestamp >> 16) & 0xFF, + (timestamp >> 8) & 0xFF, + timestamp & 0xFF, + -(new Date().getTimezoneOffset() / 60) + ]); + if(await write(EpdCmd.SET_TIME, data)) { + addLog("日历模式:时间已同步!需要一定时间刷新,请耐心等待。"); + } +} + +async function clearScreen() { if(confirm('确认清除屏幕内容?')) { await write(EpdCmd.CLEAR); } @@ -163,6 +187,7 @@ function updateButtonStatus() { const status = connected ? null : 'disabled'; document.getElementById("reconnectbutton").disabled = (gattServer == null || gattServer.connected) ? 'disabled' : null; document.getElementById("sendcmdbutton").disabled = status; + document.getElementById("synctimebutton").disabled = status; document.getElementById("clearscreenbutton").disabled = status; document.getElementById("sendimgbutton").disabled = status; document.getElementById("setDriverbutton").disabled = status; @@ -178,18 +203,18 @@ function disconnect() { async function preConnect() { if (gattServer != null && gattServer.connected) { if (bleDevice != null && bleDevice.gatt.connected) { - await write(EpdCmd.SLEEP); bleDevice.gatt.disconnect(); } } else { - connectTrys = 0; + reconnectTrys = 0; try { bleDevice = await navigator.bluetooth.requestDevice({ optionalServices: ['62750001-d828-918d-fb46-b6c11c675aec'], acceptAllDevices: true }); } catch (e) { + console.error(e); if (e.message) addLog(e.message); return; } @@ -204,7 +229,7 @@ async function preConnect() { } async function reConnect() { - connectTrys = 0; + reconnectTrys = 0; if (bleDevice != null && bleDevice.gatt.connected) bleDevice.gatt.disconnect(); resetVariables();