ESPHome  2024.4.1
ac_dimmer.h
Go to the documentation of this file.
1 #pragma once
2 
3 #ifdef USE_ARDUINO
4 
6 #include "esphome/core/hal.h"
8 
9 namespace esphome {
10 namespace ac_dimmer {
11 
13 
22  uint16_t value;
24  uint16_t min_power;
26  uint32_t cycle_time_us;
28  uint32_t crossed_zero_at;
30  uint32_t enable_time_us;
32  uint32_t disable_time_us;
34  bool init_cycle;
37 
38  uint32_t timer_intr(uint32_t now);
39 
40  void gpio_intr();
41  static void s_gpio_intr(AcDimmerDataStore *store);
42 #ifdef USE_ESP32
43  static void s_timer_intr();
44 #endif
45 };
46 
47 class AcDimmer : public output::FloatOutput, public Component {
48  public:
49  void setup() override;
50 
51  void dump_config() override;
54  void set_init_with_half_cycle(bool init_with_half_cycle) { init_with_half_cycle_ = init_with_half_cycle; }
55  void set_method(DimMethod method) { method_ = method; }
56 
57  protected:
58  void write_state(float state) override;
59 
65 };
66 
67 } // namespace ac_dimmer
68 } // namespace esphome
69 
70 #endif // USE_ARDUINO
void setup()
uint32_t enable_time_us
Time since last ZC pulse to enable gate pin. 0 means not set.
Definition: ac_dimmer.h:30
Copy of GPIOPin that is safe to use from ISRs (with no virtual functions)
Definition: gpio.h:66
Base class for all output components that can output a variable level, like PWM.
Definition: float_output.h:31
uint32_t cycle_time_us
Time between the last two ZC pulses.
Definition: ac_dimmer.h:26
uint32_t crossed_zero_at
Time (in micros()) of last ZC signal.
Definition: ac_dimmer.h:28
void set_gate_pin(InternalGPIOPin *gate_pin)
Definition: ac_dimmer.h:52
uint16_t min_power
Minimum power for activation.
Definition: ac_dimmer.h:24
DimMethod method
Dimmer method.
Definition: ac_dimmer.h:36
bool init_cycle
Set to send the first half ac cycle complete.
Definition: ac_dimmer.h:34
void set_method(DimMethod method)
Definition: ac_dimmer.h:55
static void s_gpio_intr(AcDimmerDataStore *store)
Definition: ac_dimmer.cpp:138
InternalGPIOPin * zero_cross_pin_
Definition: ac_dimmer.h:61
uint32_t timer_intr(uint32_t now)
Function called from timer interrupt Input is current time in microseconds (micros()) Returns when ne...
Definition: ac_dimmer.cpp:34
uint16_t value
Value of the dimmer - 0 to 65535.
Definition: ac_dimmer.h:22
ISRInternalGPIOPin gate_pin
Output pin to write to.
Definition: ac_dimmer.h:20
AcDimmerDataStore store_
Definition: ac_dimmer.h:62
This is a workaround until we can figure out a way to get the tflite-micro idf component code availab...
Definition: a01nyub.cpp:7
void set_init_with_half_cycle(bool init_with_half_cycle)
Definition: ac_dimmer.h:54
ISRInternalGPIOPin zero_cross_pin
Zero-cross pin.
Definition: ac_dimmer.h:16
uint32_t disable_time_us
Time since last ZC pulse to disable gate pin. 0 means no disable.
Definition: ac_dimmer.h:32
void set_zero_cross_pin(InternalGPIOPin *zero_cross_pin)
Definition: ac_dimmer.h:53
InternalGPIOPin * gate_pin_
Definition: ac_dimmer.h:60
void gpio_intr()
GPIO interrupt routine, called when ZC pin triggers.
Definition: ac_dimmer.cpp:90
bool state
Definition: fan.h:34
uint8_t zero_cross_pin_number
Zero-cross pin number - used to share ZC pin across multiple dimmers.
Definition: ac_dimmer.h:18