ESPHome  2022.8.0
ssd1306_base.h
Go to the documentation of this file.
1 #pragma once
2 
4 #include "esphome/core/hal.h"
6 
7 namespace esphome {
8 namespace ssd1306_base {
9 
23 };
24 
26  public:
27  void setup() override;
28 
29  void display();
30 
31  void update() override;
32 
33  void set_model(SSD1306Model model) { this->model_ = model; }
34  void set_reset_pin(GPIOPin *reset_pin) { this->reset_pin_ = reset_pin; }
35  void set_external_vcc(bool external_vcc) { this->external_vcc_ = external_vcc; }
36  void init_contrast(float contrast) { this->contrast_ = contrast; }
37  void set_contrast(float contrast);
38  void init_brightness(float brightness) { this->brightness_ = brightness; }
39  void set_brightness(float brightness);
40  void init_flip_x(bool flip_x) { this->flip_x_ = flip_x; }
41  void init_flip_y(bool flip_y) { this->flip_y_ = flip_y; }
42  void init_offset_x(uint8_t offset_x) { this->offset_x_ = offset_x; }
43  void init_offset_y(uint8_t offset_y) { this->offset_y_ = offset_y; }
44  void init_invert(bool invert) { this->invert_ = invert; }
45  bool is_on();
46  void turn_on();
47  void turn_off();
48  float get_setup_priority() const override { return setup_priority::PROCESSOR; }
49  void fill(Color color) override;
50 
52 
53  protected:
54  virtual void command(uint8_t value) = 0;
55  virtual void write_display_data() = 0;
56  void init_reset_();
57 
58  bool is_sh1106_() const;
59  bool is_ssd1305_() const;
60 
61  void draw_absolute_pixel_internal(int x, int y, Color color) override;
62 
63  int get_height_internal() override;
64  int get_width_internal() override;
65  size_t get_buffer_length_();
66  const char *model_str_();
67 
69  GPIOPin *reset_pin_{nullptr};
70  bool external_vcc_{false};
71  bool is_on_{false};
72  float contrast_{1.0};
73  float brightness_{1.0};
74  bool flip_x_{true};
75  bool flip_y_{true};
76  uint8_t offset_x_{0};
77  uint8_t offset_y_{0};
78  bool invert_{false};
79 };
80 
81 } // namespace ssd1306_base
82 } // namespace esphome
void init_flip_x(bool flip_x)
Definition: ssd1306_base.h:40
void set_model(SSD1306Model model)
Definition: ssd1306_base.h:33
void init_offset_y(uint8_t offset_y)
Definition: ssd1306_base.h:43
void set_reset_pin(GPIOPin *reset_pin)
Definition: ssd1306_base.h:34
void set_external_vcc(bool external_vcc)
Definition: ssd1306_base.h:35
virtual void write_display_data()=0
This class simplifies creating components that periodically check a state.
Definition: component.h:266
void set_contrast(float contrast)
void init_flip_y(bool flip_y)
Definition: ssd1306_base.h:41
void init_brightness(float brightness)
Definition: ssd1306_base.h:38
void init_offset_x(uint8_t offset_x)
Definition: ssd1306_base.h:42
float get_setup_priority() const override
Definition: ssd1306_base.h:48
const float PROCESSOR
For components that use data from sensors like displays.
Definition: component.cpp:19
void draw_absolute_pixel_internal(int x, int y, Color color) override
void init_contrast(float contrast)
Definition: ssd1306_base.h:36
display::DisplayType get_display_type() override
Definition: ssd1306_base.h:51
Definition: a4988.cpp:4
virtual void command(uint8_t value)=0
void init_invert(bool invert)
Definition: ssd1306_base.h:44
void fill(Color color) override
void set_brightness(float brightness)