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
This commit is contained in:
Raph 2023-03-15 23:23:01 +01:00 committed by GitHub
parent dfc7cd7f5d
commit a31fb3c987
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 15 additions and 2 deletions

View file

@ -7,6 +7,7 @@ CODEOWNERS = ["@rspaargaren"]
DEPENDENCIES = ["spi"] DEPENDENCIES = ["spi"]
CONF_ROTATE_CHIP = "rotate_chip" CONF_ROTATE_CHIP = "rotate_chip"
CONF_FLIP_X = "flip_x"
CONF_SCROLL_SPEED = "scroll_speed" CONF_SCROLL_SPEED = "scroll_speed"
CONF_SCROLL_DWELL = "scroll_dwell" CONF_SCROLL_DWELL = "scroll_dwell"
CONF_SCROLL_DELAY = "scroll_delay" CONF_SCROLL_DELAY = "scroll_delay"
@ -67,6 +68,7 @@ CONFIG_SCHEMA = (
CONF_SCROLL_DWELL, default="1000ms" CONF_SCROLL_DWELL, default="1000ms"
): cv.positive_time_period_milliseconds, ): cv.positive_time_period_milliseconds,
cv.Optional(CONF_REVERSE_ENABLE, default=False): cv.boolean, cv.Optional(CONF_REVERSE_ENABLE, default=False): cv.boolean,
cv.Optional(CONF_FLIP_X, default=False): cv.boolean,
} }
) )
.extend(cv.polling_component_schema("500ms")) .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(config[CONF_SCROLL_ENABLE]))
cg.add(var.set_scroll_mode(config[CONF_SCROLL_MODE])) cg.add(var.set_scroll_mode(config[CONF_SCROLL_MODE]))
cg.add(var.set_reverse(config[CONF_REVERSE_ENABLE])) cg.add(var.set_reverse(config[CONF_REVERSE_ENABLE]))
cg.add(var.set_flip_x([CONF_FLIP_X]))
if CONF_LAMBDA in config: if CONF_LAMBDA in config:
lambda_ = await cg.process_lambda( lambda_ = await cg.process_lambda(

View file

@ -261,14 +261,22 @@ void MAX7219Component::send64pixels(uint8_t chip, const uint8_t pixels[8]) {
if (this->orientation_ == 0) { if (this->orientation_ == 0) {
for (uint8_t i = 0; i < 8; i++) { for (uint8_t i = 0; i < 8; i++) {
// run this loop 8 times for all the pixels[8] received // run this loop 8 times for all the pixels[8] received
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 b |= ((pixels[i] >> col) & 1) << (7 - i); // change the column bits into row bits
} }
}
} else if (this->orientation_ == 1) { } else if (this->orientation_ == 1) {
b = pixels[col]; b = pixels[col];
} else if (this->orientation_ == 2) { } else if (this->orientation_ == 2) {
for (uint8_t i = 0; i < 8; i++) { for (uint8_t i = 0; i < 8; i++) {
if (this->flip_x_) {
b |= ((pixels[i] >> (7 - col)) & 1) << (7 - i);
} else {
b |= ((pixels[i] >> (7 - col)) & 1) << i; b |= ((pixels[i] >> (7 - col)) & 1) << i;
} }
}
} else { } else {
b = pixels[7 - col]; b = pixels[7 - col];
} }

View file

@ -67,6 +67,7 @@ class MAX7219Component : public PollingComponent,
void set_scroll(bool on_off) { this->scroll_ = on_off; }; void set_scroll(bool on_off) { this->scroll_ = on_off; };
void set_scroll_mode(ScrollMode mode) { this->scroll_mode_ = mode; }; void set_scroll_mode(ScrollMode mode) { this->scroll_mode_ = mode; };
void set_reverse(bool on_off) { this->reverse_ = on_off; }; 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 send_char(uint8_t chip, uint8_t data);
void send64pixels(uint8_t chip, const uint8_t pixels[8]); void send64pixels(uint8_t chip, const uint8_t pixels[8]);
@ -108,6 +109,7 @@ class MAX7219Component : public PollingComponent,
ChipLinesStyle chip_lines_style_; ChipLinesStyle chip_lines_style_;
bool scroll_; bool scroll_;
bool reverse_; bool reverse_;
bool flip_x_;
bool update_{false}; bool update_{false};
uint16_t scroll_speed_; uint16_t scroll_speed_;
uint16_t scroll_delay_; uint16_t scroll_delay_;