mirror of
https://github.com/google/bumble.git
synced 2026-05-10 04:18:03 +00:00
wip
This commit is contained in:
@@ -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()
|
||||
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)
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user