diff options
author | Javier <dev.git@javispedro.com> | 2025-08-24 18:15:57 +0200 |
---|---|---|
committer | Javier <dev.git@javispedro.com> | 2025-08-24 18:15:57 +0200 |
commit | e0311435a4cc96da9c1a990c6075f82c7d30e340 (patch) | |
tree | b51abc6cb094004f205e4a35204622fdc7db1af0 | |
parent | d98b141421a2f9325d748ad93361211e65603fce (diff) | |
download | ctbtw-master.tar.gz ctbtw-master.zip |
-rwxr-xr-x | ctbtw.py | 22 |
1 files changed, 18 insertions, 4 deletions
@@ -497,20 +497,25 @@ class SetFeatureReq(BTReq): return "SetFeatureReq(feature=%s,value=%r)"%(self.feature,self.value) class PairedDevice(NamedTuple): + """Tuple representing a paired bluetooth receiver.""" name: str addr: BTAddr class CTBTWDevice: + """Main class representing a transmitter device.""" # List of messages that can be received MSG_TYPES = [AckMsg, GetNumPairedDevicesMsg, GetPairedDeviceDetailsMsg, GetInquiryDataMsg, GetStateMsg, GetFeatureMsg] + # HID report number used to both receive/send messages REPORT_ID = 3 # Size of this report (hardcoded...) REPORT_SIZE = 64 + # This is the usage page for the above report_id, at least on BT-W6. Some platforms need this to be correct. + USAGE_PAGE = 0xFF01 # Vendor ID to search for - CT_VENDOR_ID = 0x041e + VENDOR_ID = 0x041e # Product IDs to search for. Hardcoded to [BT-W4, BT-W5, BT-W6] - CT_PRODUCT_IDS = [0x312B, 0x3130, 0x3132] + PRODUCT_IDS = [0x312B, 0x3130, 0x3132] def __init__(self, devpath, verbose=False): self._hid = hid.device() @@ -585,8 +590,10 @@ def codec_name(codec): return codec.name def find_device(): - for device in hid.enumerate(vendor_id=CTBTWDevice.CT_VENDOR_ID): - if device['vendor_id'] == CTBTWDevice.CT_VENDOR_ID and device['product_id'] in CTBTWDevice.CT_PRODUCT_IDS: + for device in hid.enumerate(vendor_id=CTBTWDevice.VENDOR_ID): + if (device['vendor_id'] == CTBTWDevice.VENDOR_ID and + device['product_id'] in CTBTWDevice.PRODUCT_IDS and + device['usage_page'] == CTBTWDevice.USAGE_PAGE): return device return None @@ -658,6 +665,13 @@ if __name__ == '__main__': verbose = args.verbose use_color = os.getenv("NO_COLOR", "") == "" and os.getenv("TERM") != "dumb" and sys.stdout.isatty() + if use_color: + try: + from colorama import just_fix_windows_console + just_fix_windows_console() + except Exception: + pass + devinfo = find_device() if not devinfo: print("Could not find device with valid vendor/product IDs") |