Skip to content

Commit

Permalink
Merge pull request #149 from pimoroni/driver/what_ssd1683
Browse files Browse the repository at this point in the history
Driver for SSD1683-based Inky wHAT
  • Loading branch information
Gadgetoid authored Sep 27, 2022
2 parents 45024c0 + e6b4b97 commit b14173e
Show file tree
Hide file tree
Showing 12 changed files with 467 additions and 51 deletions.
1 change: 0 additions & 1 deletion examples/7color/stripes.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,3 @@
inky.show()
# To simulate:
# inky.wait_for_window_close()

16 changes: 7 additions & 9 deletions examples/what/dither-image-what.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,26 @@

import argparse
from PIL import Image
from inky import InkyWHAT
from inky.auto import auto

print("""Inky wHAT: Dither image
Converts and displays dithered images on Inky wHAT.
""")

# Command line arguments to set display type and colour, and enter your name
# Set up the inky wHAT display and border colour

inky_display = auto(ask_user=True, verbose=True)
inky_display.set_border(inky_display.WHITE)

# Grab the image argument from the command line

parser = argparse.ArgumentParser()
parser.add_argument('--colour', '-c', type=str, required=True, choices=["red", "black", "yellow"], help="ePaper display colour")
parser.add_argument('--image', '-i', type=str, required=True, help="Input image to be converted/displayed")
args = parser.parse_args()

colour = args.colour
img_file = args.image

# Set up the inky wHAT display and border colour

inky_display = InkyWHAT(colour)
inky_display.set_border(inky_display.WHITE)

# Open our image file that was passed in from the command line

img = Image.open(img_file)
Expand Down
57 changes: 31 additions & 26 deletions examples/what/quotes-what.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import argparse
import random
import sys

from inky import InkyWHAT
from inky.auto import auto

from PIL import Image, ImageFont, ImageDraw
from font_source_serif_pro import SourceSerifProSemibold
Expand All @@ -22,18 +21,16 @@
print("""This script requires the wikiquotes module.
Install with:
sudo apt install python-lxml
sudo pip install wikiquotes
sudo apt install python3-lxml
python3 -m pip install wikiquotes
""")
sys.exit(1)

# Command line arguments to set display type and colour, and enter your name

parser = argparse.ArgumentParser()
parser.add_argument('--colour', '-c', type=str, required=True, choices=["red", "black", "yellow"], help="ePaper display colour")
args = parser.parse_args()
# Set up the correct display and scaling factors

colour = args.colour
inky_display = auto(ask_user=True, verbose=True)
inky_display.set_border(inky_display.WHITE)
# inky_display.set_rotation(180)

# This function will take a quote as a string, a width to fit
# it into, and a font (one that's been loaded) and then reflow
Expand Down Expand Up @@ -61,17 +58,12 @@ def reflow_quote(quote, width, font):
return reflowed


# Set up the correct display and scaling factors
inky_display = InkyWHAT(colour)
inky_display.set_border(inky_display.WHITE)
# inky_display.set_rotation(180)

w = inky_display.WIDTH
h = inky_display.HEIGHT
WIDTH = inky_display.width
HEIGHT = inky_display.height

# Create a new canvas to draw on

img = Image.new("P", (inky_display.WIDTH, inky_display.HEIGHT))
img = Image.new("P", (WIDTH, HEIGHT))
draw = ImageDraw.Draw(img)

# Load the fonts
Expand Down Expand Up @@ -112,8 +104,8 @@ def reflow_quote(quote, width, font):
# Also define the max width and height for the quote.

padding = 50
max_width = w - padding
max_height = h - padding - author_font.getsize("ABCD ")[1]
max_width = WIDTH - padding
max_height = HEIGHT - padding - author_font.getsize("ABCD ")[1]

below_max_length = False

Expand All @@ -136,8 +128,8 @@ def reflow_quote(quote, width, font):

# x- and y-coordinates for the top left of the quote

quote_x = (w - max_width) / 2
quote_y = ((h - max_height) + (max_height - p_h - author_font.getsize("ABCD ")[1])) / 2
quote_x = (WIDTH - max_width) / 2
quote_y = ((HEIGHT - max_height) + (max_height - p_h - author_font.getsize("ABCD ")[1])) / 2

# x- and y-coordinates for the top left of the author

Expand All @@ -148,16 +140,29 @@ def reflow_quote(quote, width, font):

# Draw red rectangles top and bottom to frame quote

draw.rectangle((padding / 4, padding / 4, w - (padding / 4), quote_y - (padding / 4)), fill=inky_display.RED)
draw.rectangle((padding / 4, author_y + author_font.getsize("ABCD ")[1] + (padding / 4) + 5, w - (padding / 4), h - (padding / 4)), fill=inky_display.RED)
draw.rectangle(
(
padding / 4,
padding / 4,
WIDTH - (padding / 4),
quote_y - (padding / 4)
), fill=inky_display.RED)

draw.rectangle(
(
padding / 4,
author_y + author_font.getsize("ABCD ")[1] + (padding / 4) + 5,
WIDTH - (padding / 4),
HEIGHT - (padding / 4)
), fill=inky_display.RED)

