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.

121 lines
5.2 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
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
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. from esphome import pins
  4. from esphome.components.ledc.output import LEDCOutput
  5. from esphome.components.gpio.output import GPIOBinaryOutput
  6. from esphome.components.i2c import I2CComponent, I2CDevice
  7. from esphome.core import coroutine
  8. from esphome.core import CORE
  9. from esphome.const import (
  10. CONF_RED, CONF_GREEN, CONF_BLUE, CONF_WHITE, CONF_TRIGGER_PIN,
  11. CONF_SDA, CONF_SCL, CONF_ADDRESS, CONF_PLATFORM
  12. )
  13. CODEOWNERS = ["@mmakaay"]
  14. CONF_RED_ID = "red_id"
  15. CONF_GREEN_ID = "green_id"
  16. CONF_BLUE_ID = "blue_id"
  17. CONF_WHITE_ID = "white_id"
  18. CONF_MASTER1 = "master1"
  19. CONF_MASTER1_ID = "master1_id"
  20. CONF_MASTER2 = "master2"
  21. CONF_MASTER2_ID = "master2_id"
  22. CONF_FP_I2C_ID = "front_panel_i2c_id"
  23. CONF_LIGHT_HAL_ID = "light_hal_id"
  24. CONF_FRONT_PANEL_HAL_ID = "front_panel_hal_id"
  25. CONF_ON_BRIGHTNESS = "on_brightness"
  26. CONF_LEDS = "leds"
  27. AUTO_LOAD = ["ledc", "output", "i2c"]
  28. xiaomi_ns = cg.esphome_ns.namespace("xiaomi")
  29. bslamp2_ns = xiaomi_ns.namespace("bslamp2")
  30. LightHAL = bslamp2_ns.class_("LightHAL", cg.Component)
  31. FrontPanelHAL = bslamp2_ns.class_("FrontPanelHAL", cg.Component, I2CDevice)
  32. CONFIG_SCHEMA = cv.COMPONENT_SCHEMA.extend({
  33. # RGBWW Light
  34. cv.GenerateID(CONF_LIGHT_HAL_ID): cv.declare_id(LightHAL),
  35. cv.GenerateID(CONF_RED_ID): cv.declare_id(LEDCOutput),
  36. cv.Optional(CONF_RED, default="GPIO13"): pins.validate_gpio_pin,
  37. cv.GenerateID(CONF_GREEN_ID): cv.declare_id(LEDCOutput),
  38. cv.Optional(CONF_GREEN, default="GPIO14"): pins.validate_gpio_pin,
  39. cv.GenerateID(CONF_BLUE_ID): cv.declare_id(LEDCOutput),
  40. cv.Optional(CONF_BLUE, default="GPIO5"): pins.validate_gpio_pin,
  41. cv.GenerateID(CONF_WHITE_ID): cv.declare_id(LEDCOutput),
  42. cv.Optional(CONF_WHITE, default="GPIO12"): pins.validate_gpio_pin,
  43. cv.GenerateID(CONF_MASTER1_ID): cv.declare_id(GPIOBinaryOutput),
  44. cv.Optional(CONF_MASTER1, default="GPIO33"): pins.validate_gpio_pin,
  45. cv.GenerateID(CONF_MASTER2_ID): cv.declare_id(GPIOBinaryOutput),
  46. cv.Optional(CONF_MASTER2, default="GPIO4"): pins.validate_gpio_pin,
  47. # Front panel I2C
  48. cv.GenerateID(CONF_FRONT_PANEL_HAL_ID): cv.declare_id(FrontPanelHAL),
  49. cv.GenerateID(CONF_FP_I2C_ID): cv.use_id(I2CComponent),
  50. cv.Optional(CONF_SDA, default="GPIO21"): pins.validate_gpio_pin,
  51. cv.Optional(CONF_SCL, default="GPIO19"): pins.validate_gpio_pin,
  52. cv.Optional(CONF_ADDRESS, default="0x2C"): cv.i2c_address,
  53. cv.Optional(CONF_TRIGGER_PIN, default="GPIO16"): cv.All(
  54. pins.validate_gpio_pin,
  55. pins.validate_has_interrupt
  56. ),
  57. })
  58. async def make_gpio(number, mode="OUTPUT"):
  59. return await cg.gpio_pin_expression({ "number": number, "mode": mode });
  60. async def make_gpio_binary_output(id_, number):
  61. gpio_var = await make_gpio(number)
  62. output_var = cg.new_Pvariable(id_)
  63. cg.add(output_var.set_pin(gpio_var))
  64. return await cg.register_component(output_var, {})
  65. async def make_ledc_output(id_, number, frequency, channel):
  66. gpio_var = await make_gpio(number)
  67. ledc_var = cg.new_Pvariable(id_, gpio_var)
  68. cg.add(ledc_var.set_frequency(frequency));
  69. cg.add(ledc_var.set_channel(channel));
  70. return await cg.register_component(ledc_var, {})
  71. async def make_light_hal(config):
  72. r_var = await make_ledc_output(config[CONF_RED_ID], config[CONF_RED], 3000, 0)
  73. g_var = await make_ledc_output(config[CONF_GREEN_ID], config[CONF_GREEN], 3000, 1)
  74. b_var = await make_ledc_output(config[CONF_BLUE_ID], config[CONF_BLUE], 3000, 2)
  75. w_var = await make_ledc_output(config[CONF_WHITE_ID], config[CONF_WHITE], 10000, 4)
  76. m1_var = await make_gpio_binary_output(config[CONF_MASTER1_ID], config[CONF_MASTER1])
  77. m2_var = await make_gpio_binary_output(config[CONF_MASTER2_ID], config[CONF_MASTER2])
  78. light_hal = cg.new_Pvariable(config[CONF_LIGHT_HAL_ID])
  79. await cg.register_component(light_hal, config)
  80. cg.add(light_hal.set_red_pin(r_var))
  81. cg.add(light_hal.set_green_pin(g_var))
  82. cg.add(light_hal.set_blue_pin(b_var))
  83. cg.add(light_hal.set_white_pin(w_var))
  84. cg.add(light_hal.set_master1_pin(m1_var))
  85. cg.add(light_hal.set_master2_pin(m2_var))
  86. async def make_front_panel_hal(config):
  87. trigger_pin = await make_gpio(config[CONF_TRIGGER_PIN], "INPUT")
  88. fp_hal = cg.new_Pvariable(config[CONF_FRONT_PANEL_HAL_ID])
  89. await cg.register_component(fp_hal, config)
  90. cg.add(fp_hal.set_trigger_pin(trigger_pin))
  91. # The i2c component automatically sets up one I2C bus.
  92. # Take that bus and update is to make it work for the
  93. # front panel I2C communication.
  94. fp_i2c_var = await cg.get_variable(config[CONF_FP_I2C_ID])
  95. cg.add(fp_i2c_var.set_sda_pin(config[CONF_SDA]))
  96. cg.add(fp_i2c_var.set_scl_pin(config[CONF_SCL]))
  97. cg.add(fp_i2c_var.set_scan(True))
  98. cg.add(fp_hal.set_i2c_parent(fp_i2c_var))
  99. cg.add(fp_hal.set_i2c_address(config[CONF_ADDRESS]))
  100. async def to_code(config):
  101. # Dirty little hack to make the ESPHome component loader include
  102. # the code for the "gpio" platform for the "output" domain.
  103. # Loading specific platform components is not possible using
  104. # the AUTO_LOAD feature unfortunately.
  105. CORE.config["output"].append({ CONF_PLATFORM: "gpio" })
  106. await make_light_hal(config)
  107. await make_front_panel_hal(config)