1
- import ugfx , time , ntp , badge , machine , deepsleep , network , esp , gc
2
- import appglue , services
3
-
4
1
# File: splash.py
5
- # Version: 3
2
+ # Version: 4
6
3
# Description: Homescreen for SHA2017 badge
7
4
# License: MIT
8
5
# Authors: Renze Nicolai <renze@rnplus.nl>
9
6
# Thomas Roos <?>
10
7
8
+ import ugfx , time , ntp , badge , machine , deepsleep , network , esp , gc
9
+ import appglue , services
11
10
12
- ### FUNCTIONS
11
+ import easydraw , easywifi , easyrtc
13
12
14
- # RTC
15
- def splash_rtc_string (date = False , time = True ):
16
- [year , month , mday , wday , hour , min , sec , usec ] = machine .RTC ().datetime ()
17
- monthstr = str (month )
18
- if (month < 10 ):
19
- monthstr = "0" + monthstr
20
- daystr = str (mday )
21
- if (mday < 10 ):
22
- daystr = "0" + daystr
23
- hourstr = str (hour )
24
- if (hour < 10 ):
25
- hourstr = "0" + hourstr
26
- minstr = str (min )
27
- if (min < 10 ):
28
- minstr = "0" + minstr
29
- output = ""
30
- if date :
31
- output += daystr + "-" + monthstr + "-" + str (year )
32
- if time :
33
- output += " "
34
- if time :
35
- output += hourstr + ":" + minstr
36
- return output
13
+ ### FUNCTIONS
37
14
38
15
# Graphics
39
16
def splash_draw_battery (vUsb , vBatt ):
@@ -80,7 +57,7 @@ def splash_draw_actions(sleeping):
80
57
if otaAvailable :
81
58
info2 = 'Press select to start OTA update'
82
59
else :
83
- info2 = splash_rtc_string (True , True )
60
+ info2 = easyrtc . string (True , True )
84
61
85
62
l = ugfx .get_string_width (info1 ,"Roboto_Regular12" )
86
63
ugfx .string (296 - l , 0 , info1 , "Roboto_Regular12" ,ugfx .BLACK )
@@ -118,111 +95,34 @@ def splash_draw(full=False,sleeping=False):
118
95
ugfx .flush (ugfx .LUT_FULL )
119
96
else :
120
97
ugfx .flush (ugfx .LUT_NORMAL )
121
-
122
-
123
- def splash_draw_msg (message , clear = False ):
124
- global splashDrawMsg
125
- splashDrawMsg = True
126
- global splashDrawMsgLineNumber
127
- try :
128
- splashDrawMsgLineNumber
129
- except :
130
- splashDrawMsgLineNumber = 0
131
-
132
- if clear :
133
- ugfx .clear (ugfx .WHITE )
134
- ugfx .string (0 , 0 , message , "PermanentMarker22" , ugfx .BLACK )
135
- ugfx .set_lut (ugfx .LUT_FASTER )
136
- ugfx .flush ()
137
- splashDrawMsgLineNumber = 0
138
- else :
139
- ugfx .string (0 , 30 + (splashDrawMsgLineNumber * 15 ), message , "Roboto_Regular12" , ugfx .BLACK )
140
- ugfx .flush ()
141
- splashDrawMsgLineNumber += 1
142
98
143
- # WiFi
144
- def splash_wifi_connect ():
145
- global wifiStatus
146
- try :
147
- wifiStatus
148
- except :
149
- wifiStatus = False
150
-
151
- if not wifiStatus :
152
- nw = network .WLAN (network .STA_IF )
153
- if not nw .isconnected ():
154
- nw .active (True )
155
- ssid = badge .nvs_get_str ('badge' , 'wifi.ssid' , 'SHA2017-insecure' )
156
- password = badge .nvs_get_str ('badge' , 'wifi.password' )
157
- nw .connect (ssid , password ) if password else nw .connect (ssid )
158
-
159
- splash_draw_msg ("Connecting to WiFi..." , True )
160
- splash_draw_msg ("(" + ssid + ")" )
161
-
162
- timeout = badge .nvs_get_u8 ('splash' , 'wifi.timeout' , 40 )
163
- while not nw .isconnected ():
164
- time .sleep (0.1 )
165
- timeout = timeout - 1
166
- if (timeout < 1 ):
167
- splash_draw_msg ("Timeout while connecting!" )
168
- splash_wifi_disable ()
169
- return False
170
- wifiStatus = True
171
- return True
172
- return False
173
-
174
- def splash_wifi_active ():
175
- global wifiStatus
176
- try :
177
- wifiStatus
178
- except :
179
- wifiStatus = False
180
- return wifiStatus
181
-
182
-
183
- def splash_wifi_disable ():
184
- global wifiStatus
185
- wifiStatus = False
186
- nw = network .WLAN (network .STA_IF )
187
- nw .active (False )
188
-
189
- # NTP clock configuration
190
- def splash_ntp ():
191
- if not splash_wifi_active ():
192
- if not splash_wifi_connect ():
193
- return False
194
- splash_draw_msg ("Configuring clock..." , True )
195
- ntp .set_NTP_time ()
196
- splash_draw_msg ("Done" )
197
- return True
198
-
199
99
# OTA update checking
200
100
201
101
def splash_ota_download_info ():
202
102
import urequests as requests
203
- splash_draw_msg ("Checking for updates..." , True )
103
+ easydraw . msg ("Checking for updates..." , True )
204
104
result = False
205
105
try :
206
106
data = requests .get ("https://badge.sha2017.org/version" )
207
107
except :
208
- splash_draw_msg ("Error:" )
209
- splash_draw_msg ("Could not download JSON!" )
108
+ easydraw . msg ("Error:" )
109
+ easydraw . msg ("Could not download JSON!" )
210
110
time .sleep (5 )
211
111
return False
212
112
try :
213
113
result = data .json ()
214
114
except :
215
115
data .close ()
216
- splash_draw_msg ("Error:" )
217
- splash_draw_msg ("Could not decode JSON!" )
116
+ easydraw . msg ("Error:" )
117
+ easydraw . msg ("Could not decode JSON!" )
218
118
time .sleep (5 )
219
119
return False
220
120
data .close ()
221
121
return result
222
122
223
123
def splash_ota_check ():
224
- if not splash_wifi_active ():
225
- if not splash_wifi_connect ():
124
+ if not easywifi . status ():
125
+ if not easywifi . enable ():
226
126
return False
227
127
228
128
info = splash_ota_download_info ()
@@ -240,9 +140,9 @@ def splash_ota_start():
240
140
241
141
# Resources
242
142
def splash_resources_install ():
243
- splash_draw_msg ("Installing resources..." ,True )
244
- if not splash_wifi_active ():
245
- if not splash_wifi_connect ():
143
+ easydraw . msg ("Installing resources..." ,True )
144
+ if not easywifi . status ():
145
+ if not easywifi . enable ():
246
146
return False
247
147
import woezel
248
148
woezel .install ("resources" )
@@ -426,24 +326,24 @@ def splash_timer_callback(tmr):
426
326
elif setupState == 2 : # Third boot: force OTA check
427
327
print ("[SPLASH] Third boot..." )
428
328
badge .nvs_set_u8 ('badge' , 'setup.state' , 3 )
429
- otaCheck = splash_ntp () if time .time () < 1482192000 else True
329
+ otaCheck = easyrtc . configure () if time .time () < 1482192000 else True
430
330
otaAvailable = splash_ota_check ()
431
331
else : # Normal boot
432
332
print ("[SPLASH] Normal boot..." )
433
- otaCheck = splash_ntp () if time .time () < 1482192000 else True
333
+ otaCheck = easyrtc . configure () if time .time () < 1482192000 else True
434
334
if (machine .reset_cause () != machine .DEEPSLEEP_RESET ) and otaCheck :
435
335
otaAvailable = splash_ota_check ()
436
336
else :
437
337
otaAvailable = badge .nvs_get_u8 ('badge' ,'OTA.ready' ,0 )
438
338
439
339
# Download resources to fatfs
440
340
splash_resources_check ()
441
-
442
- # Disable WiFi if active
443
- splash_wifi_disable ()
444
341
445
342
# Initialize services
446
343
services .setup ()
344
+
345
+ # Disable WiFi if active
346
+ easywifi .disable ()
447
347
448
348
# Initialize timer
449
349
splash_timer_init ()
0 commit comments