Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MAX7219 - Update intensity #5477

Merged
merged 1 commit into from Oct 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 11 additions & 1 deletion esphome/components/max7219/max7219.cpp
Expand Up @@ -164,6 +164,10 @@ void MAX7219Component::send_to_all_(uint8_t a_register, uint8_t data) {
this->disable();
}
void MAX7219Component::update() {
if (this->intensity_changed_) {
this->send_to_all_(MAX7219_REGISTER_INTENSITY, this->intensity_);
this->intensity_changed_ = false;
}
for (uint8_t i = 0; i < this->num_chips_ * 8; i++)
this->buffer_[i] = 0;
if (this->writer_.has_value())
Expand Down Expand Up @@ -217,7 +221,13 @@ uint8_t MAX7219Component::printf(const char *format, ...) {
return 0;
}
void MAX7219Component::set_writer(max7219_writer_t &&writer) { this->writer_ = writer; }
void MAX7219Component::set_intensity(uint8_t intensity) { this->intensity_ = intensity; }
void MAX7219Component::set_intensity(uint8_t intensity) {
intensity &= 0xF;
if (intensity != this->intensity_) {
this->intensity_changed_ = true;
this->intensity_ = intensity;
}
}
void MAX7219Component::set_num_chips(uint8_t num_chips) { this->num_chips_ = num_chips; }

uint8_t MAX7219Component::strftime(uint8_t pos, const char *format, ESPTime time) {
Expand Down
3 changes: 2 additions & 1 deletion esphome/components/max7219/max7219.h
Expand Up @@ -52,7 +52,8 @@ class MAX7219Component : public PollingComponent,
void send_byte_(uint8_t a_register, uint8_t data);
void send_to_all_(uint8_t a_register, uint8_t data);

uint8_t intensity_{15}; /// Intensity of the display from 0 to 15 (most)
uint8_t intensity_{15}; // Intensity of the display from 0 to 15 (most)
bool intensity_changed_{}; // True if we need to re-send the intensity
uint8_t num_chips_{1};
uint8_t *buffer_;
bool reverse_{false};
Expand Down