Add bluetooth battery port autodetection
This commit is contained in:
parent
fa48f88cba
commit
c429e84e53
@ -107,6 +107,7 @@ with deviceSpecific; {
|
||||
grub.device = "nodev";
|
||||
grub.efiInstallAsRemovable = true; # NVRAM is unreliable
|
||||
});
|
||||
kernelPackages = pkgs.linuxPackages_latest;
|
||||
consoleLogLevel = 3;
|
||||
extraModprobeConfig = "options ec_sys write_support=1";
|
||||
kernel.sysctl."vm.swappiness" = 0;
|
||||
@ -141,6 +142,7 @@ with deviceSpecific; {
|
||||
support32Bit = true;
|
||||
extraConfig = ''
|
||||
load-module module-native-protocol-tcp auth-ip-acl=127.0.0.1
|
||||
load-module module-bluetooth-policy auto_switch=2
|
||||
'';
|
||||
};
|
||||
}
|
||||
|
@ -2,8 +2,6 @@
|
||||
|
||||
"""
|
||||
A python script to get battery level from Bluetooth headsets
|
||||
|
||||
Shamelessly stolen from https://github.com/TheWeirdDev/Bluetooth_Headset_Battery_Level
|
||||
"""
|
||||
|
||||
# License: GPL-3.0
|
||||
@ -63,17 +61,28 @@ def getATCommand(sock, line, device):
|
||||
|
||||
return True
|
||||
|
||||
def find_rfcomm_port(device):
|
||||
uuid="0000111e-0000-1000-8000-00805f9b34fb"
|
||||
proto = bluetooth.find_service(address=device, uuid=uuid)
|
||||
if len(proto) == 0:
|
||||
print("Couldn't find the RFCOMM port number")
|
||||
return 4
|
||||
else:
|
||||
for j in range(len(proto)):
|
||||
if 'protocol' in proto[j] and proto[j]['protocol'] == 'RFCOMM':
|
||||
port = proto[j]['port']
|
||||
return port
|
||||
|
||||
def main():
|
||||
if (len(sys.argv) < 2):
|
||||
print("Usage: bl_battery.py <BT_MAC_ADDRESS_1>[.PORT] ...")
|
||||
print(" Port number is optional (default = 4)")
|
||||
print(" Port number is optional")
|
||||
exit()
|
||||
else:
|
||||
for device in sys.argv[1:]:
|
||||
i = device.find('.')
|
||||
if i == -1:
|
||||
port = 10
|
||||
port = find_rfcomm_port(device)
|
||||
else:
|
||||
port = int(device[i+1:])
|
||||
device = device[:i]
|
||||
|
Loading…
Reference in New Issue
Block a user