initial SSD1619 support

This commit is contained in:
Shuanglei Tao
2025-03-11 10:14:12 +08:00
parent d427580198
commit 19456a5886
11 changed files with 253 additions and 26 deletions

View File

@@ -122,7 +122,7 @@ function canvas2gray(canvas) {
}
// white: 1, black/red: 0
function canvas2bytes(canvas, type='bw') {
function canvas2bytes(canvas, type='bw', invert = false) {
const ctx = canvas.getContext("2d");
const imageData = ctx.getImageData(0, 0, canvas.width, canvas.height);
@@ -132,11 +132,14 @@ function canvas2bytes(canvas, type='bw') {
for (let y = 0; y < canvas.height; y++) {
for (let x = 0; x < canvas.width; x++) {
const i = (canvas.width * y + x) * 4;
let data;
if (type !== 'red') {
buffer.push(imageData.data[i] === 0 && imageData.data[i+1] === 0 && imageData.data[i+2] === 0 ? 0 : 1);
data = imageData.data[i] === 0 && imageData.data[i+1] === 0 && imageData.data[i+2] === 0 ? 0 : 1;
} else {
buffer.push(imageData.data[i] > 0 && imageData.data[i+1] === 0 && imageData.data[i+2] === 0 ? 0 : 1);
data = imageData.data[i] > 0 && imageData.data[i+1] === 0 && imageData.data[i+2] === 0 ? 0 : 1;
}
if (invert) data = ~data;
buffer.push(data);
if (buffer.length === 8) {
arr.push(parseInt(buffer.join(''), 2));

View File

@@ -147,8 +147,8 @@ function getImageData(canvas, driver, mode) {
return canvas2gray(canvas);
} else {
let data = canvas2bytes(canvas, 'bw');
if (driver === '03' && mode.startsWith('bwr')) {
data.push(...canvas2bytes(canvas, 'red'));
if (mode.startsWith('bwr')) {
data.push(...canvas2bytes(canvas, 'red', driver === '02'));
}
return data;
}
@@ -167,9 +167,9 @@ async function sendimg() {
return;
}
if (imgArray.length == ramSize * 2) {
await epdWrite(0x10, imgArray.slice(0, ramSize));
await epdWrite(0x13, imgArray.slice(ramSize));
if (imgArray.length === ramSize * 2) {
await epdWrite(driver === "02" ? 0x24 : 0x10, imgArray.slice(0, ramSize));
await epdWrite(driver === "02" ? 0x26 : 0x13, imgArray.slice(ramSize));
} else {
await epdWrite(driver === "03" ? 0x10 : 0x13, imgArray);
}