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

This commit is contained in:
mathieu-mp 2023-12-19 04:29:00 +01:00 committed by GitHub
parent 0a117eb562
commit 52b9668170
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 51 additions and 7 deletions

View File

@ -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);
@ -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;
@ -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_) {
@ -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:

View File

@ -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_();
}
@ -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;
@ -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 {