ESPHome  2023.5.5
tm1638.h
Go to the documentation of this file.
1 #pragma once
2 
4 #include "esphome/core/defines.h"
6 #include "esphome/core/hal.h"
7 
8 #include <vector>
9 
10 #ifdef USE_TIME
12 #endif
13 
14 namespace esphome {
15 namespace tm1638 {
16 
17 class KeyListener {
18  public:
19  virtual void keys_update(uint8_t keys){};
20 };
21 
22 class TM1638Component;
23 
24 using tm1638_writer_t = std::function<void(TM1638Component &)>;
25 
27  public:
28  void set_writer(tm1638_writer_t &&writer) { this->writer_ = writer; }
29  void setup() override;
30  void dump_config() override;
31  void update() override;
32  float get_setup_priority() const override;
33  void set_intensity(uint8_t brightness_level);
34  void display();
35 
36  void set_clk_pin(GPIOPin *pin) { this->clk_pin_ = pin; }
37  void set_dio_pin(GPIOPin *pin) { this->dio_pin_ = pin; }
38  void set_stb_pin(GPIOPin *pin) { this->stb_pin_ = pin; }
39 
40  void register_listener(KeyListener *listener) { this->listeners_.push_back(listener); }
41 
43  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 
48  uint8_t print(uint8_t pos, const char *str);
50  uint8_t print(const char *str);
51 
52  void loop() override;
53  uint8_t get_keys();
54 
55 #ifdef USE_TIME
56  uint8_t strftime(uint8_t pos, const char *format, time::ESPTime time) __attribute__((format(strftime, 3, 0)));
59  uint8_t strftime(const char *format, time::ESPTime time) __attribute__((format(strftime, 2, 0)));
60 #endif
61 
62  void set_led(int led_pos, bool led_on_off);
63 
64  protected:
65  void set_7seg_(int seg_pos, uint8_t seg_bits);
66  void send_command_(uint8_t value);
67  void send_command_leave_open_(uint8_t value);
68  void send_commands_(uint8_t const commands[], uint8_t num_commands);
69  void send_command_sequence_(uint8_t commands[], uint8_t num_commands, uint8_t starting_address);
70  void shift_out_(uint8_t value);
71  void reset_();
72  uint8_t shift_in_();
73  uint8_t intensity_{};
77  uint8_t *buffer_ = new uint8_t[8];
79  std::vector<KeyListener *> listeners_{};
80 };
81 
82 } // namespace tm1638
83 } // namespace esphome
void setup()
void loop()
GPIOPin * clk_pin_
brghtness of the display 0 through 7
Definition: tm1638.h:74
std::function< void(TM1638Component &)> tm1638_writer_t
Definition: tm1638.h:24
void set_clk_pin(GPIOPin *pin)
Definition: tm1638.h:36
This class simplifies creating components that periodically check a state.
Definition: component.h:282
void set_stb_pin(GPIOPin *pin)
Definition: tm1638.h:38
A more user-friendly version of struct tm from time.h.
enum esphome::EntityCategory __attribute__
void set_writer(tm1638_writer_t &&writer)
Definition: tm1638.h:28
Definition: a4988.cpp:4
void register_listener(KeyListener *listener)
Definition: tm1638.h:40
void set_dio_pin(GPIOPin *pin)
Definition: tm1638.h:37
virtual void keys_update(uint8_t keys)
Definition: tm1638.h:19