Add reset_duration option for waveshare epaper HAT rev 2.1 (#1481)

Co-authored-by: Jesse Hills <3060199+jesserockz@users.noreply.github.com>
This commit is contained in:
Ben Owen 2021-12-12 16:27:11 -05:00 committed by GitHub
parent da45923d05
commit cec4a81e14
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 13 additions and 2 deletions

View file

@ -1,6 +1,6 @@
import esphome.codegen as cg import esphome.codegen as cg
import esphome.config_validation as cv import esphome.config_validation as cv
from esphome import pins from esphome import core, pins
from esphome.components import display, spi from esphome.components import display, spi
from esphome.const import ( from esphome.const import (
CONF_BUSY_PIN, CONF_BUSY_PIN,
@ -10,6 +10,7 @@ from esphome.const import (
CONF_LAMBDA, CONF_LAMBDA,
CONF_MODEL, CONF_MODEL,
CONF_PAGES, CONF_PAGES,
CONF_RESET_DURATION,
CONF_RESET_PIN, CONF_RESET_PIN,
) )
@ -95,6 +96,10 @@ CONFIG_SCHEMA = cv.All(
cv.Optional(CONF_RESET_PIN): pins.gpio_output_pin_schema, cv.Optional(CONF_RESET_PIN): pins.gpio_output_pin_schema,
cv.Optional(CONF_BUSY_PIN): pins.gpio_input_pin_schema, cv.Optional(CONF_BUSY_PIN): pins.gpio_input_pin_schema,
cv.Optional(CONF_FULL_UPDATE_EVERY): cv.uint32_t, cv.Optional(CONF_FULL_UPDATE_EVERY): cv.uint32_t,
cv.Optional(CONF_RESET_DURATION): cv.All(
cv.positive_time_period_milliseconds,
cv.Range(max=core.TimePeriod(milliseconds=500)),
),
} }
) )
.extend(cv.polling_component_schema("1s")) .extend(cv.polling_component_schema("1s"))
@ -135,3 +140,5 @@ async def to_code(config):
cg.add(var.set_busy_pin(reset)) cg.add(var.set_busy_pin(reset))
if CONF_FULL_UPDATE_EVERY in config: if CONF_FULL_UPDATE_EVERY in config:
cg.add(var.set_full_update_every(config[CONF_FULL_UPDATE_EVERY])) cg.add(var.set_full_update_every(config[CONF_FULL_UPDATE_EVERY]))
if CONF_RESET_DURATION in config:
cg.add(var.set_reset_duration(config[CONF_RESET_DURATION]))

View file

@ -16,6 +16,7 @@ class WaveshareEPaper : public PollingComponent,
float get_setup_priority() const override; float get_setup_priority() const override;
void set_reset_pin(GPIOPin *reset) { this->reset_pin_ = reset; } void set_reset_pin(GPIOPin *reset) { this->reset_pin_ = reset; }
void set_busy_pin(GPIOPin *busy) { this->busy_pin_ = busy; } void set_busy_pin(GPIOPin *busy) { this->busy_pin_ = busy; }
void set_reset_duration(uint32_t reset_duration) { this->reset_duration_ = reset_duration; }
void command(uint8_t value); void command(uint8_t value);
void data(uint8_t value); void data(uint8_t value);
@ -45,13 +46,14 @@ class WaveshareEPaper : public PollingComponent,
void reset_() { void reset_() {
if (this->reset_pin_ != nullptr) { if (this->reset_pin_ != nullptr) {
this->reset_pin_->digital_write(false); this->reset_pin_->digital_write(false);
delay(200); // NOLINT delay(reset_duration_); // NOLINT
this->reset_pin_->digital_write(true); this->reset_pin_->digital_write(true);
delay(200); // NOLINT delay(200); // NOLINT
} }
} }
uint32_t get_buffer_length_(); uint32_t get_buffer_length_();
uint32_t reset_duration_{200};
void start_command_(); void start_command_();
void end_command_(); void end_command_();

View file

@ -539,6 +539,7 @@ CONF_REFERENCE_TEMPERATURE = "reference_temperature"
CONF_REFRESH = "refresh" CONF_REFRESH = "refresh"
CONF_REPEAT = "repeat" CONF_REPEAT = "repeat"
CONF_REPOSITORY = "repository" CONF_REPOSITORY = "repository"
CONF_RESET_DURATION = "reset_duration"
CONF_RESET_PIN = "reset_pin" CONF_RESET_PIN = "reset_pin"
CONF_RESIZE = "resize" CONF_RESIZE = "resize"
CONF_RESOLUTION = "resolution" CONF_RESOLUTION = "resolution"

View file

@ -413,6 +413,7 @@ display:
reset_pin: GPIO23 reset_pin: GPIO23
model: 2.90in model: 2.90in
full_update_every: 30 full_update_every: 30
reset_duration: 200ms
lambda: |- lambda: |-
it.rectangle(0, 0, it.get_width(), it.get_height()); it.rectangle(0, 0, it.get_width(), it.get_height());
- platform: waveshare_epaper - platform: waveshare_epaper