-
Notifications
You must be signed in to change notification settings - Fork 1
/
_photos.py
70 lines (52 loc) · 1.46 KB
/
_photos.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
64
65
66
67
68
69
"""
photos.py
Displays contents of a folder
Derived from https://github.com/russhughes/st7789_mpy/tree/master/examples/clock
"""
import gc, os, utime
from machine import Pin, SPI
import st7789
import tft_config, tft_typeset
tft = tft_config.config(1)
timeout = 0
def cycle(p):
"""return the next item in a list"""
try:
len(p)
except TypeError:
cache = []
for i in p:
yield i
cache.append(i)
p = cache
while p:
yield from p
def last_btn(pin):
global timeout
print('prev')
timeout = 0
def next_btn(pin):
global timeout
print('next')
timeout = 0
def main():
"""
Initialize the display and show the time
"""
tft.init()
backgrounds = cycle(os.listdir("./photos_{}x{}/".format(tft.width(), tft.height())))
btn1 = tft_typeset.Button(pin=Pin(0, mode=Pin.IN, pull=Pin.PULL_UP), callback=next_btn)
btn2 = tft_typeset.Button(pin=Pin(35, mode=Pin.IN, pull=Pin.PULL_UP), callback=last_btn)
while True:
global timeout, background_change
if timeout < 0:
timeout = 10
image = next(backgrounds)
print(image)
gc.collect()
# draw the new background from the nasa_{WIDTH}x{HEIGHT} directory
image_file = "photos_{}x{}/{}".format(tft.width(), tft.height(), image)
tft.jpg(image_file, 0, 0, st7789.SLOW)
utime.sleep(0.5)
timeout -= 1
main()