ESPHome  2021.10.2
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 
21 };
22 
24  public:
25  void setup() override;
26 
27  void display();
28 
29  void update() override;
30 
31  void set_model(SSD1306Model model) { this->model_ = model; }
32  void set_reset_pin(GPIOPin *reset_pin) { this->reset_pin_ = reset_pin; }
33  void set_external_vcc(bool external_vcc) { this->external_vcc_ = external_vcc; }
34  void init_contrast(float contrast) { this->contrast_ = contrast; }
35  void set_contrast(float contrast);
36  void init_brightness(float brightness) { this->brightness_ = brightness; }
37  void set_brightness(float brightness);
38  void init_flip_x(bool flip_x) { this->flip_x_ = flip_x; }
39  void init_flip_y(bool flip_y) { this->flip_y_ = flip_y; }
40  void init_offset_x(uint8_t offset_x) { this->offset_x_ = offset_x; }
41  void init_offset_y(uint8_t offset_y) { this->offset_y_ = offset_y; }
42  void init_invert(bool invert) { this->invert_ = invert; }
43  bool is_on();
44  void turn_on();
45  void turn_off();
46  float get_setup_priority() const override { return setup_priority::PROCESSOR; }
47  void fill(Color color) override;
48 
49  protected:
50  virtual void command(uint8_t value) = 0;
51  virtual void write_display_data() = 0;
52  void init_reset_();
53 
54  bool is_sh1106_() const;
55  bool is_ssd1305_() const;
56 
57  void draw_absolute_pixel_internal(int x, int y, Color color) override;
58 
59  int get_height_internal() override;
60  int get_width_internal() override;
61  size_t get_buffer_length_();
62  const char *model_str_();
63 
65  GPIOPin *reset_pin_{nullptr};
66  bool external_vcc_{false};
67  bool is_on_{false};
68  float contrast_{1.0};
69  float brightness_{1.0};
70  bool flip_x_{true};
71  bool flip_y_{true};
72  uint8_t offset_x_{0};
73  uint8_t offset_y_{0};
74  bool invert_{false};
75 };
76 
77 } // namespace ssd1306_base
78 } // namespace esphome
void init_flip_x(bool flip_x)
Definition: ssd1306_base.h:38
void set_model(SSD1306Model model)
Definition: ssd1306_base.h:31
void init_offset_y(uint8_t offset_y)
Definition: ssd1306_base.h:41
void set_reset_pin(GPIOPin *reset_pin)
Definition: ssd1306_base.h:32
void set_external_vcc(bool external_vcc)
Definition: ssd1306_base.h:33
virtual void write_display_data()=0
This class simplifies creating components that periodically check a state.
Definition: component.h:234
void set_contrast(float contrast)
void init_flip_y(bool flip_y)
Definition: ssd1306_base.h:39
void init_brightness(float brightness)
Definition: ssd1306_base.h:36
void init_offset_x(uint8_t offset_x)
Definition: ssd1306_base.h:40
float get_setup_priority() const override
Definition: ssd1306_base.h:46
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:34
Library based on https://github.com/miguelbalboa/rfid and adapted to ESPHome by . ...
Definition: a4988.cpp:4
virtual void command(uint8_t value)=0
void init_invert(bool invert)
Definition: ssd1306_base.h:42
void fill(Color color) override
void set_brightness(float brightness)