From a52ad83b8c78d84b4c519de400b1702bcfb9a43d Mon Sep 17 00:00:00 2001 From: Shuanglei Tao Date: Sun, 13 Apr 2025 12:11:24 +0800 Subject: [PATCH] drop 4gray support --- EPD/EPD_service.c | 2 +- EPD/EPD_service.h | 2 +- GUI/GUI.c | 1 - html/index.html | 5 +--- html/js/dithering.js | 40 ----------------------------- html/js/main.js | 61 ++++++++------------------------------------ 6 files changed, 14 insertions(+), 97 deletions(-) diff --git a/EPD/EPD_service.c b/EPD/EPD_service.c index 8e6b693..f929f68 100644 --- a/EPD/EPD_service.c +++ b/EPD/EPD_service.c @@ -148,7 +148,7 @@ static void epd_service_process(ble_epd_t * p_epd, uint8_t * p_data, uint16_t le EPD_WriteData(&p_data[1], length - 1); break; - case EPD_CMD_DISPLAY: + case EPD_CMD_REFRESH: p_epd->display_mode = MODE_NONE; p_epd->epd->drv->refresh(); break; diff --git a/EPD/EPD_service.h b/EPD/EPD_service.h index fb9d0a6..c83a875 100644 --- a/EPD/EPD_service.h +++ b/EPD/EPD_service.h @@ -60,7 +60,7 @@ enum EPD_CMDS EPD_CMD_CLEAR, /**< clear EPD screen */ EPD_CMD_SEND_COMMAND, /**< send command to EPD */ EPD_CMD_SEND_DATA, /**< send data to EPD */ - EPD_CMD_DISPLAY, /**< diaplay EPD ram on screen */ + EPD_CMD_REFRESH, /**< diaplay EPD ram on screen */ EPD_CMD_SLEEP, /**< EPD enter sleep mode */ EPD_CMD_SET_TIME = 0x20, /** < set time with unix timestamp */ diff --git a/GUI/GUI.c b/GUI/GUI.c index 38bbdfd..38d0629 100644 --- a/GUI/GUI.c +++ b/GUI/GUI.c @@ -2,7 +2,6 @@ #include "fonts.h" #include "Lunar.h" #include "GUI.h" -#include "nrf.h" #include "nrf_log.h" #include diff --git a/html/index.html b/html/index.html index 86ed9cf..cae241e 100644 --- a/html/index.html +++ b/html/index.html @@ -63,13 +63,10 @@ - + - - -
diff --git a/html/js/dithering.js b/html/js/dithering.js index 64b5d11..9be0141 100644 --- a/html/js/dithering.js +++ b/html/js/dithering.js @@ -81,46 +81,6 @@ function dithering(ctx, width, height, threshold, type) { ctx.putImageData(imageData, 0, 0); } -/****Color display description**** - white gray1 gray2 black -0x10| 01 01 00 00 -0x13| 01 00 01 00 -*********************************/ -function canvas2gray(canvas) { - const ctx = canvas.getContext("2d"); - const imageData = ctx.getImageData(0, 0, canvas.width, canvas.height); - - const arr10 = []; - const arr13 = []; - let buffer10 = []; - let buffer13 = []; - - for (let y = 0; y < canvas.height; y++) { - for (let x = 0; x < canvas.width; x++) { - const i = (canvas.width * y + x) * 4; - const level = imageData.data[i] / 85; - const bin = level.toString(2).split('').map(bit => parseInt(bit, 2)); - if (bin.length > 1) { - buffer10.push(bin[0]); - buffer13.push(bin[1]); - } else { - buffer10.push(0); - buffer13.push(bin[0]); - } - - if (buffer10.length === 8) { - arr10.push(parseInt(buffer10.join(''), 2)); - buffer10 = []; - } - if (buffer13.length === 8) { - arr13.push(parseInt(buffer13.join(''), 2)); - buffer13 = []; - } - } - } - return arr10.concat(arr13); -} - // white: 1, black/red: 0 function canvas2bytes(canvas, type='bw', invert = false) { const ctx = canvas.getContext("2d"); diff --git a/html/js/main.js b/html/js/main.js index 0e5356e..d036401 100644 --- a/html/js/main.js +++ b/html/js/main.js @@ -1,10 +1,8 @@ -let bleDevice; -let gattServer; -let epdService; -let epdCharacteristic; +let bleDevice, gattServer; +let epdService, epdCharacteristic; let reconnectTrys = 0; -let canvas; +let canvas, ctx; let startTime; const EpdCmd = { @@ -13,7 +11,7 @@ const EpdCmd = { CLEAR: 0x02, SEND_CMD: 0x03, SEND_DATA: 0x04, - DISPLAY: 0x05, + REFRESH: 0x05, SLEEP: 0x06, SET_TIME: 0x20, @@ -128,35 +126,10 @@ async function sendcmd() { await write(bytes[0], bytes.length > 1 ? bytes.slice(1) : null); } -async function send4GrayLut() { - await epdWrite(0x20, "000A0000000160141400000100140000000100130A010001000000000000000000000000000000000000"); // vcom - await epdWrite(0x21, "400A0000000190141400000110140A000001A01301000001000000000000000000000000000000000000"); // red not use - await epdWrite(0x22, "400A0000000190141400000100140A000001990C01030401000000000000000000000000000000000000"); // bw r - await epdWrite(0x23, "400A0000000190141400000100140A000001990B04040101000000000000000000000000000000000000"); // wb w - await epdWrite(0x24, "800A0000000190141400000120140A000001501301000001000000000000000000000000000000000000"); // bb b - await epdWrite(0x25, "400A0000000190141400000110140A000001A01301000001000000000000000000000000000000000000"); // vcom -} - -function getImageData(canvas, driver, mode) { - if (mode === '4gray') { - return canvas2gray(canvas); - } else { - let data = canvas2bytes(canvas, 'bw'); - if (mode.startsWith('bwr')) { - const invert = (driver === '02') || (driver === '05'); - data.push(...canvas2bytes(canvas, 'red', invert)); - } - return data; - } -} - async function sendimg() { const status = document.getElementById("status"); - const canvas = document.getElementById("canvas"); const driver = document.getElementById("epddriver").value; const mode = document.getElementById('dithering').value; - const imgArray = getImageData(canvas, driver, mode); - const ramSize = canvas.width * canvas.height / 8; if (mode === '') { alert('请选择一种取模算法!'); @@ -166,21 +139,15 @@ async function sendimg() { startTime = new Date().getTime(); status.parentElement.style.display = "block"; - if (imgArray.length === ramSize * 2) { - await epdWrite(driver === "02" ? 0x24 : 0x10, imgArray.slice(0, ramSize)); - await epdWrite(driver === "02" ? 0x26 : 0x13, imgArray.slice(ramSize)); + if (mode.startsWith('bwr')) { + const invert = (driver === '02') || (driver === '05'); + await epdWrite(driver === "02" ? 0x24 : 0x10, canvas2bytes(canvas, 'bw')); + await epdWrite(driver === "02" ? 0x26 : 0x13, canvas2bytes(canvas, 'red', invert)); } else { - await epdWrite(driver === "04" ? 0x24 : 0x13, imgArray); + await epdWrite(driver === "04" ? 0x24 : 0x13, canvas2bytes(canvas, 'bw')); } - if (mode === "4gray") { - await epdWrite(0x00, [0x3F]); // Load LUT from register - await send4GrayLut(); - await write(EpdCmd.DISPLAY); - await epdWrite(0x00, [0x1F]); // Load LUT from OTP - } else { - await write(EpdCmd.DISPLAY); - } + await write(EpdCmd.REFRESH); const sendTime = (new Date().getTime() - startTime) / 1000.0; addLog(`发送完成!耗时: ${sendTime}s`); @@ -320,9 +287,6 @@ function intToHex(intIn) { } async function update_image() { - const canvas = document.getElementById("canvas"); - const ctx = canvas.getContext("2d"); - let image = new Image();; const image_file = document.getElementById('image_file'); if (image_file.files.length > 0) { @@ -341,21 +305,17 @@ async function update_image() { function clear_canvas() { if(confirm('确认清除画布内容?')) { - const ctx = canvas.getContext("2d"); ctx.fillStyle = 'white'; ctx.fillRect(0, 0, canvas.width, canvas.height); } } function convert_dithering() { - const ctx = canvas.getContext("2d"); const mode = document.getElementById('dithering').value; if (mode === '') return; if (mode.startsWith('bwr')) { ditheringCanvasByPalette(canvas, bwrPalette, mode); - } else if (mode === '4gray') { - dithering(ctx, canvas.width, canvas.height, 4, "gray"); } else { dithering(ctx, canvas.width, canvas.height, parseInt(document.getElementById('threshold').value), mode); } @@ -396,6 +356,7 @@ function checkDebugMode() { document.body.onload = () => { canvas = document.getElementById('canvas'); + ctx = canvas.getContext("2d"); updateButtonStatus(); update_image();