Skip to content

Instantly share code, notes, and snippets.

@dbushell
Last active April 30, 2018 13:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dbushell/2207ee93f5d751c526c8909fd2f8ad28 to your computer and use it in GitHub Desktop.
Save dbushell/2207ee93f5d751c526c8909fd2f8ad28 to your computer and use it in GitHub Desktop.
const fs = require('fs');
const path = require('path');
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() {
let screen = new EPD();
await screen.init();
const imagePath = path.resolve(process.cwd(), 'picture.png');
const image = await readImage(imagePath);
const data = EPD.getImageRAM(image);
await screen.writeDisplayFull(data);
await screen.exit();
screen = null;
await EPD.sleep(500);
}
run();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment