ESPHome 2026.3.0-dev
Loading...
Searching...
No Matches
as3935.h
Go to the documentation of this file.
1#pragma once
2
5#include "esphome/core/hal.h"
6#ifdef USE_SENSOR
8#endif
9#ifdef USE_BINARY_SENSOR
11#endif
12
13namespace esphome {
14namespace as3935 {
15
16static const uint8_t DIRECT_COMMAND = 0x96;
17static const uint8_t ANTFREQ = 3;
18
34
54
57 INDOOR = 0x12,
58 OUTDOOR = 0xE,
61 NOISE_INT = 0x01
62};
63
64class AS3935Component : public Component {
65#ifdef USE_SENSOR
66 SUB_SENSOR(distance)
67 SUB_SENSOR(energy)
68#endif
69
70#ifdef USE_BINARY_SENSOR
71 SUB_BINARY_SENSOR(thunder_alert)
72#endif
73
74 public:
75 void setup() override;
76 void dump_config() override;
77 void loop() override;
78
79 void set_irq_pin(GPIOPin *irq_pin) { irq_pin_ = irq_pin; }
80
81 void set_indoor(bool indoor) { indoor_ = indoor; }
82 void write_indoor(bool indoor);
83 void set_noise_level(uint8_t noise_level) { noise_level_ = noise_level; }
84 void write_noise_level(uint8_t noise_level);
85 void set_watchdog_threshold(uint8_t watchdog_threshold) { watchdog_threshold_ = watchdog_threshold; }
86 void write_watchdog_threshold(uint8_t watchdog_threshold);
87 void set_spike_rejection(uint8_t spike_rejection) { spike_rejection_ = spike_rejection; }
88 void write_spike_rejection(uint8_t write_spike_rejection);
89 void set_lightning_threshold(uint8_t lightning_threshold) { lightning_threshold_ = lightning_threshold; }
90 void write_lightning_threshold(uint8_t lightning_threshold);
91 void set_mask_disturber(bool mask_disturber) { mask_disturber_ = mask_disturber; }
92 void write_mask_disturber(bool enabled);
93 void set_div_ratio(uint8_t div_ratio) { div_ratio_ = div_ratio; }
94 void write_div_ratio(uint8_t div_ratio);
95 void set_capacitance(uint8_t capacitance) { capacitance_ = capacitance; }
96 void write_capacitance(uint8_t capacitance);
97 uint8_t read_div_ratio();
98 uint8_t read_capacitance();
99 bool calibrate_oscillator();
100 void display_oscillator(bool state, uint8_t osc);
101 void tune_antenna();
102 void set_tune_antenna(bool tune_antenna) { tune_antenna_ = tune_antenna; }
103 void set_calibration(bool calibration) { calibration_ = calibration; }
104
105 protected:
106 uint8_t read_interrupt_register_();
107 void clear_statistics_();
108 uint8_t get_distance_to_storm_();
109 uint32_t get_lightning_energy_();
110
111 virtual uint8_t read_register(uint8_t reg) = 0;
112 uint8_t read_register_(uint8_t reg, uint8_t mask);
113
114 virtual void write_register(uint8_t reg, uint8_t mask, uint8_t bits, uint8_t start_position) = 0;
115
117
124 uint8_t div_ratio_;
128};
129
130} // namespace as3935
131} // namespace esphome
virtual void setup()
Where the component's initialization should happen.
Definition component.cpp:94
virtual uint8_t read_register(uint8_t reg)=0
virtual void write_register(uint8_t reg, uint8_t mask, uint8_t bits, uint8_t start_position)=0
uint8_t read_register_(uint8_t reg, uint8_t mask)
Definition as3935.cpp:317
bool state
Definition fan.h:2
@ ENERGY_LIGHT_MMSB
Definition as3935.h:26
Providing packet encoding functions for exchanging data with a remote host.
Definition a01nyub.cpp:7