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.

139 lines
5.7 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. FrontPanelLEDs = bslamp2_ns.enum("FrontPanelLEDs")
  33. FRONT_PANEL_LED_OPTIONS = {
  34. "NONE": FrontPanelLEDs.LED_NONE,
  35. "ALL": FrontPanelLEDs.LED_ALL,
  36. "POWER": FrontPanelLEDs.LED_POWER,
  37. "COLOR": FrontPanelLEDs.LED_COLOR,
  38. "1": FrontPanelLEDs.LED_1,
  39. "2": FrontPanelLEDs.LED_2,
  40. "3": FrontPanelLEDs.LED_3,
  41. "4": FrontPanelLEDs.LED_4,
  42. "5": FrontPanelLEDs.LED_5,
  43. "6": FrontPanelLEDs.LED_6,
  44. "7": FrontPanelLEDs.LED_7,
  45. "8": FrontPanelLEDs.LED_8,
  46. "9": FrontPanelLEDs.LED_9,
  47. "10": FrontPanelLEDs.LED_10,
  48. }
  49. CONFIG_SCHEMA = cv.COMPONENT_SCHEMA.extend({
  50. # RGBWW Light
  51. cv.GenerateID(CONF_LIGHT_HAL_ID): cv.declare_id(LightHAL),
  52. cv.GenerateID(CONF_RED_ID): cv.declare_id(LEDCOutput),
  53. cv.Optional(CONF_RED, default="GPIO13"): pins.validate_gpio_pin,
  54. cv.GenerateID(CONF_GREEN_ID): cv.declare_id(LEDCOutput),
  55. cv.Optional(CONF_GREEN, default="GPIO14"): pins.validate_gpio_pin,
  56. cv.GenerateID(CONF_BLUE_ID): cv.declare_id(LEDCOutput),
  57. cv.Optional(CONF_BLUE, default="GPIO5"): pins.validate_gpio_pin,
  58. cv.GenerateID(CONF_WHITE_ID): cv.declare_id(LEDCOutput),
  59. cv.Optional(CONF_WHITE, default="GPIO12"): pins.validate_gpio_pin,
  60. cv.GenerateID(CONF_MASTER1_ID): cv.declare_id(GPIOBinaryOutput),
  61. cv.Optional(CONF_MASTER1, default="GPIO33"): pins.validate_gpio_pin,
  62. cv.GenerateID(CONF_MASTER2_ID): cv.declare_id(GPIOBinaryOutput),
  63. cv.Optional(CONF_MASTER2, default="GPIO4"): pins.validate_gpio_pin,
  64. # Front panel I2C
  65. cv.GenerateID(CONF_FRONT_PANEL_HAL_ID): cv.declare_id(FrontPanelHAL),
  66. cv.GenerateID(CONF_FP_I2C_ID): cv.use_id(I2CComponent),
  67. cv.Optional(CONF_SDA, default="GPIO21"): pins.validate_gpio_pin,
  68. cv.Optional(CONF_SCL, default="GPIO19"): pins.validate_gpio_pin,
  69. cv.Optional(CONF_ADDRESS, default="0x2C"): cv.i2c_address,
  70. cv.Optional(CONF_TRIGGER_PIN, default="GPIO16"): cv.All(
  71. pins.validate_gpio_pin,
  72. pins.validate_has_interrupt
  73. ),
  74. })
  75. async def make_gpio(number, mode="OUTPUT"):
  76. return await cg.gpio_pin_expression({ "number": number, "mode": mode });
  77. async def make_gpio_binary_output(id_, number):
  78. gpio_var = await make_gpio(number)
  79. output_var = cg.new_Pvariable(id_)
  80. cg.add(output_var.set_pin(gpio_var))
  81. return await cg.register_component(output_var, {})
  82. async def make_ledc_output(id_, number, frequency, channel):
  83. gpio_var = await make_gpio(number)
  84. ledc_var = cg.new_Pvariable(id_, gpio_var)
  85. cg.add(ledc_var.set_frequency(frequency));
  86. cg.add(ledc_var.set_channel(channel));
  87. return await cg.register_component(ledc_var, {})
  88. async def make_light_hal(config):
  89. r_var = await make_ledc_output(config[CONF_RED_ID], config[CONF_RED], 3000, 0)
  90. g_var = await make_ledc_output(config[CONF_GREEN_ID], config[CONF_GREEN], 3000, 1)
  91. b_var = await make_ledc_output(config[CONF_BLUE_ID], config[CONF_BLUE], 3000, 2)
  92. w_var = await make_ledc_output(config[CONF_WHITE_ID], config[CONF_WHITE], 10000, 4)
  93. m1_var = await make_gpio_binary_output(config[CONF_MASTER1_ID], config[CONF_MASTER1])
  94. m2_var = await make_gpio_binary_output(config[CONF_MASTER2_ID], config[CONF_MASTER2])
  95. light_hal = cg.new_Pvariable(config[CONF_LIGHT_HAL_ID])
  96. await cg.register_component(light_hal, config)
  97. cg.add(light_hal.set_red_pin(r_var))
  98. cg.add(light_hal.set_green_pin(g_var))
  99. cg.add(light_hal.set_blue_pin(b_var))
  100. cg.add(light_hal.set_white_pin(w_var))
  101. cg.add(light_hal.set_master1_pin(m1_var))
  102. cg.add(light_hal.set_master2_pin(m2_var))
  103. async def make_front_panel_hal(config):
  104. trigger_pin = await make_gpio(config[CONF_TRIGGER_PIN], "INPUT")
  105. fp_hal = cg.new_Pvariable(config[CONF_FRONT_PANEL_HAL_ID])
  106. await cg.register_component(fp_hal, config)
  107. cg.add(fp_hal.set_trigger_pin(trigger_pin))
  108. # The i2c component automatically sets up one I2C bus.
  109. # Take that bus and update is to make it work for the
  110. # front panel I2C communication.
  111. fp_i2c_var = await cg.get_variable(config[CONF_FP_I2C_ID])
  112. cg.add(fp_i2c_var.set_sda_pin(config[CONF_SDA]))
  113. cg.add(fp_i2c_var.set_scl_pin(config[CONF_SCL]))
  114. cg.add(fp_i2c_var.set_scan(True))
  115. cg.add(fp_hal.set_i2c_parent(fp_i2c_var))
  116. cg.add(fp_hal.set_i2c_address(config[CONF_ADDRESS]))
  117. async def to_code(config):
  118. # Dirty little hack to make the ESPHome component loader include
  119. # the code for the "gpio" platform for the "output" domain.
  120. # Loading specific platform components is not possible using
  121. # the AUTO_LOAD feature unfortunately.
  122. CORE.config["output"].append({ CONF_PLATFORM: "gpio" })
  123. await make_light_hal(config)
  124. await make_front_panel_hal(config)