add bp connect
This commit is contained in:
parent
4dc76de17c
commit
b90adfd155
5
qqqq
5
qqqq
@ -3,3 +3,8 @@ export DISPLAY=:0
|
|||||||
./.venv/bin/python3 ./main.py
|
./.venv/bin/python3 ./main.py
|
||||||
|
|
||||||
sudo usermod -aG bluetooth cheykrym
|
sudo usermod -aG bluetooth cheykrym
|
||||||
|
|
||||||
|
rfkill list
|
||||||
|
sudo rfkill unblock bluetooth
|
||||||
|
|
||||||
|
cat ~/.cache/car_ui/bluetooth.log
|
||||||
@ -140,15 +140,19 @@ class BluetoothScreen(QWidget):
|
|||||||
|
|
||||||
def _make_visible(self):
|
def _make_visible(self):
|
||||||
self._last_error = ""
|
self._last_error = ""
|
||||||
self._run_cmd(["bluetoothctl", "power", "on"])
|
script_out = self._run_btctl_script(
|
||||||
if self._last_error:
|
[
|
||||||
|
"power on",
|
||||||
|
"discoverable-timeout 0",
|
||||||
|
"discoverable on",
|
||||||
|
"pairable on",
|
||||||
|
"agent NoInputNoOutput",
|
||||||
|
"default-agent",
|
||||||
|
]
|
||||||
|
)
|
||||||
|
if "Failed to set power on" in script_out or "org.bluez.Error" in script_out:
|
||||||
self.status.setText("Статус: питание BT выключено (проверьте rfkill)")
|
self.status.setText("Статус: питание BT выключено (проверьте rfkill)")
|
||||||
return
|
return
|
||||||
self._run_cmd(["bluetoothctl", "discoverable-timeout", "0"])
|
|
||||||
self._run_cmd(["bluetoothctl", "discoverable", "on"])
|
|
||||||
self._run_cmd(["bluetoothctl", "pairable", "on"])
|
|
||||||
self._run_cmd(["bluetoothctl", "agent", "NoInputNoOutput"])
|
|
||||||
self._run_cmd(["bluetoothctl", "default-agent"])
|
|
||||||
if self._last_error:
|
if self._last_error:
|
||||||
self.status.setText(f"Статус: ошибка ({self._last_error})")
|
self.status.setText(f"Статус: ошибка ({self._last_error})")
|
||||||
else:
|
else:
|
||||||
@ -240,6 +244,28 @@ class BluetoothScreen(QWidget):
|
|||||||
self._log(args, stdout, stderr, result.returncode)
|
self._log(args, stdout, stderr, result.returncode)
|
||||||
return stdout
|
return stdout
|
||||||
|
|
||||||
|
def _run_btctl_script(self, commands: list[str]) -> str:
|
||||||
|
script = "\n".join(commands + ["quit"]) + "\n"
|
||||||
|
try:
|
||||||
|
result = subprocess.run(
|
||||||
|
["bluetoothctl"],
|
||||||
|
input=script,
|
||||||
|
capture_output=True,
|
||||||
|
text=True,
|
||||||
|
timeout=4,
|
||||||
|
check=False,
|
||||||
|
)
|
||||||
|
except (subprocess.SubprocessError, OSError):
|
||||||
|
self._last_error = "run-failed"
|
||||||
|
self._log(["bluetoothctl", "(script)"], "", "run-failed", 1)
|
||||||
|
return ""
|
||||||
|
stdout = result.stdout.strip()
|
||||||
|
stderr = result.stderr.strip()
|
||||||
|
if result.returncode != 0 or stderr:
|
||||||
|
self._last_error = stderr or f"exit={result.returncode}"
|
||||||
|
self._log(["bluetoothctl", "(script)"], stdout, stderr, result.returncode)
|
||||||
|
return stdout
|
||||||
|
|
||||||
def _log(self, args: list[str], stdout: str, stderr: str, code: int):
|
def _log(self, args: list[str], stdout: str, stderr: str, code: int):
|
||||||
try:
|
try:
|
||||||
os.makedirs(os.path.dirname(self._log_path), exist_ok=True)
|
os.makedirs(os.path.dirname(self._log_path), exist_ok=True)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user