Skip to content

Commit

Permalink
Add frequency option to ESP8266 PWM
Browse files Browse the repository at this point in the history
  • Loading branch information
OttoWinter committed Nov 13, 2018
1 parent 7f91141 commit 01aaf14
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
18 changes: 11 additions & 7 deletions esphomeyaml/components/output/esp8266_pwm.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
import voluptuous as vol

from esphomeyaml import pins
import esphomeyaml.config_validation as cv
from esphomeyaml.components import output
from esphomeyaml.const import CONF_ID, CONF_NUMBER, CONF_PIN, ESP_PLATFORM_ESP8266
from esphomeyaml.core import ESPHomeYAMLError
from esphomeyaml.helpers import App, Pvariable, gpio_output_pin_expression, setup_component, \
Component
import esphomeyaml.config_validation as cv
from esphomeyaml.const import CONF_ID, CONF_NUMBER, CONF_PIN, ESP_PLATFORM_ESP8266, CONF_FREQUENCY
from esphomeyaml.helpers import App, Component, Pvariable, gpio_output_pin_expression, \
setup_component, add

ESP_PLATFORMS = [ESP_PLATFORM_ESP8266]


def valid_pwm_pin(value):
if value[CONF_NUMBER] > 16:
raise ESPHomeYAMLError(u"ESP8266: Only pins 0-16 support PWM.")
num = value[CONF_NUMBER]
cv.one_of(0, 1, 2, 3, 4, 5, 12, 13, 14, 15, 16)(num)
return value


Expand All @@ -22,6 +21,7 @@ def valid_pwm_pin(value):
PLATFORM_SCHEMA = output.FLOAT_OUTPUT_PLATFORM_SCHEMA.extend({
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.Optional(CONF_FREQUENCY): vol.All(cv.frequency, vol.Range(min=1.0e-6)),
}).extend(cv.COMPONENT_SCHEMA.schema)


Expand All @@ -30,6 +30,10 @@ def to_code(config):
yield
rhs = App.make_esp8266_pwm_output(pin)
gpio = Pvariable(config[CONF_ID], rhs)

if CONF_FREQUENCY in config:
add(gpio.set_frequency(config[CONF_FREQUENCY]))

output.setup_output_platform(gpio, config)
setup_component(gpio, config)

Expand Down
2 changes: 1 addition & 1 deletion esphomeyaml/config_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,7 @@ def percentage(value):
if value > 1:
msg = "Percentage must not be higher than 100%."
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)
return zero_to_one_float(value)

Expand Down

0 comments on commit 01aaf14

Please sign in to comment.