2018-08-18 21:40:59 +02:00
|
|
|
import voluptuous as vol
|
|
|
|
|
|
|
|
from esphomeyaml import pins
|
2018-11-12 23:30:31 +01:00
|
|
|
from esphomeyaml.components import display, spi
|
2018-08-18 21:40:59 +02:00
|
|
|
from esphomeyaml.components.spi import SPIComponent
|
2018-11-19 22:12:24 +01:00
|
|
|
import esphomeyaml.config_validation as cv
|
2018-08-18 21:40:59 +02:00
|
|
|
from esphomeyaml.const import CONF_CS_PIN, CONF_ID, CONF_INTENSITY, CONF_LAMBDA, CONF_NUM_CHIPS, \
|
|
|
|
CONF_SPI_ID
|
2018-11-19 22:12:24 +01:00
|
|
|
from esphomeyaml.cpp_generator import Pvariable, add, get_variable, process_lambda
|
|
|
|
from esphomeyaml.cpp_helpers import gpio_output_pin_expression, setup_component
|
|
|
|
from esphomeyaml.cpp_types import App, PollingComponent
|
2018-08-18 21:40:59 +02:00
|
|
|
|
|
|
|
DEPENDENCIES = ['spi']
|
|
|
|
|
2018-11-12 23:30:31 +01:00
|
|
|
MAX7219Component = display.display_ns.class_('MAX7219Component', PollingComponent, spi.SPIDevice)
|
2018-08-18 21:40:59 +02:00
|
|
|
MAX7219ComponentRef = MAX7219Component.operator('ref')
|
|
|
|
|
|
|
|
PLATFORM_SCHEMA = display.BASIC_DISPLAY_PLATFORM_SCHEMA.extend({
|
|
|
|
cv.GenerateID(): cv.declare_variable_id(MAX7219Component),
|
|
|
|
cv.GenerateID(CONF_SPI_ID): cv.use_variable_id(SPIComponent),
|
|
|
|
vol.Required(CONF_CS_PIN): pins.gpio_output_pin_schema,
|
|
|
|
|
|
|
|
vol.Optional(CONF_NUM_CHIPS): vol.All(cv.uint8_t, vol.Range(min=1)),
|
|
|
|
vol.Optional(CONF_INTENSITY): vol.All(cv.uint8_t, vol.Range(min=0, max=15)),
|
2018-11-12 23:30:31 +01:00
|
|
|
}).extend(cv.COMPONENT_SCHEMA.schema)
|
2018-08-18 21:40:59 +02:00
|
|
|
|
|
|
|
|
|
|
|
def to_code(config):
|
2018-11-12 23:30:31 +01:00
|
|
|
for spi_ in get_variable(config[CONF_SPI_ID]):
|
2018-08-18 21:40:59 +02:00
|
|
|
yield
|
|
|
|
for cs in gpio_output_pin_expression(config[CONF_CS_PIN]):
|
|
|
|
yield
|
2018-11-12 23:30:31 +01:00
|
|
|
rhs = App.make_max7219(spi_, cs)
|
2018-08-18 21:40:59 +02:00
|
|
|
max7219 = Pvariable(config[CONF_ID], rhs)
|
|
|
|
|
|
|
|
if CONF_NUM_CHIPS in config:
|
|
|
|
add(max7219.set_num_chips(config[CONF_NUM_CHIPS]))
|
|
|
|
if CONF_INTENSITY in config:
|
|
|
|
add(max7219.set_intensity(config[CONF_INTENSITY]))
|
|
|
|
|
|
|
|
if CONF_LAMBDA in config:
|
|
|
|
for lambda_ in process_lambda(config[CONF_LAMBDA], [(MAX7219ComponentRef, 'it')]):
|
|
|
|
yield
|
|
|
|
add(max7219.set_writer(lambda_))
|
|
|
|
|
|
|
|
display.setup_display(max7219, config)
|
2018-11-12 23:30:31 +01:00
|
|
|
setup_component(max7219, config)
|
2018-08-18 21:40:59 +02:00
|
|
|
|
|
|
|
|
|
|
|
BUILD_FLAGS = '-DUSE_MAX7219'
|