ESPHome 2026.1.5
Loading...
Searching...
No Matches
ac_dimmer.h
Go to the documentation of this file.
1#pragma once
2
4#include "esphome/core/hal.h"
6
7namespace esphome::ac_dimmer {
8
10
19 uint16_t value;
21 uint16_t min_power;
23 uint32_t cycle_time_us;
34
35 uint32_t timer_intr(uint32_t now);
36
37 void gpio_intr();
38 static void s_gpio_intr(AcDimmerDataStore *store);
39#ifdef USE_ESP32
40 static void s_timer_intr();
41#endif
42};
43
44class AcDimmer : public output::FloatOutput, public Component {
45 public:
46 void setup() override;
47
48 void dump_config() override;
49 void set_gate_pin(InternalGPIOPin *gate_pin) { gate_pin_ = gate_pin; }
50 void set_zero_cross_pin(InternalGPIOPin *zero_cross_pin) { zero_cross_pin_ = zero_cross_pin; }
51 void set_init_with_half_cycle(bool init_with_half_cycle) { init_with_half_cycle_ = init_with_half_cycle; }
52 void set_method(DimMethod method) { method_ = method; }
53
54 protected:
55 void write_state(float state) override;
56
62};
63
64} // namespace esphome::ac_dimmer
Copy of GPIOPin that is safe to use from ISRs (with no virtual functions)
Definition gpio.h:92
void set_method(DimMethod method)
Definition ac_dimmer.h:52
void write_state(float state) override
InternalGPIOPin * gate_pin_
Definition ac_dimmer.h:57
InternalGPIOPin * zero_cross_pin_
Definition ac_dimmer.h:58
void set_init_with_half_cycle(bool init_with_half_cycle)
Definition ac_dimmer.h:51
void set_zero_cross_pin(InternalGPIOPin *zero_cross_pin)
Definition ac_dimmer.h:50
void set_gate_pin(InternalGPIOPin *gate_pin)
Definition ac_dimmer.h:49
AcDimmerDataStore store_
Definition ac_dimmer.h:59
Base class for all output components that can output a variable level, like PWM.
bool state
Definition fan.h:0
uint32_t cycle_time_us
Time between the last two ZC pulses.
Definition ac_dimmer.h:23
bool init_cycle
Set to send the first half ac cycle complete.
Definition ac_dimmer.h:31
uint32_t disable_time_us
Time since last ZC pulse to disable gate pin. 0 means no disable.
Definition ac_dimmer.h:29
uint32_t enable_time_us
Time since last ZC pulse to enable gate pin. 0 means not set.
Definition ac_dimmer.h:27
uint16_t min_power
Minimum power for activation.
Definition ac_dimmer.h:21
uint32_t crossed_zero_at
Time (in micros()) of last ZC signal.
Definition ac_dimmer.h:25
uint8_t zero_cross_pin_number
Zero-cross pin number - used to share ZC pin across multiple dimmers.
Definition ac_dimmer.h:15
uint16_t value
Value of the dimmer - 0 to 65535.
Definition ac_dimmer.h:19
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:40
ISRInternalGPIOPin gate_pin
Output pin to write to.
Definition ac_dimmer.h:17
ISRInternalGPIOPin zero_cross_pin
Zero-cross pin.
Definition ac_dimmer.h:13
DimMethod method
Dimmer method.
Definition ac_dimmer.h:33
void gpio_intr()
GPIO interrupt routine, called when ZC pin triggers.
Definition ac_dimmer.cpp:96
static void s_gpio_intr(AcDimmerDataStore *store)