Skip to content

Commit

Permalink
Version 1.1.8
Browse files Browse the repository at this point in the history
- fix for incomplete download in GxEPD2_WiFi_Example
- added missing method displayWindow() to GxEPD2_GFX base class
- fix and clean up of initial refresh for panels with differential update
- add clean of controller buffer(s) on initial write to controller, for partial update.
  • Loading branch information
ZinggJM committed May 31, 2019
1 parent 49aaf2b commit febed07
Show file tree
Hide file tree
Showing 34 changed files with 212 additions and 343 deletions.
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,14 @@
#### other supported panels
- ED060SCT 6" grey levels, on Waveshare e-Paper IT8951 Driver HAT

### Version 1.1.7
### Version 1.1.8
- fix for incomplete download in GxEPD2_WiFi_Example
- added missing method displayWindow() to GxEPD2_GFX base class
- fix and clean up of initial refresh for panels with differential update
- initial refresh needs to be full update, not "fast partial update", for these panels,
- as the screen content may differ from the "previous buffer" content.
- add clean of controller buffer(s) on initial write to controller, for partial update.
#### Version 1.1.7
- enhanced support for full buffered, non-paged use, for processors with enough RAM
- use void display(bool partial_update_mode = false); corresponds to update() in GxEPD
- use added void displayWindow(uint16_t x, uint16_t y, uint16_t w, uint16_t h);
Expand Down
3 changes: 2 additions & 1 deletion examples/GxEPD2_Example/GxEPD2_Example.ino
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,14 @@

// mapping suggestion from Waveshare SPI e-Paper to Wemos D1 mini
// BUSY -> D2, RST -> D4, DC -> D3, CS -> D8, CLK -> D5, DIN -> D7, GND -> GND, 3.3V -> 3.3V
// NOTE for ESP8266: using SS (GPIO15) for CS may cause boot mode problems, use different pin in case

// mapping suggestion from Waveshare SPI e-Paper to generic ESP8266
// BUSY -> GPIO4, RST -> GPIO2, DC -> GPIO0, CS -> GPIO15, CLK -> GPIO14, DIN -> GPIO13, GND -> GND, 3.3V -> 3.3V
// NOTE for ESP8266: using SS (GPIO15) for CS may cause boot mode problems, use different pin in case

// mapping of Waveshare e-Paper ESP8266 Driver Board
// BUSY -> GPIO16, RST -> GPIO5, DC -> GPIO4, CS -> GPIO15, CLK -> GPIO14, DIN -> GPIO13, GND -> GND, 3.3V -> 3.3V

// NOTE for ESP8266: using SS (GPIO15) for CS may cause boot mode problems, use different pin in case