# Add some white hatching to the red rectangles to make
# it look a bit more interesting

hatch_spacing = 12

for x in range(0, 2 * w, hatch_spacing):
draw.line((x, 0, x - w, h), fill=inky_display.WHITE, width=3)
for x in range(0, 2 * WIDTH, hatch_spacing):
draw.line((x, 0, x - WIDTH, HEIGHT), fill=inky_display.WHITE, width=3)

# Write our quote and author to the canvas

Expand Down
1 change: 1 addition & 0 deletions library/inky/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from .what import InkyWHAT # noqa: F401
from .mock import InkyMockPHAT, InkyMockWHAT # noqa: F401
from .inky_uc8159 import Inky as Inky7Colour # noqa: F401
from .inky_ssd1683 import Inky as InkyWHAT_SSD1683 # noqa: F401
from .auto import auto # noqa: F401

__version__ = '1.3.2'
Expand Down
16 changes: 14 additions & 2 deletions library/inky/auto.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,15 @@
from .phat import InkyPHAT, InkyPHAT_SSD1608 # noqa: F401
from .what import InkyWHAT # noqa: F401
from .inky_uc8159 import Inky as InkyUC8159 # noqa: F401
from .inky_ssd1683 import Inky as InkyWHAT_SSD1683 # noqa: F401
from . import eeprom
import argparse


DISPLAY_TYPES = ["what", "phat", "phatssd1608", "impressions", "7colour", "whatssd1683"]
DISPLAY_COLORS = ["red", "black", "yellow"]


def auto(i2c_bus=None, ask_user=False, verbose=False):
"""Auto-detect Inky board from EEPROM and return an Inky class instance."""
_eeprom = eeprom.read_eeprom(i2c_bus=i2c_bus)
Expand All @@ -24,14 +29,16 @@ def auto(i2c_bus=None, ask_user=False, verbose=False):
return InkyUC8159(resolution=(600, 448))
if _eeprom.display_variant in (15, 16):
return InkyUC8159(resolution=(640, 400))
if _eeprom.display_variant in (17, 18, 19):
return InkyWHAT_SSD1683((400, 300), _eeprom.get_color())

if ask_user:
if verbose:
print("Failed to detect an Inky board. Trying --type/--colour arguments instead...\n")
parser = argparse.ArgumentParser()
parser.add_argument('--simulate', '-s', action='store_true', default=False, help="Simulate Inky display")
parser.add_argument('--type', '-t', type=str, required=True, choices=["what", "phat", "phatssd1608", "impressions", "7colour"], help="Type of display")
parser.add_argument('--colour', '-c', type=str, required=False, choices=["red", "black", "yellow"], help="Display colour")
parser.add_argument('--type', '-t', type=str, required=True, choices=DISPLAY_TYPES, help="Type of display")
parser.add_argument('--colour', '-c', type=str, required=False, choices=DISPLAY_COLORS, help="Display colour")
args, _ = parser.parse_known_args()
if args.simulate:
cls = None
Expand All @@ -47,6 +54,9 @@ def auto(i2c_bus=None, ask_user=False, verbose=False):
if args.type in ("impressions", "7colour"):
from .mock import InkyMockImpression
cls = InkyMockImpression()
if args.type == "whatssd1683":
from .mock import InkyMockWHAT
cls = InkyMockWHAT(args.colour)
if cls is not None:
import atexit
atexit.register(cls.wait_for_window_close)
Expand All @@ -59,6 +69,8 @@ def auto(i2c_bus=None, ask_user=False, verbose=False):
return InkyPHAT_SSD1608(args.colour)
if args.type == "what":
return InkyWHAT(args.colour)
if args.type == "whatssd1683":
return InkyWHAT_SSD1683(colour=args.colour)
if args.type in ("impressions", "7colour"):
return InkyUC8159()

Expand Down
8 changes: 7 additions & 1 deletion library/inky/eeprom.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@
None,
'7-Colour (UC8159)',
'7-Colour 640x400 (UC8159)',
'7-Colour 640x400 (UC8159)'
'7-Colour 640x400 (UC8159)',
'Black wHAT (SSD1683)',
'Red wHAT (SSD1683)',
'Yellow wHAT (SSD1683)'
]


Expand Down Expand Up @@ -83,6 +86,9 @@ def encode(self):

def to_list(self):
"""Return a list of bytes representing the EEPROM data structure."""
result = self.encode()
if type(result) is bytes:
return result
return [ord(c) for c in self.encode()]

def set_color(self, color):
Expand Down
2 changes: 1 addition & 1 deletion library/inky/inky.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ def setup(self):

def _busy_wait(self):
"""Wait for busy/wait pin."""
while(self._gpio.input(self.busy_pin) != self._gpio.LOW):
while self._gpio.input(self.busy_pin) != self._gpio.LOW:
time.sleep(0.01)

def _update(self, buf_a, buf_b, busy_wait=True):
Expand Down
Loading

0 comments on commit b14173e

Please sign in to comment.