mirror of
https://github.com/esphome/esphome.git
synced 2024-11-26 17:05:21 +01:00
CAN bus: on_frame remote_transmission_request (#3376)
This commit is contained in:
parent
98c733108e
commit
5fac67ce15
3 changed files with 23 additions and 4 deletions
|
@ -78,6 +78,7 @@ CANBUS_SCHEMA = cv.Schema(
|
||||||
min=0, max=0x1FFFFFFF
|
min=0, max=0x1FFFFFFF
|
||||||
),
|
),
|
||||||
cv.Optional(CONF_USE_EXTENDED_ID, default=False): cv.boolean,
|
cv.Optional(CONF_USE_EXTENDED_ID, default=False): cv.boolean,
|
||||||
|
cv.Optional(CONF_REMOTE_TRANSMISSION_REQUEST): cv.boolean,
|
||||||
},
|
},
|
||||||
validate_id,
|
validate_id,
|
||||||
),
|
),
|
||||||
|
@ -100,10 +101,20 @@ async def setup_canbus_core_(var, config):
|
||||||
trigger = cg.new_Pvariable(
|
trigger = cg.new_Pvariable(
|
||||||
conf[CONF_TRIGGER_ID], var, can_id, can_id_mask, ext_id
|
conf[CONF_TRIGGER_ID], var, can_id, can_id_mask, ext_id
|
||||||
)
|
)
|
||||||
|
if CONF_REMOTE_TRANSMISSION_REQUEST in conf:
|
||||||
|
cg.add(
|
||||||
|
trigger.set_remote_transmission_request(
|
||||||
|
conf[CONF_REMOTE_TRANSMISSION_REQUEST]
|
||||||
|
)
|
||||||
|
)
|
||||||
await cg.register_component(trigger, conf)
|
await cg.register_component(trigger, conf)
|
||||||
await automation.build_automation(
|
await automation.build_automation(
|
||||||
trigger,
|
trigger,
|
||||||
[(cg.std_vector.template(cg.uint8), "x"), (cg.uint32, "can_id")],
|
[
|
||||||
|
(cg.std_vector.template(cg.uint8), "x"),
|
||||||
|
(cg.uint32, "can_id"),
|
||||||
|
(cg.bool_, "remote_transmission_request"),
|
||||||
|
],
|
||||||
conf,
|
conf,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -81,8 +81,10 @@ 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 & trigger->can_id_mask_)) &&
|
if ((trigger->can_id_ == (can_message.can_id & trigger->can_id_mask_)) &&
|
||||||
(trigger->use_extended_id_ == can_message.use_extended_id)) {
|
(trigger->use_extended_id_ == can_message.use_extended_id) &&
|
||||||
trigger->trigger(data, can_message.can_id);
|
(!trigger->remote_transmission_request_.has_value() ||
|
||||||
|
trigger->remote_transmission_request_.value() == can_message.remote_transmission_request)) {
|
||||||
|
trigger->trigger(data, can_message.can_id, can_message.remote_transmission_request);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -126,13 +126,18 @@ template<typename... Ts> class CanbusSendAction : public Action<Ts...>, public P
|
||||||
std::vector<uint8_t> data_static_{};
|
std::vector<uint8_t> data_static_{};
|
||||||
};
|
};
|
||||||
|
|
||||||
class CanbusTrigger : public Trigger<std::vector<uint8_t>, uint32_t>, public Component {
|
class CanbusTrigger : public Trigger<std::vector<uint8_t>, uint32_t, bool>, public Component {
|
||||||
friend class Canbus;
|
friend class Canbus;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit CanbusTrigger(Canbus *parent, const std::uint32_t can_id, const std::uint32_t can_id_mask,
|
explicit CanbusTrigger(Canbus *parent, const std::uint32_t can_id, const std::uint32_t can_id_mask,
|
||||||
const bool use_extended_id)
|
const bool use_extended_id)
|
||||||
: parent_(parent), can_id_(can_id), can_id_mask_(can_id_mask), use_extended_id_(use_extended_id){};
|
: parent_(parent), can_id_(can_id), can_id_mask_(can_id_mask), use_extended_id_(use_extended_id){};
|
||||||
|
|
||||||
|
void set_remote_transmission_request(bool remote_transmission_request) {
|
||||||
|
this->remote_transmission_request_ = remote_transmission_request;
|
||||||
|
}
|
||||||
|
|
||||||
void setup() override { this->parent_->add_trigger(this); }
|
void setup() override { this->parent_->add_trigger(this); }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
@ -140,6 +145,7 @@ class CanbusTrigger : public Trigger<std::vector<uint8_t>, uint32_t>, public Com
|
||||||
uint32_t can_id_;
|
uint32_t can_id_;
|
||||||
uint32_t can_id_mask_;
|
uint32_t can_id_mask_;
|
||||||
bool use_extended_id_;
|
bool use_extended_id_;
|
||||||
|
optional<bool> remote_transmission_request_{};
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace canbus
|
} // namespace canbus
|
||||||
|
|
Loading…
Reference in a new issue