ESPHome 2025.5.0
Loading...
Searching...
No Matches
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
9namespace esphome {
10namespace ac_dimmer {
11
13
22 uint16_t value;
24 uint16_t min_power;
26 uint32_t cycle_time_us;
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
47class AcDimmer : public output::FloatOutput, public Component {
48 public:
49 void setup() override;
50
51 void dump_config() override;
52 void set_gate_pin(InternalGPIOPin *gate_pin) { gate_pin_ = gate_pin; }
53 void set_zero_cross_pin(InternalGPIOPin *zero_cross_pin) { zero_cross_pin_ = zero_cross_pin; }
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
Copy of GPIOPin that is safe to use from ISRs (with no virtual functions)
Definition gpio.h:73
void set_method(DimMethod method)
Definition ac_dimmer.h:55
void write_state(float state) override
InternalGPIOPin * gate_pin_
Definition ac_dimmer.h:60
InternalGPIOPin * zero_cross_pin_
Definition ac_dimmer.h:61
void set_init_with_half_cycle(bool init_with_half_cycle)
Definition ac_dimmer.h:54
void set_zero_cross_pin(InternalGPIOPin *zero_cross_pin)
Definition ac_dimmer.h:53
void set_gate_pin(InternalGPIOPin *gate_pin)
Definition ac_dimmer.h:52
AcDimmerDataStore store_
Definition ac_dimmer.h:62
Base class for all output components that can output a variable level, like PWM.
bool state
Definition fan.h:0
Providing packet encoding functions for exchanging data with a remote host.
Definition a01nyub.cpp:7
uint32_t cycle_time_us
Time between the last two ZC pulses.
Definition ac_dimmer.h:26
bool init_cycle
Set to send the first half ac cycle complete.
Definition ac_dimmer.h:34
uint32_t disable_time_us
Time since last ZC pulse to disable gate pin. 0 means no disable.
Definition ac_dimmer.h:32
uint32_t enable_time_us
Time since last ZC pulse to enable gate pin. 0 means not set.
Definition ac_dimmer.h:30
uint16_t min_power
Minimum power for activation.
Definition ac_dimmer.h:24
uint32_t crossed_zero_at
Time (in micros()) of last ZC signal.
Definition ac_dimmer.h:28
uint8_t zero_cross_pin_number
Zero-cross pin number - used to share ZC pin across multiple dimmers.
Definition ac_dimmer.h:18
uint16_t value
Value of the dimmer - 0 to 65535.
Definition ac_dimmer.h:22
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
ISRInternalGPIOPin gate_pin
Output pin to write to.
Definition ac_dimmer.h:20
ISRInternalGPIOPin zero_cross_pin
Zero-cross pin.
Definition ac_dimmer.h:16
DimMethod method
Dimmer method.
Definition ac_dimmer.h:36
void gpio_intr()
GPIO interrupt routine, called when ZC pin triggers.
Definition ac_dimmer.cpp:90
static void s_gpio_intr(AcDimmerDataStore *store)