ESPHome 2026.12.0-dev
Loading...
Searching...
No Matches
canopen_node.cpp
Go to the documentation of this file.
1#include "canopen_node.h"
2
3namespace esphome::canopen {
4
5CANopenNode::CANopenNode(CANopenComponent *parent, uint8_t node_id) : canopen_(parent), node_id_(node_id) {
6 // the hooks run from the hub's processing, after construction
7#ifdef USE_CANOPEN_NODE_MONITOR
8 parent->add_on_node_event_callback([this](uint8_t node_id, NodeEvent event, NMTState state) {
9 if (node_id != this->node_id_)
10 return;
11 switch (event) {
13 this->on_node_online();
14 break;
16 this->on_node_offline();
17 break;
19 this->on_node_nmt_changed(state);
20 break;
22 this->on_node_reset();
23 break;
24 }
25 });
26#endif
27#ifdef USE_CANOPEN_EMCY // from register_node(); this file builds without a subclass too
28 parent->add_on_emcy_callback([this](uint8_t node_id, const Emergency &emergency) {
29 if (node_id == this->node_id_)
30 this->on_node_emcy(emergency);
31 });
32#endif
33}
34
35} // namespace esphome::canopen
void add_on_node_event_callback(F &&callback)
Definition canopen.h:143
void add_on_emcy_callback(F &&callback)
Definition canopen.h:170
virtual void on_node_nmt_changed(NMTState state)
CANopenNode(CANopenComponent *parent, uint8_t node_id)
virtual void on_node_emcy(const Emergency &emergency)
bool state
Definition fan.h:2