ESPHome 2026.4.0
Loading...
Searching...
No Matches
tm1637.h
Go to the documentation of this file.
1#pragma once
2
5#include "esphome/core/hal.h"
6#include "esphome/core/time.h"
8
9#include <vector>
10
11#ifdef USE_BINARY_SENSOR
13#endif
14
15namespace esphome {
16namespace tm1637 {
17
18class TM1637Display;
19#ifdef USE_BINARY_SENSOR
20class TM1637Key;
21#endif
22
24
26 public:
27 void set_writer(tm1637_writer_t &&writer) { this->writer_ = writer; }
28
29 void setup() override;
30
31 void dump_config() override;
32
33 void set_clk_pin(GPIOPin *pin) { clk_pin_ = pin; }
34 void set_dio_pin(GPIOPin *pin) { dio_pin_ = pin; }
35
36 float get_setup_priority() const override;
37
38 void update() override;
39
41 uint8_t printf(uint8_t pos, const char *format, ...) __attribute__((format(printf, 3, 4)));
43 uint8_t printf(const char *format, ...) __attribute__((format(printf, 2, 3)));
44
46 uint8_t print(uint8_t pos, const char *str);
48 uint8_t print(const char *str);
49
51 void set_buffer(const uint8_t *data, uint8_t length);
52
53 void set_intensity(uint8_t intensity) { this->intensity_ = intensity; }
54 void set_inverted(bool inverted) { this->inverted_ = inverted; }
55 void set_length(uint8_t length) { this->length_ = length; }
56 void set_on(bool on) { this->on_ = on; }
57
58 void display();
59
60#ifdef USE_BINARY_SENSOR
61 void loop() override;
62 uint8_t get_keys();
63 void add_tm1637_key(TM1637Key *tm1637_key) { this->tm1637_keys_.push_back(tm1637_key); }
64#endif
65
67 uint8_t strftime(uint8_t pos, const char *format, ESPTime time) __attribute__((format(strftime, 3, 0)));
69 uint8_t strftime(const char *format, ESPTime time) __attribute__((format(strftime, 2, 0)));
70
71 protected:
72 void bit_delay_();
74 bool send_byte_(uint8_t b);
75 uint8_t read_byte_();
76 void start_();
77 void stop_();
78
81 uint8_t intensity_;
82 uint8_t length_;
84 bool on_{true};
86 uint8_t buffer_[6] = {0};
87#ifdef USE_BINARY_SENSOR
88 std::vector<TM1637Key *> tm1637_keys_{};
89#endif
90};
91
92#ifdef USE_BINARY_SENSOR
94 friend class TM1637Display;
95
96 public:
97 void set_keycode(uint8_t key_code) { key_code_ = key_code; }
98 void process(uint8_t data) { this->publish_state(static_cast<bool>(data == this->key_code_)); }
99
100 protected:
101 uint8_t key_code_{0};
102};
103#endif
104
105} // namespace tm1637
106} // namespace esphome
This class simplifies creating components that periodically check a state.
Definition component.h:589
Base class for all binary_sensor-type classes.
void publish_state(bool new_state)
Publish a new state to the front-end.
void set_writer(tm1637_writer_t &&writer)
Definition tm1637.h:27
float get_setup_priority() const override
Definition tm1637.cpp:185
void dump_config() override
Definition tm1637.cpp:135
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 tm1637.cpp:378
tm1637_writer_t writer_
Definition tm1637.h:85
void set_clk_pin(GPIOPin *pin)
Definition tm1637.h:33
std::vector< TM1637Key * > tm1637_keys_
Definition tm1637.h:88
void set_inverted(bool inverted)
Definition tm1637.h:54
void set_length(uint8_t length)
Definition tm1637.h:55
void set_buffer(const uint8_t *data, uint8_t length)
Set raw buffer bytes from data array up to length bytes.
Definition tm1637.cpp:352
void add_tm1637_key(TM1637Key *tm1637_key)
Definition tm1637.h:63
void set_dio_pin(GPIOPin *pin)
Definition tm1637.h:34
void set_intensity(uint8_t intensity)
Definition tm1637.h:53
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 tm1637.cpp:357
void process(uint8_t data)
Definition tm1637.h:98
void set_keycode(uint8_t key_code)
Definition tm1637.h:97
struct @65::@66 __attribute__
Providing packet encoding functions for exchanging data with a remote host.
Definition a01nyub.cpp:7
const char int const __FlashStringHelper * format
Definition log.h:74
size_t size_t pos
Definition helpers.h:1082
A more user-friendly version of struct tm from time.h.
Definition time.h:23
std::string print()
uint16_t length
Definition tt21100.cpp:0