ESPHome 2025.5.0
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"
8
9#include <vector>
10
11namespace esphome {
12namespace tm1638 {
13
15 public:
16 virtual void keys_update(uint8_t keys){};
17};
18
19class TM1638Component;
20
21using tm1638_writer_t = std::function<void(TM1638Component &)>;
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_ = new uint8_t[8];
74 std::vector<KeyListener *> listeners_{};
75};
76
77} // namespace tm1638
78} // namespace esphome
This class simplifies creating components that periodically check a state.
Definition component.h:301
virtual void keys_update(uint8_t keys)
Definition tm1638.h:16
optional< tm1638_writer_t > writer_
Definition tm1638.h:73
void set_7seg_(int seg_pos, uint8_t seg_bits)
Definition tm1638.cpp:126
float get_setup_priority() const override
Definition tm1638.cpp:94
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:214
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:242
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:247
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:193
void set_writer(tm1638_writer_t &&writer)
Definition tm1638.h:25
void set_intensity(uint8_t brightness_level)
Definition tm1638.cpp:137
uint8_t uint8_t void set_led(int led_pos, bool led_on_off)
Definition tm1638.cpp:115
void set_dio_pin(GPIOPin *pin)
Definition tm1638.h:34
void send_commands_(uint8_t const commands[], uint8_t num_commands)
Definition tm1638.cpp:232
void shift_out_(uint8_t value)
Definition tm1638.cpp:272
void send_command_(uint8_t value)
Definition tm1638.cpp:225
struct @67::@68 __attribute__
std::function< void(TM1638Component &)> tm1638_writer_t
Definition tm1638.h:21
Providing packet encoding functions for exchanging data with a remote host.
Definition a01nyub.cpp:7
A more user-friendly version of struct tm from time.h.
Definition time.h:15
std::string print()