Skip to content

Instantly share code, notes, and snippets.

@dbushell
Created October 2, 2017 07:45
Show Gist options
  • Save dbushell/dd36bef27ffd278140516151b1ed365c to your computer and use it in GitHub Desktop.
Save dbushell/dd36bef27ffd278140516151b1ed365c to your computer and use it in GitHub Desktop.
rpi-gpio-epaper full picture example
const fs = require('fs');
const PNG = require('pngjs').PNG;
const EPD = require('rpi-gpio-epaper');
function readImage(imagePath) {
return new Promise((resolve, reject) => {
fs
.createReadStream(imagePath)
.pipe(new PNG())
.on('parsed', function() {
const image = EPD.createImage(this.width, this.height);
for (let y = 0; y < this.height; y++) {
for (let x = 0; x < this.width; x++) {
image.view[y].writeUInt8(
EPD.toUInt8(
this.data[(this.width * y + x) << 2] > 128 ? 0xff : 0x00
),
x,
1
);
}
}
resolve(image);
});
});
}
async function run() {
const epd = new EPD({
model: {
/* ...model constants */
}
});
await epd.init();
const image = await readImage(picPath);
const data = EPD.getImageRAM(image);
await epd.writeDisplayFull(data);
await epd.exit();
}
run();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment