File tree Expand file tree Collapse file tree 1 file changed +18
-16
lines changed
micropython/examples/badger2040 Expand file tree Collapse file tree 1 file changed +18
-16
lines changed Original file line number Diff line number Diff line change 10
10
except OSError :
11
11
pass
12
12
13
- # Check that there is a qrcode.txt, if not preload
13
+ # Load all available QR Code Files
14
14
try :
15
- text = open ( "qrcodes/qrcode.txt" , "r" )
15
+ CODES = [ f for f in os . listdir ( "/qrcodes" ) if f . endswith ( ".txt" )]
16
16
except OSError :
17
- text = open ("qrcodes/qrcode.txt" , "w" )
18
- text .write ("""https://pimoroni.com/badger2040
17
+ CODES = []
18
+
19
+ # create demo QR code file if no QR code files exist
20
+ if len (CODES ) == 0 :
21
+ try :
22
+ newQRcodeFilename = "qrcode.txt"
23
+ text = open ("qrcodes/{}" .format (newQRcodeFilename ), "w" )
24
+ text .write ("""https://pimoroni.com/badger2040
19
25
Badger 2040
20
26
* 296x128 1-bit e-ink
21
27
* six user buttons
25
31
Scan this code to learn
26
32
more about Badger 2040.
27
33
""" )
28
- text .flush ()
29
- text .seek (0 )
34
+ text .flush ()
35
+ text .seek (0 )
30
36
31
- # Load all available QR Code Files
32
- try :
33
- CODES = [f for f in os .listdir ("/qrcodes" ) if f .endswith (".txt" )]
34
- TOTAL_CODES = len (CODES )
35
- except OSError :
36
- pass
37
+ # Set the CODES list to contain the newQRcodeFilename (created above)
38
+ CODES = [newQRcodeFilename ]
37
39
40
+ except :
41
+ CODES = []
38
42
39
- print (f'There are { TOTAL_CODES } QR Codes available:' )
40
- for codename in CODES :
41
- print (f'File: { codename } ' )
43
+ TOTAL_CODES = len (CODES )
42
44
43
45
display = badger2040 .Badger2040 ()
44
46
@@ -60,7 +62,7 @@ def set_state_current_index_in_range():
60
62
state ["current_qr" ] = 0
61
63
62
64
badger_os .state_save ("qrcodes" , state )
63
-
65
+
64
66
65
67
def measure_qr_code (size , code ):
66
68
w , h = code .get_size ()
You can’t perform that action at this time.
0 commit comments