Skip to content

Commit

Permalink
Examples and tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
Gadgetoid committed Sep 18, 2018
1 parent 1dba680 commit 9332f4d
Show file tree
Hide file tree
Showing 9 changed files with 257 additions and 2 deletions.
28 changes: 28 additions & 0 deletions .gitignore
@@ -0,0 +1,28 @@
__pycache__/
sphinx/_build/
*.py[cod]
*.swp
dist/
sdist/
env/
build/
develop-eggs/
eggs/
*.egg-info/
.installed.cfg
*.egg
*.deb
*.dsc
*.build
*.changes
*.orig.*
testing/
MANIFEST
.idea
pip-log.txt
pip-delete-this-directory.txt
library/test/scrollphat/
library/debian/
packaging/*tar.xz
.DS_Store
sphinx.virtualenv
Binary file added examples/InkyPhat-212x104-bw.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added examples/InkyPhat-212x104.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
36 changes: 36 additions & 0 deletions examples/logo-what.py
@@ -0,0 +1,36 @@
#!/usr/bin/env python

from PIL import Image
import sys

sys.path.insert(0, '../library/')

from inky import what as inkywhat

inkywhat.set_colour('yellow')

print("""Inky wHAT: Logo
Displays the Inky wHAT logo.
""")

if len(sys.argv) < 2:
print("""Usage: {} <colour>
Valid colours: red, yellow, black
""".format(sys.argv[0]))
sys.exit(0)

colour = sys.argv[1].lower()
inkywhat.set_colour(colour)

inkywhat.set_border(inkywhat.BLACK)

if colour == 'black':
img = Image.open("InkyPhat-212x104-bw.png")
else:
img = Image.open("InkyPhat-212x104.png")

inkywhat.set_image(img)

inkywhat.show()
36 changes: 36 additions & 0 deletions examples/logo.py
@@ -0,0 +1,36 @@
#!/usr/bin/env python

from PIL import Image
import sys

sys.path.insert(0, '../library/')

from inky import phat as inkyphat

inkyphat.set_colour('yellow')

print("""Inky pHAT: Logo
Displays the Inky pHAT logo.
""")

if len(sys.argv) < 2:
print("""Usage: {} <colour>
Valid colours: red, yellow, black
""".format(sys.argv[0]))
sys.exit(0)

colour = sys.argv[1].lower()
inkyphat.set_colour(colour)

inkyphat.set_border(inkyphat.BLACK)

if colour == 'black':
img = Image.open("InkyPhat-212x104-bw.png")
else:
img = Image.open("InkyPhat-212x104.png")

inkyphat.set_image(img)

inkyphat.show()
15 changes: 15 additions & 0 deletions examples/test.py
@@ -0,0 +1,15 @@
import sys

sys.path.insert(0, '../library/')

import inky

phat = inky.Inky(resolution=(104,212), colour='red')

phat.setup()

for x in range(104):
for y in range(212):
phat.set_pixel(x, y, 1)

phat.update()
4 changes: 2 additions & 2 deletions library/inky/__init__.py
Expand Up @@ -190,8 +190,8 @@ def update(self):
if self.h_flip:
region = numpy.flipud(region)

buf_a = numpy.packbits(numpy.where(region == RED, 1, 0)).tolist()
buf_b = numpy.packbits(numpy.where(region == BLACK, 0, 1)).tolist()
buf_a = numpy.packbits(numpy.where(region == BLACK, 0, 1)).tolist()
buf_b = numpy.packbits(numpy.where(region == RED, 1, 0)).tolist()

self._update(buf_a, buf_b)

Expand Down
70 changes: 70 additions & 0 deletions library/inky/phat.py
@@ -0,0 +1,70 @@
import inky

__version__ = '0.0.1'

_colour = None
_flip_h = False
_flip_v = True

WIDTH = 212
HEIGHT = 104

WHITE = 0
BLACK = 1
RED = YELLOW = 2

phat = None


def setup():
global phat
if phat is not None:
return
phat = inky.Inky(
resolution=(HEIGHT, WIDTH),
colour=_colour,
h_flip=_flip_h,
v_flip=_flip_v)


def set_colour(colour):
global _colour
_colour = colour


def set_border(color):
pass


def set_image(image):
"""Copy an image to the Inky pHAT."""
setup()
# Two dimensional list
if isinstance(image, list):
w, h = len(image), len(image[0])
w = min(w, WIDTH)
h = min(h, HEIGHT)
for x in range(w):
for y in range(h):
pixel = image[x][y]
phat.set_pixel(y, x, pixel)
return

# PIL image
if getattr(image, 'size') and getattr(image, 'getpixel'):
w, h = image.size
w = min(w, WIDTH)
h = min(h, HEIGHT)
for x in range(w):
for y in range(h):
pixel = image.getpixel((x, y))
phat.set_pixel(y, x, pixel)
return


def show():
"""Show the image on the Inky pHAT."""
setup()
phat.setup()
phat.update()

70 changes: 70 additions & 0 deletions library/inky/what.py
@@ -0,0 +1,70 @@
import inky

__version__ = '0.0.1'

_colour = None
_flip_h = False
_flip_v = False

WIDTH = 400
HEIGHT = 300

WHITE = 0
BLACK = 1
RED = YELLOW = 2

what = None


def setup():
global what
if what is not None:
return
what = inky.Inky(
resolution=(WIDTH, HEIGHT),
colour=_colour,
h_flip=_flip_h,
v_flip=_flip_v)


def set_colour(colour):
global _colour
_colour = colour


def set_border(color):
pass


def set_image(image):
"""Copy an image to the Inky wHAT."""
setup()
# Two dimensional list
if isinstance(image, list):
w, h = len(image), len(image[0])
w = min(w, WIDTH)
h = min(h, HEIGHT)
for x in range(w):
for y in range(h):
pixel = image[x][y]
what.set_pixel(y, x, pixel)
return

# PIL image
if getattr(image, 'size') and getattr(image, 'getpixel'):
w, h = image.size
w = min(w, WIDTH)
h = min(h, HEIGHT)
for x in range(w):
for y in range(h):
pixel = image.getpixel((x, y))
what.set_pixel(x, y, pixel)
return


def show():
"""Show the image on the Inky wHAT."""
setup()
what.setup()
what.update()

0 comments on commit 9332f4d

Please sign in to comment.