Skip to content

Commit

Permalink
Clean up CM108 GPIO PTT code
Browse files Browse the repository at this point in the history
  • Loading branch information
AG7GN committed Jun 16, 2023
1 parent ac92a64 commit de3dca1
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 17 deletions.
2 changes: 1 addition & 1 deletion 710.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
__copyright__ = "Copyright 2023, Steve Magnuson"
__credits__ = ["Steve Magnuson"]
__license__ = "GPL v3.0"
__version__ = "2.3.0"
__version__ = "2.3.1"
__maintainer__ = "Steve Magnuson"
__email__ = "ag7gn@arrl.net"
__status__ = "Production"
Expand Down
33 changes: 17 additions & 16 deletions cat710.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
__copyright__ = "Copyright 2022, Steve Magnuson"
__credits__ = ["Steve Magnuson"]
__license__ = "GPL v3.0"
__version__ = "2.0.6"
__version__ = "2.0.7"
__maintainer__ = "Steve Magnuson"
__email__ = "ag7gn@arrl.net"
__status__ = "Production"
Expand Down Expand Up @@ -101,17 +101,17 @@ def __init__(self, pin: int):
# Product IDs with known GPIO capability from the CM1xx family
self.product_ids = (0x8, 0x9, 0xa, 0xb, 0xc, 0xd, 0xe, 0xf,
0x139, 0x12, 0x13, 0x13a, 0x13c)
self.product_id = None
for device_dict in hid.enumerate():
if self.vendor_id in device_dict.values():
if device_dict['product_id'] in self.product_ids:
self.product_id = device_dict['product_id']
# print(f"{stamp()}: Found CM108 device "
# f"0x{self.vendor_id:04x}:0x{self.product_id:04x}",
# file=sys.stderr)
break
if self.product_id is None:
print(f"{stamp()}: No CM108 device with GPIO found", file=sys.stderr)
self.path = None
for device_dict in hid.enumerate(vendor_id=self.vendor_id):
if device_dict['product_id'] in self.product_ids:
self.path = device_dict['path']
# There is no way to identify the cheap SYBA CM1xx
# USB sound cards because there is no serial number.
# So, use the first CM1xx sound card we find.
break
if self.path is None:
print(f"{stamp()}: No CM1xx sound device with GPIO found",
file=sys.stderr)
return
else:
self.device = hid.device()
Expand All @@ -123,18 +123,19 @@ def __init__(self, pin: int):

def _open(self) -> bool:
try:
self.device.open(self.vendor_id, self.product_id)
self.device.open_path(self.path)
except (OSError, IOError) as e:
print(f"{stamp()}: Unable to open CM108 device "
f"0x{self.vendor_id:04x}:0x{self.product_id:04x}: {e}",
print(f"{stamp()}: Unable to open CM1xx sound device "
f"at path {self.path}: {e}",
file=sys.stderr)
return False
else:
self.device.set_nonblocking(1)
return True

def _close(self):
self.device.close()
if self.device is not None:
self.device.close()

def on(self):
if self._open():
Expand Down

0 comments on commit de3dca1

Please sign in to comment.