1
0
mirror of https://github.com/esphome/esphome.git synced 2025-10-30 14:43:51 +00:00

Add SSD1351 OLED display support (#1100)

* Add SSD1351 display support

* Linting round 2

* Updated/rebased for proper Color support

* Fix color image processing
This commit is contained in:
Keith Burzinski
2020-07-09 21:49:26 -05:00
committed by GitHub
parent 7fa98e288f
commit 417a3cdf51
11 changed files with 440 additions and 18 deletions

View File

@@ -11,7 +11,7 @@ _LOGGER = logging.getLogger(__name__)
DEPENDENCIES = ['display']
MULTI_CONF = True
ImageType = {'binary': 0, 'grayscale': 1, 'rgb565': 2}
ImageType = {'binary': 0, 'grayscale': 1, 'rgb': 2}
Image_ = display.display_ns.class_('Image')
@@ -53,24 +53,22 @@ def to_code(config):
rhs = [HexInt(x) for x in data]
prog_arr = cg.progmem_array(config[CONF_RAW_DATA_ID], rhs)
cg.new_Pvariable(config[CONF_ID], prog_arr, width, height, ImageType['grayscale'])
elif config[CONF_TYPE].startswith('RGB565'):
elif config[CONF_TYPE].startswith('RGB'):
width, height = image.size
image = image.convert('RGB')
pixels = list(image.getdata())
data = [0 for _ in range(height * width * 2)]
data = [0 for _ in range(height * width * 3)]
pos = 0
for pix in pixels:
r = (pix[0] >> 3) & 0x1F
g = (pix[1] >> 2) & 0x3F
b = (pix[2] >> 3) & 0x1F
p = (r << 11) + (g << 5) + b
data[pos] = (p >> 8) & 0xFF
data[pos] = pix[0]
pos += 1
data[pos] = p & 0xFF
data[pos] = pix[1]
pos += 1
data[pos] = pix[2]
pos += 1
rhs = [HexInt(x) for x in data]
prog_arr = cg.progmem_array(config[CONF_RAW_DATA_ID], rhs)
cg.new_Pvariable(config[CONF_ID], prog_arr, width, height, ImageType['rgb565'])
cg.new_Pvariable(config[CONF_ID], prog_arr, width, height, ImageType['rgb'])
else:
image = image.convert('1', dither=Image.NONE)
width, height = image.size