5
5
import board
6
6
import displayio
7
7
import terminalio
8
- import adafruit_imageload
9
8
from adafruit_display_shapes .rect import Rect
10
9
from adafruit_display_text import label
11
10
from adafruit_pyportal import PyPortal
17
16
# Set the backlight brightness, 0.0 (off) to 1.0 (max brightness)
18
17
BACKLIGHT_BRIGHTNESS = 0.5
19
18
# Location text and images
20
- LOCATION_IMAGES = { 'home' : 'images/home.bmp' , 'work' : 'images/office.bmp' , 'gym' : 'images/workout.bmp' , 'commute' : 'images/subway.bmp' }
19
+ LOCATION_IMAGES = { 'home' : 'images/home.bmp' , 'work' : 'images/office.bmp' ,
20
+ 'gym' : 'images/workout.bmp' , 'commute' : 'images/subway.bmp' }
21
21
22
22
# Create the PyPortal object
23
23
pyportal = PyPortal (status_neopixel = board .NEOPIXEL )
@@ -72,16 +72,10 @@ def set_image(group, filename):
72
72
if group :
73
73
group .pop ()
74
74
75
- if not filename :
76
- return # we're done, no icon desired
77
- try :
78
- if image_file :
79
- image_file .close
80
- except NameError :
81
- pass
82
75
image_file = open (filename , "rb" )
83
76
image = displayio .OnDiskBitmap (image_file )
84
- image_sprite = displayio .TileGrid (image , pixel_shader = getattr (image , 'pixel_shader' , displayio .ColorConverter ()))
77
+ image_sprite = displayio .TileGrid (image ,
78
+ pixel_shader = getattr (image , 'pixel_shader' , displayio .ColorConverter ()))
85
79
image_sprite .x = IMAGE_SPRITE_X
86
80
image_sprite .y = IMAGE_SPRITE_Y
87
81
group .append (image_sprite )
@@ -114,9 +108,9 @@ def set_image(group, filename):
114
108
text_area_location .text = f"Error: Unknown Value!"
115
109
# Show the refreshed group
116
110
display .root_group = group
117
- except Exception as e :
118
- print (f "Failed to fetch location data: { e } " )
111
+ except RuntimeError as e :
112
+ print ("Failed to fetch location data: " , e )
119
113
120
114
# Wait 5 minutes (300 seconds) before fetching the location feed again
121
115
print ("Sleeping, fetching the location again in 5 minutes!" )
122
- time .sleep (SLEEP_DELAY_SECONDS * 60 )
116
+ time .sleep (SLEEP_DELAY_SECONDS * 60 )
0 commit comments