From 371ea074426bf16f576dd4873dbf82af3ad78b39 Mon Sep 17 00:00:00 2001 From: Gilles Boccon-Gibod Date: Fri, 19 May 2023 16:05:21 -0700 Subject: [PATCH] wip --- apps/speaker/speaker.py | 30 ++++++++++++++++++++++++------ bumble/hci.py | 18 +++++++++++------- 2 files changed, 35 insertions(+), 13 deletions(-) diff --git a/apps/speaker/speaker.py b/apps/speaker/speaker.py index 8de2bad..56282cb 100644 --- a/apps/speaker/speaker.py +++ b/apps/speaker/speaker.py @@ -390,7 +390,8 @@ class UiServer: # ----------------------------------------------------------------------------- class Speaker: - def __init__(self, transport, codec, discover, outputs, ui_port): + def __init__(self, device_config, transport, codec, discover, outputs, ui_port): + self.device_config = device_config self.transport = transport self.codec = codec self.discover = discover @@ -573,7 +574,6 @@ class Speaker: print('@@@', endpoint) async def run(self, connect_address): - print(f'Speaker ready to play, codec={color(self.codec, "cyan")}') await self.ui_server.start_http() self.outputs.append( WebSocketOutput( @@ -584,9 +584,13 @@ class Speaker: async with await open_transport(self.transport) as (hci_source, hci_sink): # Create a device device_config = DeviceConfiguration() - device_config.name = "Bumble Speaker" - device_config.class_of_device = 0x240404 - device_config.keystore = "JsonKeyStore" + if self.device_config: + device_config.load_from_file(self.device_config) + else: + device_config.name = "Bumble Speaker" + device_config.class_of_device = 0x240404 + device_config.keystore = "JsonKeyStore" + device_config.classic_enabled = True device_config.le_enabled = False self.device = Device.from_config_with_hci( @@ -599,6 +603,16 @@ class Speaker: # Start the controller await self.device.power_on() + # Print some of the config/properties + print("Speaker Name:", color(device_config.name, 'yellow')) + print( + "Speaker Bluetooth Address:", + color( + self.device.public_address.to_string(with_type_qualifier=False), + 'yellow', + ), + ) + # Listen for Bluetooth connections self.device.on('connection', self.on_bluetooth_connection) @@ -606,6 +620,8 @@ class Speaker: self.listener = Listener(Listener.create_registrar(self.device)) self.listener.on('connection', self.on_avdtp_connection) + print(f'Speaker ready to play, codec={color(self.codec, "cyan")}') + if connect_address: # Connect to the source await self.connect(connect_address) @@ -686,7 +702,9 @@ def play(ctx, transport, codec, connect_address, discover, output, ui_port): output = list(filter(lambda x: x != '@ffplay', output)) asyncio.run( - Speaker(transport, codec, discover, output, ui_port).run(connect_address) + Speaker( + ctx.obj['device_config'], transport, codec, discover, output, ui_port + ).run(connect_address) ) diff --git a/bumble/hci.py b/bumble/hci.py index 4349426..ab4dc3f 100644 --- a/bumble/hci.py +++ b/bumble/hci.py @@ -1795,6 +1795,16 @@ class Address: def to_bytes(self): return self.address_bytes + def to_string(self, with_type_qualifier=True): + ''' + String representation of the address, MSB first, with an optional type + qualifier. + ''' + result = ':'.join([f'{x:02X}' for x in reversed(self.address_bytes)]) + if not with_type_qualifier or not self.is_public: + return result + return result + '/P' + def __bytes__(self): return self.to_bytes() @@ -1808,13 +1818,7 @@ class Address: ) def __str__(self): - ''' - String representation of the address, MSB first - ''' - result = ':'.join([f'{x:02X}' for x in reversed(self.address_bytes)]) - if not self.is_public: - return result - return result + '/P' + return self.to_string() # Predefined address values