Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions dfplayermini.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import utime
import ubinascii
from machine import UART, Timer

IDLE = 0
Expand Down Expand Up @@ -44,6 +45,21 @@ def play(self, track_id=False):
elif isinstance(track_id, int):
self.cmd(0x03, track_id)

def num_tracks_sd(self):
print(f'throw away current serial input buffer: {self.uart.read()}')
self.cmd(0x48)
utime.sleep(0.5)
response = self.uart.read()
# TODO:
# - error handling for sd card communication
# - properly parse response with correct opcode
# instead of just throwing them away and guessing
# that the number is in between 7eff0648 and fea8ef
# with typical response being b'7eff064800000bfea8ef'
# where the number of tracks on the SD card is
# '00000b' in hex (11 in decimal)
return int(ubinascii.hexlify(response)[8:-6], 16)

def pause(self):
self.cmd(0x0E)

Expand Down