mirror of
https://github.com/esphome/esphome.git
synced 2025-03-15 15:18:16 +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')
|
||||
CanbusComponent = canbus_ns.class_('CanbusComponent', cg.Component)
|
||||
CanbusTrigger = canbus_ns.class_('CanbusTrigger', automation.Trigger.template(),
|
||||
cg.Component)
|
||||
CanbusTrigger = canbus_ns.class_('CanbusTrigger', automation.Trigger.template(cg.std_vector.template(cg.uint8)),
|
||||
cg.Component)
|
||||
CanSpeed = canbus_ns.enum('CAN_SPEED')
|
||||
|
||||
CAN_SPEEDS = {
|
||||
@ -88,7 +88,7 @@ def setup_canbus_core_(var, config):
|
||||
for conf in config.get(CONF_ON_MESSAGE, []):
|
||||
trigger = cg.new_Pvariable(conf[CONF_TRIGGER_ID], var, conf[CONF_CAN_ID])
|
||||
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
|
||||
|
@ -50,7 +50,8 @@ void Canbus::loop() {
|
||||
// fire all triggers
|
||||
for (auto trigger : this->triggers_) {
|
||||
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_{};
|
||||
};
|
||||
|
||||
class CanbusTrigger : public Trigger<> , public Component {
|
||||
class CanbusTrigger : public Trigger< std::vector<uint8_t> > , public Component {
|
||||
friend class Canbus;
|
||||
public:
|
||||
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.config_validation as cv
|
||||
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
|
||||
|
||||
AUTO_LOAD = ['canbus']
|
||||
DEPENDENCIES = ['spi']
|
||||
|
||||
CONF_MCP_CLOCK = 'clock'
|
||||
CONF_MCP_MODE = 'mode'
|
||||
|
||||
mcp2515_ns = cg.esphome_ns.namespace('mcp2515')
|
||||
mcp2515 = mcp2515_ns.class_('MCP2515', CanbusComponent, spi.SPIDevice)
|
||||
@ -30,7 +29,7 @@ MCP_MODE = {
|
||||
CONFIG_SCHEMA = canbus.CONFIG_SCHEMA.extend({
|
||||
cv.GenerateID(): cv.declare_id(mcp2515),
|
||||
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)
|
||||
|
||||
|
||||
@ -41,8 +40,8 @@ def to_code(config):
|
||||
if CONF_MCP_CLOCK in config:
|
||||
canclock = CAN_CLOCK[config[CONF_MCP_CLOCK]]
|
||||
cg.add(var.set_mcp_clock(canclock))
|
||||
if CONF_MCP_MODE in config:
|
||||
mode = MCP_MODE[config[CONF_MCP_MODE]]
|
||||
if CONF_MODE in config:
|
||||
mode = MCP_MODE[config[CONF_MODE]]
|
||||
cg.add(var.set_mcp_mode(mode))
|
||||
|
||||
yield spi.register_spi_device(var, config)
|
||||
|
Loading…
x
Reference in New Issue
Block a user