chore: cleanup and mild refactoring
This commit is contained in:
parent
70458d4ed9
commit
519b36bfed
3 changed files with 26 additions and 189 deletions
|
|
@ -8,7 +8,6 @@ void Wordclock::setup() {
|
|||
if (!this->valid_time) {
|
||||
this->start_idle_animation();
|
||||
}
|
||||
// this->valid_time = true;
|
||||
}
|
||||
|
||||
void Wordclock::update() {
|
||||
|
|
@ -45,62 +44,42 @@ void Wordclock::update() {
|
|||
|
||||
if (dirty) {
|
||||
this->previous_segments->clear();
|
||||
|
||||
for (uint16_t segment_idx : *this->current_segments) {
|
||||
this->previous_segments->push_back(segment_idx);
|
||||
}
|
||||
// std::sort(this->previous_segments->begin(), this->previous_segments->end());
|
||||
|
||||
// std::sort(s.begin(), s.end(), [](int a, int b)
|
||||
// {
|
||||
// return a > b;
|
||||
// });
|
||||
|
||||
this->current_segments->clear();
|
||||
|
||||
for (uint16_t segment_idx : *this->static_segments) {
|
||||
this->current_segments->push_back(segment_idx);
|
||||
// this->draw_segment(segment_idx);
|
||||
}
|
||||
|
||||
for (uint16_t segment_idx : *(this->minutes->at(minute).segments)) {
|
||||
this->current_segments->push_back(segment_idx);
|
||||
// this->draw_segment(segment_idx);
|
||||
}
|
||||
|
||||
for (uint16_t segment_idx : *(this->hours->at(hour).segments)) {
|
||||
this->current_segments->push_back(segment_idx);
|
||||
// this->draw_segment(segment_idx);
|
||||
}
|
||||
|
||||
std::sort(this->current_segments->begin(), this->current_segments->end());
|
||||
|
||||
this->find_difference(this->previous_segments, this->current_segments);
|
||||
// ESP_LOGD("wordclock.cpp", "reset");
|
||||
|
||||
this->on_transformer->reset();
|
||||
this->off_transformer->reset();
|
||||
}
|
||||
|
||||
// Color on = this->on_color * this->on_transformer->apply().value_or(255);
|
||||
// Color off = this->off_color * this->off_transformer->apply().value_or(255);
|
||||
this->current_position = 0;
|
||||
uint8_t transition_progress = this->on_transformer->apply().value_or(255);
|
||||
// uint8_t on_progress = this->on_transformer->apply().value_or(255);
|
||||
// uint8_t off_progress = this->off_transformer->apply().value_or(255);
|
||||
// ESP_LOGD("wordclock.cpp", "off progress [%d]", off_progress);
|
||||
// Color added_color = this->off_color.gradient(this->on_color, transition_progress);
|
||||
Color removed_color = this->on_color.gradient(this->off_color, transition_progress);
|
||||
// ESP_LOGD("wordclock.cpp", "transition progress [%d], added [0x%06x], removed [0x%06x]", transition_progress, added_color.raw_32, removed_color.raw_32);
|
||||
|
||||
for (uint16_t segment_idx : *this->removed_segments) {
|
||||
// ESP_LOGD("wordclock.cpp", "off [%d]", segment_idx);
|
||||
// this->disable_segment(segment_idx, this->off_color, transition_progress);
|
||||
this->disable_segment_effect(segment_idx, this->off_color, transition_progress);
|
||||
// this->disable_segment(segment_idx, removed_color);
|
||||
// this->draw_segment(segment_idx, off_progress);
|
||||
}
|
||||
for (uint16_t segment_idx : *this->added_segments) {
|
||||
// ESP_LOGD("wordclock.cpp", "on [%d]", segment_idx);
|
||||
// this->segment_effect_base(segment_idx, this->off_color, transition_progress);
|
||||
this->enable_segment_effect(segment_idx, this->off_color, transition_progress);
|
||||
// this->draw_segment(segment_idx, on_progress);
|
||||
}
|
||||
for (uint16_t segment_idx : *this->staying_segments) {
|
||||
this->apply_segment_effect(segment_idx);
|
||||
|
|
@ -109,14 +88,10 @@ void Wordclock::update() {
|
|||
}
|
||||
|
||||
void Wordclock::find_difference(std::vector<uint16_t> *a_vec, std::vector<uint16_t> *b_vec) {
|
||||
// for (uint16_t segment_idx : a) {
|
||||
// this->current_segments->push_back(segment_idx);
|
||||
// }
|
||||
this->added_segments->clear();
|
||||
this->removed_segments->clear();
|
||||
this->staying_segments->clear();
|
||||
|
||||
|
||||
auto a = a_vec->begin();
|
||||
auto b = b_vec->begin();
|
||||
|
||||
|
|
@ -129,18 +104,20 @@ void Wordclock::find_difference(std::vector<uint16_t> *a_vec, std::vector<uint16
|
|||
}
|
||||
}
|
||||
|
||||
Color Wordclock::get_next_color(uint32_t position, const Color ¤t_color) {
|
||||
uint32_t speed_ = 3;
|
||||
uint16_t width_ = 100;
|
||||
// uint16_t width_ = 50;
|
||||
Color Wordclock::get_next_color_base_(uint32_t position, uint32_t speed, uint16_t width, const Color ¤t_color) {
|
||||
esphome::light::ESPHSVColor hsv;
|
||||
hsv.value = 255;
|
||||
hsv.saturation = 240;
|
||||
hsv.hue = ((millis() * speed_ + (position * (0xFFFF / width_))) % 0xFFFF) >> 8;
|
||||
// hsv.hue = hue >> 8;
|
||||
hsv.hue = ((millis() * speed + (position * (0xFFFF / width))) % 0xFFFF) >> 8;
|
||||
return hsv.to_rgb();
|
||||
}
|
||||
|
||||
Color Wordclock::get_next_color(uint32_t position, const Color ¤t_color) {
|
||||
uint32_t speed_ = 3;
|
||||
uint16_t width_ = 100; // Original width_ = 50
|
||||
return get_next_color_base_(position, speed_, width_, current_color);
|
||||
}
|
||||
|
||||
int8_t Wordclock::find_hour(uint8_t target_value) {
|
||||
std::vector<Hour> *elements = this->hours;
|
||||
for (int i = 0; i < elements->size(); i++) {
|
||||
|
|
@ -151,15 +128,6 @@ int8_t Wordclock::find_hour(uint8_t target_value) {
|
|||
}
|
||||
}
|
||||
return elements->size() - 1;
|
||||
// uint16_t last_defined_index = -1;
|
||||
// for (int i = 0; i < elements->size(); i++) {
|
||||
// if (elements->at(i).size()) {
|
||||
// last_defined_index = i;
|
||||
// }
|
||||
// if (i >= target_value) break;
|
||||
// }
|
||||
// return last_defined_index;
|
||||
|
||||
}
|
||||
|
||||
int8_t Wordclock::find_minute(uint8_t target_value) {
|
||||
|
|
@ -179,11 +147,6 @@ void Wordclock::setup_transitions(uint32_t milliseconds) {
|
|||
this->off_transformer->setup(this->brightness, 0, milliseconds);
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Wordclock::Wordclock() : PollingComponent(1000) {
|
||||
// }
|
||||
|
||||
Wordclock::Wordclock(
|
||||
esphome::time::RealTimeClock *time,
|
||||
esphome::addressable_light::AddressableLightDisplay *display,
|
||||
|
|
@ -209,20 +172,7 @@ Wordclock::Wordclock(
|
|||
this->staying_segments = new std::vector<uint16_t>();
|
||||
|
||||
this->on_transformer = new BrightnessTransitionTransformer();
|
||||
// this->on_transformer->setup(0, this->brightness, 700);
|
||||
this->off_transformer = new BrightnessTransitionTransformer();
|
||||
// this->off_transformer->setup(this->brightness, 0, 700);
|
||||
|
||||
// wordclock_wordclock->add_segment(wordclock::SegmentCoords{
|
||||
// .x1 = 0,
|
||||
// .x2 = 4,
|
||||
// .y1 = 8,
|
||||
// .y2 = 8,
|
||||
// });
|
||||
|
||||
// this->hour_offsets = new std::vector<int8_t>(60, 0);
|
||||
// this->minutes = new std::vector<std::vector<uint16_t>>(60, std::vector<uint16_t>());
|
||||
// this->hours = new std::vector<std::vector<uint16_t>>(24, std::vector<uint16_t>());
|
||||
}
|
||||
} // namespace wordclock
|
||||
} // namespace esphome
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue