Merge pull request #9 from Thorinair/master

Add 4 and 8 bit bitmap support, add invert parameters, VariPass example, fixes
This commit is contained in:
David Zovko 2020-07-27 22:45:56 +02:00 committed by GitHub
commit 59fa532d64
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 307 additions and 61 deletions

View File

@ -330,13 +330,13 @@ uint8_t Inkplate::getDisplayMode() {
return _displayMode;
}
int Inkplate::drawBitmapFromSD(SdFile* p, int x, int y) {
int Inkplate::drawBitmapFromSD(SdFile* p, int x, int y, bool invert) {
if(sdCardOk == 0) return 0;
struct bitmapHeader bmpHeader;
readBmpHeaderSd(p, &bmpHeader);
if (bmpHeader.signature != 0x4D42 || bmpHeader.compression != 0 || !(bmpHeader.color == 1 || bmpHeader.color == 24)) return 0;
if (bmpHeader.signature != 0x4D42 || bmpHeader.compression != 0 || !(bmpHeader.color == 1 || bmpHeader.color == 4 || bmpHeader.color == 8 || bmpHeader.color == 24)) return 0;
if ((bmpHeader.color == 24 || bmpHeader.color == 32) && getDisplayMode() != INKPLATE_3BIT) {
if ((bmpHeader.color == 4 || bmpHeader.color == 8 || bmpHeader.color == 24 || bmpHeader.color == 32) && getDisplayMode() != INKPLATE_3BIT) {
selectDisplayMode(INKPLATE_3BIT);
}
@ -344,17 +344,19 @@ int Inkplate::drawBitmapFromSD(SdFile* p, int x, int y) {
selectDisplayMode(INKPLATE_1BIT);
}
if (bmpHeader.color == 1) drawMonochromeBitmapSd(p, bmpHeader, x, y);
if (bmpHeader.color == 24) drawGrayscaleBitmap24Sd(p, bmpHeader, x, y);
if (bmpHeader.color == 1) drawMonochromeBitmapSd(p, bmpHeader, x, y, invert);
if (bmpHeader.color == 4) drawGrayscaleBitmap4Sd(p, bmpHeader, x, y, invert);
if (bmpHeader.color == 8) drawGrayscaleBitmap8Sd(p, bmpHeader, x, y, invert);
if (bmpHeader.color == 24) drawGrayscaleBitmap24Sd(p, bmpHeader, x, y, invert);
return 1;
}
int Inkplate::drawBitmapFromSD(char* fileName, int x, int y) {
int Inkplate::drawBitmapFromSD(char* fileName, int x, int y, bool invert) {
if(sdCardOk == 0) return 0;
SdFile dat;
if (dat.open(fileName, O_RDONLY)) {
return drawBitmapFromSD(&dat, x, y);
return drawBitmapFromSD(&dat, x, y, invert);
} else {
return 0;
}
@ -363,9 +365,9 @@ int Inkplate::drawBitmapFromSD(char* fileName, int x, int y) {
int Inkplate::drawBitmapFromWeb(WiFiClient* s, int x, int y, int len, bool invert) {
struct bitmapHeader bmpHeader;
readBmpHeaderWeb(s, &bmpHeader);
if (bmpHeader.signature != 0x4D42 || bmpHeader.compression != 0 || !(bmpHeader.color == 1 || bmpHeader.color == 24)) return 0;
if (bmpHeader.signature != 0x4D42 || bmpHeader.compression != 0 || !(bmpHeader.color == 1 || bmpHeader.color == 4 || bmpHeader.color == 8 || bmpHeader.color == 24)) return 0;
if ((bmpHeader.color == 24 || bmpHeader.color == 32) && getDisplayMode() != INKPLATE_3BIT) {
if ((bmpHeader.color == 4 || bmpHeader.color == 8 || bmpHeader.color == 24 || bmpHeader.color == 32) && getDisplayMode() != INKPLATE_3BIT) {
selectDisplayMode(INKPLATE_3BIT);
}
@ -374,6 +376,8 @@ int Inkplate::drawBitmapFromWeb(WiFiClient* s, int x, int y, int len, bool inver
}
if (bmpHeader.color == 1) drawMonochromeBitmapWeb(s, bmpHeader, x, y, len, invert);
if (bmpHeader.color == 4) drawGrayscaleBitmap4Web(s, bmpHeader, x, y, len, invert);
if (bmpHeader.color == 8) drawGrayscaleBitmap8Web(s, bmpHeader, x, y, len, invert);
if (bmpHeader.color == 24) drawGrayscaleBitmap24Web(s, bmpHeader, x, y, len, invert);
return 1;
@ -844,7 +848,7 @@ void Inkplate::readBmpHeaderWeb(WiFiClient *_s, struct bitmapHeader *_h) {
return;
}
int Inkplate::drawMonochromeBitmapSd(SdFile *f, struct bitmapHeader bmpHeader, int x, int y) {
int Inkplate::drawMonochromeBitmapSd(SdFile *f, struct bitmapHeader bmpHeader, int x, int y, bool invert) {
int w = bmpHeader.width;
int h = bmpHeader.height;
uint8_t paddingBits = w % 32;
@ -855,14 +859,18 @@ int Inkplate::drawMonochromeBitmapSd(SdFile *f, struct bitmapHeader bmpHeader, i
for (j = 0; j < h; j++) {
for (i = 0; i < w; i++) {
uint32_t pixelRow = f->read() << 24 | f->read() << 16 | f->read() << 8 | f->read();
if (invert)
pixelRow = ~pixelRow;
for (int n = 0; n < 32; n++) {
drawPixel((i * 32) + n + x, h - j + y, !(pixelRow & (1ULL << (31 - n))));
drawPixel((i * 32) + n + x, h - 1 - j + y, !(pixelRow & (1ULL << (31 - n))));
}
}
if (paddingBits) {
uint32_t pixelRow = f->read() << 24 | f->read() << 16 | f->read() << 8 | f->read();
if (invert)
pixelRow = ~pixelRow;
for (int n = 0; n < paddingBits; n++) {
drawPixel((i * 32) + n + x, h - j + y, !(pixelRow & (1ULL << (31 - n))));
drawPixel((i * 32) + n + x, h - 1 - j + y, !(pixelRow & (1ULL << (31 - n))));
}
}
}
@ -870,7 +878,62 @@ int Inkplate::drawMonochromeBitmapSd(SdFile *f, struct bitmapHeader bmpHeader, i
return 1;
}
int Inkplate::drawGrayscaleBitmap24Sd(SdFile *f, struct bitmapHeader bmpHeader, int x, int y) {
int Inkplate::drawGrayscaleBitmap4Sd(SdFile *f, struct bitmapHeader bmpHeader, int x, int y, bool invert) {
int w = bmpHeader.width;
int h = bmpHeader.height;
uint8_t paddingBits = w % 8;
w /= 8;
f->seekSet(bmpHeader.startRAW);
int i, j;
for (j = 0; j < h; j++) {
for (i = 0; i < w; i++) {
uint32_t pixelRow = f->read() << 24 | f->read() << 16 | f->read() << 8 | f->read();
if (invert)
pixelRow = ~pixelRow;
for (int n = 0; n < 8; n++) {
drawPixel((i * 8) + n + x, h - 1 - j + y, (pixelRow & (0xFULL << (28 - n*4))) >> (28 - n*4 + 1));
}
}
if (paddingBits) {
uint32_t pixelRow = f->read() << 24 | f->read() << 16 | f->read() << 8 | f->read();
if (invert)
pixelRow = ~pixelRow;
for (int n = 0; n < paddingBits; n++) {
drawPixel((i * 8) + n + x, h - 1 - j + y, ((pixelRow & (0xFULL << (28 - n*4)))) >> (28 - n*4 + 1));
}
}
}
f->close();
return 1;
}
int Inkplate::drawGrayscaleBitmap8Sd(SdFile *f, struct bitmapHeader bmpHeader, int x, int y, bool invert) {
int w = bmpHeader.width;
int h = bmpHeader.height;
char padding = w % 4;
f->seekSet(bmpHeader.startRAW);
int i, j;
for (j = 0; j < h; j++) {
for (i = 0; i < w; i++) {
uint8_t px = 0;
if (invert)
px = 255-f->read();
else
px = f->read();
drawPixel(i + x, h - 1 - j + y, px>>5);
}
if (padding) {
for (int p = 0; p < 4-padding; p++) {
f->read();
}
}
}
f->close();
return 1;
}
int Inkplate::drawGrayscaleBitmap24Sd(SdFile *f, struct bitmapHeader bmpHeader, int x, int y, bool invert) {
int w = bmpHeader.width;
int h = bmpHeader.height;
char padding = w % 4;
@ -884,10 +947,14 @@ int Inkplate::drawGrayscaleBitmap24Sd(SdFile *f, struct bitmapHeader bmpHeader,
//display.drawPixel(i + x, h - j + y, (uint8_t)(px*7));
//So then, we are convertng it to grayscale using good old average and gamma correction (from LUT). With this metod, it is still slow (full size image takes 4 seconds), but much beter than prev mentioned method.
uint8_t px = (f->read() * 2126 / 10000) + (f->read() * 7152 / 10000) + (f->read() * 722 / 10000);
uint8_t px = 0;
if (invert)
px = ((255-f->read()) * 2126 / 10000) + ((255-f->read()) * 7152 / 10000) + ((255-f->read()) * 722 / 10000);
else
px = (f->read() * 2126 / 10000) + (f->read() * 7152 / 10000) + (f->read() * 722 / 10000);
//drawPixel(i + x, h - j + y, gammaLUT[px]);
drawPixel(i + x, h - j + y, px>>5);
//drawPixel(i + x, h - j + y, px/32);
drawPixel(i + x, h - 1 - j + y, px>>5);
//drawPixel(i + x, h - j + y, px/32);
}
if (padding) {
for (int p = 0; p < padding; p++) {
@ -923,27 +990,107 @@ int Inkplate::drawMonochromeBitmapWeb(WiFiClient *s, struct bitmapHeader bmpHead
int i, j, k = bmpHeader.startRAW - 34;
for (j = 0; j < h; j++) {
for (i = 0; i < w; i++) {
uint8_t a = buf[k++];
uint8_t b = buf[k++];
uint8_t c = buf[k++];
uint8_t d = buf[k++];
uint32_t pixelRow = a << 24 | b << 16 | c << 8 | d;
uint32_t pixelRow = buf[k++] << 24 | buf[k++] << 16 | buf[k++] << 8 | buf[k++];
if (invert)
pixelRow = ~pixelRow;
for (int n = 0; n < 32; n++) {
drawPixel((i * 32) + n + x, h - j + y, !(pixelRow & (1ULL << (31 - n))));
drawPixel((i * 32) + n + x, h - 1 - j + y, !(pixelRow & (1ULL << (31 - n))));
}
}
if (paddingBits) {
uint8_t a = buf[k++];
uint8_t b = buf[k++];
uint8_t c = buf[k++];
uint8_t d = buf[k++];
uint32_t pixelRow = a << 24 | b << 16 | c << 8 | d;
uint32_t pixelRow = buf[k++] << 24 | buf[k++] << 16 | buf[k++] << 8 | buf[k++];
if (invert)
pixelRow = ~pixelRow;
for (int n = 0; n < paddingBits; n++) {
drawPixel((i * 32) + n + x, h - j + y, !(pixelRow & (1ULL << (31 - n))));
drawPixel((i * 32) + n + x, h - 1 - j + y, !(pixelRow & (1ULL << (31 - n))));
}
}
}
free(buf);
return 1;
}
int Inkplate::drawGrayscaleBitmap4Web(WiFiClient *s, struct bitmapHeader bmpHeader, int x, int y, int len, bool invert) {
int w = bmpHeader.width;
int h = bmpHeader.height;
char paddingBits = w % 8;
int total = len - 34;
w /= 8;
uint8_t* buf = (uint8_t*) ps_malloc(total);
if (buf == NULL)
return 0;
int pnt = 0;
while (pnt < total) {
int toread = s->available();
if (toread > 0) {
int read = s->read(buf+pnt, toread);
if (read > 0)
pnt += read;
}
}
int i, j, k = bmpHeader.startRAW - 34;
for (j = 0; j < h; j++) {
for (i = 0; i < w; i++) {
uint32_t pixelRow = buf[k++] << 24 | buf[k++] << 16 | buf[k++] << 8 | buf[k++];
if (invert)
pixelRow = ~pixelRow;
for (int n = 0; n < 8; n++) {
drawPixel((i * 8) + n + x, h - 1 - j + y, (pixelRow & (0xFULL << (28 - n*4))) >> (28 - n*4 + 1));
}
}
if (paddingBits) {
uint32_t pixelRow = buf[k++] << 24 | buf[k++] << 16 | buf[k++] << 8 | buf[k++];
if (invert)
pixelRow = ~pixelRow;
for (int n = 0; n < paddingBits; n++) {
drawPixel((i * 8) + n + x, h - 1 - j + y, ((pixelRow & (0xFULL << (28 - n*4)))) >> (28 - n*4 + 1));
}
}
}
free(buf);
return 1;
}
int Inkplate::drawGrayscaleBitmap8Web(WiFiClient *s, struct bitmapHeader bmpHeader, int x, int y, int len, bool invert) {
int w = bmpHeader.width;
int h = bmpHeader.height;
char padding = w % 4;
int total = len - 34;
uint8_t* buf = (uint8_t*) ps_malloc(total);
if (buf == NULL)
return 0;
int pnt = 0;
while (pnt < total) {
int toread = s->available();
if (toread > 0) {
int read = s->read(buf+pnt, toread);
if (read > 0)
pnt += read;
}
}
int i, j, k = bmpHeader.startRAW - 34;
for (j = 0; j < h; j++) {
for (i = 0; i < w; i++) {
uint8_t px = 0;
if (invert)
px = 255-buf[k++];
else
px = buf[k++];
drawPixel(i + x, h - 1 - j + y, px>>5);
}
if (padding) {
for (int p = 0; p < 4-padding; p++) {
k++;
}
}
}
@ -976,24 +1123,20 @@ int Inkplate::drawGrayscaleBitmap24Web(WiFiClient *s, struct bitmapHeader bmpHea
int i, j, k = bmpHeader.startRAW - 34;
for (j = 0; j < h; j++) {
for (i = 0; i < w; i++) {
uint8_t r = buf[k++];
uint8_t g = buf[k++];
uint8_t b = buf[k++];
if (invert) {
r = 255 - r;
g = 255 - g;
b = 255 - b;
}
//This is the proper way of converting True Color (24 Bit RGB) bitmap file into grayscale, but it takes waaay too much time (full size picture takes about 17s to decode!)
//float px = (0.2126 * (readByteFromSD(&file) / 255.0)) + (0.7152 * (readByteFromSD(&file) / 255.0)) + (0.0722 * (readByteFromSD(&file) / 255.0));
//px = pow(px, 1.5);
//display.drawPixel(i + x, h - j + y, (uint8_t)(px*7));
//So then, we are convertng it to grayscale using good old average and gamma correction (from LUT). With this metod, it is still slow (full size image takes 4 seconds), but much beter than prev mentioned method.
uint8_t px = (r * 2126 / 10000) + (g * 7152 / 10000) + (b * 722 / 10000);
uint8_t px = 0;
if (invert)
px = ((255-buf[k++]) * 2126 / 10000) + ((255-buf[k++]) * 7152 / 10000) + ((255-buf[k++]) * 722 / 10000);
else
px = (buf[k++] * 2126 / 10000) + (buf[k++] * 7152 / 10000) + (buf[k++] * 722 / 10000);
//drawPixel(i + x, h - j + y, gammaLUT[px]);
drawPixel(i + x, h - j + y, px>>5);
//drawPixel(i + x, h - j + y, px/32);
drawPixel(i + x, h - 1 - j + y, px>>5);
//drawPixel(i + x, h - j + y, px/32);
}
if (padding) {
for (int p = 0; p < padding; p++) {

View File

@ -131,8 +131,8 @@ class Inkplate : public Adafruit_GFX {
void einkOn(void);
void selectDisplayMode(uint8_t _mode);
uint8_t getDisplayMode();
int drawBitmapFromSD(SdFile* p, int x, int y);
int drawBitmapFromSD(char* fileName, int x, int y);
int drawBitmapFromSD(SdFile* p, int x, int y, bool invert = false);
int drawBitmapFromSD(char* fileName, int x, int y, bool invert = false);
int drawBitmapFromWeb(WiFiClient* s, int x, int y, int len, bool invert = false);
int drawBitmapFromWeb(char* url, int x, int y, bool invert = false);
int sdCardInit();
@ -168,9 +168,13 @@ class Inkplate : public Adafruit_GFX {
uint16_t read16(uint8_t* c);
void readBmpHeaderSd(SdFile *_f, struct bitmapHeader *_h);
void readBmpHeaderWeb(WiFiClient *_s, struct bitmapHeader *_h);
int drawMonochromeBitmapSd(SdFile *f, struct bitmapHeader bmpHeader, int x, int y);
int drawGrayscaleBitmap24Sd(SdFile *f, struct bitmapHeader bmpHeader, int x, int y);
int drawMonochromeBitmapSd(SdFile *f, struct bitmapHeader bmpHeader, int x, int y, bool invert);
int drawGrayscaleBitmap4Sd(SdFile *f, struct bitmapHeader bmpHeader, int x, int y, bool invert);
int drawGrayscaleBitmap8Sd(SdFile *f, struct bitmapHeader bmpHeader, int x, int y, bool invert);
int drawGrayscaleBitmap24Sd(SdFile *f, struct bitmapHeader bmpHeader, int x, int y, bool invert);
int drawMonochromeBitmapWeb(WiFiClient *s, struct bitmapHeader bmpHeader, int x, int y, int len, bool invert);
int drawGrayscaleBitmap4Web(WiFiClient *s, struct bitmapHeader bmpHeader, int x, int y, int len, bool invert);
int drawGrayscaleBitmap8Web(WiFiClient *s, struct bitmapHeader bmpHeader, int x, int y, int len, bool invert);
int drawGrayscaleBitmap24Web(WiFiClient *s, struct bitmapHeader bmpHeader, int x, int y, int len, bool invert);
void precalculateGamma(uint8_t* c, float gamma);
};

View File

@ -1,18 +1,14 @@
/*
10_Inkplate_Download_And_Show example for e-radionica Inkplate6
For this example you will need a micro USB cable, Inkplate6, an SD card and an
available WiFi connection.
For this example you will need a micro USB cable, Inkplate6, and an available WiFi connection.
Select "Inkplate 6(ESP32)" from Tools -> Board menu.
Don't have "Inkplate 6(ESP32)" option? Follow our tutorial and add it:
https://e-radionica.com/en/blog/add-inkplate-6-to-arduino-ide/
To work with SD card on Inkplate, you will need to add one extra library.
Download and install it from here: https://github.com/e-radionicacom/Inkplate-6-SDFat-Arduino-Library
You can open .bmp files that have color depth of 1 bit (monochrome bitmap) and
You can open .bmp files that have color depth of 1 bit (monochrome bitmap), 4 bit, 8 bit and
24 bit AND have resoluton smaller than 800x600 or otherwise it won't fit on screen.
This example will show you how you can download a .bmp file (picture) from the web to the SD card and
This example will show you how you can download a .bmp file (picture) from the web and
display that image on e-paper display.
Want to learn more about Inkplate? Visit www.inkplate.io
@ -21,9 +17,9 @@
*/
#include "Inkplate.h" //Include Inkplate library to the sketch
#include "HTTPClient.h" //Include library for HTTPClient
#include "WiFi.h" //Include library for WiFi
Inkplate display(INKPLATE_1BIT); //Create an object on Inkplate library and also set library into 1 Bit mode (Monochrome)
SdFile file; //Create SdFile object used for accessing files on SD card
const char* ssid = "YourWiFiSSID"; //Your WiFi SSID
const char* password = "YourPass"; //Your WiFi password
@ -49,26 +45,53 @@ void setup() {
//Draw the first image from web.
//Monochromatic bitmap with 1 bit depth. Images like this load quickest.
//The parameter set to true at the end may be used to swap the black and white channels.
//NOTE: Both drawBitmapFromWeb methods allow for an optional fourth "invert" parameter. Setting this parameter to true
//will flip all colors on the image, making black white and white black. This may be necessary when exporting bitmaps from
//certain softwares.
//Photo taken by: Roberto Fernandez
if(!display.drawBitmapFromWeb("https://varipass.org/neowise_mono.bmp", 0, 0, true)) {
//If is something failed (wrong filename or wrong bitmap format), write error message on the screen.
//REMEMBER! You can only use Windows Bitmap file with color depth of 1 or 24 bits with no compression!
//REMEMBER! You can only use Windows Bitmap file with color depth of 1, 4, 8 or 24 bits with no compression!
display.println("Image open error");
display.display();
}
display.display();
//Draw the second image from web.
//Draw the second image from web, this time using a HTTPClient to fetch the response manually.
//Full color 24 bit images are large and take a long time to load, will take around 20 secs.
HTTPClient http;
//Set parameters to speed up the download process.
http.getStream().setNoDelay(true);
http.getStream().setTimeout(1);
//Photo taken by: Roberto Fernandez
if(!display.drawBitmapFromWeb("https://varipass.org/neowise.bmp", 0, 0)) {
//If is something failed (wrong filename or wrong bitmap format), write error message on the screen.
//REMEMBER! You can only use Windows Bitmap file with color depth of 1 or 24 bits with no compression!
display.println("Image open error");
http.begin("https://varipass.org/neowise.bmp");
//Check response code.
int httpCode = http.GET();
if (httpCode == 200) {
//Get the response length and make sure it is not 0.
int32_t len = http.getSize();
if (len > 0) {
if(!display.drawBitmapFromWeb(http.getStreamPtr(), 0, 0, len)) {
//If is something failed (wrong filename or wrong bitmap format), write error message on the screen.
//REMEMBER! You can only use Windows Bitmap file with color depth of 1, 4, 8 or 24 bits with no compression!
display.println("Image open error");
display.display();
}
display.display();
}
else {
display.println("Invalid response length");
display.display();
}
}
else {
display.println("HTTP error");
display.display();
}
display.display();
http.end();
WiFi.mode(WIFI_OFF);
}

View File

@ -9,7 +9,7 @@
To work with SD card on Inkplate, you will need to add one extra library.
Download and install it from here: https://github.com/e-radionicacom/Inkplate-6-SDFat-Arduino-Library
You can open .bmp files that have color depth of 1 bit (monochrome bitmap) and
You can open .bmp files that have color depth of 1 bit (monochrome bitmap), 4 bit, 8 bit and
24 bit AND have resoluton smaller than 800x600 or otherwise it won't fit on screen.
This example will show you how you can read .bmp files (pictures) from SD card and
@ -36,9 +36,12 @@ void setup() {
display.partialUpdate();
//If card is properly init, try to load image and display it on e-paper at position X=0, Y=0
//NOTE: Both drawBitmapFromSD methods allow for an optional fourth "invert" parameter. Setting this parameter to true
//will flip all colors on the image, making black white and white black. This may be necessary when exporting bitmaps from
//certain softwares.
if(!display.drawBitmapFromSD("image1.bmp", 0, 0)) {
//If is something failed (wrong filename or wrong bitmap format), write error message on the screen.
//REMEMBER! You can only use Windows Bitmap file with color depth of 1 or 24 bits with no compression!
//REMEMBER! You can only use Windows Bitmap file with color depth of 1, 4, 8 or 24 bits with no compression!
display.println("Image open error");
display.display();
}

View File

@ -0,0 +1,73 @@
/*
3-Inkplate_VariPass_Graphs example for e-radionica Inkplate6
For this example you will need a micro USB cable, Inkplate6, and an available WiFi connection.
Select "Inkplate 6(ESP32)" from Tools -> Board menu.
Don't have "Inkplate 6(ESP32)" option? Follow our tutorial and add it:
https://e-radionica.com/en/blog/add-inkplate-6-to-arduino-ide/
This example will show you how you can use the API on the VariPass website to download and display
a sensor graph on the e-paper display.
VariPass is a website which allows you to host various online "variables" which you can write to
and read from using the VariPass API. This allows you to store sensor logs and later retrieve them
for graphing, analysis, etc.
This example uses an already public variable as an example. The graph is fed every minute with data
from Thorinair's (https://github.com/Thorinair/) geiger counter, so each startup of the Inkplate will
display updated values.
To learn more about VariPass and how you can use it for your own projects, please visit: https://varipass.org/
If you want to easily integrate the read/write functionality in your project, use the official library:
https://github.com/Thorinair/VariPass-for-ESP8266-ESP32
Want to learn more about Inkplate? Visit www.inkplate.io
Looking to get support? Write on our forums: http://forum.e-radionica.com/en/
23 July 2020 by e-radionica.com
*/
#include "Inkplate.h" //Include Inkplate library to the sketch
#include "WiFi.h" //Include library for WiFi
Inkplate display(INKPLATE_1BIT); //Create an object on Inkplate library and also set library into 1 Bit mode (Monochrome)
const char* ssid = "YourWiFiSSID"; //Your WiFi SSID
const char* password = "YourPass"; //Your WiFi password
void setup() {
display.begin(); //Init Inkplate library (you should call this function ONLY ONCE)
display.clearDisplay(); //Clear frame buffer of display
display.display(); //Put clear image on display
display.print("Connecting to WiFi...");
display.partialUpdate();
//Connect to the WiFi network.
WiFi.mode(WIFI_MODE_STA);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
display.print(".");
display.partialUpdate();
}
display.println("\nWiFi OK! Downloading...");
display.partialUpdate();
//Use a HTTP get request to fetch the graph from VariPass.
//The API expects a few parameters in the URL to allow it to work.
// action - Should be set to "sgraph" or "graph" in order to generate a compatible image.
// id - ID of the variable. It is enough to specify just the ID if the variable is public,
// but a "key" parameter should also be specified if not.
// width - Width of the generated graph, here set to half the Inkplate's width.
// height - Height of the generated graph, here set to half the Inkplate's height.
// eink - Should be set to true to generate a monochrome 1 bit bitmap better suitable for Inkplate.
// For more detailed explanation and more parameters, please visit the docs page: https://varipass.org/docs/
if(!display.drawBitmapFromWeb("https://api.varipass.org/?action=sgraph&id=kbg3eQfA&width=400&height=300&eink=true", 200, 150)) {
display.println("Image open error");
display.partialUpdate();
}
display.partialUpdate();
WiFi.mode(WIFI_OFF);
}
void loop() {
//Nothing...
}