@@ -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
@@ -318,7 +336,7 @@ def __init__(self, *, url=None, json_path=None, regexp_path=None,
318
336
319
337
gc .collect ()
320
338
321
- def set_background (self , file_or_color ):
339
+ def set_background (self , file_or_color , position = None ):
322
340
"""The background image to a bitmap file.
323
341
324
342
:param file_or_color: The filename of the chosen background image, or a hex color.
@@ -328,6 +346,9 @@ def set_background(self, file_or_color):
328
346
while self ._bg_group :
329
347
self ._bg_group .pop ()
330
348
349
+ if not position :
350
+ position = (0 , 0 ) # default in top corner
351
+
331
352
if not file_or_color :
332
353
return # we're done, no background desired
333
354
if self ._bg_file :
@@ -337,7 +358,7 @@ def set_background(self, file_or_color):
337
358
background = displayio .OnDiskBitmap (self ._bg_file )
338
359
self ._bg_sprite = displayio .TileGrid (background ,
339
360
pixel_shader = displayio .ColorConverter (),
340
- position = ( 0 , 0 ) )
361
+ position = position )
341
362
elif isinstance (file_or_color , int ):
342
363
# Make a background color fill
343
364
color_bitmap = displayio .Bitmap (320 , 240 , 1 )
@@ -570,12 +591,13 @@ def _connect_esp(self):
570
591
# secrets dictionary must contain 'ssid' and 'password' at a minimum
571
592
print ("Connecting to AP" , secrets ['ssid' ])
572
593
if secrets ['ssid' ] == 'CHANGE ME' or secrets ['ssid' ] == 'CHANGE ME' :
573
- print ("*" * 45 )
574
- print ("Please update the 'secrets.py' file on your" )
575
- print ("CIRCUITPY drive to include your local access" )
576
- print ("point SSID name in 'ssid' and SSID password" )
577
- print ("in 'password'. Then save to reload!" )
578
- 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 )
579
601
self .neo_status ((100 , 0 , 0 )) # red = not connected
580
602
try :
581
603
self ._esp .connect (secrets )
@@ -688,7 +710,7 @@ def fetch(self):
688
710
except OSError as error :
689
711
print (error )
690
712
raise OSError ("""\n \n No writable filesystem found for saving datastream. Insert an SD card or set internal filesystem to be unsafe by setting 'disable_concurrent_write_protection' in the mount options in boot.py""" ) # pylint: disable=line-too-long
691
- self .set_background (filename )
713
+ self .set_background (filename , self . _image_position )
692
714
except ValueError as error :
693
715
print ("Error displaying cached image. " + error .args [0 ])
694
716
self .set_background (self ._default_bg )
@@ -717,7 +739,8 @@ def fetch(self):
717
739
if self ._text_wrap [i ]:
718
740
if self ._debug :
719
741
print ("Wrapping text" )
720
- 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 )
721
744
self .set_text (string , index = i )
722
745
if len (values ) == 1 :
723
746
return values [0 ]
@@ -807,6 +830,7 @@ def wrap_nicely(string, max_chars):
807
830
:param int max_chars: The maximum number of characters on a line before wrapping.
808
831
809
832
"""
833
+ string = string .replace ('\n ' , '' ).replace ('\r ' , '' ) # strip confusing newlines
810
834
words = string .split (' ' )
811
835
the_lines = []
812
836
the_line = ""
@@ -818,4 +842,6 @@ def wrap_nicely(string, max_chars):
818
842
the_line = '' + w
819
843
if the_line : # last line remaining
820
844
the_lines .append (the_line )
845
+ # remove first space from first line:
846
+ the_lines [0 ] = the_lines [0 ][1 :]
821
847
return the_lines
0 commit comments