mirror of
https://github.com/esphome/esphome.git
synced 2024-12-22 13:34:54 +01:00
Add reverse_enable for max7219 (#1489)
This commit is contained in:
parent
c92c439d17
commit
acc1af0f51
3 changed files with 11 additions and 3 deletions
|
@ -9,11 +9,14 @@ max7219_ns = cg.esphome_ns.namespace('max7219')
|
||||||
MAX7219Component = max7219_ns.class_('MAX7219Component', cg.PollingComponent, spi.SPIDevice)
|
MAX7219Component = max7219_ns.class_('MAX7219Component', cg.PollingComponent, spi.SPIDevice)
|
||||||
MAX7219ComponentRef = MAX7219Component.operator('ref')
|
MAX7219ComponentRef = MAX7219Component.operator('ref')
|
||||||
|
|
||||||
|
CONF_REVERSE_ENABLE = 'reverse_enable'
|
||||||
|
|
||||||
CONFIG_SCHEMA = display.BASIC_DISPLAY_SCHEMA.extend({
|
CONFIG_SCHEMA = display.BASIC_DISPLAY_SCHEMA.extend({
|
||||||
cv.GenerateID(): cv.declare_id(MAX7219Component),
|
cv.GenerateID(): cv.declare_id(MAX7219Component),
|
||||||
|
|
||||||
cv.Optional(CONF_NUM_CHIPS, default=1): cv.int_range(min=1, max=255),
|
cv.Optional(CONF_NUM_CHIPS, default=1): cv.int_range(min=1, max=255),
|
||||||
cv.Optional(CONF_INTENSITY, default=15): cv.int_range(min=0, max=15),
|
cv.Optional(CONF_INTENSITY, default=15): cv.int_range(min=0, max=15),
|
||||||
|
cv.Optional(CONF_REVERSE_ENABLE, default=False): cv.boolean,
|
||||||
}).extend(cv.polling_component_schema('1s')).extend(spi.spi_device_schema())
|
}).extend(cv.polling_component_schema('1s')).extend(spi.spi_device_schema())
|
||||||
|
|
||||||
|
|
||||||
|
@ -25,6 +28,7 @@ def to_code(config):
|
||||||
|
|
||||||
cg.add(var.set_num_chips(config[CONF_NUM_CHIPS]))
|
cg.add(var.set_num_chips(config[CONF_NUM_CHIPS]))
|
||||||
cg.add(var.set_intensity(config[CONF_INTENSITY]))
|
cg.add(var.set_intensity(config[CONF_INTENSITY]))
|
||||||
|
cg.add(var.set_reverse(config[CONF_REVERSE_ENABLE]))
|
||||||
|
|
||||||
if CONF_LAMBDA in config:
|
if CONF_LAMBDA in config:
|
||||||
lambda_ = yield cg.process_lambda(config[CONF_LAMBDA], [(MAX7219ComponentRef, 'it')],
|
lambda_ = yield cg.process_lambda(config[CONF_LAMBDA], [(MAX7219ComponentRef, 'it')],
|
||||||
|
|
|
@ -142,9 +142,11 @@ void MAX7219Component::dump_config() {
|
||||||
void MAX7219Component::display() {
|
void MAX7219Component::display() {
|
||||||
for (uint8_t i = 0; i < 8; i++) {
|
for (uint8_t i = 0; i < 8; i++) {
|
||||||
this->enable();
|
this->enable();
|
||||||
for (uint8_t j = 0; j < this->num_chips_; j++) {
|
for (uint8_t j = 0; j < this->num_chips_; j++)
|
||||||
this->send_byte_(8 - i, this->buffer_[j * 8 + i]);
|
if (reverse_)
|
||||||
}
|
this->send_byte_(8 - i, buffer_[(num_chips_ - j - 1) * 8 + i]);
|
||||||
|
else
|
||||||
|
this->send_byte_(8 - i, buffer_[j * 8 + i]);
|
||||||
this->disable();
|
this->disable();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,6 +34,7 @@ class MAX7219Component : public PollingComponent,
|
||||||
|
|
||||||
void set_intensity(uint8_t intensity);
|
void set_intensity(uint8_t intensity);
|
||||||
void set_num_chips(uint8_t num_chips);
|
void set_num_chips(uint8_t num_chips);
|
||||||
|
void set_reverse(bool reverse) { this->reverse_ = reverse; };
|
||||||
|
|
||||||
/// Evaluate the printf-format and print the result at the given position.
|
/// Evaluate the printf-format and print the result at the given position.
|
||||||
uint8_t printf(uint8_t pos, const char *format, ...) __attribute__((format(printf, 3, 4)));
|
uint8_t printf(uint8_t pos, const char *format, ...) __attribute__((format(printf, 3, 4)));
|
||||||
|
@ -60,6 +61,7 @@ class MAX7219Component : public PollingComponent,
|
||||||
uint8_t intensity_{15}; /// Intensity of the display from 0 to 15 (most)
|
uint8_t intensity_{15}; /// Intensity of the display from 0 to 15 (most)
|
||||||
uint8_t num_chips_{1};
|
uint8_t num_chips_{1};
|
||||||
uint8_t *buffer_;
|
uint8_t *buffer_;
|
||||||
|
bool reverse_{false};
|
||||||
optional<max7219_writer_t> writer_{};
|
optional<max7219_writer_t> writer_{};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue