1
0
mirror of https://github.com/esphome/esphome.git synced 2025-10-30 06:33:51 +00: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

@@ -2,7 +2,8 @@ import esphome.codegen as cg
import esphome.config_validation as cv
from esphome import pins
from esphome.components import lcd_base
from esphome.const import CONF_DATA_PINS, CONF_ENABLE_PIN, CONF_RS_PIN, CONF_RW_PIN, CONF_ID
from esphome.const import CONF_DATA_PINS, CONF_ENABLE_PIN, CONF_RS_PIN, CONF_RW_PIN, CONF_ID, \
CONF_LAMBDA
AUTO_LOAD = ['lcd_base']
@@ -42,3 +43,9 @@ def to_code(config):
if CONF_RW_PIN in config:
rw = yield cg.gpio_pin_expression(config[CONF_RW_PIN])
cg.add(var.set_rw_pin(rw))
if CONF_LAMBDA in config:
lambda_ = yield cg.process_lambda(config[CONF_LAMBDA],
[(GPIOLCDDisplay.operator('ref'), 'it')],
return_type=cg.void)
cg.add(var.set_writer(lambda_))

View File

@@ -8,6 +8,7 @@ namespace lcd_gpio {
class GPIOLCDDisplay : public lcd_base::LCDDisplay {
public:
void set_writer(std::function<void(GPIOLCDDisplay &)> &&writer) { this->writer_ = std::move(writer); }
void setup() override;
void set_data_pins(GPIOPin *d0, GPIOPin *d1, GPIOPin *d2, GPIOPin *d3) {
this->data_pins_[0] = d0;
@@ -36,10 +37,13 @@ class GPIOLCDDisplay : public lcd_base::LCDDisplay {
void write_n_bits(uint8_t value, uint8_t n) override;
void send(uint8_t value, bool rs) override;
void call_writer() override { this->writer_(*this); }
GPIOPin *rs_pin_{nullptr};
GPIOPin *rw_pin_{nullptr};
GPIOPin *enable_pin_{nullptr};
GPIOPin *data_pins_[8]{nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr};
std::function<void(GPIOLCDDisplay &)> writer_;
};
} // namespace lcd_gpio