ESPHome 2026.5.1
Loading...
Searching...
No Matches
tm1638.h
Go to the documentation of this file.
1#pragma once
2
6#include "esphome/core/hal.h"
7#include "esphome/core/time.h"
9
10#include <vector>
11
12namespace esphome::tm1638 {
13
15 public:
16 virtual void keys_update(uint8_t keys){};
17};
18
19class TM1638Component;
20
22
24 public:
25 void set_writer(tm1638_writer_t &&writer) { this->writer_ = writer; }
26 void setup() override;
27 void dump_config() override;
28 void update() override;
29 float get_setup_priority() const override;
30 void set_intensity(uint8_t brightness_level);
31 void display();
32
33 void set_clk_pin(GPIOPin *pin) { this->clk_pin_ = pin; }
34 void set_dio_pin(GPIOPin *pin) { this->dio_pin_ = pin; }
35 void set_stb_pin(GPIOPin *pin) { this->stb_pin_ = pin; }
36
37 void register_listener(KeyListener *listener) { this->listeners_.push_back(listener); }
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 void loop() override;
50 uint8_t get_keys();
51
53 uint8_t strftime(uint8_t pos, const char *format, ESPTime time) __attribute__((format(strftime, 3, 0)));
55 uint8_t strftime(const char *format, ESPTime time) __attribute__((format(strftime, 2, 0)));
56
57 void set_led(int led_pos, bool led_on_off);
58
59 protected:
60 void set_7seg_(int seg_pos, uint8_t seg_bits);
61 void send_command_(uint8_t value);
62 void send_command_leave_open_(uint8_t value);
63 void send_commands_(uint8_t const commands[], uint8_t num_commands);
64 void send_command_sequence_(uint8_t commands[], uint8_t num_commands, uint8_t starting_address);
65 void shift_out_(uint8_t value);
66 void reset_();
67 uint8_t shift_in_();
68 uint8_t intensity_{};
72 uint8_t buffer_[8]{};
74 std::vector<KeyListener *> listeners_{};
75};
76
77} // namespace esphome::tm1638
This class simplifies creating components that periodically check a state.
Definition component.h:602
virtual void keys_update(uint8_t keys)
Definition tm1638.h:16
void set_7seg_(int seg_pos, uint8_t seg_bits)
Definition tm1638.cpp:122
float get_setup_priority() const override
Definition tm1638.cpp:90
std::vector< KeyListener * > listeners_
Definition tm1638.h:74
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 tm1638.cpp:213
GPIOPin * clk_pin_
brghtness of the display 0 through 7
Definition tm1638.h:69
void register_listener(KeyListener *listener)
Definition tm1638.h:37
void send_command_leave_open_(uint8_t value)
Definition tm1638.cpp:241
void set_stb_pin(GPIOPin *pin)
Definition tm1638.h:35
void set_clk_pin(GPIOPin *pin)
Definition tm1638.h:33
void send_command_sequence_(uint8_t commands[], uint8_t num_commands, uint8_t starting_address)
Definition tm1638.cpp:246
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 tm1638.cpp:192
void set_writer(tm1638_writer_t &&writer)
Definition tm1638.h:25
void set_intensity(uint8_t brightness_level)
Definition tm1638.cpp:133
uint8_t uint8_t void set_led(int led_pos, bool led_on_off)
Definition tm1638.cpp:111
void set_dio_pin(GPIOPin *pin)
Definition tm1638.h:34
void send_commands_(uint8_t const commands[], uint8_t num_commands)
Definition tm1638.cpp:231
void shift_out_(uint8_t value)
Definition tm1638.cpp:271
void send_command_(uint8_t value)
Definition tm1638.cpp:224
struct @65::@66 __attribute__
Wake the main loop task from an ISR. ISR-safe.
Definition main_task.h:32
const char int const __FlashStringHelper * format
Definition log.h:74
size_t size_t pos
Definition helpers.h:1038
A more user-friendly version of struct tm from time.h.
Definition time.h:23
std::string print()