You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

50 lines
1.9 KiB

Introduced a HUB component + front panel IRQ handling A HUB component was introduced. This HUB component has all the knowledge about the Yeelight Bedside Lamp 2 hardware. It known what pins are used, that PWM frequencies to use, what pins to switch in binary mode, etc. etc. No configuration is required for this HUB component. It's automatically loaded when the light component is loaded. The light component will use the HUB component to access the pins that are required for driving the LED circuitry. Note that this simplifies the configuration by A LOT. There's no need anymore to configure the pinouts in the YAML file. This is a logical route to take, since we're talking about a factory-produced PCB with a soldered on ESP32 chip, which uses the same GPIO's and settings on all produced devices (I presume). It would be quite redundant to force every user into configuring these pinouts themselves. ** Beware to update your device yaml configuration ** There are a few pinouts left to move into the HUB. I will do that in the next commit. Your device yaml configuration can be simplified along with these changes. Some of the keys in the existing light configuration block will no longer work and will have to be removed (red, green, blue, white). ** Further development ** The HUB will be extended make it the central component that also handles the I2C communication. This way, there is a central place to regulate the traffic to and from the front panel. We will be able to build upon this by implementing extra, fully separated components that handle for example the front panel light level, the power button, the color button and the slider. ** Interrupt handler for the I2C IRQ trigger pin ** One requirement for the I2C communication has already been implemented: an interrupt handler for the GPIO that is used by the front panel to signal the ESP that a new touch or release event is avilable to be read. It doens't do anything functionally right now, but if you watch the log file, you will see that touch events are detected and that they trigger some log messages.
3 years ago
Introduced a HUB component + front panel IRQ handling A HUB component was introduced. This HUB component has all the knowledge about the Yeelight Bedside Lamp 2 hardware. It known what pins are used, that PWM frequencies to use, what pins to switch in binary mode, etc. etc. No configuration is required for this HUB component. It's automatically loaded when the light component is loaded. The light component will use the HUB component to access the pins that are required for driving the LED circuitry. Note that this simplifies the configuration by A LOT. There's no need anymore to configure the pinouts in the YAML file. This is a logical route to take, since we're talking about a factory-produced PCB with a soldered on ESP32 chip, which uses the same GPIO's and settings on all produced devices (I presume). It would be quite redundant to force every user into configuring these pinouts themselves. ** Beware to update your device yaml configuration ** There are a few pinouts left to move into the HUB. I will do that in the next commit. Your device yaml configuration can be simplified along with these changes. Some of the keys in the existing light configuration block will no longer work and will have to be removed (red, green, blue, white). ** Further development ** The HUB will be extended make it the central component that also handles the I2C communication. This way, there is a central place to regulate the traffic to and from the front panel. We will be able to build upon this by implementing extra, fully separated components that handle for example the front panel light level, the power button, the color button and the slider. ** Interrupt handler for the I2C IRQ trigger pin ** One requirement for the I2C communication has already been implemented: an interrupt handler for the GPIO that is used by the front panel to signal the ESP that a new touch or release event is avilable to be read. It doens't do anything functionally right now, but if you watch the log file, you will see that touch events are detected and that they trigger some log messages.
3 years ago
Introduced a HUB component + front panel IRQ handling A HUB component was introduced. This HUB component has all the knowledge about the Yeelight Bedside Lamp 2 hardware. It known what pins are used, that PWM frequencies to use, what pins to switch in binary mode, etc. etc. No configuration is required for this HUB component. It's automatically loaded when the light component is loaded. The light component will use the HUB component to access the pins that are required for driving the LED circuitry. Note that this simplifies the configuration by A LOT. There's no need anymore to configure the pinouts in the YAML file. This is a logical route to take, since we're talking about a factory-produced PCB with a soldered on ESP32 chip, which uses the same GPIO's and settings on all produced devices (I presume). It would be quite redundant to force every user into configuring these pinouts themselves. ** Beware to update your device yaml configuration ** There are a few pinouts left to move into the HUB. I will do that in the next commit. Your device yaml configuration can be simplified along with these changes. Some of the keys in the existing light configuration block will no longer work and will have to be removed (red, green, blue, white). ** Further development ** The HUB will be extended make it the central component that also handles the I2C communication. This way, there is a central place to regulate the traffic to and from the front panel. We will be able to build upon this by implementing extra, fully separated components that handle for example the front panel light level, the power button, the color button and the slider. ** Interrupt handler for the I2C IRQ trigger pin ** One requirement for the I2C communication has already been implemented: an interrupt handler for the GPIO that is used by the front panel to signal the ESP that a new touch or release event is avilable to be read. It doens't do anything functionally right now, but if you watch the log file, you will see that touch events are detected and that they trigger some log messages.
3 years ago
  1. import esphome.codegen as cg
  2. import esphome.config_validation as cv
  3. import esphome.components.gpio.output as gpio_output
  4. from esphome.components import light, gpio, ledc
  5. from esphome.const import CONF_RED, CONF_GREEN, CONF_BLUE, CONF_WHITE, CONF_OUTPUT_ID, CONF_TRIGGER_ID
  6. from esphome import automation
  7. from .. import bs2_ns, CODEOWNERS, CONF_HUB_ID, YeelightBS2Hub
  8. AUTO_LOAD = ["yeelight_bs2"]
  9. CONF_MASTER1 = "master1"
  10. CONF_MASTER2 = "master2"
  11. CONF_ON_BRIGHTNESS = "on_brightness"
  12. light_state = bs2_ns.class_("YeelightBS2LightState", light.LightState)
  13. light_output = bs2_ns.class_("YeelightBS2LightOutput", light.LightOutput)
  14. BrightnessTrigger = bs2_ns.class_("BrightnessTrigger", automation.Trigger.template())
  15. CONFIG_SCHEMA = light.RGB_LIGHT_SCHEMA.extend(
  16. {
  17. cv.GenerateID(): cv.declare_id(light_state),
  18. cv.GenerateID(CONF_HUB_ID): cv.use_id(YeelightBS2Hub),
  19. cv.GenerateID(CONF_OUTPUT_ID): cv.declare_id(light_output),
  20. cv.Required(CONF_MASTER1): cv.use_id(gpio_output.GPIOBinaryOutput),
  21. cv.Required(CONF_MASTER2): cv.use_id(gpio_output.GPIOBinaryOutput),
  22. cv.Optional(CONF_ON_BRIGHTNESS): automation.validate_automation(
  23. {
  24. cv.GenerateID(CONF_TRIGGER_ID): cv.declare_id(BrightnessTrigger),
  25. }
  26. ),
  27. }
  28. )
  29. def to_code(config):
  30. var = cg.new_Pvariable(config[CONF_OUTPUT_ID])
  31. yield light.register_light(var, config)
  32. hub_var = yield cg.get_variable(config[CONF_HUB_ID])
  33. cg.add(var.set_hub(hub_var))
  34. master1 = yield cg.get_variable(config[CONF_MASTER1])
  35. cg.add(var.set_master1_output(master1))
  36. master2 = yield cg.get_variable(config[CONF_MASTER2])
  37. cg.add(var.set_master2_output(master2))
  38. for conf in config.get(CONF_ON_BRIGHTNESS, []):
  39. trigger = cg.new_Pvariable(conf[CONF_TRIGGER_ID], var)
  40. yield automation.build_automation(trigger, [(float, "x")], conf)