1
0
mirror of https://github.com/esphome/esphome.git synced 2025-09-22 13:12:22 +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

@@ -11,7 +11,7 @@ _LOGGER = logging.getLogger(__name__)
DEPENDENCIES = ['display']
MULTI_CONF = True
ImageType = {'binary': 0, 'grayscale4': 1, 'rgb565': 2}
ImageType = {'binary': 0, 'grayscale': 1, 'rgb565': 2}
Image_ = display.display_ns.class_('Image')
@@ -41,20 +41,18 @@ def to_code(config):
image.thumbnail(config[CONF_RESIZE])
if CONF_TYPE in config:
if config[CONF_TYPE].startswith('GRAYSCALE4'):
if config[CONF_TYPE].startswith('GRAYSCALE'):
width, height = image.size
image = image.convert('L', dither=Image.NONE)
pixels = list(image.getdata())
data = [0 for _ in range(height * width // 2)]
data = [0 for _ in range(height * width)]
pos = 0
for pixnum, pix in enumerate(pixels):
pixshift = (pixnum % 2) * 4
data[pos] |= (pix >> 4) << pixshift
if pixshift != 0:
pos += 1
for pix in pixels:
data[pos] = pix
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['grayscale4'])
cg.new_Pvariable(config[CONF_ID], prog_arr, width, height, ImageType['grayscale'])
elif config[CONF_TYPE].startswith('RGB565'):
width, height = image.size
image = image.convert('RGB')