ESPHome  2024.11.2
max7219.h
Go to the documentation of this file.
1 #pragma once
2 
4 #include "esphome/core/time.h"
5 
7 
8 namespace esphome {
9 namespace max7219 {
10 
11 class MAX7219Component;
12 
13 using max7219_writer_t = std::function<void(MAX7219Component &)>;
14 
16  public spi::SPIDevice<spi::BIT_ORDER_MSB_FIRST, spi::CLOCK_POLARITY_LOW,
17  spi::CLOCK_PHASE_LEADING, spi::DATA_RATE_1MHZ> {
18  public:
19  void set_writer(max7219_writer_t &&writer);
20 
21  void setup() override;
22 
23  void dump_config() override;
24 
25  void update() override;
26 
27  float get_setup_priority() const override;
28 
29  void display();
30 
31  void set_intensity(uint8_t intensity);
32  void set_num_chips(uint8_t num_chips);
33  void set_reverse(bool reverse) { this->reverse_ = reverse; };
34 
36  uint8_t printf(uint8_t pos, const char *format, ...) __attribute__((format(printf, 3, 4)));
38  uint8_t printf(const char *format, ...) __attribute__((format(printf, 2, 3)));
39 
41  uint8_t print(uint8_t pos, const char *str);
43  uint8_t print(const char *str);
44 
46  uint8_t strftime(uint8_t pos, const char *format, ESPTime time) __attribute__((format(strftime, 3, 0)));
47 
49  uint8_t strftime(const char *format, ESPTime time) __attribute__((format(strftime, 2, 0)));
50 
51  protected:
52  void send_byte_(uint8_t a_register, uint8_t data);
53  void send_to_all_(uint8_t a_register, uint8_t data);
54 
55  uint8_t intensity_{15}; // Intensity of the display from 0 to 15 (most)
56  bool intensity_changed_{}; // True if we need to re-send the intensity
57  uint8_t num_chips_{1};
58  uint8_t *buffer_;
59  bool reverse_{false};
61 };
62 
63 } // namespace max7219
64 } // namespace esphome
void send_to_all_(uint8_t a_register, uint8_t data)
Definition: max7219.cpp:160
uint8_t uint8_t uint8_t print(uint8_t pos, const char *str)
Print str at the given position.
Definition: max7219.cpp:177
A more user-friendly version of struct tm from time.h.
Definition: time.h:17
void set_intensity(uint8_t intensity)
Definition: max7219.cpp:224
void send_byte_(uint8_t a_register, uint8_t data)
Definition: max7219.cpp:156
This class simplifies creating components that periodically check a state.
Definition: component.h:283
void set_reverse(bool reverse)
Definition: max7219.h:33
The SPIDevice is what components using the SPI will create.
Definition: spi.h:391
optional< max7219_writer_t > writer_
Definition: max7219.h:60
enum esphome::EntityCategory __attribute__
uint8_t printf(uint8_t pos, const char *format,...) __attribute__((format(printf
Evaluate the printf-format and print the result at the given position.
Definition: max7219.cpp:203
uint8_t strftime(uint8_t pos, const char *format, ESPTime time) __attribute__((format(strftime
Evaluate the strftime-format and print the result at the given position.
Definition: max7219.cpp:233
std::function< void(MAX7219Component &)> max7219_writer_t
Definition: max7219.h:13
float get_setup_priority() const override
Definition: max7219.cpp:117
void set_writer(max7219_writer_t &&writer)
Definition: max7219.cpp:223
Implementation of SPI Controller mode.
Definition: a01nyub.cpp:7
void set_num_chips(uint8_t num_chips)
Definition: max7219.cpp:231