Add Invert method for SSD1306 (#5292)

This commit is contained in:
Christian 2023-08-22 23:13:38 +01:00 committed by GitHub
parent f814b6d47c
commit 11ed2d5f18
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 1 deletions

View file

@ -132,7 +132,7 @@ void SSD1306::setup() {
this->command(SSD1306_COMMAND_DISPLAY_ALL_ON_RESUME); this->command(SSD1306_COMMAND_DISPLAY_ALL_ON_RESUME);
// Inverse display mode (0xA6, 0xA7) // Inverse display mode (0xA6, 0xA7)
this->command(SSD1306_COMMAND_NORMAL_DISPLAY | this->invert_); this->set_invert(this->invert_);
// Disable scrolling mode (0x2E) // Disable scrolling mode (0x2E)
this->command(SSD1306_COMMAND_DEACTIVATE_SCROLL); this->command(SSD1306_COMMAND_DEACTIVATE_SCROLL);
@ -190,6 +190,12 @@ void SSD1306::update() {
this->do_update_(); this->do_update_();
this->display(); this->display();
} }
void SSD1306::set_invert(bool invert) {
this->invert_ = invert;
// Inverse display mode (0xA6, 0xA7)
this->command(SSD1306_COMMAND_NORMAL_DISPLAY | this->invert_);
}
void SSD1306::set_contrast(float contrast) { void SSD1306::set_contrast(float contrast) {
// validation // validation
this->contrast_ = clamp(contrast, 0.0F, 1.0F); this->contrast_ = clamp(contrast, 0.0F, 1.0F);

View file

@ -43,6 +43,7 @@ class SSD1306 : public PollingComponent, public display::DisplayBuffer {
void init_offset_x(uint8_t offset_x) { this->offset_x_ = offset_x; } void init_offset_x(uint8_t offset_x) { this->offset_x_ = offset_x; }
void init_offset_y(uint8_t offset_y) { this->offset_y_ = offset_y; } void init_offset_y(uint8_t offset_y) { this->offset_y_ = offset_y; }
void init_invert(bool invert) { this->invert_ = invert; } void init_invert(bool invert) { this->invert_ = invert; }
void set_invert(bool invert);
bool is_on(); bool is_on();
void turn_on(); void turn_on();
void turn_off(); void turn_off();