Skip to content

Commit

Permalink
LVGL render OK yay!
Browse files Browse the repository at this point in the history
  • Loading branch information
lupyuen committed May 28, 2023
1 parent 2e1c97e commit 5e4d661
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
5 changes: 3 additions & 2 deletions display.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@ lv_color_t *get_canvas_buffer(void)
int count = 0;
for (int i = 0; i < BUFFER_SIZE; i++) {
if (canvas_buffer[i].full != 0xfff5f5f5) { // TODO
lv_log("get_canvas_buffer: 0x%x", canvas_buffer[i].full);
// lv_log("get_canvas_buffer: 0x%x", canvas_buffer[i].full);
count++;
}
}
lv_log("get_canvas_buffer: %d", count);
lv_log("get_canvas_buffer: %d non-empty pixels", count);
lv_log("canvas_buffer: %p", canvas_buffer);
return canvas_buffer;
}

Expand Down
16 changes: 11 additions & 5 deletions lvglwasm.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,20 @@ request.onload = function() {
env: {
// Render the LVGL Canvas from Zig to HTML
// https://github.com/daneelsan/minimal-zig-wasm-canvas/blob/master/script.js
render: function() {
render: function() { // TODO: Add ptr, width, height
console.log("render: start");
const bufferOffset = wasm.instance.exports.getCanvasBuffer();
console.log({ bufferOffset });
const imageDataArray = wasmMemoryArray.slice(
bufferOffset,
bufferOffset + (canvas.width * canvas.height) * 4
);

// const imageDataArray = wasmMemoryArray.slice(
// bufferOffset,
// bufferOffset + (canvas.width * canvas.height) * 4
// );

const memory = wasm.instance.exports.memory;
const ptr = bufferOffset;
const len = (canvas.width * canvas.height) * 4;
const imageDataArray = new Uint8Array(memory.buffer, ptr, len)
imageData.data.set(imageDataArray);

context.clearRect(0, 0, canvas.width, canvas.height);
Expand Down
Binary file modified lvglwasm.wasm
Binary file not shown.

0 comments on commit 5e4d661

Please sign in to comment.