2019-04-17 12:06:00 +02:00
|
|
|
import esphome.codegen as cg
|
|
|
|
import esphome.config_validation as cv
|
|
|
|
from esphome.components import display, spi
|
2019-04-22 21:56:30 +02:00
|
|
|
from esphome.const import CONF_ID, CONF_INTENSITY, CONF_LAMBDA, CONF_NUM_CHIPS
|
2019-04-17 12:06:00 +02:00
|
|
|
|
|
|
|
DEPENDENCIES = ['spi']
|
|
|
|
|
|
|
|
max7219_ns = cg.esphome_ns.namespace('max7219')
|
|
|
|
MAX7219Component = max7219_ns.class_('MAX7219Component', cg.PollingComponent, spi.SPIDevice)
|
|
|
|
MAX7219ComponentRef = MAX7219Component.operator('ref')
|
|
|
|
|
|
|
|
CONFIG_SCHEMA = display.BASIC_DISPLAY_SCHEMA.extend({
|
2019-04-22 21:56:30 +02:00
|
|
|
cv.GenerateID(): cv.declare_id(MAX7219Component),
|
2019-04-17 12:06:00 +02:00
|
|
|
|
2019-05-11 11:40:29 +02:00
|
|
|
cv.Optional(CONF_NUM_CHIPS, default=1): cv.int_range(min=1, max=255),
|
|
|
|
cv.Optional(CONF_INTENSITY, default=15): cv.int_range(min=0, max=15),
|
2019-04-22 21:56:30 +02:00
|
|
|
}).extend(cv.polling_component_schema('1s')).extend(spi.SPI_DEVICE_SCHEMA)
|
2019-04-17 12:06:00 +02:00
|
|
|
|
|
|
|
|
|
|
|
def to_code(config):
|
2019-04-22 21:56:30 +02:00
|
|
|
var = cg.new_Pvariable(config[CONF_ID])
|
2019-04-17 12:06:00 +02:00
|
|
|
yield cg.register_component(var, config)
|
|
|
|
yield spi.register_spi_device(var, config)
|
|
|
|
yield display.register_display(var, config)
|
|
|
|
|
|
|
|
cg.add(var.set_num_chips(config[CONF_NUM_CHIPS]))
|
|
|
|
cg.add(var.set_intensity(config[CONF_INTENSITY]))
|
|
|
|
|
|
|
|
if CONF_LAMBDA in config:
|
|
|
|
lambda_ = yield cg.process_lambda(config[CONF_LAMBDA], [(MAX7219ComponentRef, 'it')],
|
|
|
|
return_type=cg.void)
|
|
|
|
cg.add(var.set_writer(lambda_))
|