Forked from dbushell/rpi-gpio-epaper-full-picture.js
Created
January 5, 2018 23:26
-
-
Save kingsloi/8516dfbd242044b36c176e3982057e47 to your computer and use it in GitHub Desktop.
rpi-gpio-epaper full picture example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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