mirror of
https://github.com/esphome/esphome.git
synced 2024-11-25 00:18:11 +01:00
Add frequency option to ESP8266 PWM
This commit is contained in:
parent
7f91141df2
commit
01aaf14078
2 changed files with 12 additions and 8 deletions
|
@ -1,19 +1,18 @@
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
from esphomeyaml import pins
|
from esphomeyaml import pins
|
||||||
import esphomeyaml.config_validation as cv
|
|
||||||
from esphomeyaml.components import output
|
from esphomeyaml.components import output
|
||||||
from esphomeyaml.const import CONF_ID, CONF_NUMBER, CONF_PIN, ESP_PLATFORM_ESP8266
|
import esphomeyaml.config_validation as cv
|
||||||
from esphomeyaml.core import ESPHomeYAMLError
|
from esphomeyaml.const import CONF_ID, CONF_NUMBER, CONF_PIN, ESP_PLATFORM_ESP8266, CONF_FREQUENCY
|
||||||
from esphomeyaml.helpers import App, Pvariable, gpio_output_pin_expression, setup_component, \
|
from esphomeyaml.helpers import App, Component, Pvariable, gpio_output_pin_expression, \
|
||||||
Component
|
setup_component, add
|
||||||
|
|
||||||
ESP_PLATFORMS = [ESP_PLATFORM_ESP8266]
|
ESP_PLATFORMS = [ESP_PLATFORM_ESP8266]
|
||||||
|
|
||||||
|
|
||||||
def valid_pwm_pin(value):
|
def valid_pwm_pin(value):
|
||||||
if value[CONF_NUMBER] > 16:
|
num = value[CONF_NUMBER]
|
||||||
raise ESPHomeYAMLError(u"ESP8266: Only pins 0-16 support PWM.")
|
cv.one_of(0, 1, 2, 3, 4, 5, 12, 13, 14, 15, 16)(num)
|
||||||
return value
|
return value
|
||||||
|
|
||||||
|
|
||||||
|
@ -22,6 +21,7 @@ ESP8266PWMOutput = output.output_ns.class_('ESP8266PWMOutput', output.FloatOutpu
|
||||||
PLATFORM_SCHEMA = output.FLOAT_OUTPUT_PLATFORM_SCHEMA.extend({
|
PLATFORM_SCHEMA = output.FLOAT_OUTPUT_PLATFORM_SCHEMA.extend({
|
||||||
vol.Required(CONF_ID): cv.declare_variable_id(ESP8266PWMOutput),
|
vol.Required(CONF_ID): cv.declare_variable_id(ESP8266PWMOutput),
|
||||||
vol.Required(CONF_PIN): vol.All(pins.internal_gpio_output_pin_schema, valid_pwm_pin),
|
vol.Required(CONF_PIN): vol.All(pins.internal_gpio_output_pin_schema, valid_pwm_pin),
|
||||||
|
vol.Optional(CONF_FREQUENCY): vol.All(cv.frequency, vol.Range(min=1.0e-6)),
|
||||||
}).extend(cv.COMPONENT_SCHEMA.schema)
|
}).extend(cv.COMPONENT_SCHEMA.schema)
|
||||||
|
|
||||||
|
|
||||||
|
@ -30,6 +30,10 @@ def to_code(config):
|
||||||
yield
|
yield
|
||||||
rhs = App.make_esp8266_pwm_output(pin)
|
rhs = App.make_esp8266_pwm_output(pin)
|
||||||
gpio = Pvariable(config[CONF_ID], rhs)
|
gpio = Pvariable(config[CONF_ID], rhs)
|
||||||
|
|
||||||
|
if CONF_FREQUENCY in config:
|
||||||
|
add(gpio.set_frequency(config[CONF_FREQUENCY]))
|
||||||
|
|
||||||
output.setup_output_platform(gpio, config)
|
output.setup_output_platform(gpio, config)
|
||||||
setup_component(gpio, config)
|
setup_component(gpio, config)
|
||||||
|
|
||||||
|
|
|
@ -562,7 +562,7 @@ def percentage(value):
|
||||||
if value > 1:
|
if value > 1:
|
||||||
msg = "Percentage must not be higher than 100%."
|
msg = "Percentage must not be higher than 100%."
|
||||||
if not has_percent_sign:
|
if not has_percent_sign:
|
||||||
msg += " Please don't put to put a percent sign after the number!"
|
msg += " Please put a percent sign after the number!"
|
||||||
raise vol.Invalid(msg)
|
raise vol.Invalid(msg)
|
||||||
return zero_to_one_float(value)
|
return zero_to_one_float(value)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue