ESPHome  2024.10.2
tm1638.h
Go to the documentation of this file.
1 #pragma once
2 
5 #include "esphome/core/defines.h"
6 #include "esphome/core/hal.h"
7 #include "esphome/core/time.h"
8 
9 #include <vector>
10 
11 namespace esphome {
12 namespace tm1638 {
13 
14 class KeyListener {
15  public:
16  virtual void keys_update(uint8_t keys){};
17 };
18 
19 class TM1638Component;
20 
21 using 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
void setup()
void loop()
GPIOPin * clk_pin_
brghtness of the display 0 through 7
Definition: tm1638.h:69
std::function< void(TM1638Component &)> tm1638_writer_t
Definition: tm1638.h:21
A more user-friendly version of struct tm from time.h.
Definition: time.h:17
void set_clk_pin(GPIOPin *pin)
Definition: tm1638.h:33
This class simplifies creating components that periodically check a state.
Definition: component.h:283
void set_stb_pin(GPIOPin *pin)
Definition: tm1638.h:35
enum esphome::EntityCategory __attribute__
void set_writer(tm1638_writer_t &&writer)
Definition: tm1638.h:25
Implementation of SPI Controller mode.
Definition: a01nyub.cpp:7
void register_listener(KeyListener *listener)
Definition: tm1638.h:37
void set_dio_pin(GPIOPin *pin)
Definition: tm1638.h:34
virtual void keys_update(uint8_t keys)
Definition: tm1638.h:16