forked from auracaster/bumble_mirror
wip
This commit is contained in:
@@ -390,7 +390,8 @@ class UiServer:
|
|||||||
|
|
||||||
# -----------------------------------------------------------------------------
|
# -----------------------------------------------------------------------------
|
||||||
class Speaker:
|
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.transport = transport
|
||||||
self.codec = codec
|
self.codec = codec
|
||||||
self.discover = discover
|
self.discover = discover
|
||||||
@@ -573,7 +574,6 @@ class Speaker:
|
|||||||
print('@@@', endpoint)
|
print('@@@', endpoint)
|
||||||
|
|
||||||
async def run(self, connect_address):
|
async def run(self, connect_address):
|
||||||
print(f'Speaker ready to play, codec={color(self.codec, "cyan")}')
|
|
||||||
await self.ui_server.start_http()
|
await self.ui_server.start_http()
|
||||||
self.outputs.append(
|
self.outputs.append(
|
||||||
WebSocketOutput(
|
WebSocketOutput(
|
||||||
@@ -584,9 +584,13 @@ class Speaker:
|
|||||||
async with await open_transport(self.transport) as (hci_source, hci_sink):
|
async with await open_transport(self.transport) as (hci_source, hci_sink):
|
||||||
# Create a device
|
# Create a device
|
||||||
device_config = DeviceConfiguration()
|
device_config = DeviceConfiguration()
|
||||||
device_config.name = "Bumble Speaker"
|
if self.device_config:
|
||||||
device_config.class_of_device = 0x240404
|
device_config.load_from_file(self.device_config)
|
||||||
device_config.keystore = "JsonKeyStore"
|
else:
|
||||||
|
device_config.name = "Bumble Speaker"
|
||||||
|
device_config.class_of_device = 0x240404
|
||||||
|
device_config.keystore = "JsonKeyStore"
|
||||||
|
|
||||||
device_config.classic_enabled = True
|
device_config.classic_enabled = True
|
||||||
device_config.le_enabled = False
|
device_config.le_enabled = False
|
||||||
self.device = Device.from_config_with_hci(
|
self.device = Device.from_config_with_hci(
|
||||||
@@ -599,6 +603,16 @@ class Speaker:
|
|||||||
# Start the controller
|
# Start the controller
|
||||||
await self.device.power_on()
|
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
|
# Listen for Bluetooth connections
|
||||||
self.device.on('connection', self.on_bluetooth_connection)
|
self.device.on('connection', self.on_bluetooth_connection)
|
||||||
|
|
||||||
@@ -606,6 +620,8 @@ class Speaker:
|
|||||||
self.listener = Listener(Listener.create_registrar(self.device))
|
self.listener = Listener(Listener.create_registrar(self.device))
|
||||||
self.listener.on('connection', self.on_avdtp_connection)
|
self.listener.on('connection', self.on_avdtp_connection)
|
||||||
|
|
||||||
|
print(f'Speaker ready to play, codec={color(self.codec, "cyan")}')
|
||||||
|
|
||||||
if connect_address:
|
if connect_address:
|
||||||
# Connect to the source
|
# Connect to the source
|
||||||
await self.connect(connect_address)
|
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))
|
output = list(filter(lambda x: x != '@ffplay', output))
|
||||||
|
|
||||||
asyncio.run(
|
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):
|
def to_bytes(self):
|
||||||
return self.address_bytes
|
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):
|
def __bytes__(self):
|
||||||
return self.to_bytes()
|
return self.to_bytes()
|
||||||
|
|
||||||
@@ -1808,13 +1818,7 @@ class Address:
|
|||||||
)
|
)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
'''
|
return self.to_string()
|
||||||
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'
|
|
||||||
|
|
||||||
|
|
||||||
# Predefined address values
|
# Predefined address values
|
||||||
|
|||||||
Reference in New Issue
Block a user