From 2642750466d0d1ac07e66a37c98f98d6543277a1 Mon Sep 17 00:00:00 2001 From: Otto Winter Date: Mon, 3 Jun 2019 09:05:20 +0200 Subject: [PATCH] Fix color wipe effect (#599) --- .../components/light/addressable_light.cpp | 31 ++++++++++++++++++- esphome/components/light/addressable_light.h | 28 +---------------- .../light/addressable_light_effect.h | 2 +- esphome/components/xiaomi_ble/xiaomi_ble.cpp | 2 +- 4 files changed, 33 insertions(+), 30 deletions(-) diff --git a/esphome/components/light/addressable_light.cpp b/esphome/components/light/addressable_light.cpp index bbb475d534..c93392418c 100644 --- a/esphome/components/light/addressable_light.cpp +++ b/esphome/components/light/addressable_light.cpp @@ -82,7 +82,7 @@ void ESPRangeView::set(const ESPColor &color) { } } ESPColorView ESPRangeView::operator[](int32_t index) const { - index = interpret_index(index, this->size()); + index = interpret_index(index, this->size()) + this->begin_; return (*this->parent_)[index]; } ESPRangeIterator ESPRangeView::begin() { return {*this, this->begin_}; } @@ -123,6 +123,35 @@ void ESPRangeView::darken(uint8_t delta) { for (auto c : *this) c.darken(delta); } +ESPRangeView &ESPRangeView::operator=(const ESPRangeView &rhs) { + // If size doesn't match, error (todo warning) + if (rhs.size() != this->size()) + return *this; + + if (this->parent_ != rhs.parent_) { + for (int32_t i = 0; i < this->size(); i++) + (*this)[i].set(rhs[i].get()); + return *this; + } + + // If both equal, already done + if (rhs.begin_ == this->begin_) + return *this; + + if (rhs.begin_ > this->begin_) { + // Copy from left + for (int32_t i = 0; i < this->size(); i++) { + (*this)[i].set(rhs[i].get()); + } + } else { + // Copy from right + for (int32_t i = this->size() - 1; i >= 0; i--) { + (*this)[i].set(rhs[i].get()); + } + } + + return *this; +} ESPColorView ESPRangeIterator::operator*() const { return this->range_.parent_->get(this->i_); } diff --git a/esphome/components/light/addressable_light.h b/esphome/components/light/addressable_light.h index a933ca3dea..4383b4b245 100644 --- a/esphome/components/light/addressable_light.h +++ b/esphome/components/light/addressable_light.h @@ -399,33 +399,7 @@ class ESPRangeView : public ESPColorSettable { this->set_hsv(rhs); return *this; } - ESPRangeView &operator=(const ESPRangeView &rhs) { - // If size doesn't match, error (todo warning) - if (rhs.size() != this->size()) - return *this; - - if (this->parent_ != rhs.parent_) { - for (int32_t i = 0; i < this->size(); i++) - (*this)[i].set(rhs[i].get()); - return *this; - } - - // If both equal, already done - if (rhs.begin_ == this->begin_) - return *this; - - if (rhs.begin_ < this->begin_) { - // Copy into rhs - for (int32_t i = 0; i < this->size(); i++) - rhs[i].set((*this)[i].get()); - } else { - // Copy into this - for (int32_t i = 0; i < this->size(); i++) - (*this)[i].set(rhs[i].get()); - } - - return *this; - } + ESPRangeView &operator=(const ESPRangeView &rhs); void set_red(uint8_t red) override; void set_green(uint8_t green) override; void set_blue(uint8_t blue) override; diff --git a/esphome/components/light/addressable_light_effect.h b/esphome/components/light/addressable_light_effect.h index edde7ad626..1e0b540285 100644 --- a/esphome/components/light/addressable_light_effect.h +++ b/esphome/components/light/addressable_light_effect.h @@ -113,7 +113,7 @@ class AddressableColorWipeEffect : public AddressableLightEffect { it.shift_right(1); const AddressableColorWipeEffectColor color = this->colors_[this->at_color_]; const ESPColor esp_color = ESPColor(color.r, color.g, color.b, color.w); - if (!this->reverse_) + if (this->reverse_) it[-1] = esp_color; else it[0] = esp_color; diff --git a/esphome/components/xiaomi_ble/xiaomi_ble.cpp b/esphome/components/xiaomi_ble/xiaomi_ble.cpp index 7431b84491..4367b5fd1e 100644 --- a/esphome/components/xiaomi_ble/xiaomi_ble.cpp +++ b/esphome/components/xiaomi_ble/xiaomi_ble.cpp @@ -115,7 +115,7 @@ bool XiaomiListener::parse_device(const esp32_ble_tracker::ESPBTDevice &device) const char *name = res->type == XiaomiParseResult::TYPE_MIFLORA ? "Mi Flora" : "Mi Jia"; - ESP_LOGD(TAG, "Got Xiaomi %s:", name); + ESP_LOGD(TAG, "Got Xiaomi %s (%s):", name, device.address_str().c_str()); if (res->temperature.has_value()) { ESP_LOGD(TAG, " Temperature: %.1f°C", *res->temperature);