-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgallery.py
More file actions
71 lines (58 loc) · 1.86 KB
/
gallery.py
File metadata and controls
71 lines (58 loc) · 1.86 KB
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
64
65
66
67
68
69
70
71
# Show saved drawings on display
# PRESS ENTER to cycle thru the images
import time
import sys
import os
import glob
import platform
from PIL import Image
from drive import SSD1305
# Initialize display
disp = SSD1305.SSD1305()
disp.Init()
disp.clear()
width = disp.width
height = disp.height
image_folder = "Saved"
file_extension = ".png"
# Use glob to find all PNG files in the folder
file_paths = glob.glob(os.path.join(image_folder, '*' + file_extension))
file_paths.sort()
try:
while True:
for n in file_paths:
# Open and resize the image
picture = Image.open(n).resize((width, height)).convert('1')
# Display the image on the OLED display
disp.clear()
disp.getbuffer(picture)
disp.ShowImage()
# Close the image to free up resources
picture.close()
# Wait for any key press to display the next frame
if platform.system() == 'Windows':
import msvcrt
if msvcrt.kbhit():
if ord(msvcrt.getch()) == 27: # Check if the key pressed is ESC
raise KeyboardInterrupt
else:
import termios
import tty
import sys
def getkey():
fd = sys.stdin.fileno()
old_settings = termios.tcgetattr(fd)
try:
tty.setraw(fd)
ch = sys.stdin.read(1)
finally:
termios.tcsetattr(fd, termios.TCSADRAIN, old_settings)
return ch
if getkey() == '\x1b': # Check if the key pressed is ESC
raise KeyboardInterrupt
except KeyboardInterrupt:
print("\n")
print("Exiting the program...")
finally:
disp.clear()
sys.exit(0)