Skip to content

Commit 16270af

Browse files
authored
Update boot.py
Buttons working instantly for CD, "loading..." screen for cd, previous button returning to 0:0 if you are further in song, faster menu refresh time. Next thing planned is writing a function to update only changed parts of display
1 parent f708b22 commit 16270af

File tree

1 file changed

+50
-15
lines changed

1 file changed

+50
-15
lines changed

boot.py

Lines changed: 50 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -201,10 +201,9 @@ def PlayCd(conn):
201201
while True:
202202
dump = conn.recv()
203203
index = medialist.index_of_item(listplayer.get_media_player().get_media())
204-
conn.send([index+1, i_tracks, track_list[index], artists[index], album, MsToTime(player.get_time(), player.get_length()), player.get_state()])
205204
match dump:
206205
case 0:
207-
pass
206+
conn.send([index+1, i_tracks, track_list[index], artists[index], album, MsToTime(player.get_time(), player.get_length()), player.get_state()])
208207
#case 1:
209208
#listplayer.play()
210209
case 2:
@@ -219,8 +218,10 @@ def PlayCd(conn):
219218
listplayer.next()
220219
#last_scrobble=""
221220
case 5:
222-
listplayer.previous()
223-
#last_scrobble=""
221+
if(player.get_position()>0.4):
222+
player.set_position(0)
223+
else:
224+
listplayer.previous()
224225
if((player.get_position()*100 > 50) and last_scrobble != track_list[index]):
225226
last_scrobble= track_list[index]
226227
try:
@@ -274,19 +275,51 @@ class DeviceNotFoundError(Exception):
274275
def __init__(self):
275276
super().__init__('No music bluetooth device was found')
276277

278+
def next(event):
279+
global run, command
280+
match page:
281+
case 0:
282+
if(not run):
283+
command = 4
284+
else:
285+
parent_conn.send(4)
286+
case 1:
287+
288+
command = 4
289+
def back(event):
290+
global run, command
291+
match page:
292+
case 0:
293+
if(not run):
294+
command = 5
295+
else:
296+
parent_conn.send(5)
297+
case 1:
298+
299+
command = 5
300+
def stop(event):
301+
global run, command
302+
match page:
303+
case 0:
304+
parent_conn.send(3)
305+
case 1:
306+
command = 3
307+
def pause(event):
308+
global run, command
309+
match page:
310+
case 0:
311+
parent_conn.send(2)
312+
case 1:
313+
command = 2
277314

278-
279-
GPIO.add_event_detect(BUTTONS["Right"], GPIO.FALLING, callback=lambda event: globals().update(command = 4), bouncetime=1000) #forward
280-
GPIO.add_event_detect(BUTTONS["Left"], GPIO.FALLING, callback=lambda event: globals().update(command = 5), bouncetime=1000) #previous
281-
GPIO.add_event_detect(BUTTONS["Down"], GPIO.FALLING, callback=lambda event: globals().update(command = 3), bouncetime=1000) #stop
282-
GPIO.add_event_detect(BUTTONS["Up"], GPIO.FALLING, callback=lambda event: globals().update(command = 2), bouncetime=1000) #pause
315+
GPIO.add_event_detect(BUTTONS["Right"], GPIO.FALLING, callback=next, bouncetime=100) #forward
316+
GPIO.add_event_detect(BUTTONS["Left"], GPIO.FALLING, callback=back, bouncetime=100) #previous
317+
GPIO.add_event_detect(BUTTONS["Down"], GPIO.FALLING, callback=stop, bouncetime=100) #stop
318+
GPIO.add_event_detect(BUTTONS["Up"], GPIO.FALLING, callback=pause, bouncetime=100) #pause
283319
#GPIO.add_event_detect(BUTTONS[4], GPIO.FALLING, callback=lambda event: globals().update(command = 1), bouncetime=1000) #play
284-
GPIO.add_event_detect(BUTTONS["Middle"], GPIO.FALLING, callback=lambda event: globals().update(command = -1), bouncetime=1000) #off
320+
GPIO.add_event_detect(BUTTONS["Middle"], GPIO.FALLING, callback=lambda event: globals().update(command = -1), bouncetime=100) #off
285321

286322
parent_conn, child_conn = Pipe()
287-
cdplayer = Process(target=PlayCd, args=(child_conn,))
288-
289-
290323
lcd.clear()
291324

292325
while True:
@@ -309,6 +342,8 @@ def __init__(self):
309342
lcd.clear()
310343
lcd.message = "CD Player"
311344
if(run):
345+
lcd.clear()
346+
lcd.message = "Loading..."
312347
cdplayer = Process(target=PlayCd, args=(child_conn,))
313348
cdplayer.start()
314349
time.sleep(5)
@@ -318,7 +353,7 @@ def __init__(self):
318353
cdplayer.join()
319354
run = False
320355
elif cdplayer.is_alive():
321-
parent_conn.send(command)
356+
parent_conn.send(0)#you must send to recive
322357
time.sleep(0.1)
323358
dump=parent_conn.recv()
324359
if(dump[6] == vlc.State.Ended):
@@ -360,5 +395,5 @@ def __init__(self):
360395
run=False
361396
command = 0
362397
time.sleep(1)
363-
time.sleep(1)
398+
time.sleep(0.5)
364399

0 commit comments

Comments
 (0)