ESPHome 2026.11.0b6
Loading...
Searching...
No Matches
ht16k33_char.h
Go to the documentation of this file.
1#pragma once
2
8#include "esphome/core/time.h"
9
10namespace esphome::ht16k33_char {
11
12class HT16K33CharDisplay;
14
16 public:
18 HT16K33CharDisplay(char *message, uint8_t capacity, uint8_t intensity)
19 : message_(message), capacity_(capacity), intensity_(intensity) {}
20
21 void setup() override;
22 void update() override;
23 void dump_config() override;
24 float get_setup_priority() const override { return setup_priority::PROCESSOR; }
25
26 void set_writer(ht16k33_char_writer_t &&writer) { this->writer_ = std::move(writer); }
28 void set_intensity(uint8_t intensity);
29#ifdef HT16K33_CHAR_SECONDARY_COUNT
31#endif
32#ifdef USE_HT16K33_CHAR_GLYPH_OVERRIDES
35 void set_glyph_overrides(const uint32_t *glyphs) { this->glyph_overrides_ = glyphs; }
36#endif
37
39 void clear() { this->length_ = 0; }
42 uint8_t print(uint8_t pos, const char *str);
43 uint8_t print(const char *str) { return this->print(0, str); }
44 uint8_t printf(uint8_t pos, const char *format, ...) __attribute__((format(printf, 3, 4)));
45 uint8_t printf(const char *format, ...) __attribute__((format(printf, 2, 3)));
46 uint8_t strftime(uint8_t pos, const char *format, ESPTime time) __attribute__((format(strftime, 3, 0)));
47 uint8_t strftime(const char *format, ESPTime time) __attribute__((format(strftime, 2, 0))) {
48 return this->strftime(0, format, time);
49 }
51 uint8_t clock_display(uint8_t pos, bool show_leading_zero, bool use_ampm, ESPTime time);
52
54 void set_blink(uint8_t blink);
56 void display_power(bool power_status);
58 void display_standby(bool standby);
60 void blank();
61
62 protected:
63 uint8_t chip_count_() const {
64#ifdef HT16K33_CHAR_SECONDARY_COUNT
65 return 1 + this->secondary_addresses_.size();
66#else
67 return 1;
68#endif
69 }
70 uint8_t chip_address_(uint8_t chip) const {
71#ifdef HT16K33_CHAR_SECONDARY_COUNT
72 if (chip > 0)
73 return this->secondary_addresses_[chip - 1];
74#endif
75 return this->address_;
76 }
77 // One call site, so a small f inlines
78 template<typename F> void for_each_chip_(F &&f) {
79 for (uint8_t chip = 0, count = this->chip_count_(); chip < count; chip++)
80 f(this->chip_address_(chip));
81 }
82 uint8_t system_setup_() const;
83 uint8_t display_setup_command_() const;
84 bool write_all_(uint8_t command);
86 void send_(uint8_t command);
88 bool write_frames_(uint8_t length);
89 uint8_t find_segments_(uint32_t codepoint) const;
90 uint8_t vprintf_(uint8_t pos, const char *format, va_list arg);
91
92 char *const message_;
93 const uint8_t capacity_;
94 uint8_t length_{0};
95 uint8_t intensity_;
97 uint8_t display_setup_{1};
99#ifdef HT16K33_CHAR_SECONDARY_COUNT
101#endif
102#ifdef USE_HT16K33_CHAR_GLYPH_OVERRIDES
103 const uint32_t *glyph_overrides_{nullptr};
104#endif
105};
106
107} // namespace esphome::ht16k33_char
This class simplifies creating components that periodically check a state.
Definition component.h:532
Minimal static vector - saves memory by avoiding std::vector overhead.
Definition helpers.h:304
size_t size() const
Definition helpers.h:373
void push_back(const T &value)
Definition helpers.h:343
void add_secondary_display(uint8_t address)
void set_intensity(uint8_t intensity)
0 (dimmest) to 15, clamped
uint8_t printf(uint8_t pos, const char *format,...) __attribute__((format(printf
void send_(uint8_t command)
Send a command to every chip once set up, and report the result.
uint8_t uint8_t uint8_t strftime(uint8_t pos, const char *format, ESPTime time) __attribute__((format(strftime
uint8_t display_setup_
Display setup register: on bit and blink rate; bit 7 remembers standby, which the register does not u...
void clear()
For printing from automations; the lambda starts from an empty message.
bool write_frames_(uint8_t length)
Draw the first length bytes of the message; the chips it does not reach are cleared.
void display_power(bool power_status)
Turn the display on or off.
float get_setup_priority() const override
StaticVector< uint8_t, HT16K33_CHAR_SECONDARY_COUNT > secondary_addresses_
void set_writer(ht16k33_char_writer_t &&writer)
void set_glyph_overrides(const uint32_t *glyphs)
add_characters entries, each a word with the code point in the low half and the segments in the high ...
HT16K33CharDisplay(char *message, uint8_t capacity, uint8_t intensity)
message holds capacity bytes of UTF-8 text; intensity is 0 (dimmest) to 15
uint8_t chip_address_(uint8_t chip) const
uint8_t vprintf_(uint8_t pos, const char *format, va_list arg)
void set_blink(uint8_t blink)
0 steady, 1 at 2 Hz, 2 at 1 Hz, 3 at 0.5 Hz; before setup only the value is kept
uint8_t find_segments_(uint32_t codepoint) const
void display_standby(bool standby)
Stop the oscillator, the lowest power state; before setup only the value is kept.
void blank()
Clear the display memory; the next update redraws the message.
uint8_t uint8_t uint8_t uint8_t uint8_t clock_display(uint8_t pos, bool show_leading_zero, bool use_ampm, ESPTime time)
HH:MM, or H:MM without the leading zero; 12-hour when use_ampm.
This Class provides the methods to read/write bytes from/to an i2c device.
Definition i2c.h:144
uint8_t address_
store the address of the device on the bus
Definition i2c.h:327
const LogString * message
Definition component.cpp:35
unsigned count
Definition gif.cpp:51
const char * format
constexpr float PROCESSOR
For components that use data from sensors like displays.
Definition component.h:47
size_t size_t pos
Definition helpers.h:1333
uint16_t uint16_t & capacity
Definition helpers.cpp:34
static void uint32_t
A more user-friendly version of struct tm from time.h.
Definition time.h:23
std::string print()