mirror of
https://github.com/esphome/esphome.git
synced 2025-03-14 06:38:17 +00:00
C Code cleanup
This commit is contained in:
parent
51b7777e91
commit
dcf05efc3e
@ -3,6 +3,8 @@
|
||||
#include "esphome/components/sensor/sensor.h"
|
||||
#include "esphome/components/binary_sensor/binary_sensor.h"
|
||||
|
||||
#pragma once
|
||||
|
||||
namespace esphome {
|
||||
namespace obd {
|
||||
|
||||
@ -34,7 +36,7 @@ class OBDComponent : public PollingComponent {
|
||||
|
||||
std::vector<PIDRequest *> pidrequests_{};
|
||||
|
||||
PIDRequest* current_request_{nullptr};
|
||||
PIDRequest *current_request_{nullptr};
|
||||
};
|
||||
|
||||
using data_to_value_t = std::function<float(std::vector<uint8_t>)>;
|
||||
@ -51,7 +53,11 @@ class PIDRequest : public Component {
|
||||
public:
|
||||
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)
|
||||
: 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;
|
||||
};
|
||||
|
||||
@ -90,7 +96,7 @@ class PIDRequest : public Component {
|
||||
|
||||
class OBDPidTrigger : public Trigger<std::vector<uint8_t>>, public Component {
|
||||
public:
|
||||
explicit OBDPidTrigger(PIDRequest *parent) : parent_(parent){}
|
||||
explicit OBDPidTrigger(PIDRequest *parent) : parent_(parent) {}
|
||||
|
||||
void setup() override { this->parent_->add_trigger(this); }
|
||||
|
||||
@ -105,11 +111,11 @@ class OBDSensorBase {
|
||||
|
||||
class OBDSensor : public OBDSensorBase, public sensor::Sensor, public Component {
|
||||
public:
|
||||
explicit OBDSensor(PIDRequest *parent) : parent_(parent){}
|
||||
explicit OBDSensor(PIDRequest *parent) : parent_(parent) {}
|
||||
|
||||
void set_template(data_to_value_t &&lambda) { this->data_to_value_func_ = lambda; }
|
||||
|
||||
void update(const std::vector<uint8_t> &data) override ;
|
||||
void update(const std::vector<uint8_t> &data) override;
|
||||
void setup() override { this->parent_->add_sensor(this); }
|
||||
void dump_config() override;
|
||||
|
||||
@ -120,7 +126,7 @@ class OBDSensor : public OBDSensorBase, public sensor::Sensor, public Component
|
||||
|
||||
class OBDBinarySensor : public OBDSensorBase, public binary_sensor::BinarySensor, public Component {
|
||||
public:
|
||||
explicit OBDBinarySensor(PIDRequest *parent) : parent_(parent){}
|
||||
explicit OBDBinarySensor(PIDRequest *parent) : parent_(parent) {}
|
||||
|
||||
void set_template(data_to_bool_t &&lambda) { this->data_to_value_func_ = lambda; }
|
||||
void update(const std::vector<uint8_t> &data) override;
|
||||
@ -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> {
|
||||
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);
|
||||
automation->add_action(this);
|
||||
};
|
||||
|
||||
void play(std::vector<uint8_t> data, uint32_t can_id, bool rx) override {
|
||||
this->parent_->handle_incoming(data);
|
||||
}
|
||||
void play(std::vector<uint8_t> data, uint32_t can_id, bool rx) override { this->parent_->handle_incoming(data); }
|
||||
|
||||
protected:
|
||||
PIDRequest *parent_;
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace obd
|
||||
} // namespace esphome
|
||||
|
Loading…
x
Reference in New Issue
Block a user