// mapping suggestion for ESP32, e.g. LOLIN32, see .../variants/.../pins_arduino.h for your board
Expand Down
12 changes: 6 additions & 6 deletions examples/GxEPD2_Spiffs_Loader/GxEPD2_Spiffs_Loader.ino
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ void downloadFile_HTTP(const char* host, const char* path, const char* filename,
"Connection: close\r\n\r\n");
Serial.println("request sent");
bool ok = false;
while (client.connected())
while (client.connected() || client.available())
{
String line = client.readStringUntil('\n');
if (!ok)
Expand Down Expand Up @@ -212,7 +212,7 @@ void downloadFile_HTTP(const char* host, const char* path, const char* filename,
Serial.print(target); Serial.println(" open failed");
return;
}
while (client.connected())
while (client.connected() || client.available())
{
size_t available = client.available();
size_t fetch = available <= sizeof(buffer) ? available : sizeof(buffer);
Expand Down Expand Up @@ -268,7 +268,7 @@ void downloadFile_HTTPS(const char* host, const char* path, const char* filename
"Connection: close\r\n\r\n");
Serial.println("request sent");
bool ok = false;
while (client.connected())
while (client.connected() || client.available())
{
String line = client.readStringUntil('\n');
if (!ok)
Expand Down Expand Up @@ -302,17 +302,17 @@ void downloadFile_HTTPS(const char* host, const char* path, const char* filename
Serial.print(target); Serial.println(" open failed");
return;
}
while (client.connected())
while (client.connected() || client.available())
{
// this doesn't work as expected, but it helps for long downloads
int32_t start = millis();
for (int16_t t = 0, dly = 50; t < 20; t++, dly += 50)
{
if (!client.connected()) break;
if (!(client.connected() || client.available())) break;
if (client.available()) break; // read would not recover after having returned 0
delay(dly);
}
if (!client.connected()) break;
if (!(client.connected() || client.available())) break;
int32_t elapsed = millis() - start;
if (elapsed > 250)
{
Expand Down
32 changes: 16 additions & 16 deletions examples/GxEPD2_WiFi_Example/GxEPD2_WiFi_Example.ino
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ void showBitmapFrom_HTTP(const char* host, const char* path, const char* filenam
Serial.println(String("http://") + host + path + filename);
client.print(String("GET ") + path + filename + " HTTP/1.1\r\n" +
"Host: " + host + "\r\n" +
"User-Agent: GxEPD2_Spiffs_Loader\r\n" +
"User-Agent: GxEPD2_WiFi_Example\r\n" +
"Connection: close\r\n\r\n");
Serial.println("request sent");
while (client.connected())
Expand Down Expand Up @@ -443,7 +443,7 @@ void showBitmapFrom_HTTP(const char* host, const char* path, const char* filenam
bytes_read += skip(client, rowPosition - bytes_read);
for (uint16_t row = 0; row < h; row++, rowPosition += rowSize) // for each line
{
if (!connection_ok || !client.connected()) break;
if (!connection_ok || !(client.connected() || client.available())) break;
delay(1); // yield() to avoid WDT
uint32_t in_remain = rowSize;
uint32_t in_idx = 0;
Expand All @@ -456,7 +456,7 @@ void showBitmapFrom_HTTP(const char* host, const char* path, const char* filenam
for (uint16_t col = 0; col < w; col++) // for each pixel
{
yield();
if (!connection_ok || !client.connected()) break;
if (!connection_ok || !(client.connected() || client.available())) break;
// Time to read more pixel data?
if (in_idx >= in_bytes) // ok, exact match for 24bit also (size IS multiple of 3)
{
Expand Down Expand Up @@ -580,7 +580,7 @@ void drawBitmapFrom_HTTP_ToBuffer(const char* host, const char* path, const char
Serial.println(String("http://") + host + path + filename);
client.print(String("GET ") + path + filename + " HTTP/1.1\r\n" +
"Host: " + host + "\r\n" +
"User-Agent: GxEPD2_Spiffs_Loader\r\n" +
"User-Agent: GxEPD2_WiFi_Example\r\n" +
"Connection: close\r\n\r\n");
Serial.println("request sent");
while (client.connected())
Expand Down Expand Up @@ -671,7 +671,7 @@ void drawBitmapFrom_HTTP_ToBuffer(const char* host, const char* path, const char
bytes_read += skip(client, rowPosition - bytes_read);
for (uint16_t row = 0; row < h; row++, rowPosition += rowSize) // for each line
{
if (!connection_ok || !client.connected()) break;
if (!connection_ok || !(client.connected() || client.available())) break;
delay(1); // yield() to avoid WDT
uint32_t in_remain = rowSize;
uint32_t in_idx = 0;
Expand All @@ -682,7 +682,7 @@ void drawBitmapFrom_HTTP_ToBuffer(const char* host, const char* path, const char
for (uint16_t col = 0; col < w; col++) // for each pixel
{
yield();
if (!connection_ok || !client.connected()) break;
if (!connection_ok || !(client.connected() || client.available())) break;
// Time to read more pixel data?
if (in_idx >= in_bytes) // ok, exact match for 24bit also (size IS multiple of 3)
{
Expand Down Expand Up @@ -830,7 +830,7 @@ void showBitmapFrom_HTTPS(const char* host, const char* path, const char* filena
Serial.println(String("https://") + host + path + filename);
client.print(String("GET ") + path + filename + " HTTP/1.1\r\n" +
"Host: " + host + "\r\n" +
"User-Agent: GxEPD2_Spiffs_Loader\r\n" +
"User-Agent: GxEPD2_WiFi_Example\r\n" +
"Connection: close\r\n\r\n");
Serial.println("request sent");
while (client.connected())
Expand Down Expand Up @@ -919,7 +919,7 @@ void showBitmapFrom_HTTPS(const char* host, const char* path, const char* filena
bytes_read += skip(client, rowPosition - bytes_read);
for (uint16_t row = 0; row < h; row++, rowPosition += rowSize) // for each line
{
if (!connection_ok || !client.connected()) break;
if (!connection_ok || !(client.connected() || client.available())) break;
delay(1); // yield() to avoid WDT
uint32_t in_remain = rowSize;
uint32_t in_idx = 0;
Expand All @@ -932,7 +932,7 @@ void showBitmapFrom_HTTPS(const char* host, const char* path, const char* filena
for (uint16_t col = 0; col < w; col++) // for each pixel
{
yield();
if (!connection_ok || !client.connected()) break;
if (!connection_ok || !(client.connected() || client.available())) break;
// Time to read more pixel data?
if (in_idx >= in_bytes) // ok, exact match for 24bit also (size IS multiple of 3)
{
Expand Down Expand Up @@ -1077,7 +1077,7 @@ void drawBitmapFrom_HTTPS_ToBuffer(const char* host, const char* path, const cha
Serial.println(String("https://") + host + path + filename);
client.print(String("GET ") + path + filename + " HTTP/1.1\r\n" +
"Host: " + host + "\r\n" +
"User-Agent: GxEPD2_Spiffs_Loader\r\n" +
"User-Agent: GxEPD2_WiFi_Example\r\n" +
"Connection: close\r\n\r\n");
Serial.println("request sent");
while (client.connected())
Expand Down Expand Up @@ -1168,7 +1168,7 @@ void drawBitmapFrom_HTTPS_ToBuffer(const char* host, const char* path, const cha
bytes_read += skip(client, rowPosition - bytes_read);
for (uint16_t row = 0; row < h; row++, rowPosition += rowSize) // for each line
{
if (!connection_ok || !client.connected()) break;
if (!connection_ok || !(client.connected() || client.available())) break;
delay(1); // yield() to avoid WDT
uint32_t in_remain = rowSize;
uint32_t in_idx = 0;
Expand All @@ -1179,7 +1179,7 @@ void drawBitmapFrom_HTTPS_ToBuffer(const char* host, const char* path, const cha
for (uint16_t col = 0; col < w; col++) // for each pixel
{
yield();
if (!connection_ok || !client.connected()) break;
if (!connection_ok || !(client.connected() || client.available())) break;
// Time to read more pixel data?
if (in_idx >= in_bytes) // ok, exact match for 24bit also (size IS multiple of 3)
{
Expand Down Expand Up @@ -1312,7 +1312,7 @@ uint32_t skip(BearSSL::WiFiClientSecure& client, int32_t bytes)
{
int32_t remain = bytes;
uint32_t start = millis();
while (client.connected() && (remain > 0))
while ((client.connected() || client.available()) && (remain > 0))
{
if (client.available())
{
Expand All @@ -1329,7 +1329,7 @@ uint32_t read(BearSSL::WiFiClientSecure& client, uint8_t* buffer, int32_t bytes)
{
int32_t remain = bytes;
uint32_t start = millis();
while (client.connected() && (remain > 0))
while ((client.connected() || client.available()) && (remain > 0))
{
if (client.available())
{
Expand All @@ -1349,7 +1349,7 @@ uint32_t skip(WiFiClient& client, int32_t bytes)
{
int32_t remain = bytes;
uint32_t start = millis();
while (client.connected() && (remain > 0))
while ((client.connected() || client.available()) && (remain > 0))
{
if (client.available())
{
Expand All @@ -1366,7 +1366,7 @@ uint32_t read(WiFiClient& client, uint8_t* buffer, int32_t bytes)
{
int32_t remain = bytes;
uint32_t start = millis();
while (client.connected() && (remain > 0))
while ((client.connected() || client.available()) && (remain > 0))
{
if (client.available())
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
name=GxEPD2_ParticleExample
dependencies.GxEPD2=1.1.7
dependencies.GxEPD2=1.1.8
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=GxEPD2
version=1.1.7
version=1.1.8
author=Jean-Marc Zingg
maintainer=Jean-Marc Zingg
sentence=Arduino Display Library for SPI E-Paper displays from Dalian Good Display and Waveshare.
Expand Down
5 changes: 4 additions & 1 deletion src/GxEPD2_EPD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ GxEPD2_EPD::GxEPD2_EPD(int8_t cs, int8_t dc, int8_t rst, int8_t busy, int8_t bus
_cs(cs), _dc(dc), _rst(rst), _busy(busy), _busy_level(busy_level), _busy_timeout(busy_timeout), _diag_enabled(false),
_spi_settings(4000000, MSBFIRST, SPI_MODE0)
{
_initial_write = true;
_initial_refresh = true;
_power_is_on = false;
_using_partial_mode = false;
_hibernating = false;
Expand All @@ -35,7 +37,8 @@ void GxEPD2_EPD::init(uint32_t serial_diag_bitrate)

void GxEPD2_EPD::init(uint32_t serial_diag_bitrate, bool initial, bool pulldown_rst_mode)
{
_initial = initial;
_initial_write = initial;
_initial_refresh = initial;
_pulldown_rst_mode = pulldown_rst_mode;
_power_is_on = false;
_using_partial_mode = false;
Expand Down
3 changes: 2 additions & 1 deletion src/GxEPD2_EPD.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ class GxEPD2_EPD
uint32_t _busy_timeout;
bool _diag_enabled, _pulldown_rst_mode;
SPISettings _spi_settings;
bool _initial, _power_is_on, _using_partial_mode, _hibernating;
bool _initial_write, _initial_refresh;
bool _power_is_on, _using_partial_mode, _hibernating;
};

#endif
9 changes: 9 additions & 0 deletions src/GxEPD2_GFX.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#define _GxEPD2_GFX_H_

#include <Adafruit_GFX.h>
#include <GxEPD2_EPD.h>

class GxEPD2_GFX : public Adafruit_GFX
{
Expand All @@ -29,7 +30,15 @@ class GxEPD2_GFX : public Adafruit_GFX
// pulldown_rst_mode true for alternate RST handling to avoid feeding 5V through RST pin
virtual void init(uint32_t serial_diag_bitrate, bool initial, bool pulldown_rst_mode = false) = 0;
virtual void fillScreen(uint16_t color) = 0; // 0x0 black, >0x0 white, to buffer
// display buffer content to screen, useful for full screen buffer
virtual void display(bool partial_update_mode = false) = 0;
// display part of buffer content to screen, useful for full screen buffer
// displayWindow, use parameters according to actual rotation.
// x and w should be multiple of 8, for rotation 0 or 2,
// y and h should be multiple of 8, for rotation 1 or 3,
// else window is increased as needed,
// this is an addressing limitation of the e-paper controllers
virtual void displayWindow(uint16_t x, uint16_t y, uint16_t w, uint16_t h) = 0;
virtual void setFullWindow() = 0;
// setPartialWindow, use parameters according to actual rotation.
// x and w should be multiple of 8, for rotation 0 or 2,
Expand Down
13 changes: 10 additions & 3 deletions src/epd/GxEPD2_154.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ GxEPD2_154::GxEPD2_154(int8_t cs, int8_t dc, int8_t rst, int8_t busy) :

void GxEPD2_154::clearScreen(uint8_t value)
{
if (_initial)
_initial_write = false; // initial full screen buffer clean done
if (_initial_refresh)
{
_Init_Full();
_setPartialRamArea(0, 0, WIDTH, HEIGHT);
Expand All @@ -29,6 +30,7 @@ void GxEPD2_154::clearScreen(uint8_t value)
_writeData(value);
}
_Update_Full();
_initial_refresh = false; // initial full update done
}
else
{
Expand All @@ -49,12 +51,13 @@ void GxEPD2_154::clearScreen(uint8_t value)
_writeData(value);
}
_Update_Part();
_initial = false;
}

void GxEPD2_154::writeScreenBuffer(uint8_t value)
{
if (_initial) clearScreen(value);
_initial_write = false; // initial full screen buffer clean done
// this controller has no command to write "old data"
if (_initial_refresh) clearScreen(value);
else _writeScreenBuffer(value);
}

Expand All @@ -71,6 +74,7 @@ void GxEPD2_154::_writeScreenBuffer(uint8_t value)

void GxEPD2_154::writeImage(const uint8_t bitmap[], int16_t x, int16_t y, int16_t w, int16_t h, bool invert, bool mirror_y, bool pgm)
{
if (_initial_write) writeScreenBuffer(); // initial full screen buffer clean
delay(1); // yield() to avoid WDT on ESP8266 and ESP32
int16_t wb = (w + 7) / 8; // width bytes, bitmaps are padded
x -= x % 8; // byte boundary
Expand Down Expand Up @@ -116,6 +120,7 @@ void GxEPD2_154::writeImage(const uint8_t bitmap[], int16_t x, int16_t y, int16_
void GxEPD2_154::writeImagePart(const uint8_t bitmap[], int16_t x_part, int16_t y_part, int16_t w_bitmap, int16_t h_bitmap,
int16_t x, int16_t y, int16_t w, int16_t h, bool invert, bool mirror_y, bool pgm)
{
if (_initial_write) writeScreenBuffer(); // initial full screen buffer clean
delay(1); // yield() to avoid WDT on ESP8266 and ESP32
if ((w_bitmap < 0) || (h_bitmap < 0) || (w < 0) || (h < 0)) return;
if ((x_part < 0) || (x_part >= w_bitmap)) return;
Expand Down Expand Up @@ -233,11 +238,13 @@ void GxEPD2_154::refresh(bool partial_update_mode)
{
if (_using_partial_mode) _Init_Full();
_Update_Full();
_initial_refresh = false; // initial full update done
}
}

void GxEPD2_154::refresh(int16_t x, int16_t y, int16_t w, int16_t h)
{
if (_initial_refresh) return refresh(false); // initial update needs be full update
x -= x % 8; // byte boundary
w -= x % 8; // byte boundary
int16_t x1 = x < 0 ? 0 : x; // limit
Expand Down
Loading

0 comments on commit febed07

Please sign in to comment.