10 static const char *
const TAG =
"display.tm1638";
11 static const uint8_t TM1638_REGISTER_FIXEDADDRESS = 0x44;
12 static const uint8_t TM1638_REGISTER_AUTOADDRESS = 0x40;
13 static const uint8_t TM1638_REGISTER_READBUTTONS = 0x42;
14 static const uint8_t TM1638_REGISTER_DISPLAYOFF = 0x80;
15 static const uint8_t TM1638_REGISTER_DISPLAYON = 0x88;
16 static const uint8_t TM1638_REGISTER_7SEG_0 = 0xC0;
17 static const uint8_t TM1638_REGISTER_LED_0 = 0xC1;
18 static const uint8_t TM1638_UNKNOWN_CHAR = 0b11111111;
20 static const uint8_t TM1638_SHIFT_DELAY = 4;
23 ESP_LOGD(TAG,
"Setting up TM1638...");
41 for (uint8_t i = 0; i < 8; i++)
46 ESP_LOGCONFIG(TAG,
"TM1638:");
47 ESP_LOGCONFIG(TAG,
" Intensity: %u", this->
intensity_);
48 LOG_PIN(
" CLK Pin: ", this->
clk_pin_);
49 LOG_PIN(
" DIO Pin: ", this->
dio_pin_);
50 LOG_PIN(
" STB Pin: ", this->
stb_pin_);
51 LOG_UPDATE_INTERVAL(
this);
60 listener->keys_update(keys);
74 for (uint8_t i = 0; i < 4; i++) {
97 for (uint8_t i = 0; i < 8; i++) {
103 uint8_t num_commands = 16;
104 uint8_t commands[num_commands];
106 for (uint8_t i = 0; i < num_commands; i++) {
120 commands[0] = TM1638_REGISTER_LED_0 + (led_pos << 1);
121 commands[1] = led_on_off;
129 uint8_t commands[2] = {};
131 commands[0] = TM1638_REGISTER_7SEG_0 + (seg_pos << 1);
132 commands[1] = seg_bits;
142 if (brightness_level > 0) {
152 uint8_t pos = start_pos;
154 bool last_was_dot =
false;
156 for (; *str !=
'\0'; str++) {
157 uint8_t data = TM1638_UNKNOWN_CHAR;
159 if (*str >=
' ' && *str <=
'~') {
161 }
else if (data == TM1638_UNKNOWN_CHAR) {
162 ESP_LOGW(TAG,
"Encountered character '%c' with no TM1638 representation while translating string!", *str);
167 if (pos != start_pos &&
172 this->
buffer_[pos] |= 0b10000000;
177 ESP_LOGI(TAG,
"TM1638 String is too long for the display!");
181 last_was_dot =
false;
186 return pos - start_pos;
195 va_start(arg, format);
197 int ret = vsnprintf(buffer,
sizeof(buffer), format, arg);
200 return this->
print(pos, buffer);
205 va_start(arg, format);
207 int ret = vsnprintf(buffer,
sizeof(buffer), format, arg);
210 return this->
print(buffer);
216 size_t ret = time.
strftime(buffer,
sizeof(buffer), format);
218 return this->
print(pos, buffer);
235 for (uint8_t i = 0; i < num_commands; i++) {
236 uint8_t command = commands[i];
251 for (uint8_t i = 0; i < num_commands; i++) {
261 for (
int i = 0; i < 8; ++i) {
273 for (
int i = 0; i < 8; i++) {
virtual void digital_write(bool value)=0
GPIOPin * clk_pin_
brghtness of the display 0 through 7
size_t strftime(char *buffer, size_t buffer_len, const char *format)
Convert this ESPTime struct to a null-terminated c string buffer as specified by the format argument...
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.
A more user-friendly version of struct tm from time.h.
void send_command_(uint8_t value)
virtual void pin_mode(gpio::Flags flags)=0
uint8_t uint8_t void set_led(int led_pos, bool led_on_off)
optional< tm1638_writer_t > writer_
uint8_t printf(uint8_t pos, const char *format,...) __attribute__((format(printf
Evaluate the printf-format and print the result at the given position.
void send_command_leave_open_(uint8_t value)
const float PROCESSOR
For components that use data from sensors like displays.
void send_command_sequence_(uint8_t commands[], uint8_t num_commands, uint8_t starting_address)
uint8_t uint8_t uint8_t print(uint8_t pos, const char *str)
Print str at the given position.
virtual bool digital_read()=0
void dump_config() override
uint8_t progmem_read_byte(const uint8_t *addr)
std::vector< KeyListener * > listeners_
Implementation of SPI Controller mode.
void send_commands_(uint8_t const commands[], uint8_t num_commands)
void IRAM_ATTR HOT delayMicroseconds(uint32_t us)
float get_setup_priority() const override
void set_intensity(uint8_t brightness_level)
void shift_out_(uint8_t value)
void set_7seg_(int seg_pos, uint8_t seg_bits)