mirror of
https://github.com/esphome/esphome.git
synced 2024-11-25 08:28:12 +01:00
Add MY9231 support (#227)
This commit is contained in:
parent
c99d4e2815
commit
083c2fce05
4 changed files with 113 additions and 0 deletions
51
esphomeyaml/components/my9231.py
Normal file
51
esphomeyaml/components/my9231.py
Normal file
|
@ -0,0 +1,51 @@
|
|||
import voluptuous as vol
|
||||
|
||||
import esphomeyaml.config_validation as cv
|
||||
from esphomeyaml import pins
|
||||
from esphomeyaml.components import output
|
||||
from esphomeyaml.const import (CONF_DATA_PIN, CONF_CLOCK_PIN, CONF_NUM_CHANNELS,
|
||||
CONF_NUM_CHIPS, CONF_BIT_DEPTH, CONF_ID,
|
||||
CONF_UPDATE_ON_BOOT)
|
||||
from esphomeyaml.helpers import (gpio_output_pin_expression, App, Pvariable,
|
||||
add)
|
||||
|
||||
MY9231OutputComponent = output.output_ns.namespace('MY9231OutputComponent')
|
||||
|
||||
|
||||
MY9231_SCHEMA = vol.Schema({
|
||||
cv.GenerateID(): cv.declare_variable_id(MY9231OutputComponent),
|
||||
vol.Required(CONF_DATA_PIN): pins.gpio_output_pin_schema,
|
||||
vol.Required(CONF_CLOCK_PIN): pins.gpio_output_pin_schema,
|
||||
vol.Optional(CONF_NUM_CHANNELS): vol.All(vol.Coerce(int),
|
||||
vol.Range(3, 1020)),
|
||||
vol.Optional(CONF_NUM_CHIPS): vol.All(vol.Coerce(int),
|
||||
vol.Range(1, 255)),
|
||||
vol.Optional(CONF_BIT_DEPTH): vol.All(vol.Coerce(int),
|
||||
cv.one_of(8, 12, 14, 16)),
|
||||
vol.Optional(CONF_UPDATE_ON_BOOT): vol.Coerce(bool),
|
||||
})
|
||||
|
||||
CONFIG_SCHEMA = vol.All(cv.ensure_list, [MY9231_SCHEMA])
|
||||
|
||||
|
||||
def to_code(config):
|
||||
for conf in config:
|
||||
di = None
|
||||
for di in gpio_output_pin_expression(conf[CONF_DATA_PIN]):
|
||||
yield
|
||||
dcki = None
|
||||
for dcki in gpio_output_pin_expression(conf[CONF_CLOCK_PIN]):
|
||||
yield
|
||||
rhs = App.make_my9231_component(di, dcki)
|
||||
my9231 = Pvariable(conf[CONF_ID], rhs)
|
||||
if CONF_NUM_CHANNELS in conf:
|
||||
add(my9231.set_num_channels(conf[CONF_NUM_CHANNELS]))
|
||||
if CONF_NUM_CHIPS in conf:
|
||||
add(my9231.set_num_chips(conf[CONF_NUM_CHIPS]))
|
||||
if CONF_BIT_DEPTH in conf:
|
||||
add(my9231.set_bit_depth(conf[CONF_BIT_DEPTH]))
|
||||
if CONF_UPDATE_ON_BOOT in conf:
|
||||
add(my9231.set_update(conf[CONF_UPDATE_ON_BOOT]))
|
||||
|
||||
|
||||
BUILD_FLAGS = '-DUSE_MY9231_OUTPUT'
|
34
esphomeyaml/components/output/my9231.py
Normal file
34
esphomeyaml/components/output/my9231.py
Normal file
|
@ -0,0 +1,34 @@
|
|||
import voluptuous as vol
|
||||
|
||||
import esphomeyaml.config_validation as cv
|
||||
from esphomeyaml.components import output
|
||||
from esphomeyaml.components.my9231 import MY9231OutputComponent
|
||||
from esphomeyaml.const import CONF_CHANNEL, CONF_ID, CONF_MY9231_ID, CONF_POWER_SUPPLY
|
||||
from esphomeyaml.helpers import Pvariable, get_variable
|
||||
|
||||
DEPENDENCIES = ['my9231']
|
||||
|
||||
Channel = MY9231OutputComponent.Channel
|
||||
|
||||
PLATFORM_SCHEMA = output.FLOAT_OUTPUT_PLATFORM_SCHEMA.extend({
|
||||
vol.Required(CONF_ID): cv.declare_variable_id(Channel),
|
||||
vol.Required(CONF_CHANNEL): vol.All(vol.Coerce(int),
|
||||
vol.Range(min=0, max=65535)),
|
||||
cv.GenerateID(CONF_MY9231_ID): cv.use_variable_id(MY9231OutputComponent),
|
||||
})
|
||||
|
||||
|
||||
def to_code(config):
|
||||
power_supply = None
|
||||
if CONF_POWER_SUPPLY in config:
|
||||
for power_supply in get_variable(config[CONF_POWER_SUPPLY]):
|
||||
yield
|
||||
my9231 = None
|
||||
for my9231 in get_variable(config[CONF_MY9231_ID]):
|
||||
yield
|
||||
rhs = my9231.create_channel(config[CONF_CHANNEL], power_supply)
|
||||
out = Pvariable(config[CONF_ID], rhs)
|
||||
output.setup_output_platform(out, config, skip_power_supply=True)
|
||||
|
||||
|
||||
BUILD_FLAGS = '-DUSE_MY9231_OUTPUT'
|
|
@ -365,6 +365,9 @@ CONF_TIME_ID = 'time_id'
|
|||
CONF_RESTORE_STATE = 'restore_state'
|
||||
CONF_TIMING = 'timing'
|
||||
CONF_INVALID_COOLDOWN = 'invalid_cooldown'
|
||||
CONF_MY9231_ID = 'my9231_id'
|
||||
CONF_NUM_CHANNELS = 'num_channels'
|
||||
CONF_UPDATE_ON_BOOT = 'update_on_boot'
|
||||
CONF_INITIAL_VALUE = 'initial_value'
|
||||
CONF_RESTORE_VALUE = 'restore_value'
|
||||
CONF_PINS = 'pins'
|
||||
|
|
|
@ -571,6 +571,13 @@ pca9685:
|
|||
frequency: 500
|
||||
address: 0x0
|
||||
|
||||
my9231:
|
||||
data_pin: GPIO12
|
||||
clock_pin: GPIO14
|
||||
num_channels: 6
|
||||
num_chips: 2
|
||||
bit_depth: 16
|
||||
|
||||
output:
|
||||
- platform: gpio
|
||||
pin: GPIO26
|
||||
|
@ -615,6 +622,24 @@ output:
|
|||
number: 0
|
||||
mode: OUTPUT
|
||||
inverted: False
|
||||
- platform: my9231
|
||||
id: my_0
|
||||
channel: 0
|
||||
- platform: my9231
|
||||
id: my_1
|
||||
channel: 1
|
||||
- platform: my9231
|
||||
id: my_2
|
||||
channel: 2
|
||||
- platform: my9231
|
||||
id: my_3
|
||||
channel: 3
|
||||
- platform: my9231
|
||||
id: my_4
|
||||
channel: 4
|
||||
- platform: my9231
|
||||
id: my_5
|
||||
channel: 5
|
||||
|
||||
light:
|
||||
- platform: binary
|
||||
|
|
Loading…
Reference in a new issue