-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrPiEinkQREPD.py
58 lines (46 loc) · 1.79 KB
/
rPiEinkQREPD.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
import sys
import os
import time
from PIL import Image
from PIL import ImageOps
from EPD import EPD
#initiate oldcmd
oldcmd = ""
#initiate epd element
epd = EPD()
while True:
# takes input from the command line. Keyboard or scanner emulating a keyboard. newline/return to send.
usercmd = raw_input("Command:")
# test for 'end' so we can stop the script when done
if usercmd == 'end':
break
else:
# are oldcmd and usercmd the same? If so, nothing new has been input, go around the loop again
if oldcmd == usercmd:
pass #do nothing, need pass, can't have empty if in python
else:
#put together system command for making the QR code from usercmd
QRname = "qrencode -o qrcode.png -s 7 -l L -v 1 -m 1 \"" + usercmd + "\""
# s is size of single block, l is level of code 1 = simple, m is border in blocks (relative to s)
# send assembled system command
os.system(QRname)
#load image for processing into correct size
imgName = "qrcode.png"
im = Image.open(imgName)
#put together system command to pad picture with white pixels and put it on the right end of the image
convertname = "convert " + imgName + " -background white -gravity east -extent 264x176 "+ imgName
#send assembled system command
os.system(convertname)
#add text label of usercmd to image for human readabilty
convertlabel = "convert " + imgName + " -rotate -90 -gravity South -pointsize 20 -font 'FreeMono-Bold' -annotate +0+2 \""+ usercmd + "\"" " -rotate 90 " + imgName
os.system(convertlabel)
#reopen image after padding (need exact size for epyper)
im = Image.open(imgName)
im = ImageOps.grayscale(im)
#clear epd
epd.clear()
#display it!
epd.display(im)
epd.update()
# set oldcmd to the usercmd so it's ready for next loop test
oldcmd = usercmd