MAX6921: fix CI errors (round 4)

This commit is contained in:
endym 2024-08-08 18:34:27 +02:00
parent df0a897e69
commit dc73791abf
5 changed files with 82 additions and 74 deletions

View file

@ -1,5 +1,7 @@
#pragma once #pragma once
#ifdef USE_ESP32_FRAMEWORK_ARDUINO
#include "display.h" #include "display.h"
#include "esphome/core/automation.h" #include "esphome/core/automation.h"
#include "max6921.h" #include "max6921.h"
@ -87,3 +89,5 @@ template<typename... Ts> class SetDemoModeAction : public Action<Ts...> {
} // namespace max6921 } // namespace max6921
} // namespace esphome } // namespace esphome
#endif // USE_ESP32_FRAMEWORK_ARDUINO

View file

@ -138,9 +138,9 @@ void Display::setup(std::vector<uint8_t> &seg_to_out_map, std::vector<uint8_t> &
// find smallest segment DOUT number... // find smallest segment DOUT number...
this->seg_out_smallest_ = 19; this->seg_out_smallest_ = 19;
for (uint8_t i = 0; i < this->seg_to_out_map_.size(); i++) { for (unsigned char i : this->seg_to_out_map_) {
if (this->seg_to_out_map_[i] < this->seg_out_smallest_) if (i < this->seg_out_smallest_)
this->seg_out_smallest_ = this->seg_to_out_map_[i]; this->seg_out_smallest_ = i;
} }
ESP_LOGCONFIG(TAG, "Display smallest DOUT number: %u", this->seg_out_smallest_); ESP_LOGCONFIG(TAG, "Display smallest DOUT number: %u", this->seg_out_smallest_);
@ -154,7 +154,7 @@ void Display::setup(std::vector<uint8_t> &seg_to_out_map, std::vector<uint8_t> &
* well, which leads to unstable refresh cycles (flickering). Therefore a * well, which leads to unstable refresh cycles (flickering). Therefore a
* thread on 2nd MCU core is used. * thread on 2nd MCU core is used.
*/ */
xTaskCreatePinnedToCore(&Display::display_refresh_task_, xTaskCreatePinnedToCore(&Display::display_refresh_task,
"display_refresh_task", // name "display_refresh_task", // name
2048, // stack size 2048, // stack size
this, // pass component pointer as task parameter pv this, // pass component pointer as task parameter pv
@ -167,7 +167,7 @@ void Display::setup(std::vector<uint8_t> &seg_to_out_map, std::vector<uint8_t> &
// ESP_LOGCONFIG(TAG, "Display text effect: %u", this->disp_text_.effect); // ESP_LOGCONFIG(TAG, "Display text effect: %u", this->disp_text_.effect);
} }
void HOT Display::display_refresh_task_(void *pv) { void HOT Display::display_refresh_task(void *pv) {
Display *display = (Display *) pv; Display *display = (Display *) pv;
static uint count = display->num_digits_; static uint count = display->num_digits_;
static uint current_pos = 1; static uint current_pos = 1;
@ -227,9 +227,9 @@ void Display::dump_config() {
* *
* @return true, if character activates the point segment only, otherwise false * @return true, if character activates the point segment only, otherwise false
*/ */
bool Display::isPointSegOnly(char c) { return ((c == ',') || (c == '.')); } bool Display::is_point_seg_only(char c) { return ((c == ',') || (c == '.')); }
void Display::init_font__(void) { void Display::init_font__() {
uint8_t seg_data; uint8_t seg_data;
this->ascii_out_data_ = new uint8_t[ARRAY_ELEM_COUNT(ASCII_TO_SEG)]; // NOLINT this->ascii_out_data_ = new uint8_t[ARRAY_ELEM_COUNT(ASCII_TO_SEG)]; // NOLINT
@ -262,12 +262,13 @@ void Display::init_font__(void) {
* @param pos display position 0..n (optional, default=whole display) * @param pos display position 0..n (optional, default=whole display)
*/ */
void Display::clear(int pos) { void Display::clear(int pos) {
if (pos < 0) if (pos < 0) {
memset(this->out_buf_, 0, this->out_buf_size_); // clear whole display buffer memset(this->out_buf_, 0, this->out_buf_size_); // clear whole display buffer
else if (pos < this->num_digits_) } else if (pos < this->num_digits_) {
memset(&this->out_buf_[pos * 3], 0, 3); // clear display buffer at given position memset(&this->out_buf_[pos * 3], 0, 3); // clear display buffer at given position
else } else {
ESP_LOGW(TAG, "Invalid display position %i (max=%u)", pos, this->num_digits_ - 1); ESP_LOGW(TAG, "Invalid display position %i (max=%u)", pos, this->num_digits_ - 1);
}
} }
/** /**
@ -285,7 +286,7 @@ void Display::set_update_interval(uint32_t interval_ms) {
/** /**
* @brief Restores the configured display update interval. * @brief Restores the configured display update interval.
*/ */
void Display::restore_update_interval(void) { void Display::restore_update_interval() {
if (this->max6921_->get_update_interval() != this->default_update_interval_) { if (this->max6921_->get_update_interval() != this->default_update_interval_) {
ESP_LOGD(TAG, "Restore polling interval: %" PRIu32 "ms", this->default_update_interval_); ESP_LOGD(TAG, "Restore polling interval: %" PRIu32 "ms", this->default_update_interval_);
this->max6921_->stop_poller(); this->max6921_->stop_poller();
@ -297,7 +298,7 @@ void Display::restore_update_interval(void) {
/** /**
* @brief Updates the display. * @brief Updates the display.
*/ */
void Display::update(void) { void Display::update() {
// handle display brightness... // handle display brightness...
if (this->brightness_cfg_changed_) { if (this->brightness_cfg_changed_) {
uint32_t inverted_duty = uint32_t inverted_duty =
@ -341,7 +342,7 @@ void Display::update(void) {
} }
} }
void Display::set_demo_mode(demo_mode_t mode, uint32_t interval, uint8_t cycle_num) { void Display::set_demo_mode(DemoModeT mode, uint32_t interval, uint8_t cycle_num) {
uint text_idx, font_idx; uint text_idx, font_idx;
ESP_LOGD(TAG, "Set demo mode: mode=%i, update-interval=%" PRIu32 "ms, cycle_num=%u", mode, interval, cycle_num); ESP_LOGD(TAG, "Set demo mode: mode=%i, update-interval=%" PRIu32 "ms, cycle_num=%u", mode, interval, cycle_num);
@ -450,38 +451,39 @@ int Display::set_text(const char *text, uint8_t start_pos) {
* *
* @return number of visible characters * @return number of visible characters
*/ */
int Display::update_out_buf_(void) { int Display::update_out_buf_() {
uint visible_idx_offset = 0; uint visible_idx_offset = 0;
for (uint pos = 0; pos < this->num_digits_; pos++) { for (uint pos = 0; pos < this->num_digits_; pos++) {
char pos_char; char pos_char;
uint32_t out_data; uint32_t out_data;
bool bGetNextChar, bClearPos = true; bool is_get_next_char, is_clear_pos = true;
do { do {
// determine character for current display position... // determine character for current display position...
if ((pos < this->disp_text_.start_pos) || // empty position before text or if ((pos < this->disp_text_.start_pos) || // empty position before text or
(pos >= (this->disp_text_.start_pos + this->disp_text_.visible_len))) // empty position after text? (pos >= (this->disp_text_.start_pos + this->disp_text_.visible_len))) { // empty position after text?
pos_char = ' '; pos_char = ' ';
else } else {
pos_char = this->disp_text_.text[this->disp_text_.visible_idx + visible_idx_offset++]; pos_char = this->disp_text_.text[this->disp_text_.visible_idx + visible_idx_offset++];
}
// special handling for point segment... // special handling for point segment...
bGetNextChar = false; is_get_next_char = false;
if (isPointSegOnly(pos_char)) { // is point segment only? if (is_point_seg_only(pos_char)) { // is point segment only?
if (this->disp_text_.visible_idx + visible_idx_offset - 1 > 0) { // not the 1st text character? if (this->disp_text_.visible_idx + visible_idx_offset - 1 > 0) { // not the 1st text character?
if (isPointSegOnly(this->disp_text_.text[this->disp_text_.visible_idx + visible_idx_offset - if (is_point_seg_only(this->disp_text_.text[this->disp_text_.visible_idx + visible_idx_offset -
2])) { // previous text character wasn't a point? 2])) { // previous text character wasn't a point?
if (pos == 0) { // 1st (most left) display position? if (pos == 0) { // 1st (most left) display position?
bGetNextChar = true; // yes -> ignore point, get next character is_get_next_char = true; // yes -> ignore point, get next character
} else { } else {
--pos; // no -> add point to previous display position --pos; // no -> add point to previous display position
bClearPos = false; is_clear_pos = false;
} }
} }
} }
} }
} while (bGetNextChar); } while (is_get_next_char);
if (bClearPos) if (is_clear_pos)
clear(pos); clear(pos);
// create segment data... // create segment data...
@ -568,7 +570,7 @@ int DisplayText::set_text(uint start_pos, uint max_pos, const std::string &text)
/** /**
* @brief Inits the text object according to selected align. * @brief Inits the text object according to selected align.
*/ */
void DisplayText::init_text_align_(void) { void DisplayText::init_text_align_() {
this->visible_idx = 0; this->visible_idx = 0;
this->visible_len = std::min(strlen(this->text), this->max_pos + 1); this->visible_len = std::min(strlen(this->text), this->max_pos + 1);
switch (this->align) { switch (this->align) {
@ -587,7 +589,7 @@ void DisplayText::init_text_align_(void) {
/** /**
* @brief Inits the text object according to selected effect. * @brief Inits the text object according to selected effect.
*/ */
void DisplayText::init_text_effect_(void) { void DisplayText::init_text_effect_() {
switch (this->effect) { switch (this->effect) {
case TEXT_EFFECT_SCROLL_LEFT: case TEXT_EFFECT_SCROLL_LEFT:
this->start_pos = this->max_pos; // start at right side this->start_pos = this->max_pos; // start at right side
@ -609,7 +611,7 @@ void DisplayText::init_text_effect_(void) {
* *
* @param align text align * @param align text align
*/ */
void DisplayText::set_text_align(text_align_t align) { void DisplayText::set_text_align(TextAlignT align) {
if (align >= TEXT_ALIGN_LAST_ENUM) { if (align >= TEXT_ALIGN_LAST_ENUM) {
ESP_LOGE(TAG, "Invalid display text align: %i", align); ESP_LOGE(TAG, "Invalid display text align: %i", align);
return; return;
@ -626,17 +628,18 @@ void DisplayText::set_text_align(text_align_t align) {
* @param align text align (as string) * @param align text align (as string)
*/ */
void DisplayText::set_text_align(const std::string &align) { void DisplayText::set_text_align(const std::string &align) {
text_align_t text_align = TEXT_ALIGN_LAST_ENUM; TextAlignT text_align = TEXT_ALIGN_LAST_ENUM;
if (!align.empty()) { if (!align.empty()) {
if (str_equals_case_insensitive(align, "left")) if (str_equals_case_insensitive(align, "left")) {
text_align = TEXT_ALIGN_LEFT; text_align = TEXT_ALIGN_LEFT;
else if (str_equals_case_insensitive(align, "center")) } else if (str_equals_case_insensitive(align, "center")) {
text_align = TEXT_ALIGN_CENTER; text_align = TEXT_ALIGN_CENTER;
else if (str_equals_case_insensitive(align, "right")) } else if (str_equals_case_insensitive(align, "right")) {
text_align = TEXT_ALIGN_RIGHT; text_align = TEXT_ALIGN_RIGHT;
else } else {
ESP_LOGW(TAG, "Invalid text align: %s", align); ESP_LOGW(TAG, "Invalid text align: %s", align);
}
} else } else
ESP_LOGW(TAG, "No text align given"); ESP_LOGW(TAG, "No text align given");
if (text_align >= TEXT_ALIGN_LAST_ENUM) if (text_align >= TEXT_ALIGN_LAST_ENUM)
@ -650,7 +653,7 @@ void DisplayText::set_text_align(const std::string &align) {
* @param effect text effect * @param effect text effect
* @param cycle_num number of effect cycles (optional, default=endless) * @param cycle_num number of effect cycles (optional, default=endless)
*/ */
void DisplayText::set_text_effect(text_effect_t effect, uint8_t cycle_num) { void DisplayText::set_text_effect(TextEffectT effect, uint8_t cycle_num) {
if (effect >= TEXT_EFFECT_LAST_ENUM) { if (effect >= TEXT_EFFECT_LAST_ENUM) {
ESP_LOGE(TAG, "Invalid display text effect: %i", effect); ESP_LOGE(TAG, "Invalid display text effect: %i", effect);
return; return;
@ -674,17 +677,18 @@ void DisplayText::set_text_effect(text_effect_t effect, uint8_t cycle_num) {
* @param cycle_num number of effect cycles (optional, default=endless) * @param cycle_num number of effect cycles (optional, default=endless)
*/ */
void DisplayText::set_text_effect(const std::string &effect, uint8_t cycle_num) { void DisplayText::set_text_effect(const std::string &effect, uint8_t cycle_num) {
text_effect_t text_effect = TEXT_EFFECT_LAST_ENUM; TextEffectT text_effect = TEXT_EFFECT_LAST_ENUM;
if (!effect.empty()) { if (!effect.empty()) {
if (str_equals_case_insensitive(effect, "none")) if (str_equals_case_insensitive(effect, "none")) {
text_effect = TEXT_EFFECT_NONE; text_effect = TEXT_EFFECT_NONE;
else if (str_equals_case_insensitive(effect, "blink")) } else if (str_equals_case_insensitive(effect, "blink")) {
text_effect = TEXT_EFFECT_BLINK; text_effect = TEXT_EFFECT_BLINK;
else if (str_equals_case_insensitive(effect, "scroll_left")) } else if (str_equals_case_insensitive(effect, "scroll_left")) {
text_effect = TEXT_EFFECT_SCROLL_LEFT; text_effect = TEXT_EFFECT_SCROLL_LEFT;
else } else {
ESP_LOGW(TAG, "Invalid text effect: %s", effect); ESP_LOGW(TAG, "Invalid text effect: %s", effect);
}
} else } else
ESP_LOGW(TAG, "No text effect given"); ESP_LOGW(TAG, "No text effect given");
if (text_effect >= TEXT_EFFECT_LAST_ENUM) if (text_effect >= TEXT_EFFECT_LAST_ENUM)
@ -695,7 +699,7 @@ void DisplayText::set_text_effect(const std::string &effect, uint8_t cycle_num)
/** /**
* @brief Updates the mode "blink". The display buffer must be updated before. * @brief Updates the mode "blink". The display buffer must be updated before.
*/ */
void DisplayText::blink(void) { void DisplayText::blink() {
ESP_LOGV(TAG, "%s(): ENTRY: start-idx=%u, text-idx=%u, text-len=%u", __func__, this->start_pos, this->visible_idx, ESP_LOGV(TAG, "%s(): ENTRY: start-idx=%u, text-idx=%u, text-len=%u", __func__, this->start_pos, this->visible_idx,
this->visible_len); this->visible_len);
@ -726,7 +730,7 @@ void DisplayText::blink(void) {
/** /**
* @brief Updates the mode "scroll left". The display buffer must be updated before. * @brief Updates the mode "scroll left". The display buffer must be updated before.
*/ */
void DisplayText::scroll_left(void) { void DisplayText::scroll_left() {
ESP_LOGV(TAG, "%s(): ENTRY: start-idx=%u, text-idx=%u, text-len=%u", __func__, this->start_pos, this->visible_idx, ESP_LOGV(TAG, "%s(): ENTRY: start-idx=%u, text-idx=%u, text-len=%u", __func__, this->start_pos, this->visible_idx,
this->visible_len); this->visible_len);
@ -813,7 +817,7 @@ DisplayMode::DisplayMode() {
* @param duration duration in ms (optional, default=endless) * @param duration duration in ms (optional, default=endless)
* not applicable for "it" mode * not applicable for "it" mode
*/ */
void DisplayMode::set_mode(display_mode_t mode, uint32_t duration_ms) { void DisplayMode::set_mode(DisplayModeT mode, uint32_t duration_ms) {
if (mode >= DISP_MODE_LAST_ENUM) { if (mode >= DISP_MODE_LAST_ENUM) {
ESP_LOGE(TAG, "Invalid display mode: %i", mode); ESP_LOGE(TAG, "Invalid display mode: %i", mode);
return; return;

View file

@ -15,15 +15,15 @@ class MAX6921Component;
static const uint FONT_SIZE = 95; static const uint FONT_SIZE = 95;
static const uint DISPLAY_TEXT_LEN = FONT_SIZE; // at least font size for demo mode "scroll font" static const uint DISPLAY_TEXT_LEN = FONT_SIZE; // at least font size for demo mode "scroll font"
enum display_mode_t { enum DisplayModeT {
DISP_MODE_PRINT, // input by it-functions DISP_MODE_PRINT, // input by it-functions
DISP_MODE_OTHER, // input by actions DISP_MODE_OTHER, // input by actions
DISP_MODE_LAST_ENUM DISP_MODE_LAST_ENUM
}; };
enum text_align_t { TEXT_ALIGN_LEFT, TEXT_ALIGN_CENTER, TEXT_ALIGN_RIGHT, TEXT_ALIGN_LAST_ENUM }; enum TextAlignT { TEXT_ALIGN_LEFT, TEXT_ALIGN_CENTER, TEXT_ALIGN_RIGHT, TEXT_ALIGN_LAST_ENUM };
enum text_effect_t { enum TextEffectT {
TEXT_EFFECT_NONE, // show text at given position, cut if too long TEXT_EFFECT_NONE, // show text at given position, cut if too long
TEXT_EFFECT_BLINK, // blink TEXT_EFFECT_BLINK, // blink
TEXT_EFFECT_SCROLL_LEFT, // scroll left, start with 1st char at right position TEXT_EFFECT_SCROLL_LEFT, // scroll left, start with 1st char at right position
@ -31,7 +31,7 @@ enum text_effect_t {
TEXT_EFFECT_LAST_ENUM TEXT_EFFECT_LAST_ENUM
}; };
enum demo_mode_t { enum DemoModeT {
DEMO_MODE_OFF, DEMO_MODE_OFF,
DEMO_MODE_SCROLL_FONT, DEMO_MODE_SCROLL_FONT,
}; };
@ -39,7 +39,7 @@ enum demo_mode_t {
class DisplayBrightness { class DisplayBrightness {
public: public:
uint32_t config_brightness_pwm(uint8_t pwm_pin_no, uint8_t channel, uint8_t resolution, uint32_t freq_wanted); uint32_t config_brightness_pwm(uint8_t pwm_pin_no, uint8_t channel, uint8_t resolution, uint32_t freq_wanted);
float get_brightness(void) { return this->brightness_cfg_value_; } float get_brightness() { return this->brightness_cfg_value_; }
void set_brightness(float percent); void set_brightness(float percent);
protected: protected:
@ -51,10 +51,10 @@ class DisplayBrightness {
class DisplayMode { class DisplayMode {
public: public:
display_mode_t mode; DisplayModeT mode;
uint32_t duration_ms; uint32_t duration_ms;
DisplayMode(); DisplayMode();
void set_mode(display_mode_t mode, uint32_t duration_ms = 0); void set_mode(DisplayModeT mode, uint32_t duration_ms = 0);
protected: protected:
uint32_t duration_ms_start_; uint32_t duration_ms_start_;
@ -68,22 +68,22 @@ class DisplayText {
char text[DISPLAY_TEXT_LEN + 1]; // current text to display (may be larger then display) char text[DISPLAY_TEXT_LEN + 1]; // current text to display (may be larger then display)
uint visible_idx; // current index of start of visible part uint visible_idx; // current index of start of visible part
uint visible_len; // current length of visible text uint visible_len; // current length of visible text
text_align_t align; TextAlignT align;
text_effect_t effect; TextEffectT effect;
uint8_t cycle_num; uint8_t cycle_num;
DisplayText(); DisplayText();
void blink(void); void blink();
void scroll_left(void); void scroll_left();
int set_text(uint start_pos, uint max_pos, const std::string &text); int set_text(uint start_pos, uint max_pos, const std::string &text);
void set_text_align(text_align_t align); void set_text_align(TextAlignT align);
void set_text_align(const std::string &align); void set_text_align(const std::string &align);
void set_text_effect(text_effect_t effect, uint8_t cycle_num = 0); void set_text_effect(TextEffectT effect, uint8_t cycle_num = 0);
void set_text_effect(const std::string &effect, uint8_t cycle_num = 0); void set_text_effect(const std::string &effect, uint8_t cycle_num = 0);
protected: protected:
int effect_change_count_; int effect_change_count_;
void init_text_align_(void); void init_text_align_();
void init_text_effect_(void); void init_text_effect_();
}; };
class Display : public DisplayBrightness, public DisplayMode { class Display : public DisplayBrightness, public DisplayMode {
@ -91,16 +91,16 @@ class Display : public DisplayBrightness, public DisplayMode {
Display(MAX6921Component *max6921) { max6921_ = max6921; } Display(MAX6921Component *max6921) { max6921_ = max6921; }
void clear(int pos = -1); void clear(int pos = -1);
void dump_config(); void dump_config();
bool isPointSegOnly(char c); bool is_point_seg_only(char c);
void restore_update_interval(void); void restore_update_interval();
void setup(std::vector<uint8_t> &seg_to_out_map, std::vector<uint8_t> &pos_to_out_map); void setup(std::vector<uint8_t> &seg_to_out_map, std::vector<uint8_t> &pos_to_out_map);
void set_demo_mode(demo_mode_t mode, uint32_t interval, uint8_t cycle_num); void set_demo_mode(DemoModeT mode, uint32_t interval, uint8_t cycle_num);
void set_demo_mode(const std::string &mode, uint32_t interval, uint8_t cycle_num); void set_demo_mode(const std::string &mode, uint32_t interval, uint8_t cycle_num);
int set_text(const char *text, uint8_t start_pos); int set_text(const char *text, uint8_t start_pos);
int set_text(const std::string &text, uint8_t start_pos, const std::string &align, uint32_t duration, int set_text(const std::string &text, uint8_t start_pos, const std::string &align, uint32_t duration,
const std::string &effect, uint32_t interval, uint8_t cycle_num); const std::string &effect, uint32_t interval, uint8_t cycle_num);
void set_update_interval(uint32_t interval_ms); void set_update_interval(uint32_t interval_ms);
void update(void); void update();
protected: protected:
MAX6921Component *max6921_; MAX6921Component *max6921_;
@ -114,11 +114,11 @@ class Display : public DisplayBrightness, public DisplayMode {
uint32_t refresh_period_us_; uint32_t refresh_period_us_;
DisplayText disp_text_; DisplayText disp_text_;
uint32_t default_update_interval_; uint32_t default_update_interval_;
static void display_refresh_task_(void *pv); static void display_refresh_task(void *pv);
int update_out_buf_(void); int update_out_buf_();
private: private:
void init_font__(void); void init_font__();
}; };
} // namespace max6921 } // namespace max6921

View file

@ -17,8 +17,8 @@ static const char *const TAG = "max6921";
float MAX6921Component::get_setup_priority() const { return setup_priority::HARDWARE; } float MAX6921Component::get_setup_priority() const { return setup_priority::HARDWARE; }
void MAX6921Component::setup() { void MAX6921Component::setup() {
const uint32_t PWM_FREQ_WANTED = 5000; const uint32_t pwm_freq_wanted = 5000;
const uint8_t PWM_RESOLUTION = 8; const uint8_t pwm_resolution = 8;
ESP_LOGCONFIG(TAG, "Setting up MAX6921..."); ESP_LOGCONFIG(TAG, "Setting up MAX6921...");
// global_max6921 = this; // global_max6921 = this;
@ -32,14 +32,14 @@ void MAX6921Component::setup() {
this->display_->setup(this->seg_to_out_map__, this->pos_to_out_map__); this->display_->setup(this->seg_to_out_map__, this->pos_to_out_map__);
// setup display brightness (PWM for BLANK pin)... // setup display brightness (PWM for BLANK pin)...
if (this->display_->config_brightness_pwm(this->blank_pin_->get_pin(), 0, PWM_RESOLUTION, PWM_FREQ_WANTED) == 0) { if (this->display_->config_brightness_pwm(this->blank_pin_->get_pin(), 0, pwm_resolution, pwm_freq_wanted) == 0) {
ESP_LOGE(TAG, "Failed to configure PWM -> set to max. brightness"); ESP_LOGE(TAG, "Failed to configure PWM -> set to max. brightness");
this->blank_pin_->pin_mode(gpio::FLAG_OUTPUT); this->blank_pin_->pin_mode(gpio::FLAG_OUTPUT);
this->blank_pin_->setup(); this->blank_pin_->setup();
this->disable_blank_(); // enable display (max. brightness) this->disable_blank_(); // enable display (max. brightness)
} }
this->setup_finished = true; this->setup_finished_ = true;
} }
void MAX6921Component::dump_config() { void MAX6921Component::dump_config() {
@ -50,7 +50,7 @@ void MAX6921Component::dump_config() {
} }
void MAX6921Component::set_brightness(float brightness) { void MAX6921Component::set_brightness(float brightness) {
if (!this->setup_finished) { if (!this->setup_finished_) {
ESP_LOGD(TAG, "Set brightness: setup not finished -> discard brightness value"); ESP_LOGD(TAG, "Set brightness: setup not finished -> discard brightness value");
return; return;
} }

View file

@ -12,7 +12,7 @@
namespace esphome { namespace esphome {
namespace max6921 { namespace max6921 {
#define ARRAY_ELEM_COUNT(array) (sizeof(array) / sizeof(array[0])) #define ARRAY_ELEM_COUNT(array) (sizeof(array) / sizeof((array)[0]))
class MAX6921Component; class MAX6921Component;
class Display; class Display;
@ -43,12 +43,12 @@ class MAX6921Component : public PollingComponent,
protected: protected:
GPIOPin *load_pin_{}; GPIOPin *load_pin_{};
InternalGPIOPin *blank_pin_{}; InternalGPIOPin *blank_pin_{};
bool setup_finished{false}; bool setup_finished_{false};
void disable_blank_() { this->blank_pin_->digital_write(false); } // display on void disable_blank_() { this->blank_pin_->digital_write(false); } // display on
void IRAM_ATTR HOT disable_load_() { this->load_pin_->digital_write(false); } void IRAM_ATTR HOT disable_load_() { this->load_pin_->digital_write(false); }
void enable_blank_() { this->blank_pin_->digital_write(true); } // display off void enable_blank_() { this->blank_pin_->digital_write(true); } // display off
void IRAM_ATTR HOT enable_load_() { this->load_pin_->digital_write(true); } void IRAM_ATTR HOT enable_load_() { this->load_pin_->digital_write(true); }
void update_demo_mode_scroll_font_(void); void update_demo_mode_scroll_font_();
optional<max6921_writer_t> writer_{}; optional<max6921_writer_t> writer_{};
private: private: