ESPHome  2023.5.5
max7219.h
Go to the documentation of this file.
1 #pragma once
2 
4 #include "esphome/core/defines.h"
5 
6 #ifdef USE_TIME
8 #endif
9 
11 
12 namespace esphome {
13 namespace max7219 {
14 
15 class MAX7219Component;
16 
17 using max7219_writer_t = std::function<void(MAX7219Component &)>;
18 
20  public spi::SPIDevice<spi::BIT_ORDER_MSB_FIRST, spi::CLOCK_POLARITY_LOW,
21  spi::CLOCK_PHASE_LEADING, spi::DATA_RATE_1MHZ> {
22  public:
23  void set_writer(max7219_writer_t &&writer);
24 
25  void setup() override;
26 
27  void dump_config() override;
28 
29  void update() override;
30 
31  float get_setup_priority() const override;
32 
33  void display();
34 
35  void set_intensity(uint8_t intensity);
36  void set_num_chips(uint8_t num_chips);
37  void set_reverse(bool reverse) { this->reverse_ = reverse; };
38 
40  uint8_t printf(uint8_t pos, const char *format, ...) __attribute__((format(printf, 3, 4)));
42  uint8_t printf(const char *format, ...) __attribute__((format(printf, 2, 3)));
43 
45  uint8_t print(uint8_t pos, const char *str);
47  uint8_t print(const char *str);
48 
49 #ifdef USE_TIME
50  uint8_t strftime(uint8_t pos, const char *format, time::ESPTime time) __attribute__((format(strftime, 3, 0)));
52 
54  uint8_t strftime(const char *format, time::ESPTime time) __attribute__((format(strftime, 2, 0)));
55 #endif
56 
57  protected:
58  void send_byte_(uint8_t a_register, uint8_t data);
59  void send_to_all_(uint8_t a_register, uint8_t data);
60 
61  uint8_t intensity_{15};
62  uint8_t num_chips_{1};
63  uint8_t *buffer_;
64  bool reverse_{false};
66 };
67 
68 } // namespace max7219
69 } // 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:173
uint8_t strftime(uint8_t pos, const char *format, time::ESPTime time) __attribute__((format(strftime
Evaluate the strftime-format and print the result at the given position.
Definition: max7219.cpp:227
void set_intensity(uint8_t intensity)
Definition: max7219.cpp:220
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:282
void set_reverse(bool reverse)
Definition: max7219.h:37
A more user-friendly version of struct tm from time.h.
uint8_t num_chips_
Intensity of the display from 0 to 15 (most)
Definition: max7219.h:62
optional< max7219_writer_t > writer_
Definition: max7219.h:65
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:199
std::function< void(MAX7219Component &)> max7219_writer_t
Definition: max7219.h:17
float get_setup_priority() const override
Definition: max7219.cpp:117
void set_writer(max7219_writer_t &&writer)
Definition: max7219.cpp:219
Definition: a4988.cpp:4
void set_num_chips(uint8_t num_chips)
Definition: max7219.cpp:224