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
|
2019-02-11 15:50:12 +01:00
|
|
|
from esphomeyaml.cpp_generator import Pvariable, add
|
2018-12-05 21:22:06 +01:00
|
|
|
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):
|
2019-02-11 15:50:12 +01:00
|
|
|
rhs = App.init_uart(config[CONF_BAUD_RATE])
|
2018-12-05 21:22:06 +01:00
|
|
|
var = Pvariable(config[CONF_ID], rhs)
|
2018-11-12 23:30:31 +01:00
|
|
|
|
2019-02-11 15:50:12 +01:00
|
|
|
if CONF_TX_PIN in config:
|
|
|
|
add(var.set_tx_pin(config[CONF_TX_PIN]))
|
|
|
|
if CONF_RX_PIN in config:
|
|
|
|
add(var.set_rx_pin(config[CONF_RX_PIN]))
|
|
|
|
|
2018-12-05 21:22:06 +01:00
|
|
|
setup_component(var, config)
|
2018-08-13 19:11:33 +02:00
|
|
|
|
|
|
|
|
|
|
|
BUILD_FLAGS = '-DUSE_UART'
|