ESPHome  2024.11.3
tm1621.h
Go to the documentation of this file.
1 #pragma once
2 
4 #include "esphome/core/defines.h"
5 #include "esphome/core/hal.h"
6 
7 namespace esphome {
8 namespace tm1621 {
9 
10 class TM1621Display;
11 
12 using tm1621_writer_t = std::function<void(TM1621Display &)>;
13 
15  public:
16  void set_writer(tm1621_writer_t &&writer) { this->writer_ = writer; }
17 
18  void setup() override;
19 
20  void dump_config() override;
21 
22  void set_cs_pin(GPIOPin *pin) { cs_pin_ = pin; }
23  void set_data_pin(GPIOPin *pin) { data_pin_ = pin; }
24  void set_read_pin(GPIOPin *pin) { read_pin_ = pin; }
25  void set_write_pin(GPIOPin *pin) { write_pin_ = pin; }
26 
27  void display_celsius(bool d) { celsius_ = d; }
28  void display_fahrenheit(bool d) { fahrenheit_ = d; }
29  void display_humidity(bool d) { humidity_ = d; }
30  void display_voltage(bool d) { voltage_ = d; }
31  void display_kwh(bool d) { kwh_ = d; }
32 
33  float get_setup_priority() const override;
34 
35  void update() override;
36 
38  uint8_t printf(uint8_t pos, const char *format, ...) __attribute__((format(printf, 3, 4)));
40  uint8_t printf(const char *format, ...) __attribute__((format(printf, 2, 3)));
41 
43  uint8_t print(uint8_t pos, const char *str);
45  uint8_t print(const char *str);
46 
47  void display();
48 
49  protected:
50  void bit_delay_();
51  void setup_pins_();
52  bool send_command_(uint16_t command);
53  bool send_common_(uint8_t common);
54  bool send_address_(uint16_t address);
55  void stop_();
56  int get_command_code_(char *destination, size_t destination_size, const char *needle, const char *haystack);
57 
63  char row_[2][12];
64  uint8_t state_;
65  uint8_t device_;
66  bool celsius_;
68  bool humidity_;
69  bool voltage_;
70  bool kwh_;
71 };
72 
73 } // namespace tm1621
74 } // namespace esphome
int get_command_code_(char *destination, size_t destination_size, const char *needle, const char *haystack)
Definition: tm1621.cpp:251
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: tm1621.cpp:230
void set_cs_pin(GPIOPin *pin)
Definition: tm1621.h:22
void set_data_pin(GPIOPin *pin)
Definition: tm1621.h:23
optional< tm1621_writer_t > writer_
Definition: tm1621.h:62
This class simplifies creating components that periodically check a state.
Definition: component.h:283
void set_write_pin(GPIOPin *pin)
Definition: tm1621.h:25
bool send_common_(uint8_t common)
Definition: tm1621.cpp:190
bool send_address_(uint16_t address)
Definition: tm1621.cpp:206
void dump_config() override
Definition: tm1621.cpp:70
enum esphome::EntityCategory __attribute__
std::function< void(TM1621Display &)> tm1621_writer_t
Definition: tm1621.h:12
void update() override
Definition: tm1621.cpp:79
void set_writer(tm1621_writer_t &&writer)
Definition: tm1621.h:16
uint8_t uint8_t uint8_t print(uint8_t pos, const char *str)
Print str at the given position.
Definition: tm1621.cpp:225
bool send_command_(uint16_t command)
Definition: tm1621.cpp:170
void display_humidity(bool d)
Definition: tm1621.h:29
void display_kwh(bool d)
Definition: tm1621.h:31
Implementation of SPI Controller mode.
Definition: a01nyub.cpp:7
void display_voltage(bool d)
Definition: tm1621.h:30
uint8_t address
Definition: bl0906.h:211
void display_celsius(bool d)
Definition: tm1621.h:27
void display_fahrenheit(bool d)
Definition: tm1621.h:28
float get_setup_priority() const override
Definition: tm1621.cpp:86
void set_read_pin(GPIOPin *pin)
Definition: tm1621.h:24