1
0
mirror of https://github.com/esphome/esphome.git synced 2025-03-15 15:18:16 +00:00

C Code cleanup

This commit is contained in:
Marcel Koonstra 2024-12-23 06:37:38 +01:00
parent 51b7777e91
commit dcf05efc3e

View File

@ -3,6 +3,8 @@
#include "esphome/components/sensor/sensor.h" #include "esphome/components/sensor/sensor.h"
#include "esphome/components/binary_sensor/binary_sensor.h" #include "esphome/components/binary_sensor/binary_sensor.h"
#pragma once
namespace esphome { namespace esphome {
namespace obd { namespace obd {
@ -51,7 +53,11 @@ class PIDRequest : public Component {
public: public:
explicit PIDRequest(OBDComponent *parent, const std::uint32_t can_id, const std::uint32_t pid, explicit PIDRequest(OBDComponent *parent, const std::uint32_t can_id, const std::uint32_t pid,
const std::uint32_t can_response_id, const bool use_extended_id) const std::uint32_t can_response_id, const bool use_extended_id)
: parent_(parent), can_id_(can_id), pid_(pid), can_response_id_(can_response_id), use_extended_id_(use_extended_id){ : parent_(parent),
can_id_(can_id),
pid_(pid),
can_response_id_(can_response_id),
use_extended_id_(use_extended_id) {
this->state_ = WAITING; this->state_ = WAITING;
}; };
@ -136,19 +142,18 @@ class OBDBinarySensor : public OBDSensorBase, public binary_sensor::BinarySensor
class OBDCanbusTrigger : public canbus::CanbusTrigger, public Action<std::vector<uint8_t>, uint32_t, bool> { class OBDCanbusTrigger : public canbus::CanbusTrigger, public Action<std::vector<uint8_t>, uint32_t, bool> {
public: public:
explicit OBDCanbusTrigger(PIDRequest *parent) : CanbusTrigger(parent->parent_->canbus_, parent->can_response_id_, 0x1FFFFFFF, parent->use_extended_id_), parent_(parent){ explicit OBDCanbusTrigger(PIDRequest *parent)
: CanbusTrigger(parent->parent_->canbus_, parent->can_response_id_, 0x1FFFFFFF, parent->use_extended_id_),
parent_(parent) {
auto automation = new Automation<std::vector<uint8_t>, uint32_t, bool>(this); auto automation = new Automation<std::vector<uint8_t>, uint32_t, bool>(this);
automation->add_action(this); automation->add_action(this);
}; };
void play(std::vector<uint8_t> data, uint32_t can_id, bool rx) override { void play(std::vector<uint8_t> data, uint32_t can_id, bool rx) override { this->parent_->handle_incoming(data); }
this->parent_->handle_incoming(data);
}
protected: protected:
PIDRequest *parent_; PIDRequest *parent_;
}; };
} } // namespace obd
} } // namespace esphome