mirror of
https://github.com/esphome/esphome.git
synced 2024-12-04 13:44:40 +01:00
93 lines
3.8 KiB
Python
93 lines
3.8 KiB
Python
import voluptuous as vol
|
|
|
|
import esphomeyaml.config_validation as cv
|
|
from esphomeyaml import pins
|
|
from esphomeyaml.components import display, spi
|
|
from esphomeyaml.components.spi import SPIComponent
|
|
from esphomeyaml.const import CONF_BUSY_PIN, CONF_CS_PIN, CONF_DC_PIN, CONF_FULL_UPDATE_EVERY, \
|
|
CONF_ID, CONF_LAMBDA, CONF_MODEL, CONF_RESET_PIN, CONF_SPI_ID
|
|
from esphomeyaml.cpp_generator import get_variable, Pvariable, process_lambda, add
|
|
from esphomeyaml.cpp_helpers import gpio_output_pin_expression, gpio_input_pin_expression, \
|
|
setup_component
|
|
from esphomeyaml.cpp_types import PollingComponent, App
|
|
|
|
DEPENDENCIES = ['spi']
|
|
|
|
WaveshareEPaperTypeA = display.display_ns.WaveshareEPaperTypeA
|
|
WaveshareEPaper = display.display_ns.class_('WaveshareEPaper',
|
|
PollingComponent, spi.SPIDevice, display.DisplayBuffer)
|
|
|
|
|
|
WaveshareEPaperTypeAModel = display.display_ns.enum('WaveshareEPaperTypeAModel')
|
|
WaveshareEPaperTypeBModel = display.display_ns.enum('WaveshareEPaperTypeBModel')
|
|
|
|
MODELS = {
|
|
'1.54in': ('a', WaveshareEPaperTypeAModel.WAVESHARE_EPAPER_1_54_IN),
|
|
'2.13in': ('a', WaveshareEPaperTypeAModel.WAVESHARE_EPAPER_2_13_IN),
|
|
'2.90in': ('a', WaveshareEPaperTypeAModel.WAVESHARE_EPAPER_2_9_IN),
|
|
'2.70in': ('b', WaveshareEPaperTypeBModel.WAVESHARE_EPAPER_2_7_IN),
|
|
'4.20in': ('b', WaveshareEPaperTypeBModel.WAVESHARE_EPAPER_4_2_IN),
|
|
'7.50in': ('b', WaveshareEPaperTypeBModel.WAVESHARE_EPAPER_7_5_IN),
|
|
}
|
|
|
|
|
|
def validate_full_update_every_only_type_a(value):
|
|
if CONF_FULL_UPDATE_EVERY not in value:
|
|
return value
|
|
if MODELS[value[CONF_MODEL]][0] != 'a':
|
|
raise vol.Invalid("The 'full_update_every' option is only available for models "
|
|
"'1.54in', '2.13in' and '2.90in'.")
|
|
return value
|
|
|
|
|
|
PLATFORM_SCHEMA = vol.All(display.FULL_DISPLAY_PLATFORM_SCHEMA.extend({
|
|
cv.GenerateID(): cv.declare_variable_id(WaveshareEPaper),
|
|
cv.GenerateID(CONF_SPI_ID): cv.use_variable_id(SPIComponent),
|
|
vol.Required(CONF_CS_PIN): pins.gpio_output_pin_schema,
|
|
vol.Required(CONF_DC_PIN): pins.gpio_output_pin_schema,
|
|
vol.Required(CONF_MODEL): vol.All(vol.Lower, cv.one_of(*MODELS)),
|
|
vol.Optional(CONF_RESET_PIN): pins.gpio_output_pin_schema,
|
|
vol.Optional(CONF_BUSY_PIN): pins.gpio_input_pin_schema,
|
|
vol.Optional(CONF_FULL_UPDATE_EVERY): cv.uint32_t,
|
|
}).extend(cv.COMPONENT_SCHEMA.schema), validate_full_update_every_only_type_a)
|
|
|
|
|
|
def to_code(config):
|
|
for spi_ in get_variable(config[CONF_SPI_ID]):
|
|
yield
|
|
for cs in gpio_output_pin_expression(config[CONF_CS_PIN]):
|
|
yield
|
|
for dc in gpio_output_pin_expression(config[CONF_DC_PIN]):
|
|
yield
|
|
|
|
model_type, model = MODELS[config[CONF_MODEL]]
|
|
if model_type == 'a':
|
|
rhs = App.make_waveshare_epaper_type_a(spi_, cs, dc, model)
|
|
epaper = Pvariable(config[CONF_ID], rhs, type=WaveshareEPaperTypeA)
|
|
elif model_type == 'b':
|
|
rhs = App.make_waveshare_epaper_type_b(spi_, cs, dc, model)
|
|
epaper = Pvariable(config[CONF_ID], rhs, type=WaveshareEPaper)
|
|
else:
|
|
raise NotImplementedError()
|
|
|
|
if CONF_LAMBDA in config:
|
|
for lambda_ in process_lambda(config[CONF_LAMBDA], [(display.DisplayBufferRef, 'it')]):
|
|
yield
|
|
add(epaper.set_writer(lambda_))
|
|
if CONF_RESET_PIN in config:
|
|
for reset in gpio_output_pin_expression(config[CONF_RESET_PIN]):
|
|
yield
|
|
add(epaper.set_reset_pin(reset))
|
|
if CONF_BUSY_PIN in config:
|
|
for reset in gpio_input_pin_expression(config[CONF_BUSY_PIN]):
|
|
yield
|
|
add(epaper.set_busy_pin(reset))
|
|
if CONF_FULL_UPDATE_EVERY in config:
|
|
add(epaper.set_full_update_every(config[CONF_FULL_UPDATE_EVERY]))
|
|
|
|
display.setup_display(epaper, config)
|
|
setup_component(epaper, config)
|
|
|
|
|
|
BUILD_FLAGS = '-DUSE_WAVESHARE_EPAPER'
|