ESPHome  2023.5.5
max7219digit.h
Go to the documentation of this file.
1 #pragma once
2 
4 #include "esphome/core/defines.h"
7 
8 #include <vector>
9 
10 #ifdef USE_TIME
12 #endif
13 
14 namespace esphome {
15 namespace max7219digit {
16 
18  ZIGZAG = 0,
20 };
21 
22 enum ScrollMode {
25 };
26 
27 class MAX7219Component;
28 
29 using max7219_writer_t = std::function<void(MAX7219Component &)>;
30 
33  public spi::SPIDevice<spi::BIT_ORDER_MSB_FIRST, spi::CLOCK_POLARITY_LOW,
34  spi::CLOCK_PHASE_LEADING, spi::DATA_RATE_1MHZ> {
35  public:
36  void set_writer(max7219_writer_t &&writer) { this->writer_local_ = writer; };
37 
38  void setup() override;
39 
40  void loop() override;
41 
42  void dump_config() override;
43 
44  void update() override;
45 
46  float get_setup_priority() const override;
47 
48  void display();
49 
50  void invert_on_off(bool on_off);
51  void invert_on_off();
52 
53  void turn_on_off(bool on_off);
54 
55  void draw_absolute_pixel_internal(int x, int y, Color color) override;
56  int get_height_internal() override;
57  int get_width_internal() override;
58 
59  void set_intensity(uint8_t intensity) { this->intensity_ = intensity; };
60  void set_num_chips(uint8_t num_chips) { this->num_chips_ = num_chips; };
61  void set_num_chip_lines(uint8_t num_chip_lines) { this->num_chip_lines_ = num_chip_lines; };
62  void set_chip_lines_style(ChipLinesStyle chip_lines_style) { this->chip_lines_style_ = chip_lines_style; };
63  void set_chip_orientation(uint8_t rotate) { this->orientation_ = rotate; };
64  void set_scroll_speed(uint16_t speed) { this->scroll_speed_ = speed; };
65  void set_scroll_dwell(uint16_t dwell) { this->scroll_dwell_ = dwell; };
66  void set_scroll_delay(uint16_t delay) { this->scroll_delay_ = delay; };
67  void set_scroll(bool on_off) { this->scroll_ = on_off; };
69  void set_reverse(bool on_off) { this->reverse_ = on_off; };
70  void set_flip_x(bool flip_x) { this->flip_x_ = flip_x; };
71 
72  void send_char(uint8_t chip, uint8_t data);
73  void send64pixels(uint8_t chip, const uint8_t pixels[8]);
74 
75  void scroll_left();
76  void scroll(bool on_off, ScrollMode mode, uint16_t speed, uint16_t delay, uint16_t dwell);
77  void scroll(bool on_off, ScrollMode mode);
78  void scroll(bool on_off);
79  void intensity(uint8_t intensity);
80 
82  uint8_t printdigitf(uint8_t pos, const char *format, ...) __attribute__((format(printf, 3, 4)));
84  uint8_t printdigitf(const char *format, ...) __attribute__((format(printf, 2, 3)));
85 
87  uint8_t printdigit(uint8_t pos, const char *str);
89  uint8_t printdigit(const char *str);
90 
91 #ifdef USE_TIME
92  uint8_t strftimedigit(uint8_t pos, const char *format, time::ESPTime time) __attribute__((format(strftime, 3, 0)));
94 
96  uint8_t strftimedigit(const char *format, time::ESPTime time) __attribute__((format(strftime, 2, 0)));
97 #endif
98 
100 
101  protected:
102  void send_byte_(uint8_t a_register, uint8_t data);
103  void send_to_all_(uint8_t a_register, uint8_t data);
104  uint8_t orientation_180_();
105 
106  uint8_t intensity_;
107  uint8_t num_chips_;
110  bool scroll_;
111  bool reverse_;
112  bool flip_x_;
113  bool update_{false};
114  uint16_t scroll_speed_;
115  uint16_t scroll_delay_;
116  uint16_t scroll_dwell_;
117  uint16_t old_buffer_size_ = 0;
119  bool invert_ = false;
120  uint8_t orientation_;
121  uint8_t bckgrnd_ = 0x0;
122  std::vector<std::vector<uint8_t>> max_displaybuffer_;
123  uint32_t last_scroll_ = 0;
124  uint16_t stepsleft_;
125  size_t get_buffer_length_();
127 };
128 
129 } // namespace max7219digit
130 } // namespace esphome
void printf(int x, int y, Font *font, Color color, TextAlign align, const char *format,...) __attribute__((format(printf
Evaluate the printf-format format and print the result with the anchor point at [x,y] with font.
void void void void void strftime(int x, int y, Font *font, Color color, TextAlign align, const char *format, time::ESPTime time) __attribute__((format(strftime
Evaluate the strftime-format format and print the result with the anchor point at [x...
void set_writer(max7219_writer_t &&writer)
Definition: max7219digit.h:36
void draw_absolute_pixel_internal(int x, int y, Color color) override
void set_chip_lines_style(ChipLinesStyle chip_lines_style)
Definition: max7219digit.h:62
void send64pixels(uint8_t chip, const uint8_t pixels[8])
void send_to_all_(uint8_t a_register, uint8_t data)
int speed
Definition: fan.h:35
optional< max7219_writer_t > writer_local_
Definition: max7219digit.h:126
This class simplifies creating components that periodically check a state.
Definition: component.h:282
void set_scroll_mode(ScrollMode mode)
Definition: max7219digit.h:68
void send_char(uint8_t chip, uint8_t data)
void set_num_chip_lines(uint8_t num_chip_lines)
Definition: max7219digit.h:61
std::vector< std::vector< uint8_t > > max_displaybuffer_
Definition: max7219digit.h:122
A more user-friendly version of struct tm from time.h.
void set_num_chips(uint8_t num_chips)
Definition: max7219digit.h:60
BedjetMode mode
BedJet operating mode.
Definition: bedjet_codec.h:151
float get_setup_priority() const override
uint8_t strftimedigit(uint8_t pos, const char *format, time::ESPTime time) __attribute__((format(strftime
Evaluate the strftime-format and print the result at the given position.
std::function< void(MAX7219Component &)> max7219_writer_t
Definition: max7219digit.h:29
uint8_t uint8_t uint8_t printdigit(uint8_t pos, const char *str)
Print str at the given position.
void scroll(bool on_off, ScrollMode mode, uint16_t speed, uint16_t delay, uint16_t dwell)
enum esphome::EntityCategory __attribute__
uint8_t num_chips_
Intensity of the display from 0 to 15 (most)
Definition: max7219digit.h:107
uint8_t printdigitf(uint8_t pos, const char *format,...) __attribute__((format(printf
Evaluate the printf-format and print the result at the given position.
void send_byte_(uint8_t a_register, uint8_t data)
void set_chip_orientation(uint8_t rotate)
Definition: max7219digit.h:63
void set_intensity(uint8_t intensity)
Definition: max7219digit.h:59
uint8_t uint8_t display::DisplayType get_display_type() override
Definition: max7219digit.h:99
Definition: a4988.cpp:4
void IRAM_ATTR HOT delay(uint32_t ms)
Definition: core.cpp:28