1
0
mirror of https://github.com/esphome/esphome.git synced 2025-10-18 09:43:47 +01:00

SSD1325 grayscale support (#1064)

* SSD1325 grayscale support implemented

* Linted

* Fix garbage on display at power-up

* Rebase

* Linted

* Add brightness control, CS fixes

* Fix up SSD1327 init

* Add turn_on() and turn_off() methods

* Set brightness later in setup(), logging tweak

* Added is_on() method

* Added  grayscale image support

* Updated to use Color, 1327 GS fix
This commit is contained in:
Keith Burzinski
2020-07-09 19:53:49 -05:00
committed by GitHub
parent c693c219f4
commit 7fa98e288f
8 changed files with 129 additions and 86 deletions

View File

@@ -7,8 +7,8 @@ namespace display {
static const char *TAG = "display";
const Color COLOR_OFF = 0;
const Color COLOR_ON = 1;
const Color COLOR_OFF(0, 0, 0, 0);
const Color COLOR_ON(1, 1, 1, 1);
void DisplayBuffer::init_internal_(uint32_t buffer_length) {
this->buffer_ = new uint8_t[buffer_length];
@@ -214,10 +214,10 @@ void DisplayBuffer::image(int x, int y, Color color, Image *image, bool invert)
this->draw_pixel_at(x + img_x, y + img_y, image->get_pixel(img_x, img_y) ? color : COLOR_OFF);
}
}
} else if (image->get_type() == GRAYSCALE4) {
} else if (image->get_type() == GRAYSCALE) {
for (int img_x = 0; img_x < image->get_width(); img_x++) {
for (int img_y = 0; img_y < image->get_height(); img_y++) {
this->draw_pixel_at(x + img_x, y + img_y, image->get_grayscale4_pixel(img_x, img_y));
this->draw_pixel_at(x + img_x, y + img_y, image->get_grayscale_pixel(img_x, img_y));
}
}
} else if (image->get_type() == RGB565) {
@@ -457,14 +457,11 @@ int Image::get_color_pixel(int x, int y) const {
int color = (pgm_read_byte(this->data_start_ + pos) << 8) + (pgm_read_byte(this->data_start_ + pos + 1));
return color;
}
int Image::get_grayscale4_pixel(int x, int y) const {
Color Image::get_grayscale_pixel(int x, int y) const {
if (x < 0 || x >= this->width_ || y < 0 || y >= this->height_)
return 0;
const uint32_t pos = (x + y * this->width_) / 2;
// 2 = number of pixels per byte, 4 = pixel shift
uint8_t shift = (x % 2) * 4;
int color = (pgm_read_byte(this->data_start_ + pos) >> shift) & 0x0f;
return color;
const uint32_t pos = (x + y * this->width_);
return Color(pgm_read_byte(this->data_start_ + pos) << 24);
}
int Image::get_width() const { return this->width_; }
int Image::get_height() const { return this->height_; }

View File

@@ -68,7 +68,7 @@ extern const Color COLOR_OFF;
/// Turn the pixel ON.
extern const Color COLOR_ON;
enum ImageType { BINARY = 0, GRAYSCALE4 = 1, RGB565 = 2 };
enum ImageType { BINARY = 0, GRAYSCALE = 1, RGB565 = 2 };
enum DisplayRotation {
DISPLAY_ROTATION_0_DEGREES = 0,
@@ -385,7 +385,7 @@ class Image {
Image(const uint8_t *data_start, int width, int height, int type);
bool get_pixel(int x, int y) const;
int get_color_pixel(int x, int y) const;
int get_grayscale4_pixel(int x, int y) const;
Color get_grayscale_pixel(int x, int y) const;
int get_width() const;
int get_height() const;
ImageType get_type() const;