Add direct BullTron BLE connect option

This commit is contained in:
2026-07-11 11:48:05 +02:00
parent 5a249ecb86
commit b45641b2aa
2 changed files with 43 additions and 4 deletions
+27 -4
View File
@@ -55,6 +55,7 @@ WRITE_CHAR = "0000fff2-0000-1000-8000-00805f9b34fb"
AT_CHAR = "0000fff3-0000-1000-8000-00805f9b34fb"
SECRET_KEY_CHAR = "02f00000-0000-0000-0000-00000000ff05"
VERSION_CHAR = "02f00000-0000-0000-0000-00000000ff04"
BULLTRON_CAPTURE_ADDRESS = "7C:3E:82:1C:7A:86"
BULLTRON_NAME_MARKERS = ("dl", "b35")
BULLTRON_ADV_MARKERS = (b"DL", b"PU", b"JHB")
@@ -324,7 +325,7 @@ class BleWorker:
def submit(self, coro: Any) -> None:
asyncio.run_coroutine_threadsafe(coro, self.loop)
def scan(self, timeout: float = 6.0) -> None:
def scan(self, timeout: float = 12.0) -> None:
self.submit(self._scan(timeout))
async def _scan(self, timeout: float) -> None:
@@ -454,8 +455,18 @@ class BullTronGui(tk.Tk):
left = ttk.Frame(root, width=300)
root.add(left, weight=0)
ttk.Button(left, text="Scan", command=self._scan).pack(fill=tk.X, pady=(0, 6))
ttk.Button(left, text="Connect", command=self._connect_selected).pack(fill=tk.X)
scan_row = ttk.Frame(left)
scan_row.pack(fill=tk.X, pady=(0, 6))
ttk.Button(scan_row, text="Scan", command=self._scan).pack(side=tk.LEFT, fill=tk.X, expand=True)
ttk.Label(scan_row, text="sec").pack(side=tk.RIGHT, padx=(6, 0))
self.scan_timeout = tk.StringVar(value="12")
ttk.Spinbox(scan_row, from_=3, to=60, textvariable=self.scan_timeout, width=4).pack(side=tk.RIGHT)
ttk.Button(left, text="Connect selected", command=self._connect_selected).pack(fill=tk.X)
direct = ttk.LabelFrame(left, text="Direct connect")
direct.pack(fill=tk.X, pady=(8, 0))
self.direct_address = tk.StringVar(value=BULLTRON_CAPTURE_ADDRESS)
ttk.Entry(direct, textvariable=self.direct_address).pack(fill=tk.X, padx=6, pady=(6, 4))
ttk.Button(direct, text="Connect address", command=self._connect_direct).pack(fill=tk.X, padx=6, pady=(0, 6))
self.device_list = tk.Listbox(left, height=26)
self.device_list.pack(fill=tk.BOTH, expand=True, pady=8)
self.device_list.bind("<Double-Button-1>", lambda _event: self._connect_selected())
@@ -541,7 +552,12 @@ class BullTronGui(tk.Tk):
self.raw_text.pack(fill=tk.BOTH, expand=True, padx=8, pady=8)
def _scan(self) -> None:
self.worker.scan()
try:
timeout = float(self.scan_timeout.get())
except ValueError:
messagebox.showerror("Scan", "Scan duration must be a number of seconds")
return
self.worker.scan(max(3.0, min(timeout, 60.0)))
def _connect_selected(self) -> None:
selection = self.device_list.curselection()
@@ -549,6 +565,13 @@ class BullTronGui(tk.Tk):
return
self.worker.connect(self.devices[selection[0]]["address"])
def _connect_direct(self) -> None:
address = self.direct_address.get().strip()
if not address:
messagebox.showerror("Address", "Enter a BLE address first")
return
self.worker.connect(address)
def _unlock(self) -> None:
entered = self.pin_entry.get().strip()
expected = self.vars.get("read_pin", tk.StringVar(value="000000")).get()