Compare commits
2 commits
37ff1a74f9
...
816d2cd74f
Author | SHA1 | Date | |
---|---|---|---|
|
816d2cd74f | ||
|
27e84dd666 |
4 changed files with 40 additions and 24 deletions
|
@ -11,15 +11,18 @@ SPI_74HC595_DISPLAYComponent = spi_74hc595_display_ns.class_(
|
||||||
)
|
)
|
||||||
SPI_74HC595_DISPLAYComponentRef = SPI_74HC595_DISPLAYComponent.operator("ref")
|
SPI_74HC595_DISPLAYComponentRef = SPI_74HC595_DISPLAYComponent.operator("ref")
|
||||||
|
|
||||||
CONF_REVERSE_ENABLE = "reverse_enable"
|
CONF_REVERSE = "reverse"
|
||||||
|
CONF_SEGMENT_FIRST = "segment_first"
|
||||||
|
CONF_COMMON_CATHODE = "common_cathode"
|
||||||
|
|
||||||
CONFIG_SCHEMA = (
|
CONFIG_SCHEMA = (
|
||||||
display.BASIC_DISPLAY_SCHEMA.extend(
|
display.BASIC_DISPLAY_SCHEMA.extend(
|
||||||
{
|
{
|
||||||
cv.GenerateID(): cv.declare_id(SPI_74HC595_DISPLAYComponent),
|
cv.GenerateID(): cv.declare_id(SPI_74HC595_DISPLAYComponent),
|
||||||
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_REVERSE, default=False): cv.boolean,
|
||||||
cv.Optional(CONF_REVERSE_ENABLE, default=False): cv.boolean,
|
cv.Optional(CONF_SEGMENT_FIRST, default=False): cv.boolean,
|
||||||
|
cv.Optional(CONF_COMMON_CATHODE, default=False): cv.boolean,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
.extend(cv.polling_component_schema("1s"))
|
.extend(cv.polling_component_schema("1s"))
|
||||||
|
@ -33,8 +36,9 @@ async def to_code(config):
|
||||||
await display.register_display(var, config)
|
await display.register_display(var, 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_reverse(config[CONF_REVERSE]))
|
||||||
cg.add(var.set_reverse(config[CONF_REVERSE_ENABLE]))
|
cg.add(var.set_segment_first(config[CONF_SEGMENT_FIRST]))
|
||||||
|
cg.add(var.set_common_cathode(config[CONF_COMMON_CATHODE]))
|
||||||
|
|
||||||
if CONF_LAMBDA in config:
|
if CONF_LAMBDA in config:
|
||||||
lambda_ = await cg.process_lambda(
|
lambda_ = await cg.process_lambda(
|
||||||
|
|
|
@ -128,13 +128,15 @@ void SPI_74HC595_DISPLAYComponent::dump_config() {
|
||||||
|
|
||||||
void SPI_74HC595_DISPLAYComponent::display() {
|
void SPI_74HC595_DISPLAYComponent::display() {
|
||||||
uint32_t delay = static_cast<uint64_t>(this->get_update_interval())*1000 / 8;
|
uint32_t delay = static_cast<uint64_t>(this->get_update_interval())*1000 / 8;
|
||||||
|
uint8_t flip_digit=(this->common_cathode_)?0xFF:0x00;
|
||||||
|
uint8_t flip_segment = ~flip_digit;
|
||||||
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++) {
|
||||||
if (reverse_) {
|
if (reverse_) {
|
||||||
this->send_byte_(~(1U << i), buffer_[(num_chips_ - j - 1) * 8 + i]);
|
this->send_byte_((1U << i)^flip_digit, buffer_[(num_chips_ - j - 1) * 8 + i]^flip_segment);
|
||||||
} else {
|
} else {
|
||||||
this->send_byte_(~(1U << i), buffer_[j * 8 + i]);
|
this->send_byte_((1U << i)^flip_digit, (buffer_[j * 8 + i])^flip_segment);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this->disable();
|
this->disable();
|
||||||
|
@ -143,18 +145,19 @@ void SPI_74HC595_DISPLAYComponent::display() {
|
||||||
// zero out everything to have a somewhat uniform duty cycle for all digits
|
// zero out everything to have a somewhat uniform duty cycle for all digits
|
||||||
this->enable();
|
this->enable();
|
||||||
for (uint8_t j = 0; j < this->num_chips_; j++) {
|
for (uint8_t j = 0; j < this->num_chips_; j++) {
|
||||||
if (reverse_) {
|
this->send_byte_(0, 0);
|
||||||
this->send_byte_(0, 0);
|
|
||||||
} else {
|
|
||||||
this->send_byte_(0, 0);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
this->disable();
|
this->disable();
|
||||||
}
|
}
|
||||||
|
|
||||||
void SPI_74HC595_DISPLAYComponent::send_byte_(uint8_t a_register, uint8_t data) {
|
void SPI_74HC595_DISPLAYComponent::send_byte_(uint8_t a_digit, uint8_t data) {
|
||||||
this->write_byte(a_register);
|
if(this->segment_first_){
|
||||||
this->write_byte(data);
|
this->write_byte(data);
|
||||||
|
this->write_byte(a_digit);
|
||||||
|
} else {
|
||||||
|
this->write_byte(a_digit);
|
||||||
|
this->write_byte(data);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SPI_74HC595_DISPLAYComponent::update() {
|
void SPI_74HC595_DISPLAYComponent::update() {
|
||||||
|
|
|
@ -30,6 +30,8 @@ class SPI_74HC595_DISPLAYComponent : public PollingComponent,
|
||||||
|
|
||||||
void set_num_chips(uint8_t num_chips);
|
void set_num_chips(uint8_t num_chips);
|
||||||
void set_reverse(bool reverse) { this->reverse_ = reverse; };
|
void set_reverse(bool reverse) { this->reverse_ = reverse; };
|
||||||
|
void set_segment_first(bool segment_first) { this->segment_first_ = segment_first; };
|
||||||
|
void set_common_cathode(bool common_cathode) { this->common_cathode_ = common_cathode; };
|
||||||
|
|
||||||
/// 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)));
|
||||||
|
@ -54,6 +56,8 @@ class SPI_74HC595_DISPLAYComponent : public PollingComponent,
|
||||||
uint8_t num_chips_{1};
|
uint8_t num_chips_{1};
|
||||||
uint8_t *buffer_;
|
uint8_t *buffer_;
|
||||||
bool reverse_{false};
|
bool reverse_{false};
|
||||||
|
bool segment_first_{false};
|
||||||
|
bool common_cathode_{false};
|
||||||
optional<spi_74hc595_display_writer_t> writer_{};
|
optional<spi_74hc595_display_writer_t> writer_{};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -68,9 +68,12 @@ sensor:
|
||||||
display:
|
display:
|
||||||
- platform: spi_74hc595_display
|
- platform: spi_74hc595_display
|
||||||
cs_pin: GPIO5
|
cs_pin: GPIO5
|
||||||
data_rate: 10MHz
|
data_rate: 1MHz #10MHz
|
||||||
num_chips: 3
|
num_chips: 1 #3
|
||||||
update_interval: 16ms
|
update_interval: 4s #16ms
|
||||||
|
common_cathode: false
|
||||||
|
segment_first: false
|
||||||
|
reverse: false
|
||||||
lambda: |-
|
lambda: |-
|
||||||
static uint32_t clock_frames=0;
|
static uint32_t clock_frames=0;
|
||||||
static uint32_t old_clock=0;
|
static uint32_t old_clock=0;
|
||||||
|
@ -82,20 +85,22 @@ display:
|
||||||
clock_frames++;
|
clock_frames++;
|
||||||
}
|
}
|
||||||
|
|
||||||
it.printf(0, ".*`,_+'-");
|
//it.printf(0, ".*`,_+'-");
|
||||||
/*it.strftime(0, "%H%M%s", id(sntp_time).now());*/
|
it.printf(0, "88888888");
|
||||||
/*it.printf(6, "%2d", clock_frames);*/
|
//it.strftime(0, "%H%M%s", id(sntp_time).now());
|
||||||
|
//it.printf(6, "%2d", clock_frames);
|
||||||
|
|
||||||
it.strftime(8, "%H%M%s", id(sntp_time).now());
|
//it.strftime(8, "%H%M%s", id(sntp_time).now());
|
||||||
it.printf(14, "%2d", clock_frames);
|
//it.printf(14, "%2d", clock_frames);
|
||||||
/*it.strftime(8, "%H%M%s", id(sntp_time).now());*/
|
/*it.strftime(8, "%H%M%s", id(sntp_time).now());*/
|
||||||
/*it.printf(14, "%1d", 0)*/
|
/*it.printf(14, "%1d", 0)*/
|
||||||
|
|
||||||
it.printf(16, "%2d%2d%2d%2d",
|
/*it.printf(16, "%02d%02d%02d%02d",
|
||||||
uint32_t(id(runtime).state/3600) - uint32_t(id(runtime).state/86400)*1440,
|
uint32_t(id(runtime).state/3600) - uint32_t(id(runtime).state/86400)*1440,
|
||||||
uint32_t(id(runtime).state/60) - uint32_t(id(runtime).state/3600)*60,
|
uint32_t(id(runtime).state/60) - uint32_t(id(runtime).state/3600)*60,
|
||||||
uint32_t(id(runtime).state) - uint32_t(id(runtime).state/60)*60,
|
uint32_t(id(runtime).state) - uint32_t(id(runtime).state/60)*60,
|
||||||
uint32_t((id(runtime).state - uint32_t(id(runtime).state))*25) );
|
uint32_t((id(runtime).state - uint32_t(id(runtime).state))*25) );
|
||||||
|
*/
|
||||||
|
|
||||||
# the first display should display a test string to figure out the digit and segment map:
|
# the first display should display a test string to figure out the digit and segment map:
|
||||||
# digit 0: >.< character (dot segment on)
|
# digit 0: >.< character (dot segment on)
|
||||||
|
|
Loading…
Reference in a new issue