2024-01-12 22:49:50 +01:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "esphome/core/component.h"
|
|
|
|
#include "esphome/core/time.h"
|
|
|
|
|
|
|
|
#include "esphome/components/spi/spi.h"
|
|
|
|
|
|
|
|
namespace esphome {
|
|
|
|
namespace spi_74hc595_display {
|
|
|
|
|
|
|
|
class SPI_74HC595_DISPLAYComponent;
|
|
|
|
|
|
|
|
using spi_74hc595_display_writer_t = std::function<void(SPI_74HC595_DISPLAYComponent &)>;
|
|
|
|
|
|
|
|
class SPI_74HC595_DISPLAYComponent : public PollingComponent,
|
|
|
|
public spi::SPIDevice<spi::BIT_ORDER_MSB_FIRST, spi::CLOCK_POLARITY_LOW,
|
2024-01-20 02:24:56 +01:00
|
|
|
spi::CLOCK_PHASE_LEADING, spi::DATA_RATE_10MHZ> {
|
2024-01-12 22:49:50 +01:00
|
|
|
public:
|
|
|
|
void set_writer(spi_74hc595_display_writer_t &&writer);
|
|
|
|
|
|
|
|
void setup() override;
|
|
|
|
|
|
|
|
void dump_config() override;
|
|
|
|
|
|
|
|
void update() override;
|
|
|
|
|
|
|
|
float get_setup_priority() const override;
|
|
|
|
|
|
|
|
void display();
|
|
|
|
|
|
|
|
void set_num_chips(uint8_t num_chips);
|
|
|
|
void set_reverse(bool reverse) { this->reverse_ = reverse; };
|
2024-01-21 20:39:18 +01:00
|
|
|
void set_segment_first(bool segment_first) { this->segment_first_ = segment_first; };
|
|
|
|
void set_common_cathode(bool common_cathode) { this->common_cathode_ = common_cathode; };
|
2024-01-12 22:49:50 +01:00
|
|
|
|
|
|
|
/// 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)));
|
|
|
|
/// Evaluate the printf-format and print the result at position 0.
|
|
|
|
uint8_t printf(const char *format, ...) __attribute__((format(printf, 2, 3)));
|
|
|
|
|
|
|
|
/// Print `str` at the given position.
|
|
|
|
uint8_t print(uint8_t pos, const char *str);
|
|
|
|
/// Print `str` at position 0.
|
|
|
|
uint8_t print(const char *str);
|
|
|
|
|
|
|
|
/// Evaluate the strftime-format and print the result at the given position.
|
|
|
|
uint8_t strftime(uint8_t pos, const char *format, ESPTime time) __attribute__((format(strftime, 3, 0)));
|
|
|
|
|
|
|
|
/// Evaluate the strftime-format and print the result at position 0.
|
|
|
|
uint8_t strftime(const char *format, ESPTime time) __attribute__((format(strftime, 2, 0)));
|
|
|
|
|
|
|
|
protected:
|
|
|
|
void send_byte_(uint8_t a_register, uint8_t data);
|
|
|
|
void send_to_all_(uint8_t a_register, uint8_t data);
|
|
|
|
|
|
|
|
uint8_t num_chips_{1};
|
|
|
|
uint8_t *buffer_;
|
|
|
|
bool reverse_{false};
|
2024-01-21 20:39:18 +01:00
|
|
|
bool segment_first_{false};
|
|
|
|
bool common_cathode_{false};
|
2024-01-12 22:49:50 +01:00
|
|
|
optional<spi_74hc595_display_writer_t> writer_{};
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace spi_74hc595_display
|
|
|
|
} // namespace esphome
|