mirror of
https://github.com/esphome/esphome.git
synced 2024-12-22 21:44:55 +01:00
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:
parent
dfc7cd7f5d
commit
a31fb3c987
3 changed files with 15 additions and 2 deletions
|
@ -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(
|
||||
|
|
|
@ -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];
|
||||
|
|
|
@ -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_;
|
||||
|
|
Loading…
Reference in a new issue