Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add deep sleep between updates for waveshare epaper 1.54in and 1.54inv2 #5961

Merged
merged 1 commit into from
Dec 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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