2019-07-03 16:42:32 +02:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "esphome/core/component.h"
|
2021-09-20 11:47:51 +02:00
|
|
|
#include "esphome/core/hal.h"
|
2019-07-03 16:42:32 +02:00
|
|
|
#include "esphome/components/sensor/sensor.h"
|
|
|
|
|
|
|
|
namespace esphome {
|
|
|
|
namespace tx20 {
|
|
|
|
|
|
|
|
/// Store data in a class that doesn't use multiple-inheritance (vtables in flash)
|
|
|
|
struct Tx20ComponentStore {
|
|
|
|
volatile uint16_t *buffer;
|
|
|
|
volatile uint32_t start_time;
|
|
|
|
volatile uint8_t buffer_index;
|
|
|
|
volatile uint32_t spent_time;
|
|
|
|
volatile bool tx20_available;
|
|
|
|
volatile bool pin_state;
|
2021-09-20 11:47:51 +02:00
|
|
|
ISRInternalGPIOPin pin;
|
2019-07-03 16:42:32 +02:00
|
|
|
|
|
|
|
void reset();
|
|
|
|
static void gpio_intr(Tx20ComponentStore *arg);
|
|
|
|
};
|
|
|
|
|
|
|
|
/// This class implements support for the Tx20 Wind sensor.
|
|
|
|
class Tx20Component : public Component {
|
|
|
|
public:
|
|
|
|
/// Get the textual representation of the wind direction ('N', 'SSE', ..).
|
|
|
|
std::string get_wind_cardinal_direction() const;
|
|
|
|
|
2021-09-20 11:47:51 +02:00
|
|
|
void set_pin(InternalGPIOPin *pin) { pin_ = pin; }
|
2019-07-03 16:42:32 +02:00
|
|
|
void set_wind_speed_sensor(sensor::Sensor *wind_speed_sensor) { wind_speed_sensor_ = wind_speed_sensor; }
|
|
|
|
void set_wind_direction_degrees_sensor(sensor::Sensor *wind_direction_degrees_sensor) {
|
|
|
|
wind_direction_degrees_sensor_ = wind_direction_degrees_sensor;
|
|
|
|
}
|
|
|
|
|
|
|
|
void setup() override;
|
|
|
|
void dump_config() override;
|
|
|
|
float get_setup_priority() const override;
|
|
|
|
void loop() override;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
void decode_and_publish_();
|
|
|
|
|
|
|
|
std::string wind_cardinal_direction_;
|
2021-09-20 11:47:51 +02:00
|
|
|
InternalGPIOPin *pin_;
|
2022-09-15 01:53:22 +02:00
|
|
|
sensor::Sensor *wind_speed_sensor_{nullptr};
|
|
|
|
sensor::Sensor *wind_direction_degrees_sensor_{nullptr};
|
2019-07-03 16:42:32 +02:00
|
|
|
Tx20ComponentStore store_;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace tx20
|
|
|
|
} // namespace esphome
|