7
7
from adafruit_esp32spi import adafruit_esp32spi , adafruit_esp32spi_wifimanager
8
8
import adafruit_requests as requests
9
9
import digitalio
10
- import analogio
10
+ from analogio import AnalogIn
11
11
from adafruit_pyportal import PyPortal
12
12
from adafruit_bitmap_font import bitmap_font
13
13
from adafruit_display_text import label
20
20
the secrets dictionary must contain 'ssid' and 'password' at a minimum""" )
21
21
raise
22
22
23
+ # Colors for each label
24
+ LABEL_DAY_COLOR = 0xFFFFFF
25
+ LABEL_TIME_COLOR = 0x8f42f4
26
+
27
+ # the current working directory (where this file is)
28
+ cwd = ("/" + __file__ ).rsplit ('/' , 1 )[0 ]
29
+ background = None
30
+ # un-comment to set background image
31
+ # background = cwd+"/background.bmp"
32
+
23
33
# Descriptions of each hour
24
34
# https://github.com/mwfisher3/QuarantineClock/blob/master/today.html
25
35
time_name = ["midnight-ish" , "late night" , "late" , "super late" ,
29
39
"late afternoon" ,"early evening" ,"early evening" ,"dusk-ish" ,
30
40
"evening" ,"evening" ,"late evening" ,"late evening" ]
31
41
32
-
33
42
esp32_cs = digitalio .DigitalInOut (board .ESP_CS )
34
43
esp32_ready = digitalio .DigitalInOut (board .ESP_BUSY )
35
44
esp32_reset = digitalio .DigitalInOut (board .ESP_RESET )
38
47
esp = adafruit_esp32spi .ESP_SPIcontrol (spi , esp32_cs , esp32_ready , esp32_reset , debug = False )
39
48
requests .set_socket (socket , esp )
40
49
41
-
42
50
def wday_to_weekday_name (tm_wday ):
43
51
"""Returns the name of the weekday based on tm_wday value.
44
52
:param int tm_wday: Days since Sunday.
@@ -52,11 +60,15 @@ def wday_to_weekday_name(tm_wday):
52
60
4 : "Friday" ,
53
61
5 : "Saturday" ,
54
62
6 : "Sunday" ,}
55
- return switch .get (tm_wday , "Not found" )
63
+ return switch .get (tm_wday , "Day not found" )
56
64
57
65
# initialize pyportal
58
66
pyportal = PyPortal (esp = esp ,
59
- external_spi = spi )
67
+ external_spi = spi ,
68
+ default_bg = None )
69
+
70
+ # set pyportal's backlight brightness
71
+ pyportal .set_backlight (0.7 )
60
72
61
73
if esp .status == adafruit_esp32spi .WL_IDLE_STATUS :
62
74
print ("ESP32 found and in idle mode" )
@@ -72,19 +84,19 @@ def wday_to_weekday_name(tm_wday):
72
84
continue
73
85
74
86
# Set the font and preload letters
75
- font_large = bitmap_font .load_font ("/fonts/Helvetica-Bold-36 .bdf" )
87
+ font_large = bitmap_font .load_font ("/fonts/Helvetica-Bold-44 .bdf" )
76
88
font_small = bitmap_font .load_font ("/fonts/Helvetica-Bold-24.bdf" )
77
89
font_large .load_glyphs (b'abcdefghjiklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890- ' )
78
90
font_small .load_glyphs (b'abcdefghjiklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890- ()' )
79
91
80
92
# Set up label for the day
81
- label_day = label .Label (font_large , color = 0xFFFFFF , max_glyphs = 200 )
82
- label_day .x = board .DISPLAY .width // 5
83
- label_day .y = 70
93
+ label_day = label .Label (font_large , color = LABEL_DAY_COLOR , max_glyphs = 200 )
94
+ label_day .x = board .DISPLAY .width // 7
95
+ label_day .y = 80
84
96
pyportal .splash .append (label_day )
85
97
86
98
# Set up label for the time
87
- label_time = label .Label (font_small , color = 0x538ab1 , max_glyphs = 200 )
99
+ label_time = label .Label (font_small , color = LABEL_TIME_COLOR , max_glyphs = 200 )
88
100
label_time .x = board .DISPLAY .width // 4
89
101
label_time .y = 150
90
102
pyportal .splash .append (label_time )
@@ -97,22 +109,20 @@ def wday_to_weekday_name(tm_wday):
97
109
print ("Getting new time from internet..." )
98
110
pyportal .get_local_time (secrets ['timezone' ])
99
111
refresh_time = time .monotonic ()
112
+ # set the_time
113
+ the_time = time .localtime ()
114
+ # Convert tm_wday to name of day
115
+ weekday = wday_to_weekday_name (the_time .tm_wday )
100
116
except (ValueError , RuntimeError ) as error :
101
117
print ("Failed to get data, retrying\n " , e )
102
118
wifi .reset ()
103
119
continue
104
120
105
- # set the_time
106
- the_time = time .localtime ()
107
-
108
- # Convert tm_wday to name of day
109
- weekday = wday_to_weekday_name (the_time .tm_wday )
110
-
111
121
# set the day label's text
112
122
label_day .text = weekday
113
123
114
124
# set the time label's text
115
125
label_time .text = "({})" .format (time_name [the_time .tm_hour ])
116
126
117
- # update every 30s .
118
- time .sleep (30 )
127
+ # update every minute .
128
+ time .sleep (60 )
0 commit comments