summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJavier <dev.git@javispedro.com>2025-08-24 18:15:57 +0200
committerJavier <dev.git@javispedro.com>2025-08-24 18:15:57 +0200
commite0311435a4cc96da9c1a990c6075f82c7d30e340 (patch)
treeb51abc6cb094004f205e4a35204622fdc7db1af0
parentd98b141421a2f9325d748ad93361211e65603fce (diff)
downloadctbtw-master.tar.gz
ctbtw-master.zip
improve win32 support, depend on colorama optionallyHEADmaster
-rwxr-xr-xctbtw.py22
1 files changed, 18 insertions, 4 deletions
diff --git a/ctbtw.py b/ctbtw.py
index a8ae77e..90d3f95 100755
--- a/ctbtw.py
+++ b/ctbtw.py
@@ -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")