Skip to content

Commit abfad2b

Browse files
authored
Improved EPD wait with timeout
1 parent dad29e5 commit abfad2b

2 files changed

Lines changed: 22 additions & 15 deletions

File tree

src/main.cpp

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -384,15 +384,10 @@ void initDisplay(){
384384
writeSerial("Writing plane...");
385385
epd.writePlane();
386386
writeSerial("Refreshing display...");
387-
#ifdef TARGET_ESP32
388-
//no propper sleep implemented yet for ESP32
387+
389388
epd.refresh(REFRESH_FULL, false);
390-
delay(10000);
391-
#endif
392-
#ifdef TARGET_NRF
393-
epd.refresh(REFRESH_FULL, true);
394-
delay(2000);
395-
#endif
389+
waitforrefresh(60);
390+
396391
uint16_t newrotation = globalConfig.displays[0].rotation * 90 + 270;
397392
if(newrotation >= 360)newrotation = newrotation - 360;
398393
epd.setRotation(newrotation);
@@ -403,6 +398,23 @@ void initDisplay(){
403398
}
404399
}
405400

401+
bool waitforrefresh(int timeout){
402+
for (size_t i = 0; i < timeout * 10; i++){
403+
delay(100);
404+
if(i % 5 == 0)writeSerial(".",false);
405+
if(!epd.isBusy()){
406+
writeSerial(".");
407+
writeSerial("Refresh took ",false);
408+
writeSerial((String)((float)i / 10),false);
409+
writeSerial(" seconds");
410+
delay(200);
411+
return true;
412+
}
413+
}
414+
writeSerial("Refresh timed out");
415+
return false;
416+
}
417+
406418
void connect_callback(uint16_t conn_handle) {
407419
writeSerial("=== BLE CLIENT CONNECTED ===");
408420
}
@@ -774,14 +786,8 @@ void displayReceivedImage() {
774786
epd.initIO(globalConfig.displays[0].dc_pin, globalConfig.displays[0].reset_pin, globalConfig.displays[0].busy_pin, globalConfig.displays[0].cs_pin, globalConfig.displays[0].data_pin, globalConfig.displays[0].clk_pin);
775787
drawImageData();
776788
epd.writePlane();
777-
#ifdef TARGET_ESP32
778789
epd.refresh(REFRESH_FULL, false);
779-
delay(10000);
780-
#endif
781-
#ifdef TARGET_NRF
782-
epd.refresh(REFRESH_FULL, true);
783-
delay(2000);
784-
#endif
790+
waitforrefresh(60);
785791
epd.sleep(DEEP_SLEEP);
786792
pwrmgm(false);
787793
writeSerial("=== IMAGE DISPLAY COMPLETE ===");

src/main.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ uint8_t dictionaryBuffer[MAX_DICT_SIZE];
7474
uint8_t headerBuffer[6];
7575
uint8_t bleResponseBuffer[94];
7676

77+
bool waitforrefresh(int timeout);
7778
void pwrmgm(bool onoff);
7879
void writeSerial(String message, bool newLine = true);
7980
void connect_callback(uint16_t conn_handle);

0 commit comments

Comments
 (0)