/
clean.py
executable file
·63 lines (46 loc) · 1.78 KB
/
clean.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import time
import argparse
from inky import InkyPHAT, InkyWHAT
from PIL import Image
print("""Inky pHAT: Clean
Displays solid blocks of red, black, and white to clean the Inky pHAT
display of any ghosting.
""")
# Command line arguments to set display type and colour, and number of cycles to run
parser = argparse.ArgumentParser()
parser.add_argument('--type', '-t', type=str, required=True, choices=["what", "phat"], help="type of display")
parser.add_argument('--colour', '-c', type=str, required=True, choices=["red", "black", "yellow"], help="ePaper display colour")
parser.add_argument('--number', '-n', type=int, required=False, help="number of cycles")
args = parser.parse_args()
colour = args.colour
# Set up the correct display and scaling factors
if args.type == "phat":
inky_display = InkyPHAT(colour)
elif args.type == "what":
inky_display = InkyWHAT(colour)
# The number of red / black / white refreshes to run
if args.number:
cycles = args.number
else:
cycles = 3
colours = (inky_display.RED, inky_display.BLACK, inky_display.WHITE)
colour_names = (colour, "black", "white")
# Create a new canvas to draw on
img = Image.new("P", (inky_display.WIDTH, inky_display.HEIGHT))
# Loop through the specified number of cycles and completely
# fill the display with each colour in turn.
for i in range(cycles):
print("Cleaning cycle %i\n" % (i + 1))
for j, c in enumerate(colours):
print("- updating with %s" % colour_names[j])
inky_display.set_border(c)
for x in range(inky_display.WIDTH):
for y in range(inky_display.HEIGHT):
img.putpixel((x, y), c)
inky_display.set_image(img)
inky_display.show()
time.sleep(1)
print("\n")
print("Cleaning complete!")