2018-08-13 19:11:33 +02:00
|
|
|
import voluptuous as vol
|
|
|
|
|
|
|
|
from esphomeyaml import pins
|
2018-12-05 21:22:06 +01:00
|
|
|
import esphomeyaml.config_validation as cv
|
2018-08-22 22:04:56 +02:00
|
|
|
from esphomeyaml.const import CONF_BAUD_RATE, CONF_ID, CONF_RX_PIN, CONF_TX_PIN
|
2018-12-05 21:22:06 +01:00
|
|
|
from esphomeyaml.cpp_generator import Pvariable
|
|
|
|
from esphomeyaml.cpp_helpers import setup_component
|
|
|
|
from esphomeyaml.cpp_types import App, Component, esphomelib_ns
|
2018-08-13 19:11:33 +02:00
|
|
|
|
2018-11-12 23:30:31 +01:00
|
|
|
UARTComponent = esphomelib_ns.class_('UARTComponent', Component)
|
|
|
|
UARTDevice = esphomelib_ns.class_('UARTDevice')
|
2018-12-05 21:22:06 +01:00
|
|
|
MULTI_CONF = True
|
2018-08-13 19:11:33 +02:00
|
|
|
|
2018-12-05 21:22:06 +01:00
|
|
|
CONFIG_SCHEMA = vol.All(vol.Schema({
|
2018-08-13 19:11:33 +02:00
|
|
|
cv.GenerateID(): cv.declare_variable_id(UARTComponent),
|
2018-08-22 22:04:56 +02:00
|
|
|
vol.Optional(CONF_TX_PIN): pins.output_pin,
|
|
|
|
vol.Optional(CONF_RX_PIN): pins.input_pin,
|
2018-08-13 19:11:33 +02:00
|
|
|
vol.Required(CONF_BAUD_RATE): cv.positive_int,
|
2018-11-12 23:30:31 +01:00
|
|
|
}).extend(cv.COMPONENT_SCHEMA.schema), cv.has_at_least_one_key(CONF_TX_PIN, CONF_RX_PIN))
|
2018-08-13 19:11:33 +02:00
|
|
|
|
|
|
|
|
|
|
|
def to_code(config):
|
2018-12-05 21:22:06 +01:00
|
|
|
tx = config.get(CONF_TX_PIN, -1)
|
|
|
|
rx = config.get(CONF_RX_PIN, -1)
|
|
|
|
rhs = App.init_uart(tx, rx, config[CONF_BAUD_RATE])
|
|
|
|
var = Pvariable(config[CONF_ID], rhs)
|
2018-11-12 23:30:31 +01:00
|
|
|
|
2018-12-05 21:22:06 +01:00
|
|
|
setup_component(var, config)
|
2018-08-13 19:11:33 +02:00
|
|
|
|
|
|
|
|
|
|
|
BUILD_FLAGS = '-DUSE_UART'
|