Created
July 25, 2024 16:00
-
-
Save Langerz82/9799804c3068a9e361602071c0282f87 to your computer and use it in GitHub Desktop.
Emuelec 4.8 - Bluetooth Helper
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import time | |
from bluetool import Bluetooth | |
if __name__ == "__main__": | |
bt = Bluetooth() | |
print('Scanning for available devices for 60 seconds, please wait...') | |
bt.make_discoverable(); | |
bt.start_scanning(60) | |
print('Getting pairable devices, please wait...') | |
for x in range(0,10): | |
time.sleep(3) | |
devices = bt.get_available_devices() | |
for device in devices: | |
mac = device['mac_address'].decode('utf-8') | |
name = device['name'].decode('utf-8') | |
print("Icon:"+ str(bt.get_device_property(mac,'Icon'))) | |
if ((not bt.get_device_property(mac,'Icon') and | |
bt.get_device_property(mac,'Connected') == 1) or | |
bt.get_device_property(mac,'Icon') == 'input-gaming'): | |
print('Found MAC: {}\tName: {}'.format(mac,name)) | |
if bt.get_device_property(mac,'Trusted') == 1: | |
continue | |
print('Found controller {} Name: {}, trusting...'.format(mac,name)) | |
bt.trust(mac) | |
if bt.get_device_property(mac,'Trusted') == 1: | |
print('Trusted {}, quick pause, then pairing...'.format(name)) | |
time.sleep(5) | |
bt.pair(mac) | |
if bt.get_device_property(mac,'Paired') == 1: | |
print('Paired {}, quick pause, then connecting...'.format(name)) | |
time.sleep(5) | |
bt.connect(mac) | |
if bt.get_device_property(mac,'Connected') == 1: | |
print('Connected {}, exiting...'.format(name)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment