started working on bluetooth pairing

This commit is contained in:
dekunukem
2021-12-29 16:34:52 +00:00
parent 4b8a576b81
commit 359ec9cd41
2 changed files with 41 additions and 1 deletions

28
user_program/bt.py Normal file
View File

@@ -0,0 +1,28 @@
import os
import subprocess
def scan_bt_devices():
LINUX_EXIT_CODE_TIMEOUT = 124
os.system('bluetoothctl agent on')
result = os.system("timeout 10 bluetoothctl scan on") >> 8
if result != LINUX_EXIT_CODE_TIMEOUT:
print('bluetoothctl scan error')
return None
device_str = subprocess.getoutput("bluetoothctl devices")
print(device_str)
bt_dev_list = []
for line in device_str.replace('\r', '').split('\n'):
if 'device' not in line.lower() or 'yun' in line.lower():
continue
line_split = line.split(' ', maxsplit=2)
if len(line_split) < 3 or line_split[2].count('-') == 5:
continue
bt_dev_list.append((line_split[1], line_split[2]))
return bt_dev_list
def pair_bt_device(mac_addr):
result_str = subprocess.getoutput(f"timeout 10 bluetoothctl pair {mac_addr}")
print(result_str)
dev_list = scan_bt_devices()
pair_bt_device(dev_list[0][0])

View File

@@ -1,5 +1,17 @@
"""----------bluetooth---------
https://github.com/oscaracena/pygattlib
sudo apt install pkg-config libboost-python-dev libboost-thread-dev libbluetooth-dev libglib2.0-dev python-dev
pip install gattlib
sudo apt-get install bluetooth bluez libbluetooth-dev
sudo pip3 install pybluez
https://raspberrypi.stackexchange.com/questions/114149/bluetooth-library-for-raspberry-pi
https://raspberrypi.stackexchange.com/questions/45246/bluetooth-import-for-python-raspberry-pi-3
this_device = ooopened_device_dict[key]
print(source_code, source_type, target_info)
print(source_code, source_type, target_info)"""
def raw_input_event_worker():
mouse_status_dict = {}