mirror of
https://github.com/esphome/esphome.git
synced 2024-11-10 09:17:46 +01:00
Fix color wipe effect (#599)
This commit is contained in:
parent
ec9cc72320
commit
2642750466
4 changed files with 33 additions and 30 deletions
|
@ -82,7 +82,7 @@ void ESPRangeView::set(const ESPColor &color) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ESPColorView ESPRangeView::operator[](int32_t index) const {
|
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];
|
return (*this->parent_)[index];
|
||||||
}
|
}
|
||||||
ESPRangeIterator ESPRangeView::begin() { return {*this, this->begin_}; }
|
ESPRangeIterator ESPRangeView::begin() { return {*this, this->begin_}; }
|
||||||
|
@ -123,6 +123,35 @@ void ESPRangeView::darken(uint8_t delta) {
|
||||||
for (auto c : *this)
|
for (auto c : *this)
|
||||||
c.darken(delta);
|
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_); }
|
ESPColorView ESPRangeIterator::operator*() const { return this->range_.parent_->get(this->i_); }
|
||||||
|
|
||||||
|
|
|
@ -399,33 +399,7 @@ class ESPRangeView : public ESPColorSettable {
|
||||||
this->set_hsv(rhs);
|
this->set_hsv(rhs);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
ESPRangeView &operator=(const ESPRangeView &rhs) {
|
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;
|
|
||||||
}
|
|
||||||
void set_red(uint8_t red) override;
|
void set_red(uint8_t red) override;
|
||||||
void set_green(uint8_t green) override;
|
void set_green(uint8_t green) override;
|
||||||
void set_blue(uint8_t blue) override;
|
void set_blue(uint8_t blue) override;
|
||||||
|
|
|
@ -113,7 +113,7 @@ class AddressableColorWipeEffect : public AddressableLightEffect {
|
||||||
it.shift_right(1);
|
it.shift_right(1);
|
||||||
const AddressableColorWipeEffectColor color = this->colors_[this->at_color_];
|
const AddressableColorWipeEffectColor color = this->colors_[this->at_color_];
|
||||||
const ESPColor esp_color = ESPColor(color.r, color.g, color.b, color.w);
|
const ESPColor esp_color = ESPColor(color.r, color.g, color.b, color.w);
|
||||||
if (!this->reverse_)
|
if (this->reverse_)
|
||||||
it[-1] = esp_color;
|
it[-1] = esp_color;
|
||||||
else
|
else
|
||||||
it[0] = esp_color;
|
it[0] = esp_color;
|
||||||
|
|
|
@ -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";
|
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()) {
|
if (res->temperature.has_value()) {
|
||||||
ESP_LOGD(TAG, " Temperature: %.1f°C", *res->temperature);
|
ESP_LOGD(TAG, " Temperature: %.1f°C", *res->temperature);
|
||||||
|
|
Loading…
Reference in a new issue