Fix color wipe effect (#599)

This commit is contained in:
Otto Winter 2019-06-03 09:05:20 +02:00 committed by GitHub
parent ec9cc72320
commit 2642750466
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 33 additions and 30 deletions

View file

@ -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_); }

View file

@ -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;

View file

@ -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;

View file

@ -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);