1
0
mirror of https://github.com/esphome/esphome.git synced 2025-09-26 23:22:21 +01:00

Add backlight handling for lcd_pcf8574 (#573)

* Add backlight handling for lcd_pcf8574

Switch the backlight on or off by calling id(mydisplay).backlight()
or id(mydisplay).no_backlight() in lamda functions (assuming mydisplay
is the custom id for the LCD).

* Use abstract method


Co-authored-by: Attila Darazs <attila@darazs.com>
Co-authored-by: Otto Winter <otto@otto-winter.com>
This commit is contained in:
Attila Darazs
2019-06-03 19:36:00 +02:00
committed by Otto Winter
parent ebe64e24f1
commit 30a542e763
8 changed files with 45 additions and 16 deletions

View File

@@ -1,12 +1,11 @@
import esphome.codegen as cg
import esphome.config_validation as cv
from esphome.components import display
from esphome.const import CONF_DIMENSIONS, CONF_LAMBDA
from esphome.const import CONF_DIMENSIONS
from esphome.core import coroutine
lcd_base_ns = cg.esphome_ns.namespace('lcd_base')
LCDDisplay = lcd_base_ns.class_('LCDDisplay', cg.PollingComponent)
LCDDisplayRef = LCDDisplay.operator('ref')
def validate_lcd_dimensions(value):
@@ -28,8 +27,3 @@ def setup_lcd_display(var, config):
yield cg.register_component(var, config)
yield display.register_display(var, config)
cg.add(var.set_dimensions(config[CONF_DIMENSIONS][0], config[CONF_DIMENSIONS][1]))
if CONF_LAMBDA in config:
lambda_ = yield cg.process_lambda(config[CONF_LAMBDA], [(LCDDisplayRef, 'it')],
return_type=cg.void)
cg.add(var.set_writer(lambda_))

View File

@@ -107,7 +107,7 @@ void LCDDisplay::update() {
for (uint8_t i = 0; i < this->rows_ * this->columns_; i++)
this->buffer_[i] = ' ';
this->writer_(*this);
this->call_writer();
this->display();
}
void LCDDisplay::command_(uint8_t value) { this->send(value, false); }

View File

@@ -12,11 +12,8 @@ namespace lcd_base {
class LCDDisplay;
using lcd_writer_t = std::function<void(LCDDisplay &)>;
class LCDDisplay : public PollingComponent {
public:
void set_writer(lcd_writer_t &&writer) { this->writer_ = std::move(writer); }
void set_dimensions(uint8_t columns, uint8_t rows) {
this->columns_ = columns;
this->rows_ = rows;
@@ -54,11 +51,11 @@ class LCDDisplay : public PollingComponent {
virtual void send(uint8_t value, bool rs) = 0;
void command_(uint8_t value);
virtual void call_writer() = 0;
uint8_t columns_;
uint8_t rows_;
uint8_t *buffer_{nullptr};
lcd_writer_t writer_;
};
} // namespace lcd_base