mirror of
https://github.com/esphome/esphome.git
synced 2024-11-25 00:18:11 +01:00
Add deep sleep between updates for waveshare epaper 1.54in and 1.54inv2 (#5961)
This commit is contained in:
parent
820f328248
commit
977e0184a7
2 changed files with 51 additions and 7 deletions
|
@ -167,6 +167,25 @@ void WaveshareEPaper::on_safe_shutdown() { this->deep_sleep(); }
|
||||||
// ========================================================
|
// ========================================================
|
||||||
|
|
||||||
void WaveshareEPaperTypeA::initialize() {
|
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) {
|
if (this->model_ == TTGO_EPAPER_2_13_IN_B74) {
|
||||||
this->reset_pin_->digital_write(false);
|
this->reset_pin_->digital_write(false);
|
||||||
delay(10);
|
delay(10);
|
||||||
|
@ -261,6 +280,13 @@ void HOT WaveshareEPaperTypeA::display() {
|
||||||
bool full_update = this->at_update_ == 0;
|
bool full_update = this->at_update_ == 0;
|
||||||
bool prev_full_update = this->at_update_ == 1;
|
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_()) {
|
if (!this->wait_until_idle_()) {
|
||||||
this->status_set_warning();
|
this->status_set_warning();
|
||||||
return;
|
return;
|
||||||
|
@ -384,6 +410,11 @@ void HOT WaveshareEPaperTypeA::display() {
|
||||||
this->command(0xFF);
|
this->command(0xFF);
|
||||||
|
|
||||||
this->status_clear_warning();
|
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() {
|
int WaveshareEPaperTypeA::get_width_internal() {
|
||||||
switch (this->model_) {
|
switch (this->model_) {
|
||||||
|
@ -445,6 +476,8 @@ void WaveshareEPaperTypeA::set_full_update_every(uint32_t full_update_every) {
|
||||||
|
|
||||||
uint32_t WaveshareEPaperTypeA::idle_timeout_() {
|
uint32_t WaveshareEPaperTypeA::idle_timeout_() {
|
||||||
switch (this->model_) {
|
switch (this->model_) {
|
||||||
|
case WAVESHARE_EPAPER_1_54_IN:
|
||||||
|
case WAVESHARE_EPAPER_1_54_IN_V2:
|
||||||
case TTGO_EPAPER_2_13_IN_B1:
|
case TTGO_EPAPER_2_13_IN_B1:
|
||||||
return 2500;
|
return 2500;
|
||||||
default:
|
default:
|
||||||
|
|
|
@ -92,13 +92,20 @@ class WaveshareEPaperTypeA : public WaveshareEPaper {
|
||||||
void display() override;
|
void display() override;
|
||||||
|
|
||||||
void deep_sleep() override {
|
void deep_sleep() override {
|
||||||
if (this->model_ == WAVESHARE_EPAPER_2_9_IN_V2 || this->model_ == WAVESHARE_EPAPER_1_54_IN_V2) {
|
switch (this->model_) {
|
||||||
// COMMAND DEEP SLEEP MODE
|
// Models with specific deep sleep command and data
|
||||||
this->command(0x10);
|
case WAVESHARE_EPAPER_1_54_IN:
|
||||||
this->data(0x01);
|
case WAVESHARE_EPAPER_1_54_IN_V2:
|
||||||
} else {
|
case WAVESHARE_EPAPER_2_9_IN_V2:
|
||||||
// COMMAND DEEP SLEEP MODE
|
// COMMAND DEEP SLEEP MODE
|
||||||
this->command(0x10);
|
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_();
|
this->wait_until_idle_();
|
||||||
}
|
}
|
||||||
|
@ -108,6 +115,8 @@ class WaveshareEPaperTypeA : public WaveshareEPaper {
|
||||||
protected:
|
protected:
|
||||||
void write_lut_(const uint8_t *lut, uint8_t size);
|
void write_lut_(const uint8_t *lut, uint8_t size);
|
||||||
|
|
||||||
|
void init_display_();
|
||||||
|
|
||||||
int get_width_internal() override;
|
int get_width_internal() override;
|
||||||
|
|
||||||
int get_height_internal() override;
|
int get_height_internal() override;
|
||||||
|
@ -118,6 +127,8 @@ class WaveshareEPaperTypeA : public WaveshareEPaper {
|
||||||
uint32_t at_update_{0};
|
uint32_t at_update_{0};
|
||||||
WaveshareEPaperTypeAModel model_;
|
WaveshareEPaperTypeAModel model_;
|
||||||
uint32_t idle_timeout_() override;
|
uint32_t idle_timeout_() override;
|
||||||
|
|
||||||
|
bool deep_sleep_between_updates_{false};
|
||||||
};
|
};
|
||||||
|
|
||||||
enum WaveshareEPaperTypeBModel {
|
enum WaveshareEPaperTypeBModel {
|
||||||
|
|
Loading…
Reference in a new issue