mirror of
https://github.com/esphome/esphome.git
synced 2024-11-27 09:18:00 +01:00
[ac_dimmer] : Support for ANY_EDGE interrupt of zero-crossing signal
This commit is contained in:
parent
be7d09f64b
commit
efe1efb84e
5 changed files with 24 additions and 5 deletions
|
@ -182,8 +182,10 @@ void AcDimmer::setup() {
|
||||||
if (setup_zero_cross_pin) {
|
if (setup_zero_cross_pin) {
|
||||||
this->zero_cross_pin_->setup();
|
this->zero_cross_pin_->setup();
|
||||||
this->store_.zero_cross_pin = this->zero_cross_pin_->to_isr();
|
this->store_.zero_cross_pin = this->zero_cross_pin_->to_isr();
|
||||||
this->zero_cross_pin_->attach_interrupt(&AcDimmerDataStore::s_gpio_intr, &this->store_,
|
this->zero_cross_pin_->attach_interrupt(
|
||||||
gpio::INTERRUPT_ANY_EDGE);
|
&AcDimmerDataStore::s_gpio_intr, &this->store_,
|
||||||
|
this->zero_crossing_type_ == ZeroCrossingType::ZERO_CROSSING_TYPE_RISING_EDGE ? gpio::INTERRUPT_RISING_EDGE
|
||||||
|
: gpio::INTERRUPT_ANY_EDGE);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef USE_ESP8266
|
#ifdef USE_ESP8266
|
||||||
|
|
|
@ -11,6 +11,8 @@ namespace ac_dimmer {
|
||||||
|
|
||||||
enum DimMethod { DIM_METHOD_LEADING_PULSE = 0, DIM_METHOD_LEADING, DIM_METHOD_TRAILING };
|
enum DimMethod { DIM_METHOD_LEADING_PULSE = 0, DIM_METHOD_LEADING, DIM_METHOD_TRAILING };
|
||||||
|
|
||||||
|
enum ZeroCrossingType { ZERO_CROSSING_TYPE_RISING_EDGE, ZERO_CROSSING_TYPE_ANY_EDGE };
|
||||||
|
|
||||||
struct AcDimmerDataStore {
|
struct AcDimmerDataStore {
|
||||||
/// Zero-cross pin
|
/// Zero-cross pin
|
||||||
ISRInternalGPIOPin zero_cross_pin;
|
ISRInternalGPIOPin zero_cross_pin;
|
||||||
|
@ -53,6 +55,7 @@ class AcDimmer : public output::FloatOutput, public Component {
|
||||||
void set_zero_cross_pin(InternalGPIOPin *zero_cross_pin) { zero_cross_pin_ = zero_cross_pin; }
|
void set_zero_cross_pin(InternalGPIOPin *zero_cross_pin) { zero_cross_pin_ = zero_cross_pin; }
|
||||||
void set_init_with_half_cycle(bool init_with_half_cycle) { init_with_half_cycle_ = init_with_half_cycle; }
|
void set_init_with_half_cycle(bool init_with_half_cycle) { init_with_half_cycle_ = init_with_half_cycle; }
|
||||||
void set_method(DimMethod method) { method_ = method; }
|
void set_method(DimMethod method) { method_ = method; }
|
||||||
|
void set_zero_crossing_type(ZeroCrossingType zero_crossing_type) { this->zero_crossing_type_ = zero_crossing_type; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void write_state(float state) override;
|
void write_state(float state) override;
|
||||||
|
@ -62,6 +65,7 @@ class AcDimmer : public output::FloatOutput, public Component {
|
||||||
AcDimmerDataStore store_;
|
AcDimmerDataStore store_;
|
||||||
bool init_with_half_cycle_;
|
bool init_with_half_cycle_;
|
||||||
DimMethod method_;
|
DimMethod method_;
|
||||||
|
ZeroCrossingType zero_crossing_type_;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace ac_dimmer
|
} // namespace ac_dimmer
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
import esphome.codegen as cg
|
|
||||||
import esphome.config_validation as cv
|
|
||||||
from esphome import pins
|
from esphome import pins
|
||||||
|
import esphome.codegen as cg
|
||||||
from esphome.components import output
|
from esphome.components import output
|
||||||
from esphome.const import CONF_ID, CONF_MIN_POWER, CONF_METHOD
|
import esphome.config_validation as cv
|
||||||
|
from esphome.const import CONF_ID, CONF_METHOD, CONF_MIN_POWER
|
||||||
|
|
||||||
CODEOWNERS = ["@glmnet"]
|
CODEOWNERS = ["@glmnet"]
|
||||||
|
|
||||||
|
@ -16,8 +16,15 @@ DIM_METHODS = {
|
||||||
"TRAILING": DimMethod.DIM_METHOD_TRAILING,
|
"TRAILING": DimMethod.DIM_METHOD_TRAILING,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ZeroCrossingType = ac_dimmer_ns.enum("ZeroCrossingType")
|
||||||
|
ZC_TYPES = {
|
||||||
|
"RISING_EDGE": ZeroCrossingType.ZERO_CROSSING_TYPE_RISING_EDGE,
|
||||||
|
"ANY_EDGE": ZeroCrossingType.ZERO_CROSSING_TYPE_ANY_EDGE,
|
||||||
|
}
|
||||||
|
|
||||||
CONF_GATE_PIN = "gate_pin"
|
CONF_GATE_PIN = "gate_pin"
|
||||||
CONF_ZERO_CROSS_PIN = "zero_cross_pin"
|
CONF_ZERO_CROSS_PIN = "zero_cross_pin"
|
||||||
|
CONF_ZERO_CROSS_TYPE = "zero_cross_type"
|
||||||
CONF_INIT_WITH_HALF_CYCLE = "init_with_half_cycle"
|
CONF_INIT_WITH_HALF_CYCLE = "init_with_half_cycle"
|
||||||
CONFIG_SCHEMA = cv.All(
|
CONFIG_SCHEMA = cv.All(
|
||||||
output.FLOAT_OUTPUT_SCHEMA.extend(
|
output.FLOAT_OUTPUT_SCHEMA.extend(
|
||||||
|
@ -29,6 +36,9 @@ CONFIG_SCHEMA = cv.All(
|
||||||
cv.Optional(CONF_METHOD, default="leading pulse"): cv.enum(
|
cv.Optional(CONF_METHOD, default="leading pulse"): cv.enum(
|
||||||
DIM_METHODS, upper=True, space="_"
|
DIM_METHODS, upper=True, space="_"
|
||||||
),
|
),
|
||||||
|
cv.Optional(CONF_ZERO_CROSS_TYPE, default="RISING_EDGE"): cv.enum(
|
||||||
|
ZC_TYPES, upper=True
|
||||||
|
),
|
||||||
}
|
}
|
||||||
).extend(cv.COMPONENT_SCHEMA),
|
).extend(cv.COMPONENT_SCHEMA),
|
||||||
cv.only_with_arduino,
|
cv.only_with_arduino,
|
||||||
|
@ -50,3 +60,4 @@ async def to_code(config):
|
||||||
cg.add(var.set_zero_cross_pin(pin))
|
cg.add(var.set_zero_cross_pin(pin))
|
||||||
cg.add(var.set_init_with_half_cycle(config[CONF_INIT_WITH_HALF_CYCLE]))
|
cg.add(var.set_init_with_half_cycle(config[CONF_INIT_WITH_HALF_CYCLE]))
|
||||||
cg.add(var.set_method(config[CONF_METHOD]))
|
cg.add(var.set_method(config[CONF_METHOD]))
|
||||||
|
cg.add(var.set_zero_crossing_type(config[CONF_ZERO_CROSS_TYPE]))
|
||||||
|
|
|
@ -5,3 +5,4 @@ output:
|
||||||
number: 12
|
number: 12
|
||||||
zero_cross_pin:
|
zero_cross_pin:
|
||||||
number: 13
|
number: 13
|
||||||
|
zero_cross_type: ANY_EDGE
|
||||||
|
|
|
@ -5,3 +5,4 @@ output:
|
||||||
number: 5
|
number: 5
|
||||||
zero_cross_pin:
|
zero_cross_pin:
|
||||||
number: 6
|
number: 6
|
||||||
|
zero_cross_type: RISING_EDGE
|
||||||
|
|
Loading…
Reference in a new issue