ESPHome 2026.5.0b1
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::tm1637 {
16
17class TM1637Display;
18#ifdef USE_BINARY_SENSOR
19class TM1637Key;
20#endif
21
23
25 public:
26 void set_writer(tm1637_writer_t &&writer) { this->writer_ = writer; }
27
28 void setup() override;
29
30 void dump_config() override;
31
32 void set_clk_pin(GPIOPin *pin) { clk_pin_ = pin; }
33 void set_dio_pin(GPIOPin *pin) { dio_pin_ = pin; }
34
35 float get_setup_priority() const override;
36
37 void update() override;
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
50 void set_buffer(const uint8_t *data, uint8_t length);
51
54 void set_brightness(float brightness);
55 void set_intensity(uint8_t intensity) { this->intensity_ = intensity; }
56 void set_inverted(bool inverted) { this->inverted_ = inverted; }
57 void set_length(uint8_t length) { this->length_ = length; }
58 void set_on(bool on) { this->on_ = on; }
59
60 void display();
61
62#ifdef USE_BINARY_SENSOR
63 void loop() override;
64 uint8_t get_keys();
65 void add_tm1637_key(TM1637Key *tm1637_key) { this->tm1637_keys_.push_back(tm1637_key); }
66#endif
67
69 uint8_t strftime(uint8_t pos, const char *format, ESPTime time) __attribute__((format(strftime, 3, 0)));
71 uint8_t strftime(const char *format, ESPTime time) __attribute__((format(strftime, 2, 0)));
72
73 protected:
74 void bit_delay_();
76 bool send_byte_(uint8_t b);
77 uint8_t read_byte_();
78 void start_();
79 void stop_();
80
83 uint8_t intensity_;
84 uint8_t length_;
86 bool on_{true};
88 uint8_t buffer_[6] = {0};
89#ifdef USE_BINARY_SENSOR
90 std::vector<TM1637Key *> tm1637_keys_{};
91#endif
92};
93
94#ifdef USE_BINARY_SENSOR
96 friend class TM1637Display;
97
98 public:
99 void set_keycode(uint8_t key_code) { key_code_ = key_code; }
100 void process(uint8_t data) { this->publish_state(static_cast<bool>(data == this->key_code_)); }
101
102 protected:
103 uint8_t key_code_{0};
104};
105#endif
106
107} // namespace esphome::tm1637
This class simplifies creating components that periodically check a state.
Definition component.h:602
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:26
void set_brightness(float brightness)
Set the display brightness.
Definition tm1637.cpp:350
float get_setup_priority() const override
Definition tm1637.cpp:184
void dump_config() override
Definition tm1637.cpp:134
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:384
tm1637_writer_t writer_
Definition tm1637.h:87
void set_clk_pin(GPIOPin *pin)
Definition tm1637.h:32
std::vector< TM1637Key * > tm1637_keys_
Definition tm1637.h:90
void set_inverted(bool inverted)
Definition tm1637.h:56
void set_length(uint8_t length)
Definition tm1637.h:57
void set_buffer(const uint8_t *data, uint8_t length)
Set raw buffer bytes from data array up to length bytes.
Definition tm1637.cpp:358
void add_tm1637_key(TM1637Key *tm1637_key)
Definition tm1637.h:65
void set_dio_pin(GPIOPin *pin)
Definition tm1637.h:33
void set_intensity(uint8_t intensity)
Definition tm1637.h:55
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:363
void process(uint8_t data)
Definition tm1637.h:100
void set_keycode(uint8_t key_code)
Definition tm1637.h:99
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()
uint16_t length
Definition tt21100.cpp:0