Skip to content

Commit

Permalink
Add deep sleep between updates for waveshare epaper 1.54in and 1.54in…
Browse files Browse the repository at this point in the history
…v2 (#5961)
  • Loading branch information
mathieu-mp committed Dec 19, 2023
1 parent 0a117eb commit 52b9668
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 7 deletions.
33 changes: 33 additions & 0 deletions esphome/components/waveshare_epaper/waveshare_epaper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,25 @@ void WaveshareEPaper::on_safe_shutdown() { this->deep_sleep(); }
// ========================================================

void WaveshareEPaperTypeA::initialize() {
// Achieve display intialization
this->init_display_();
// If a reset pin is configured, eligible displays can be set to deep sleep
// between updates, as recommended by the hardware provider
if (this->reset_pin_ != nullptr) {
switch (this->model_) {
// More models can be added here to enable deep sleep if eligible
case WAVESHARE_EPAPER_1_54_IN:
case WAVESHARE_EPAPER_1_54_IN_V2:
this->deep_sleep_between_updates_ = true;
ESP_LOGI(TAG, "Set the display to deep sleep");
this->deep_sleep();
break;
default:
break;
}
}
}
void WaveshareEPaperTypeA::init_display_() {
if (this->model_ == TTGO_EPAPER_2_13_IN_B74) {
this->reset_pin_->digital_write(false);
delay(10);
Expand Down Expand Up @@ -261,6 +280,13 @@ void HOT WaveshareEPaperTypeA::display() {
bool full_update = this->at_update_ == 0;
bool prev_full_update = this->at_update_ == 1;

if (this->deep_sleep_between_updates_) {
ESP_LOGI(TAG, "Wake up the display");
this->reset_();
this->wait_until_idle_();
this->init_display_();
}

if (!this->wait_until_idle_()) {
this->status_set_warning();
return;
Expand Down Expand Up @@ -384,6 +410,11 @@ void HOT WaveshareEPaperTypeA::display() {
this->command(0xFF);

this->status_clear_warning();

if (this->deep_sleep_between_updates_) {
ESP_LOGI(TAG, "Set the display back to deep sleep");
this->deep_sleep();
}
}
int WaveshareEPaperTypeA::get_width_internal() {
switch (this->model_) {
Expand Down Expand Up @@ -445,6 +476,8 @@ void WaveshareEPaperTypeA::set_full_update_every(uint32_t full_update_every) {

uint32_t WaveshareEPaperTypeA::idle_timeout_() {
switch (this->model_) {
case WAVESHARE_EPAPER_1_54_IN:
case WAVESHARE_EPAPER_1_54_IN_V2:
case TTGO_EPAPER_2_13_IN_B1:
return 2500;
default:
Expand Down
25 changes: 18 additions & 7 deletions esphome/components/waveshare_epaper/waveshare_epaper.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,20 @@ class WaveshareEPaperTypeA : public WaveshareEPaper {
void display() override;

void deep_sleep() override {
if (this->model_ == WAVESHARE_EPAPER_2_9_IN_V2 || this->model_ == WAVESHARE_EPAPER_1_54_IN_V2) {
// COMMAND DEEP SLEEP MODE
this->command(0x10);
this->data(0x01);
} else {
// COMMAND DEEP SLEEP MODE
this->command(0x10);
switch (this->model_) {
// Models with specific deep sleep command and data
case WAVESHARE_EPAPER_1_54_IN:
case WAVESHARE_EPAPER_1_54_IN_V2:
case WAVESHARE_EPAPER_2_9_IN_V2:
// COMMAND DEEP SLEEP MODE
this->command(0x10);
this->data(0x01);
break;
// Other models default to simple deep sleep command
default:
// COMMAND DEEP SLEEP
this->command(0x10);
break;
}
this->wait_until_idle_();
}
Expand All @@ -108,6 +115,8 @@ class WaveshareEPaperTypeA : public WaveshareEPaper {
protected:
void write_lut_(const uint8_t *lut, uint8_t size);

void init_display_();

int get_width_internal() override;

int get_height_internal() override;
Expand All @@ -118,6 +127,8 @@ class WaveshareEPaperTypeA : public WaveshareEPaper {
uint32_t at_update_{0};
WaveshareEPaperTypeAModel model_;
uint32_t idle_timeout_() override;

bool deep_sleep_between_updates_{false};
};

enum WaveshareEPaperTypeBModel {
Expand Down

0 comments on commit 52b9668

Please sign in to comment.