Skip to content
This repository was archived by the owner on Sep 27, 2023. It is now read-only.

Commit 8e7e587

Browse files
committed
Fix light partition src offset (#525)
* Fix light partition src offset * Fix
1 parent f4f2904 commit 8e7e587

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

src/esphome/light/addressable_light.cpp

+9-5
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ void AddressableLight::mark_shown_() {
176176
}
177177

178178
int32_t PartitionLightOutput::size() const {
179-
auto last_seg = this->segments_[this->segments_.size() - 1];
179+
auto &last_seg = this->segments_[this->segments_.size() - 1];
180180
return last_seg.get_dst_offset() + last_seg.get_size();
181181
}
182182
ESPColorView PartitionLightOutput::operator[](int32_t index) const {
@@ -194,13 +194,17 @@ ESPColorView PartitionLightOutput::operator[](int32_t index) const {
194194
lo = hi = mid;
195195
}
196196
}
197-
auto seg = this->segments_[lo];
198-
auto view = (*seg.get_src())[index - seg.get_src_offset()];
197+
auto &seg = this->segments_[lo];
198+
// offset within the segment
199+
int32_t seg_off = index - seg.get_dst_offset();
200+
// offset within the src
201+
int32_t src_off = seg.get_src_offset() + seg_off;
202+
auto view = (*seg.get_src())[src_off];
199203
view.set_color_correction_(&this->correction_);
200204
return view;
201205
}
202206
void PartitionLightOutput::clear_effect_data() {
203-
for (auto seg : this->segments_) {
207+
for (auto &seg : this->segments_) {
204208
seg.get_src()->clear_effect_data();
205209
}
206210
}
@@ -209,7 +213,7 @@ LightTraits PartitionLightOutput::get_traits() {
209213
}
210214
PartitionLightOutput::PartitionLightOutput(const std::vector<AddressableSegment> &segments) : segments_(segments) {
211215
int32_t off = 0;
212-
for (auto seg : this->segments_) {
216+
for (auto &seg : this->segments_) {
213217
seg.set_dst_offset(off);
214218
off += seg.get_size();
215219
}

src/esphome/light/addressable_light.h

-1
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,6 @@ class PartitionLightOutput : public AddressableLight, public Component {
186186

187187
protected:
188188
std::vector<AddressableSegment> segments_;
189-
ESPColorCorrection correction_{};
190189
};
191190

192191
} // namespace light

0 commit comments

Comments
 (0)