mirror of
https://github.com/jam422470459/EPD-nRF52-hema213.git
synced 2025-12-06 16:42:49 +08:00
drop 4gray support
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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 */
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
#include "fonts.h"
|
||||
#include "Lunar.h"
|
||||
#include "GUI.h"
|
||||
#include "nrf.h"
|
||||
#include "nrf_log.h"
|
||||
#include <stdio.h>
|
||||
|
||||
|
||||
@@ -63,13 +63,10 @@
|
||||
<option value="floydsteinberg">floydsteinberg</option>
|
||||
<option value="Atkinson">Atkinson</option>
|
||||
</optgroup>
|
||||
<optgroup id="dithering-bwr" data-driver="02|03|05" label="黑白红多色">
|
||||
<optgroup id="dithering-bwr" data-driver="02|03|05" label="三色">
|
||||
<option value="bwr_floydsteinberg">黑白红floydsteinberg</option>
|
||||
<option value="bwr_Atkinson">黑白红Atkinson</option>
|
||||
</optgroup>
|
||||
<optgroup id="dithering-gray" data-driver="01" label="灰色">
|
||||
<option value="4gray">4 级灰度</option>
|
||||
</optgroup>
|
||||
</select>
|
||||
</div>
|
||||
<div class="flex-group">
|
||||
|
||||
@@ -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");
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user