File tree Expand file tree Collapse file tree
CircuitPython_sdcardio_sdioio
Light_Paintstick_HalloWing
light_paintstick_hallowing
Nightlight/cpx_nightlight Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11import time
22import os
33
4- import mount_sd
54
65# First, just write the file 'hello.txt' to the card
7- with open ("/sd/hello.txt" , "w" ) as f : print ("hello world" , file = f )
6+ with open ("/sd/hello.txt" , "w" ) as f :
7+ print ("hello world" , file = f )
88
99print ()
1010print ("SD card I/O benchmarks" )
1616# time taken.
1717for sz in 512 , 4096 :
1818 b = bytearray (sz )
19- for i in range (sz ): b [i ] = 0xaa
19+ for i in range (sz ):
20+ b [i ] = 0xaa
2021 for n in (1 , 16 ):
2122 with open ("/sd/hello.bin" , "wb" ) as f :
2223 t0 = time .monotonic_ns ()
Original file line number Diff line number Diff line change 11import os
22
3- import mount_sd
4-
53def print_directory (path , tabs = 0 ):
64 for file in os .listdir (path ):
75 stats = os .stat (path + "/" + file )
Original file line number Diff line number Diff line change 33import board
44import digitalio
55import microcontroller
6- import mount_sd
76
87led = digitalio .DigitalInOut (board .D13 )
98led .direction = digitalio .Direction .OUTPUT
Original file line number Diff line number Diff line change 33
44import board
55import digitalio
6- import mount_sd
76
87# Updating the display can interfere with MP3 playback if it is not
98# done carefully
109try :
1110 board .DISPLAY .auto_refresh = False
12- except :
11+ except : # pylint: disable=bare-except
1312 pass
1413
15- from audiomp3 import MP3Decoder
14+ from audiomp3 import MP3Decoder # pylint: disable=wrong-import-position
1615
1716try :
1817 from audioio import AudioOut
Original file line number Diff line number Diff line change 44import board
55import displayio
66
7- import mount_sd
8-
97display = board .DISPLAY
108
119# The bmp files on the sd card will be shown in alphabetical order
Original file line number Diff line number Diff line change @@ -84,7 +84,6 @@ def read_le(value):
8484
8585class BMPError (Exception ):
8686 """Error handler for BMP-loading function"""
87- pass
8887
8988def load_bmp (filename ):
9089 """Load BMP file, return as list of column buffers"""
@@ -159,11 +158,11 @@ def load_bmp(filename):
159158
160159 except OSError as err :
161160 if err .args [0 ] == 28 :
162- raise OSError ("OS Error 28 0.25" )
163- else :
164- raise OSError ("OS Error 0.5" )
161+ raise OSError ("OS Error 28 0.25" ) from err
162+ raise OSError ("OS Error 0.5" ) from err
165163 except BMPError as err :
166- print ("Failed to parse BMP: " + err .args [0 ])
164+ raise BMPError ("Failed to parse BMP: " + err .args [0 ]) from err
165+
167166
168167
169168# Load BMP image, return 'columns' array:
Original file line number Diff line number Diff line change @@ -58,7 +58,6 @@ def read_le(value):
5858
5959class BMPError (Exception ):
6060 """Error handler for BMP-loading function"""
61- pass
6261
6362def load_bmp (filename ):
6463 """Load BMP file, return as list of column buffers"""
@@ -133,11 +132,10 @@ def load_bmp(filename):
133132
134133 except OSError as err :
135134 if err .args [0 ] == 28 :
136- raise OSError ("OS Error 28 0.25" )
137- else :
138- raise OSError ("OS Error 0.5" )
135+ raise OSError ("OS Error 28 0.25" ) from err
136+ raise OSError ("OS Error 0.5" ) from err
139137 except BMPError as err :
140- print ("Failed to parse BMP: " + err .args [0 ])
138+ raise BMPError ("Failed to parse BMP: " + err .args [0 ]) from err
141139
142140
143141# Load BMP image, return 'COLUMNS' array:
Original file line number Diff line number Diff line change 3737 # Indicate the nightlight is off.
3838 cp .red_led = True
3939 continue
40- else :
41- cp .red_led = False
40+ cp .red_led = False
4241
4342 # Decrease brightness.
4443 if cp .touch_A7 :
You can’t perform that action at this time.
0 commit comments