@@ -180,6 +180,42 @@ def __init__(self, *, url=None, json_path=None, regexp_path=None,
180
180
except OSError :
181
181
self ._uselocal = False
182
182
183
+ if self ._debug :
184
+ print ("Init display" )
185
+ self .splash = displayio .Group (max_size = 5 )
186
+
187
+ if self ._debug :
188
+ print ("Init background" )
189
+ self ._bg_group = displayio .Group (max_size = 1 )
190
+ self ._bg_file = None
191
+ self ._default_bg = default_bg
192
+ self .splash .append (self ._bg_group )
193
+
194
+ # show thank you and bootup file if available
195
+ for bootscreen in ("/thankyou.bmp" , "/pyportal_startup.bmp" ):
196
+ try :
197
+ os .stat (bootscreen )
198
+ board .DISPLAY .show (self .splash )
199
+ for i in range (100 , - 1 , - 1 ): # dim down
200
+ self .set_backlight (i / 100 )
201
+ time .sleep (0.005 )
202
+ self .set_background (bootscreen )
203
+ board .DISPLAY .wait_for_frame ()
204
+ for i in range (100 ): # dim up
205
+ self .set_backlight (i / 100 )
206
+ time .sleep (0.005 )
207
+ time .sleep (2 )
208
+ except OSError :
209
+ pass # they removed it, skip!
210
+
211
+ self ._speaker_enable = DigitalInOut (board .SPEAKER_ENABLE )
212
+ self ._speaker_enable .switch_to_output (False )
213
+ self .audio = audioio .AudioOut (board .AUDIO_OUT )
214
+ try :
215
+ self .play_file ("pyportal_startup.wav" )
216
+ except OSError :
217
+ pass # they deleted the file, no biggie!
218
+
183
219
# Make ESP32 connection
184
220
if self ._debug :
185
221
print ("Init ESP32" )
@@ -207,6 +243,9 @@ def __init__(self, *, url=None, json_path=None, regexp_path=None,
207
243
requests .set_interface (self ._esp )
208
244
self ._connect_esp ()
209
245
246
+ # set the default background
247
+ self .set_background (self ._default_bg )
248
+
210
249
if self ._debug :
211
250
print ("Init SD Card" )
212
251
sd_cs = DigitalInOut (board .SD_CS )
@@ -218,27 +257,6 @@ def __init__(self, *, url=None, json_path=None, regexp_path=None,
218
257
except OSError as error :
219
258
print ("No SD card found:" , error )
220
259
221
- self ._speaker_enable = DigitalInOut (board .SPEAKER_ENABLE )
222
- self ._speaker_enable .switch_to_output (False )
223
- self .audio = audioio .AudioOut (board .AUDIO_OUT )
224
-
225
- try :
226
- self .play_file ("pyportal_startup.wav" )
227
- except OSError :
228
- pass # they deleted the file, no biggie!
229
-
230
- if self ._debug :
231
- print ("Init display" )
232
- self .splash = displayio .Group (max_size = 5 )
233
- board .DISPLAY .show (self .splash )
234
-
235
- if self ._debug :
236
- print ("Init background" )
237
- self ._bg_group = displayio .Group (max_size = 1 )
238
- self ._bg_file = None
239
- self ._default_bg = default_bg
240
- self .set_background (self ._default_bg )
241
- self .splash .append (self ._bg_group )
242
260
243
261
self ._qr_group = None
244
262
@@ -573,12 +591,13 @@ def _connect_esp(self):
573
591
# secrets dictionary must contain 'ssid' and 'password' at a minimum
574
592
print ("Connecting to AP" , secrets ['ssid' ])
575
593
if secrets ['ssid' ] == 'CHANGE ME' or secrets ['ssid' ] == 'CHANGE ME' :
576
- print ("*" * 45 )
577
- print ("Please update the 'secrets.py' file on your" )
578
- print ("CIRCUITPY drive to include your local access" )
579
- print ("point SSID name in 'ssid' and SSID password" )
580
- print ("in 'password'. Then save to reload!" )
581
- print ("*" * 45 )
594
+ change_me = "\n " + "*" * 45
595
+ change_me += "\n Please update the 'secrets.py' file on your\n "
596
+ change_me += "CIRCUITPY drive to include your local WiFi\n "
597
+ change_me += "access point SSID name in 'ssid' and SSID\n "
598
+ change_me += "password in 'password'. Then save to reload!\n "
599
+ change_me += "*" * 45
600
+ raise OSError (change_me )
582
601
self .neo_status ((100 , 0 , 0 )) # red = not connected
583
602
try :
584
603
self ._esp .connect (secrets )
@@ -720,7 +739,8 @@ def fetch(self):
720
739
if self ._text_wrap [i ]:
721
740
if self ._debug :
722
741
print ("Wrapping text" )
723
- string = '\n ' .join (PyPortal .wrap_nicely (string , self ._text_wrap [i ]))
742
+ lines = PyPortal .wrap_nicely (string , self ._text_wrap [i ])
743
+ string = '\n ' .join (lines )
724
744
self .set_text (string , index = i )
725
745
if len (values ) == 1 :
726
746
return values [0 ]
@@ -810,6 +830,7 @@ def wrap_nicely(string, max_chars):
810
830
:param int max_chars: The maximum number of characters on a line before wrapping.
811
831
812
832
"""
833
+ string = string .replace ('\n ' , '' ).replace ('\r ' , '' ) # strip confusing newlines
813
834
words = string .split (' ' )
814
835
the_lines = []
815
836
the_line = ""
@@ -821,4 +842,6 @@ def wrap_nicely(string, max_chars):
821
842
the_line = '' + w
822
843
if the_line : # last line remaining
823
844
the_lines .append (the_line )
845
+ # remove first space from first line:
846
+ the_lines [0 ] = the_lines [0 ][1 :]
824
847
return the_lines
0 commit comments