1616
1717import board
1818import digitalio
19- import microcontroller
2019
2120settings = {}
2221
2322with open ("/settings.txt" , "r" ) as F :
2423 for line in F :
25- k , v = line .replace ("\n " ,"" ).split (',' )
24+ k , v = line .replace ("\n " , "" ).split ("," )
2625 print (k , v )
2726 settings [k ] = v
2827
29- MODE = settings [' mode' ]
30- if settings [' delay' ] == ' RNDM' :
31- DELAY_TIME = settings [' delay' ]
28+ MODE = settings [" mode" ]
29+ if settings [" delay" ] == " RNDM" :
30+ DELAY_TIME = settings [" delay" ]
3231else :
33- DELAY_TIME = int (settings [' delay' ])
34- PB = float (settings ['pb' ])
35- PAR = float (settings [' par' ])
36- SENSITIVITY = int (settings [' sensitivity' ])
32+ DELAY_TIME = int (settings [" delay" ])
33+ PB = float (settings ["pb" ])
34+ PAR = float (settings [" par" ])
35+ SENSITIVITY = int (settings [" sensitivity" ])
3736
3837
3938gc .enable ()
102101group .append (mode_label )
103102
104103
105-
106104def normalized_rms (values ):
107- """ Gets the normalized RMS of the mic samples """
105+ """Gets the normalized RMS of the mic samples"""
108106 minbuf = int (sum (values ) / len (values ))
109107 samples_sum = sum (float (sample - minbuf ) * (sample - minbuf ) for sample in values )
110108
111109 return (samples_sum / len (values )) ** 0.5
112110
113111
114112def picker (current ):
115- """ Displays screen allowing user to set a time """
113+ """Displays screen allowing user to set a time"""
116114 pick [0 ].text , pick [1 ].text , pick [2 ].text , pick [3 ].text = list (
117115 current .replace ("." , "" )
118116 )
@@ -164,7 +162,8 @@ def rect_maker(shots):
164162 rects .append (rectangle )
165163 return rects
166164
167- def shot_label_maker (shots , grp ):
165+
166+ def shot_label_maker (grp ):
168167 txt = ""
169168
170169 for i , j in enumerate (shot_list ):
@@ -173,15 +172,25 @@ def shot_label_maker(shots, grp):
173172 else :
174173 split = j - shot_list [i - 1 ]
175174 txt = txt + f"{ i + 1 :02} \t { j :05.2f} \t { split :05.2f} \n "
176- grp .append (label .Label (font = arial18 , anchored_position = (120 , 3 ), text = txt [:- 1 ], color = 0xFFFFFF , line_spacing = 0.82 , anchor_point = (0.5 , 0 )))
175+ grp .append (
176+ label .Label (
177+ font = arial18 ,
178+ anchored_position = (120 , 3 ),
179+ text = txt [:- 1 ],
180+ color = 0xFFFFFF ,
181+ line_spacing = 0.82 ,
182+ anchor_point = (0.5 , 0 ),
183+ )
184+ )
177185 gc .collect ()
178186 return grp
179187
188+
180189def show_shot_list (shots , disp ):
181190 done = False
182191
183192 shot_group = rect_maker (shots )
184- shot_group = shot_label_maker (shots , shot_group )
193+ shot_group = shot_label_maker (shot_group )
185194 disp .show (shot_group )
186195
187196 tracker = 10
@@ -213,7 +222,9 @@ def show_shot_list(shots, disp):
213222 gc .collect ()
214223
215224
216- def menu_mode (mode , delay_time , sensitivity , pb , par , length , submenus ):
225+ def menu_mode (
226+ mode , delay_time , sensitivity_ , pb , par , length_ , submenus_
227+ ): # pylint: disable=too-many-branches,too-many-statements
217228 selected = int (menu [0 ].y / 40 ) + 1
218229 display .show (menu )
219230 display .refresh ()
@@ -222,7 +233,7 @@ def menu_mode(mode, delay_time, sensitivity, pb, par, length, submenus):
222233 pass
223234 done = False
224235 while not done :
225- if not button_a .value and selected < length :
236+ if not button_a .value and selected < length_ :
226237 started = time .monotonic ()
227238 while not button_a .value :
228239 if time .monotonic () - started > 1 :
@@ -233,9 +244,9 @@ def menu_mode(mode, delay_time, sensitivity, pb, par, length, submenus):
233244 else :
234245 page_ = menu
235246 selected = int (page_ [0 ].y / 40 ) + 1
236- length = len (page_ ) - 1
247+ length_ = len (page_ ) - 1
237248 display .show (page_ )
238- submenus = main_menu_opts
249+ submenus_ = main_menu_opts
239250 display .refresh ()
240251 break
241252 else :
@@ -261,7 +272,7 @@ def menu_mode(mode, delay_time, sensitivity, pb, par, length, submenus):
261272 while not button_a .value :
262273 pass
263274
264- if not button_a .value and selected == length and not done :
275+ if not button_a .value and selected == length_ and not done :
265276 started = time .monotonic ()
266277 while not button_a .value :
267278 if time .monotonic () - started > 1 :
@@ -272,9 +283,9 @@ def menu_mode(mode, delay_time, sensitivity, pb, par, length, submenus):
272283 else :
273284 page_ = menu
274285 selected = int (page_ [0 ].y / 40 ) + 1
275- length = len (page_ ) - 1
286+ length_ = len (page_ ) - 1
276287 display .show (page_ )
277- submenus = main_menu_opts
288+ submenus_ = main_menu_opts
278289 display .refresh ()
279290 break
280291 else :
@@ -301,10 +312,10 @@ def menu_mode(mode, delay_time, sensitivity, pb, par, length, submenus):
301312 pass
302313
303314 if not button_b .value :
304- if isinstance (submenus [1 ], list ):
305- if submenus [0 ] == mode :
306- mode = submenus [1 ][selected - 1 ]
307- submenus [0 ] = mode
315+ if isinstance (submenus_ [1 ], list ):
316+ if submenus_ [0 ] == mode :
317+ mode = submenus_ [1 ][selected - 1 ]
318+ submenus_ [0 ] = mode
308319 if mode == "PB" :
309320 pb = picker (f"{ PB :05.2f} " )
310321 mode_label .text = f"{ mode } { pb } "
@@ -319,28 +330,28 @@ def menu_mode(mode, delay_time, sensitivity, pb, par, length, submenus):
319330 display .refresh ()
320331 else :
321332 mode_label .text = mode
322- if submenus [0 ] == delay_time and len (submenus [1 ]) == 5 :
323- delay_time = submenus [1 ][selected - 1 ]
324- submenus [0 ] = delay_time
333+ if submenus_ [0 ] == delay_time and len (submenus_ [1 ]) == 5 :
334+ delay_time = submenus_ [1 ][selected - 1 ]
335+ submenus_ [0 ] = delay_time
325336 delay .text = f"Delay: { delay_time } "
326- if submenus [0 ] == sensitivity and len (submenus [1 ]) == 6 :
327- sensitivity = submenus [1 ][selected - 1 ]
328- submenus [0 ] = sensitivity
329- sens .text = f"{ sensitivity } "
337+ if submenus_ [0 ] == sensitivity_ and len (submenus_ [1 ]) == 6 :
338+ sensitivity_ = submenus_ [1 ][selected - 1 ]
339+ submenus_ [0 ] = sensitivity_
340+ sens .text = f"{ sensitivity_ } "
330341 for i in page_ :
331342 i .color = 0xFFFFFF
332343 page_ [selected ].color = 0x00FF00
333344 else :
334- page_ = submenus [selected - 1 ]
335- submenus = page_opts [selected - 1 ]
345+ page_ = submenus_ [selected - 1 ]
346+ submenus_ = page_opts [selected - 1 ]
336347 selected = int (page_ [0 ].y / 40 ) + 1
337- length = len (page_ ) - 1
348+ length_ = len (page_ ) - 1
338349 display .show (page_ )
339350 while not button_b .value :
340351 pass
341352
342353 display .refresh ()
343- return mode , delay_time , sensitivity , pb , par
354+ return mode , delay_time , sensitivity_ , pb , par
344355
345356
346357def label_maker (txt , grp , font , x , y , x_step = 0 , y_step = 0 , anchor = None , padding = 0 ):
@@ -366,6 +377,7 @@ def label_maker(txt, grp, font, x, y, x_step=0, y_step=0, anchor=None, padding=0
366377 )
367378 return grp
368379
380+
369381mode_opts = [MODE , ["Default" , "PB" , "Par" ]]
370382
371383delay_opts = [DELAY_TIME , [0 , 1 , 3 , 5 , "RNDM" ]]
@@ -445,11 +457,11 @@ def label_maker(txt, grp, font, x, y, x_step=0, y_step=0, anchor=None, padding=0
445457length = len (page ) - 1
446458
447459mic = audiobusio .PDMIn (
448- board .MICROPHONE_CLOCK ,
449- board .MICROPHONE_DATA ,
450- sample_rate = 16000 ,
451- bit_depth = 16 ,
452- )
460+ board .MICROPHONE_CLOCK ,
461+ board .MICROPHONE_DATA ,
462+ sample_rate = 16000 ,
463+ bit_depth = 16 ,
464+ )
453465
454466sensitivity_settings = [8000 , 10000 , 15000 , 20000 , 25000 , 30000 ]
455467
@@ -491,7 +503,9 @@ def label_maker(txt, grp, font, x, y, x_step=0, y_step=0, anchor=None, padding=0
491503 print ("SHOT" )
492504 shot_time = round (time .monotonic () - start , 2 )
493505 if len (shot_list ) != 0 :
494- shot_num .text = f"#{ SHOTS } SPL { shot_time - shot_list [- 1 ]:05.2f} "
506+ shot_num .text = (
507+ f"#{ SHOTS } SPL { shot_time - shot_list [- 1 ]:05.2f} "
508+ )
495509 else :
496510 shot_num .text = f"#{ SHOTS } SPL { shot_time :05.2f} "
497511 main_time .text = f"{ shot_time :05.2f} "
0 commit comments