ESPHome  1.15.3
as3935.h
Go to the documentation of this file.
1 #pragma once
2 
6 
7 namespace esphome {
8 namespace as3935 {
9 
11  AFE_GAIN = 0x00,
20  CALIB_TRCO = 0x3A,
21  CALIB_SRCO = 0x3B,
22  DEFAULT_RESET = 0x3C,
23  CALIB_RCO = 0x3D
24 };
25 
27  GAIN_MASK = 0x3E,
28  SPIKE_MASK = 0xF,
29  IO_MASK = 0xC1,
30  DISTANCE_MASK = 0xC0,
31  INT_MASK = 0xF0,
32  THRESH_MASK = 0x0F,
33  R_SPIKE_MASK = 0xF0,
34  ENERGY_MASK = 0xF0,
35  CAP_MASK = 0xF0,
36  LIGHT_MASK = 0xCF,
37  DISTURB_MASK = 0xDF,
39  OSC_MASK = 0xE0,
40  CALIB_MASK = 0x7F,
41  DIV_MASK = 0x3F
42 };
43 
45  AS3935_ADDR = 0x03,
46  INDOOR = 0x12,
47  OUTDOOR = 0xE,
48  LIGHTNING_INT = 0x08,
49  DISTURBER_INT = 0x04,
50  NOISE_INT = 0x01
51 };
52 
53 class AS3935Component : public Component {
54  public:
55  void setup() override;
56  void dump_config() override;
57  float get_setup_priority() const override;
58  void loop() override;
59 
60  void set_irq_pin(GPIOPin *irq_pin) { irq_pin_ = irq_pin; }
61  void set_distance_sensor(sensor::Sensor *distance_sensor) { distance_sensor_ = distance_sensor; }
62  void set_energy_sensor(sensor::Sensor *energy_sensor) { energy_sensor_ = energy_sensor; }
63  void set_thunder_alert_binary_sensor(binary_sensor::BinarySensor *thunder_alert_binary_sensor) {
64  thunder_alert_binary_sensor_ = thunder_alert_binary_sensor;
65  }
66  void set_indoor(bool indoor) { indoor_ = indoor; }
67  void write_indoor(bool indoor);
68  void set_noise_level(uint8_t noise_level) { noise_level_ = noise_level; }
69  void write_noise_level(uint8_t noise_level);
70  void set_watchdog_threshold(uint8_t watchdog_threshold) { watchdog_threshold_ = watchdog_threshold; }
71  void write_watchdog_threshold(uint8_t watchdog_threshold);
72  void set_spike_rejection(uint8_t spike_rejection) { spike_rejection_ = spike_rejection; }
74  void set_lightning_threshold(uint8_t lightning_threshold) { lightning_threshold_ = lightning_threshold; }
75  void write_lightning_threshold(uint8_t lightning_threshold);
76  void set_mask_disturber(bool mask_disturber) { mask_disturber_ = mask_disturber; }
77  void write_mask_disturber(bool enabled);
78  void set_div_ratio(uint8_t div_ratio) { div_ratio_ = div_ratio; }
79  void write_div_ratio(uint8_t div_ratio);
80  void set_capacitance(uint8_t capacitance) { capacitance_ = capacitance; }
81  void write_capacitance(uint8_t capacitance);
82 
83  protected:
84  uint8_t read_interrupt_register_();
85  void clear_statistics_();
86  uint8_t get_distance_to_storm_();
87  uint32_t get_lightning_energy_();
88 
89  virtual uint8_t read_register(uint8_t reg) = 0;
90  uint8_t read_register_(uint8_t reg, uint8_t mask);
91 
92  virtual void write_register(uint8_t reg, uint8_t mask, uint8_t bits, uint8_t start_position) = 0;
93 
98 
99  bool indoor_;
100  uint8_t noise_level_;
105  uint8_t div_ratio_;
106  uint8_t capacitance_;
107 };
108 
109 } // namespace as3935
110 } // namespace esphome
virtual void write_register(uint8_t reg, uint8_t mask, uint8_t bits, uint8_t start_position)=0
void set_spike_rejection(uint8_t spike_rejection)
Definition: as3935.h:72
void set_energy_sensor(sensor::Sensor *energy_sensor)
Definition: as3935.h:62
void set_indoor(bool indoor)
Definition: as3935.h:66
virtual uint8_t read_register(uint8_t reg)=0
void write_spike_rejection(uint8_t write_spike_rejection)
Definition: as3935.cpp:93
float get_setup_priority() const override
Definition: as3935.cpp:34
uint8_t read_register_(uint8_t reg, uint8_t mask)
Definition: as3935.cpp:219
void set_distance_sensor(sensor::Sensor *distance_sensor)
Definition: as3935.h:61
void write_watchdog_threshold(uint8_t watchdog_threshold)
Definition: as3935.cpp:69
void set_div_ratio(uint8_t div_ratio)
Definition: as3935.h:78
void set_mask_disturber(bool mask_disturber)
Definition: as3935.h:76
binary_sensor::BinarySensor * thunder_alert_binary_sensor_
Definition: as3935.h:96
void set_irq_pin(GPIOPin *irq_pin)
Definition: as3935.h:60
void write_div_ratio(uint8_t div_ratio)
Definition: as3935.cpp:137
void write_lightning_threshold(uint8_t lightning_threshold)
Definition: as3935.cpp:104
void set_thunder_alert_binary_sensor(binary_sensor::BinarySensor *thunder_alert_binary_sensor)
Definition: as3935.h:63
void set_watchdog_threshold(uint8_t watchdog_threshold)
Definition: as3935.h:70
void set_lightning_threshold(uint8_t lightning_threshold)
Definition: as3935.h:74
void dump_config() override
Definition: as3935.cpp:26
void set_capacitance(uint8_t capacitance)
Definition: as3935.h:80
void write_mask_disturber(bool enabled)
Definition: as3935.cpp:125
sensor::Sensor * distance_sensor_
Definition: as3935.h:94
void write_noise_level(uint8_t noise_level)
Definition: as3935.cpp:81
Definition: a4988.cpp:4
void write_indoor(bool indoor)
Definition: as3935.cpp:59
sensor::Sensor * energy_sensor_
Definition: as3935.h:95
Base class for all binary_sensor-type classes.
Definition: binary_sensor.h:25
Base-class for all sensors.
Definition: sensor.h:30
void set_noise_level(uint8_t noise_level)
Definition: as3935.h:68
A high-level abstraction class that can expose a pin together with useful options like pinMode...
Definition: esphal.h:69
void write_capacitance(uint8_t capacitance)
Definition: as3935.cpp:161