From 709137219f4f0347d275a6f92c44d82b6bdb4168 Mon Sep 17 00:00:00 2001 From: endym Date: Thu, 8 Aug 2024 20:23:25 +0200 Subject: [PATCH] MAX6921: fix CI errors (round 5) --- esphome/components/max6921/display.cpp | 17 +++++++++-------- esphome/components/max6921/display.h | 2 +- esphome/components/max6921/max6921.cpp | 4 ++-- esphome/components/max6921/max6921.h | 10 +++++----- 4 files changed, 17 insertions(+), 16 deletions(-) diff --git a/esphome/components/max6921/display.cpp b/esphome/components/max6921/display.cpp index 31de50cee0..3580e4c536 100644 --- a/esphome/components/max6921/display.cpp +++ b/esphome/components/max6921/display.cpp @@ -129,7 +129,7 @@ void Display::setup(std::vector &seg_to_out_map, std::vector & ESP_LOGCONFIG(TAG, "Display digits: %u", this->num_digits_); // setup font... - init_font__(); + init_font_(); // display output buffer... this->out_buf_size_ = this->num_digits_ * 3; @@ -229,7 +229,7 @@ void Display::dump_config() { */ bool Display::is_point_seg_only(char c) { return ((c == ',') || (c == '.')); } -void Display::init_font__() { +void Display::init_font_() { uint8_t seg_data; this->ascii_out_data_ = new uint8_t[ARRAY_ELEM_COUNT(ASCII_TO_SEG)]; // NOLINT @@ -554,7 +554,7 @@ DisplayText::DisplayText() { int DisplayText::set_text(uint start_pos, uint max_pos, const std::string &text) { // check start position... if (start_pos >= max_pos) { - ESP_LOGW(TAG, "Invalid start position: %u"); + ESP_LOGW(TAG, "Invalid start position: %u", start_pos); this->start_pos = 0; } else this->start_pos = start_pos; @@ -577,12 +577,13 @@ void DisplayText::init_text_align_() { case TEXT_ALIGN_LEFT: this->start_pos = 0; break; - case TEXT_ALIGN_CENTER: - this->start_pos = ((this->max_pos + 1) - this->visible_len) / 2; - break; case TEXT_ALIGN_RIGHT: this->start_pos = (this->max_pos + 1) - this->visible_len; break; + case TEXT_ALIGN_CENTER: + default: + this->start_pos = ((this->max_pos + 1) - this->visible_len) / 2; + break; } } @@ -638,7 +639,7 @@ void DisplayText::set_text_align(const std::string &align) { } else if (str_equals_case_insensitive(align, "right")) { text_align = TEXT_ALIGN_RIGHT; } else { - ESP_LOGW(TAG, "Invalid text align: %s", align); + ESP_LOGW(TAG, "Invalid text align: %s", align.c_str()); } } else ESP_LOGW(TAG, "No text align given"); @@ -687,7 +688,7 @@ void DisplayText::set_text_effect(const std::string &effect, uint8_t cycle_num) } else if (str_equals_case_insensitive(effect, "scroll_left")) { text_effect = TEXT_EFFECT_SCROLL_LEFT; } else { - ESP_LOGW(TAG, "Invalid text effect: %s", effect); + ESP_LOGW(TAG, "Invalid text effect: %s", effect.c_str()); } } else ESP_LOGW(TAG, "No text effect given"); diff --git a/esphome/components/max6921/display.h b/esphome/components/max6921/display.h index 0dcffb2c92..2c164115b8 100644 --- a/esphome/components/max6921/display.h +++ b/esphome/components/max6921/display.h @@ -118,7 +118,7 @@ class Display : public DisplayBrightness, public DisplayMode { int update_out_buf_(); private: - void init_font__(); + void init_font_(); }; } // namespace max6921 diff --git a/esphome/components/max6921/max6921.cpp b/esphome/components/max6921/max6921.cpp index d7e26700fa..7ef71885c0 100644 --- a/esphome/components/max6921/max6921.cpp +++ b/esphome/components/max6921/max6921.cpp @@ -28,8 +28,8 @@ void MAX6921Component::setup() { this->load_pin_->pin_mode(gpio::FLAG_OUTPUT); this->disable_load_(); // disable output latch - this->display_ = new Display(this); - this->display_->setup(this->seg_to_out_map__, this->pos_to_out_map__); + this->display_ = make_unique(this); + this->display_->setup(this->seg_to_out_map_, this->pos_to_out_map_); // 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) { diff --git a/esphome/components/max6921/max6921.h b/esphome/components/max6921/max6921.h index 305f12ae5b..0684560c5c 100644 --- a/esphome/components/max6921/max6921.h +++ b/esphome/components/max6921/max6921.h @@ -23,7 +23,7 @@ class MAX6921Component : public PollingComponent, public spi::SPIDevice { public: - Display *display_; + std::unique_ptr display_; void dump_config() override; float get_setup_priority() const override; uint8_t print(uint8_t pos, const char *str); @@ -31,8 +31,8 @@ class MAX6921Component : public PollingComponent, void set_blank_pin(InternalGPIOPin *pin) { blank_pin_ = pin; } void set_brightness(float brightness); void set_load_pin(GPIOPin *load) { this->load_pin_ = load; } - void set_seg_to_out_pin_map(const std::vector &pin_map) { this->seg_to_out_map__ = pin_map; } - void set_pos_to_out_pin_map(const std::vector &pin_map) { this->pos_to_out_map__ = pin_map; } + void set_seg_to_out_pin_map(const std::vector &pin_map) { this->seg_to_out_map_ = pin_map; } + void set_pos_to_out_pin_map(const std::vector &pin_map) { this->pos_to_out_map_ = pin_map; } void set_writer(max6921_writer_t &&writer); void setup() override; uint8_t strftime(uint8_t pos, const char *format, ESPTime time) __attribute__((format(strftime, 3, 0))); @@ -52,8 +52,8 @@ class MAX6921Component : public PollingComponent, optional writer_{}; private: - std::vector seg_to_out_map__; // mapping of display segments to MAX6921 OUT pins - std::vector pos_to_out_map__; // mapping of display positions to MAX6921 OUT pins + std::vector seg_to_out_map_; // mapping of display segments to MAX6921 OUT pins + std::vector pos_to_out_map_; // mapping of display positions to MAX6921 OUT pins }; } // namespace max6921