mirror of
https://github.com/jam422470459/EPD-nRF52-hema213.git
synced 2025-12-15 12:58:12 +08:00
optimize image transfer speed
This commit is contained in:
@@ -1,3 +0,0 @@
|
||||
#include "DEV_Config.h"
|
||||
|
||||
void EPD_4in2_test(void);
|
||||
@@ -62,6 +62,8 @@
|
||||
<div>
|
||||
<button id="clearcanvasbutton" type="button" class="secondary" onclick="clear_canvas()">清除画布</button>
|
||||
<button id="sendimgbutton" type="button" class="primary" onclick="sendimg()">发送图片</button>
|
||||
<label for="interleavedcount" style="margin-left: 20px;">确认间隔</label>
|
||||
<input type="number" id="interleavedcount" value="50">
|
||||
</div>
|
||||
<div>
|
||||
<button id="clearscreenbutton" type="button" class="secondary" onclick="clearscreen()">清除屏幕</button>
|
||||
@@ -107,6 +109,7 @@
|
||||
<ul>
|
||||
<li><b>驱动选择:</b>黑白屏可尝试 EPD_4in2 / EPD_4in2_V2, 三色屏选择 EPD_4in2b_V2 (选错驱动可能会导致任何未知的异常,重启即可恢复)</li>
|
||||
<li><b>引脚配置:</b>格式为十六进制,顺序:MOSI/SCLK/CS/DC/ST/BUSY/BS,必须按此顺序包含完整的 7 个引脚配置(没有用到的引脚可配置为 <code>FF</code>)</li>
|
||||
<li><b>确认间隔: </b>这个间隔指的是数据包数量间隔,即发送此数量的不确认响应的数据包后才发送一次需确认响应的数据包。加大此值可优化传图速度,但是丢包风险也更大(你可能会发现图片有部分位置显示不正常,此时需调小这个值)。
|
||||
<li>
|
||||
<b>指令列表(指令和参数全部要使用十六进制):</b>
|
||||
<ul>
|
||||
|
||||
@@ -45,7 +45,7 @@ async function handleError(error) {
|
||||
}
|
||||
}
|
||||
|
||||
async function write(cmd, data) {
|
||||
async function write(cmd, data, withResponse=true) {
|
||||
if (!epdCharacteristic) {
|
||||
addLog("服务不可用,请检查蓝牙连接");
|
||||
return;
|
||||
@@ -60,13 +60,18 @@ async function write(cmd, data) {
|
||||
throw new Error("BLE packet too large!");
|
||||
}
|
||||
addLog(`<span class="action">⇑</span> ${bytes2hex(payload)}`);
|
||||
await epdCharacteristic.writeValue(Uint8Array.from(payload));
|
||||
if (withResponse)
|
||||
await epdCharacteristic.writeValueWithResponse(Uint8Array.from(payload));
|
||||
else
|
||||
await epdCharacteristic.writeValueWithoutResponse(Uint8Array.from(payload));
|
||||
}
|
||||
|
||||
async function epdWrite(cmd, data) {
|
||||
const chunkSize = MAX_PACKET_SIZE - 1;
|
||||
const count = Math.round(data.length / chunkSize);
|
||||
const interleavedCount = document.getElementById('interleavedcount').value;
|
||||
let chunkIdx = 0;
|
||||
let noReplyCount = interleavedCount;
|
||||
|
||||
if (typeof data == 'string') data = hex2bytes(data);
|
||||
|
||||
@@ -74,7 +79,13 @@ async function epdWrite(cmd, data) {
|
||||
for (let i = 0; i < data.length; i += chunkSize) {
|
||||
let currentTime = (new Date().getTime() - startTime) / 1000.0;
|
||||
setStatus(`命令:0x${cmd.toString(16)}, 数据块: ${chunkIdx+1}/${count+1}, 总用时: ${currentTime}s`);
|
||||
await write(EpdCmd.SEND_DATA, data.slice(i, i + chunkSize));
|
||||
if (noReplyCount > 0) {
|
||||
await write(EpdCmd.SEND_DATA, data.slice(i, i + chunkSize), false);
|
||||
noReplyCount--;
|
||||
} else {
|
||||
await write(EpdCmd.SEND_DATA, data.slice(i, i + chunkSize), true);
|
||||
noReplyCount = interleavedCount;
|
||||
}
|
||||
chunkIdx++;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user