mirror of
https://github.com/esphome/esphome.git
synced 2025-03-21 10:08:15 +00:00
first setup for canbus
This commit is contained in:
parent
05e78123b9
commit
56df9e8299
39
esphome/components/canbus/__init__.py
Normal file
39
esphome/components/canbus/__init__.py
Normal file
@ -0,0 +1,39 @@
|
||||
import esphome.codegen as cg
|
||||
import esphome.config_validation as cv
|
||||
from esphome.automation import Condition, maybe_simple_id
|
||||
from esphome.components import binary_sensor
|
||||
from esphome import automation
|
||||
from esphome import pins
|
||||
from esphome.const import CONF_BUFFER_SIZE, CONF_DUMP, CONF_FILTER, CONF_ID, CONF_IDLE, \
|
||||
CONF_PIN, CONF_TOLERANCE
|
||||
|
||||
canbus_ns = cg.esphome_ns.namespace('canbus')
|
||||
CanbusComponent = canbus_ns.class_('CanbusComponent', cg.Component)
|
||||
|
||||
IS_PLATFORM_COMPONENT = True
|
||||
|
||||
CONF_CANBUS_ID = 'canbus_id'
|
||||
CONF_CAN_ID = 'can_id'
|
||||
CONF_DATA = 'data'
|
||||
|
||||
SendAction = canbus_ns.class_('SendAction', automation.Action)
|
||||
|
||||
CONFIG_SCHEMA = cv.Schema({
|
||||
cv.GenerateID(): cv.declare_id(CanbusComponent),
|
||||
cv.SplitDefault(CONF_BUFFER_SIZE, esp32='10000b', esp8266='1000b'): cv.validate_bytes,
|
||||
}).extend(cv.COMPONENT_SCHEMA)
|
||||
|
||||
CANBUS_ACTION_SCHEMA = maybe_simple_id({
|
||||
cv.Required(CONF_ID): cv.use_id(binary_sensor),
|
||||
})
|
||||
|
||||
@automation.register_action('canbus.send', SendAction, CANBUS_ACTION_SCHEMA)
|
||||
def canbus_send_to_code(config, action_id, template_arg, args):
|
||||
paren = yield cg.get_variable(config[CONF_ID])
|
||||
yield cg.new_Pvariable(action_id, template_arg, paren)
|
||||
|
||||
def to_code(config):
|
||||
print("canbus to_code")
|
||||
#var = cg.new_Pvariable(config[CONF_ID])
|
||||
# yield cg.register_component(var, config)
|
||||
# cg.add(var.set_buffer_size(config[CONF_BUFFER_SIZE]))
|
24
esphome/components/canbus/binary_sensor.py
Normal file
24
esphome/components/canbus/binary_sensor.py
Normal file
@ -0,0 +1,24 @@
|
||||
import esphome.codegen as cg
|
||||
import esphome.config_validation as cv
|
||||
from esphome.components import binary_sensor
|
||||
from esphome.const import CONF_ID
|
||||
from . import canbus_ns, CanbusComponent, CONF_CANBUS_ID
|
||||
|
||||
CONF_CAN_ID = 'can_id'
|
||||
|
||||
CanbusBinarySensor = canbus_ns.class_('CanbusBinarySensor', binary_sensor.BinarySensor)
|
||||
|
||||
CONFIG_SCHEMA = binary_sensor.BINARY_SENSOR_SCHEMA.extend({
|
||||
cv.GenerateID(): cv.declare_id(CanbusBinarySensor),
|
||||
cv.GenerateID(CONF_CANBUS_ID): cv.use_id(CanbusComponent),
|
||||
cv.Required(CONF_CAN_ID): cv.int_range(min=0, max=255)
|
||||
})
|
||||
|
||||
|
||||
def to_code(config):
|
||||
var = cg.new_Pvariable(config[CONF_ID])
|
||||
yield binary_sensor.register_binary_sensor(var, config)
|
||||
hub = yield cg.get_variable(config[CONF_CANBUS_ID])
|
||||
cg.add(var.set_can_id(config[CONF_CAN_ID]))
|
||||
|
||||
cg.add(hub.register_can_device(var))
|
1
esphome/components/esp32_can/__init__.py
Normal file
1
esphome/components/esp32_can/__init__.py
Normal file
@ -0,0 +1 @@
|
||||
print("esp32_can_module")
|
20
esphome/components/esp32_can/canbus.py
Normal file
20
esphome/components/esp32_can/canbus.py
Normal file
@ -0,0 +1,20 @@
|
||||
import esphome.codegen as cg
|
||||
import esphome.config_validation as cv
|
||||
from esphome.components import canbus
|
||||
from esphome.const import CONF_ID
|
||||
|
||||
|
||||
esp32_can_ns = cg.esphome_ns.namespace('esp32_can')
|
||||
esp32_can = esp32_can_ns.class_('ESP32Can', cg.Component, canbus.CanbusComponent)
|
||||
|
||||
CONFIG_SCHEMA = cv.Schema({
|
||||
cv.GenerateID(): cv.declare_id(esp32_can),
|
||||
}).extend(cv.COMPONENT_SCHEMA)
|
||||
|
||||
|
||||
def to_code(config):
|
||||
rhs = esp32_can.new()
|
||||
var = cg.Pvariable(config[CONF_ID], rhs)
|
||||
|
||||
yield cg.register_component(var, config)
|
||||
|
1
esphome/components/mcp2515/__init__.py
Normal file
1
esphome/components/mcp2515/__init__.py
Normal file
@ -0,0 +1 @@
|
||||
print "hello"
|
28
esphome/components/mcp2515/canbus.py
Normal file
28
esphome/components/mcp2515/canbus.py
Normal file
@ -0,0 +1,28 @@
|
||||
import esphome.codegen as cg
|
||||
import esphome.config_validation as cv
|
||||
from esphome import pins
|
||||
from esphome.components import spi, binary_sensor, canbus
|
||||
from esphome.const import CONF_DC_PIN, CONF_CS_PIN, CONF_ID
|
||||
|
||||
DEPENDENCIES = ['spi']
|
||||
|
||||
mcp2515_ns = cg.esphome_ns.namespace('mcp2515')
|
||||
mcp2515 = mcp2515_ns.class_('MCP2515', cg.Component, canbus.CanbusComponent, spi.SPIDevice)
|
||||
|
||||
CONFIG_SCHEMA = binary_sensor.BINARY_SENSOR_SCHEMA.extend({
|
||||
cv.GenerateID(): cv.declare_id(mcp2515),
|
||||
cv.Required(CONF_DC_PIN): pins.gpio_output_pin_schema,
|
||||
cv.Required(CONF_CS_PIN): pins.gpio_output_pin_schema,
|
||||
}).extend(spi.SPI_DEVICE_SCHEMA)
|
||||
|
||||
|
||||
def to_code(config):
|
||||
rhs = mcp2515.new()
|
||||
var = cg.Pvariable(config[CONF_ID], rhs)
|
||||
|
||||
yield cg.register_component(var, config)
|
||||
yield spi.register_spi_device(var, config)
|
||||
dc = yield cg.gpio_pin_expression(config[CONF_DC_PIN])
|
||||
cg.add(var.set_dc_pin(dc))
|
||||
cs = yield cg.gpio_pin_expression(config[CONF_CS_PIN])
|
||||
cg.add(var.set_cs_pin(cs))
|
Loading…
x
Reference in New Issue
Block a user