Skip to content

Commit

Permalink
WRGB or RGBW? WS2814 (esphome#6164)
Browse files Browse the repository at this point in the history
  • Loading branch information
mhetzi authored Feb 6, 2024
1 parent 5e9741f commit 164b42f
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
10 changes: 6 additions & 4 deletions esphome/components/esp32_rmt_led_strip/led_strip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,10 +161,12 @@ light::ESPColorView ESP32RMTLEDStripLightOutput::get_view_internal(int32_t index
break;
}
uint8_t multiplier = this->is_rgbw_ ? 4 : 3;
return {this->buf_ + (index * multiplier) + r,
this->buf_ + (index * multiplier) + g,
this->buf_ + (index * multiplier) + b,
this->is_rgbw_ ? this->buf_ + (index * multiplier) + 3 : nullptr,
uint8_t white = this->is_wrgb_ ? 0 : 3;

return {this->buf_ + (index * multiplier) + r + this->is_wrgb_,
this->buf_ + (index * multiplier) + g + this->is_wrgb_,
this->buf_ + (index * multiplier) + b + this->is_wrgb_,
this->is_rgbw_ || this->is_wrgb_ ? this->buf_ + (index * multiplier) + white : nullptr,
&this->effect_data_[index],
&this->correction_};
}
Expand Down
4 changes: 3 additions & 1 deletion esphome/components/esp32_rmt_led_strip/led_strip.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class ESP32RMTLEDStripLightOutput : public light::AddressableLight {
int32_t size() const override { return this->num_leds_; }
light::LightTraits get_traits() override {
auto traits = light::LightTraits();
if (this->is_rgbw_) {
if (this->is_rgbw_ || this->is_wrgb_) {
traits.set_supported_color_modes({light::ColorMode::RGB_WHITE, light::ColorMode::WHITE});
} else {
traits.set_supported_color_modes({light::ColorMode::RGB});
Expand All @@ -44,6 +44,7 @@ class ESP32RMTLEDStripLightOutput : public light::AddressableLight {
void set_pin(uint8_t pin) { this->pin_ = pin; }
void set_num_leds(uint16_t num_leds) { this->num_leds_ = num_leds; }
void set_is_rgbw(bool is_rgbw) { this->is_rgbw_ = is_rgbw; }
void set_is_wrgb(bool is_wrgb) { this->is_wrgb_ = is_wrgb; }

/// Set a maximum refresh rate in µs as some lights do not like being updated too often.
void set_max_refresh_rate(uint32_t interval_us) { this->max_refresh_rate_ = interval_us; }
Expand Down Expand Up @@ -72,6 +73,7 @@ class ESP32RMTLEDStripLightOutput : public light::AddressableLight {
uint8_t pin_;
uint16_t num_leds_;
bool is_rgbw_;
bool is_wrgb_;

rmt_item32_t bit0_, bit1_;
RGBOrder rgb_order_;
Expand Down
3 changes: 3 additions & 0 deletions esphome/components/esp32_rmt_led_strip/light.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ class LEDStripTimings:


CONF_IS_RGBW = "is_rgbw"
CONF_IS_WRGB = "is_wrgb"
CONF_BIT0_HIGH = "bit0_high"
CONF_BIT0_LOW = "bit0_low"
CONF_BIT1_HIGH = "bit1_high"
Expand Down Expand Up @@ -90,6 +91,7 @@ def _validate_rmt_channel(value):
cv.Optional(CONF_MAX_REFRESH_RATE): cv.positive_time_period_microseconds,
cv.Optional(CONF_CHIPSET): cv.one_of(*CHIPSETS, upper=True),
cv.Optional(CONF_IS_RGBW, default=False): cv.boolean,
cv.Optional(CONF_IS_WRGB, default=False): cv.boolean,
cv.Inclusive(
CONF_BIT0_HIGH,
"custom",
Expand Down Expand Up @@ -145,6 +147,7 @@ async def to_code(config):

cg.add(var.set_rgb_order(config[CONF_RGB_ORDER]))
cg.add(var.set_is_rgbw(config[CONF_IS_RGBW]))
cg.add(var.set_is_wrgb(config[CONF_IS_WRGB]))

cg.add(
var.set_rmt_channel(
Expand Down

0 comments on commit 164b42f

Please sign in to comment.