mirror of
https://github.com/esphome/esphome.git
synced 2025-03-15 07:08:20 +00:00
added data to lambda action processing
This commit is contained in:
parent
52e6b8d4f2
commit
4c4d36fcb0
@ -32,8 +32,8 @@ def validate_raw_data(value):
|
|||||||
|
|
||||||
canbus_ns = cg.esphome_ns.namespace('canbus')
|
canbus_ns = cg.esphome_ns.namespace('canbus')
|
||||||
CanbusComponent = canbus_ns.class_('CanbusComponent', cg.Component)
|
CanbusComponent = canbus_ns.class_('CanbusComponent', cg.Component)
|
||||||
CanbusTrigger = canbus_ns.class_('CanbusTrigger', automation.Trigger.template(),
|
CanbusTrigger = canbus_ns.class_('CanbusTrigger', automation.Trigger.template(cg.std_vector.template(cg.uint8)),
|
||||||
cg.Component)
|
cg.Component)
|
||||||
CanSpeed = canbus_ns.enum('CAN_SPEED')
|
CanSpeed = canbus_ns.enum('CAN_SPEED')
|
||||||
|
|
||||||
CAN_SPEEDS = {
|
CAN_SPEEDS = {
|
||||||
@ -88,7 +88,7 @@ def setup_canbus_core_(var, config):
|
|||||||
for conf in config.get(CONF_ON_MESSAGE, []):
|
for conf in config.get(CONF_ON_MESSAGE, []):
|
||||||
trigger = cg.new_Pvariable(conf[CONF_TRIGGER_ID], var, conf[CONF_CAN_ID])
|
trigger = cg.new_Pvariable(conf[CONF_TRIGGER_ID], var, conf[CONF_CAN_ID])
|
||||||
yield cg.register_component(trigger, conf)
|
yield cg.register_component(trigger, conf)
|
||||||
yield automation.build_automation(trigger, [], conf)
|
yield automation.build_automation(trigger, [(cg.std_vector.template(cg.uint8), 'x')], conf)
|
||||||
|
|
||||||
|
|
||||||
@coroutine
|
@coroutine
|
||||||
|
@ -50,7 +50,8 @@ void Canbus::loop() {
|
|||||||
// fire all triggers
|
// fire all triggers
|
||||||
for (auto trigger : this->triggers_) {
|
for (auto trigger : this->triggers_) {
|
||||||
if (trigger->can_id_ == can_message.can_id) {
|
if (trigger->can_id_ == can_message.can_id) {
|
||||||
trigger->trigger();
|
std::vector<uint8_t> data(&can_message.data[0], &can_message.data[can_message.can_dlc - 1]);
|
||||||
|
trigger->trigger(data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -111,7 +111,7 @@ protected:
|
|||||||
std::vector<uint8_t> data_static_{};
|
std::vector<uint8_t> data_static_{};
|
||||||
};
|
};
|
||||||
|
|
||||||
class CanbusTrigger : public Trigger<> , public Component {
|
class CanbusTrigger : public Trigger< std::vector<uint8_t> > , public Component {
|
||||||
friend class Canbus;
|
friend class Canbus;
|
||||||
public:
|
public:
|
||||||
explicit CanbusTrigger(Canbus *parent, const std::uint32_t can_id):parent_(parent), can_id_(can_id){};
|
explicit CanbusTrigger(Canbus *parent, const std::uint32_t can_id):parent_(parent), can_id_(can_id){};
|
||||||
|
@ -1,14 +1,13 @@
|
|||||||
import esphome.codegen as cg
|
import esphome.codegen as cg
|
||||||
import esphome.config_validation as cv
|
import esphome.config_validation as cv
|
||||||
from esphome.components import spi, canbus
|
from esphome.components import spi, canbus
|
||||||
from esphome.const import CONF_ID
|
from esphome.const import CONF_ID, CONF_MODE
|
||||||
from esphome.components.canbus import CanbusComponent
|
from esphome.components.canbus import CanbusComponent
|
||||||
|
|
||||||
AUTO_LOAD = ['canbus']
|
AUTO_LOAD = ['canbus']
|
||||||
DEPENDENCIES = ['spi']
|
DEPENDENCIES = ['spi']
|
||||||
|
|
||||||
CONF_MCP_CLOCK = 'clock'
|
CONF_MCP_CLOCK = 'clock'
|
||||||
CONF_MCP_MODE = 'mode'
|
|
||||||
|
|
||||||
mcp2515_ns = cg.esphome_ns.namespace('mcp2515')
|
mcp2515_ns = cg.esphome_ns.namespace('mcp2515')
|
||||||
mcp2515 = mcp2515_ns.class_('MCP2515', CanbusComponent, spi.SPIDevice)
|
mcp2515 = mcp2515_ns.class_('MCP2515', CanbusComponent, spi.SPIDevice)
|
||||||
@ -30,7 +29,7 @@ MCP_MODE = {
|
|||||||
CONFIG_SCHEMA = canbus.CONFIG_SCHEMA.extend({
|
CONFIG_SCHEMA = canbus.CONFIG_SCHEMA.extend({
|
||||||
cv.GenerateID(): cv.declare_id(mcp2515),
|
cv.GenerateID(): cv.declare_id(mcp2515),
|
||||||
cv.Optional(CONF_MCP_CLOCK, default='8MHZ'): cv.enum(CAN_CLOCK, upper=True),
|
cv.Optional(CONF_MCP_CLOCK, default='8MHZ'): cv.enum(CAN_CLOCK, upper=True),
|
||||||
cv.Optional(CONF_MCP_MODE, default='NORMAL'): cv.enum(MCP_MODE, upper=True),
|
cv.Optional(CONF_MODE, default='NORMAL'): cv.enum(MCP_MODE, upper=True),
|
||||||
}).extend(spi.SPI_DEVICE_SCHEMA)
|
}).extend(spi.SPI_DEVICE_SCHEMA)
|
||||||
|
|
||||||
|
|
||||||
@ -41,8 +40,8 @@ def to_code(config):
|
|||||||
if CONF_MCP_CLOCK in config:
|
if CONF_MCP_CLOCK in config:
|
||||||
canclock = CAN_CLOCK[config[CONF_MCP_CLOCK]]
|
canclock = CAN_CLOCK[config[CONF_MCP_CLOCK]]
|
||||||
cg.add(var.set_mcp_clock(canclock))
|
cg.add(var.set_mcp_clock(canclock))
|
||||||
if CONF_MCP_MODE in config:
|
if CONF_MODE in config:
|
||||||
mode = MCP_MODE[config[CONF_MCP_MODE]]
|
mode = MCP_MODE[config[CONF_MODE]]
|
||||||
cg.add(var.set_mcp_mode(mode))
|
cg.add(var.set_mcp_mode(mode))
|
||||||
|
|
||||||
yield spi.register_spi_device(var, config)
|
yield spi.register_spi_device(var, config)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user