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
40 changes: 17 additions & 23 deletions respeaker/firmware/tuning.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def write(self, name, value):
return

if data[5] == 'ro':
raise ValueError('{} is read-only'.format(name))
raise ValueError(f'{name} is read-only')
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Tuning.write refactored with the following changes:


id = data[0]

Expand Down Expand Up @@ -106,14 +106,9 @@ def read(self, name):
usb.util.CTRL_IN | usb.util.CTRL_TYPE_VENDOR | usb.util.CTRL_RECIPIENT_DEVICE,
0, cmd, id, length, self.TIMEOUT)

response = struct.unpack(b'ii', response.tostring())
response = struct.unpack(b'ii', response.tobytes())

if data[2] == 'int':
result = response[0]
else:
result = response[0] * (2.**response[1])

return result
return response[0] if data[2] == 'int' else response[0] * (2.**response[1])
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Tuning.read refactored with the following changes:


def set_vad_threshold(self, db):
self.write('GAMMAVAD_SR', db)
Expand All @@ -139,20 +134,19 @@ def close(self):


def find(vid=0x2886, pid=0x0018):
dev = usb.core.find(idVendor=vid, idProduct=pid)
if not dev:
return
if dev := usb.core.find(idVendor=vid, idProduct=pid):
# configuration = dev.get_active_configuration()

# configuration = dev.get_active_configuration()
# interface_number = None
# for interface in configuration:
# interface_number = interface.bInterfaceNumber

# interface_number = None
# for interface in configuration:
# interface_number = interface.bInterfaceNumber
# if dev.is_kernel_driver_active(interface_number):
# dev.detach_kernel_driver(interface_number)

# if dev.is_kernel_driver_active(interface_number):
# dev.detach_kernel_driver(interface_number)

return Tuning(dev)
Comment on lines -142 to -155
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function find refactored with the following changes:

return Tuning(dev)
else:
return



Expand All @@ -165,7 +159,7 @@ def main():
data = PARAMETERS[name]
print('{:16}\t{}'.format(name, b'\t'.join([str(i) for i in data[2:7]])))
for extra in data[7:]:
print('{}{}'.format(' '*60, extra))
print(f"{' ' * 60}{extra}")
Comment on lines -168 to +162
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function main refactored with the following changes:

else:
dev = find()
if not dev:
Expand All @@ -184,10 +178,10 @@ def main():
if name in PARAMETERS:
if len(sys.argv) > 2:
dev.write(name, sys.argv[2])
print('{}: {}'.format(name, dev.read(name)))

print(f'{name}: {dev.read(name)}')
else:
print('{} is not a valid name'.format(name))
print(f'{name} is not a valid name')

dev.close()
else:
Expand Down