Skip to content

Commit

Permalink
Updated version to 0.8.1 to capture minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelgale committed Aug 5, 2021
1 parent b8c1124 commit 280b83e
Show file tree
Hide file tree
Showing 8 changed files with 118 additions and 22 deletions.
2 changes: 1 addition & 1 deletion pfxbrick/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

# fmt: off
__project__ = 'pfxbrick'
__version__ = '0.8.0'
__version__ = '0.8.1'
# fmt: on

VERSION = __project__ + "-" + __version__
Expand Down
13 changes: 9 additions & 4 deletions pfxbrick/pfxconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -324,12 +324,17 @@ def __repr__(self):
return s

def __str__(self):
os = ""
ds = ""
if self.audioDRC:
os = "ON"
ds = "ON"
else:
os = "OFF"
s = "Audio DRC: %s Bass: 0x%02X Treble: 0x%02X" % (os, self.bass, self.treble)
ds = "OFF"
s = "Default Vol: 0x%02X Audio DRC: %s Bass: 0x%02X Treble: 0x%02X" % (
self.defaultVolume,
ds,
self.bass,
self.treble,
)
return s


Expand Down
5 changes: 4 additions & 1 deletion pfxbrick/pfxfiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,8 @@ def fs_copy_file_from(
:param boolean show_progress: a flag to show the progress bar indicator during transfer.
"""
msg = [PFX_CMD_FILE_OPEN]
if pfile is None:
return None
msg.append(pfile.id)
msg.append(0x01) # READ mode
res = usb_transaction(hdev, msg)
Expand Down Expand Up @@ -407,14 +409,15 @@ def __str__(self):
attr_str = file_attr_dict[self.attributes]
elif self.id in fileid_dict:
attr_str = fileid_dict[self.id]
s = "%3d %-24s %6.1f kB %04X %08X %08X %08X %02X %s" % (
s = "%3d %-24s %6.1f kB %04X %08X %08X %08X %04X %02X %s" % (
self.id,
self.name,
float(self.size / 1000),
self.attributes,
self.userData1,
self.userData2,
self.crc32,
self.firstSector,
self.id,
attr_str,
)
Expand Down
17 changes: 13 additions & 4 deletions pfxbrick/scripts/pfxcat.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
#! /usr/bin/env python3
import tempfile
from sys import argv

from pfxbrick import *

TMP_FILE = tempfile.gettempdir() + os.sep + "pfxdump.dat"

if __name__ == "__main__":
if len(argv) < 2 or argv[1] == "-h":
Expand All @@ -17,9 +19,16 @@
b.refresh_file_dir()
f = str(argv[1])
if f.isnumeric():
f = int(argv[1])
fid = b.file_id_from_str_or_int(f)
fid = int(f)
else:
fid = b.file_id_from_str_or_int(f)
as_bytes = True if len(argv) == 3 else False
f = b.filedir.get_file_dir_entry(fid)
fs_copy_file_from(b.dev, f, show_progress=False, as_bytes=as_bytes, to_console=True)
fd = b.filedir.get_file_dir_entry(fid)
if fd is not None:
fs_copy_file_from(
b.dev, fd, TMP_FILE, show_progress=False, as_bytes=as_bytes, to_console=True
)
os.remove(TMP_FILE)
else:
print("File %s not found" % (argv[1]))
b.close()
57 changes: 57 additions & 0 deletions pfxbrick/scripts/pfxfat.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
from rich import print
from pfxbrick import *

if __name__ == "__main__":
b = PFxBrick()
b.open()
r = b.open()
if not r:
exit()
rb = flash_read(b, 0xFFC000, 4096)
b.close()
print(len(rb))
x = []
for i in range(0, len(rb) - 1, 2):
x.append(rb[i + 1])
x.append(rb[i])

a = 0
s = []
ads = "[bold white]%06X[/] " % (a)
s.append("%s " % (ads))
for i, b in enumerate(x):
if (i % 2) == 0:
if x[i] == 0xFF and x[i + 1] == 0xFF:
cs = "[bold red]"
elif x[i] == 0xFF and x[i + 1] == 0xFE:
cs = "[bold magenta]"
elif x[i] == 0xFF and x[i + 1] == 0xF3:
cs = "[green]"
elif x[i] == 0xFF and x[i + 1] == 0xF1:
cs = "[bold orange3]"
elif x[i] == 0xFF and x[i + 1] == 0xF7:
cs = "[bold yellow]"
elif i > 1:
if abs(int(x[i + 1]) - int(x[i - 1])) > 1:
cs = "[bold cyan]"
else:
cs = "[bold white]"
else:
cs = "[bold white]"
s.append("%s%02X[/]" % (cs, b))
if (i + 1) % 2 == 0 and i > 0:
s.append(" ")
if (i + 1) % 16 == 0 and i > 0:
s.append(" ")
if (i + 1) % 32 == 0 and i > 0:
a += 16
ads = "[bold white]%06X[/] " % (a)
s.append("\n")
s.append("%s " % (ads))
nb = len(x) % 32
if nb:
for i in range(32 - nb + 1):
s.append(" ")
else:
s.pop()
print("".join(s))
22 changes: 16 additions & 6 deletions pfxbrick/scripts/pfxput.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,22 @@
#! /usr/bin/env python3
from sys import argv
from toolbox import *
from pfxbrick import *


def full_path(file):
"""Returns the fully expanded path of a file"""
if "~" in str(file):
return os.path.expanduser(file)
return os.path.expanduser(os.path.abspath(file))


def split_path(file):
"""Returns a tuple containing a file's (directory, name.ext)"""
if os.path.isdir(file):
return full_path(file), None
return os.path.split(full_path(file))


if __name__ == "__main__":
if len(argv) < 2 or argv[1] == "-h":
print("Usage: pfxput.py file id")
Expand All @@ -23,18 +36,15 @@
fid = int(argv[2])
if b.filedir.has_file(fid):
print("Replacing file %d on PFx Brick..." % (fid))
b.remove_file(fid)
else:
print("Copying file %s as %d to PFx Brick..." % (fn, fid))

else:
fid = b.filedir.find_available_file_id()
if b.filedir.has_file(fn):
fod = b.file_id_from_str_or_int(fn)
fid = b.file_id_from_str_or_int(fn)
print("Replacing file %s on PFx Brick..." % (fn))
b.remove_file(fod)
fid = fod
else:
fid = b.filedir.find_available_file_id()
print("Copying file %s to PFx Brick..." % (fn))

b.put_file(ff, fid)
Expand Down
23 changes: 17 additions & 6 deletions pfxbrick/scripts/pfxtest.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
from rich.console import Console
from rich.table import Table

from toolbox import *
from pfxbrick.pfxtesthelpers import *
from pfxbrick.pfxtestdata import *
from pfxbrick import *
Expand All @@ -22,6 +21,20 @@
TMP_FILE = tempfile.gettempdir() + os.sep + "test_script.txt"


def full_path(file):
"""Returns the fully expanded path of a file"""
if "~" in str(file):
return os.path.expanduser(file)
return os.path.expanduser(os.path.abspath(file))


def split_path(file):
"""Returns a tuple containing a file's (directory, name.ext)"""
if os.path.isdir(file):
return full_path(file), None
return os.path.split(full_path(file))


def copy_script_file(brick, text):
file = full_path(TMP_FILE)
fp, fn = split_path(file)
Expand Down Expand Up @@ -250,15 +263,14 @@ def do_test_script_events(brick, fid):


def test_scripts(brick):
fs = FileOps()
for test in SCRIPT_TESTS:
fid = copy_script_file(brick, test[0])
time.sleep(0.2)
result = test[1](brick, fid)
test_result("Executed test script [cyan]%s[/]" % (test[2]), result)
brick.remove_file(fid)
time.sleep(1)
fs.remove_file(full_path(TMP_FILE))
os.remove(TMP_FILE)


def snapshot_config(brick):
Expand Down Expand Up @@ -569,7 +581,6 @@ def test_motor_channel(brick, ch, speed):


def test_file_transfer(fdata, fid=0, fn="test_data.wav"):
fs = FileOps()
bindata = base64.b64decode(fdata)
with open(fn, "wb") as f:
f.write(bindata)
Expand All @@ -592,8 +603,8 @@ def test_file_transfer(fdata, fid=0, fn="test_data.wav"):
test_result(
"Read back file %s CRC32=0x%08X" % (fnr, read_crc32), crc32 == read_crc32
)
fs.remove_file(fn)
fs.remove_file(fnr)
os.remove(fn)
os.remove(fnr)


def test_banner(title):
Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,5 +73,6 @@ def build_description():
"pfxbrick/scripts/pfxinfo.py",
"pfxbrick/scripts/pfxplay.py",
"pfxbrick/scripts/pfxrun.py",
"pfxbrick/scripts/pfxfat.py",
],
)

0 comments on commit 280b83e

Please sign in to comment.