From a31fb3c987b7011b7ccb7735f8210f2feaff1d90 Mon Sep 17 00:00:00 2001 From: Raph Date: Wed, 15 Mar 2023 23:23:01 +0100 Subject: [PATCH] Add option flip_x (#4555) * Adding flip_x * Adding flip_x * Adding flip_x * Adding flip_x * Adding flip_x * convert tab to space * update format --- esphome/components/max7219digit/display.py | 3 +++ esphome/components/max7219digit/max7219digit.cpp | 12 ++++++++++-- esphome/components/max7219digit/max7219digit.h | 2 ++ 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/esphome/components/max7219digit/display.py b/esphome/components/max7219digit/display.py index 2753f70eef..faa8a08f4a 100644 --- a/esphome/components/max7219digit/display.py +++ b/esphome/components/max7219digit/display.py @@ -7,6 +7,7 @@ CODEOWNERS = ["@rspaargaren"] DEPENDENCIES = ["spi"] CONF_ROTATE_CHIP = "rotate_chip" +CONF_FLIP_X = "flip_x" CONF_SCROLL_SPEED = "scroll_speed" CONF_SCROLL_DWELL = "scroll_dwell" CONF_SCROLL_DELAY = "scroll_delay" @@ -67,6 +68,7 @@ CONFIG_SCHEMA = ( CONF_SCROLL_DWELL, default="1000ms" ): cv.positive_time_period_milliseconds, cv.Optional(CONF_REVERSE_ENABLE, default=False): cv.boolean, + cv.Optional(CONF_FLIP_X, default=False): cv.boolean, } ) .extend(cv.polling_component_schema("500ms")) @@ -91,6 +93,7 @@ async def to_code(config): cg.add(var.set_scroll(config[CONF_SCROLL_ENABLE])) cg.add(var.set_scroll_mode(config[CONF_SCROLL_MODE])) cg.add(var.set_reverse(config[CONF_REVERSE_ENABLE])) + cg.add(var.set_flip_x([CONF_FLIP_X])) if CONF_LAMBDA in config: lambda_ = await cg.process_lambda( diff --git a/esphome/components/max7219digit/max7219digit.cpp b/esphome/components/max7219digit/max7219digit.cpp index 1b9ae230f7..c65b8e4823 100644 --- a/esphome/components/max7219digit/max7219digit.cpp +++ b/esphome/components/max7219digit/max7219digit.cpp @@ -261,13 +261,21 @@ void MAX7219Component::send64pixels(uint8_t chip, const uint8_t pixels[8]) { if (this->orientation_ == 0) { for (uint8_t i = 0; i < 8; i++) { // run this loop 8 times for all the pixels[8] received - b |= ((pixels[i] >> col) & 1) << (7 - i); // change the column bits into row bits + if (this->flip_x_) { + b |= ((pixels[i] >> col) & 1) << i; // change the column bits into row bits + } else { + b |= ((pixels[i] >> col) & 1) << (7 - i); // change the column bits into row bits + } } } else if (this->orientation_ == 1) { b = pixels[col]; } else if (this->orientation_ == 2) { for (uint8_t i = 0; i < 8; i++) { - b |= ((pixels[i] >> (7 - col)) & 1) << i; + if (this->flip_x_) { + b |= ((pixels[i] >> (7 - col)) & 1) << (7 - i); + } else { + b |= ((pixels[i] >> (7 - col)) & 1) << i; + } } } else { b = pixels[7 - col]; diff --git a/esphome/components/max7219digit/max7219digit.h b/esphome/components/max7219digit/max7219digit.h index 3619478697..17e369a9d9 100644 --- a/esphome/components/max7219digit/max7219digit.h +++ b/esphome/components/max7219digit/max7219digit.h @@ -67,6 +67,7 @@ class MAX7219Component : public PollingComponent, void set_scroll(bool on_off) { this->scroll_ = on_off; }; void set_scroll_mode(ScrollMode mode) { this->scroll_mode_ = mode; }; void set_reverse(bool on_off) { this->reverse_ = on_off; }; + void set_flip_x(bool flip_x) { this->flip_x_ = flip_x; }; void send_char(uint8_t chip, uint8_t data); void send64pixels(uint8_t chip, const uint8_t pixels[8]); @@ -108,6 +109,7 @@ class MAX7219Component : public PollingComponent, ChipLinesStyle chip_lines_style_; bool scroll_; bool reverse_; + bool flip_x_; bool update_{false}; uint16_t scroll_speed_; uint16_t scroll_delay_;