forked from auracaster/bumble_mirror
Merge pull request #149 from yuyangh/yuyangh/add_ASHA_event_emit
Add ASHA event emitter
This commit is contained in:
@@ -56,13 +56,13 @@ class AshaService(TemplateService):
|
|||||||
self.hisyncid = hisyncid
|
self.hisyncid = hisyncid
|
||||||
self.capability = capability # Device Capabilities [Left, Monaural]
|
self.capability = capability # Device Capabilities [Left, Monaural]
|
||||||
self.device = device
|
self.device = device
|
||||||
self.emitted_data_name = 'ASHA_data_' + str(self.capability)
|
|
||||||
self.audio_out_data = b''
|
self.audio_out_data = b''
|
||||||
self.psm = psm # a non-zero psm is mainly for testing purpose
|
self.psm = psm # a non-zero psm is mainly for testing purpose
|
||||||
|
|
||||||
# Handler for volume control
|
# Handler for volume control
|
||||||
def on_volume_write(_connection, value):
|
def on_volume_write(_connection, value):
|
||||||
logger.info(f'--- VOLUME Write:{value[0]}')
|
logger.info(f'--- VOLUME Write:{value[0]}')
|
||||||
|
self.emit('volume', value[0])
|
||||||
|
|
||||||
# Handler for audio control commands
|
# Handler for audio control commands
|
||||||
def on_audio_control_point_write(_connection, value):
|
def on_audio_control_point_write(_connection, value):
|
||||||
@@ -77,8 +77,18 @@ class AshaService(TemplateService):
|
|||||||
f'volume={value[3]}, '
|
f'volume={value[3]}, '
|
||||||
f'otherstate={value[4]}'
|
f'otherstate={value[4]}'
|
||||||
)
|
)
|
||||||
|
self.emit(
|
||||||
|
'start',
|
||||||
|
{
|
||||||
|
'codec': value[1],
|
||||||
|
'audiotype': value[2],
|
||||||
|
'volume': value[3],
|
||||||
|
'otherstate': value[4],
|
||||||
|
},
|
||||||
|
)
|
||||||
elif opcode == AshaService.OPCODE_STOP:
|
elif opcode == AshaService.OPCODE_STOP:
|
||||||
logger.info('### STOP')
|
logger.info('### STOP')
|
||||||
|
self.emit('stop')
|
||||||
elif opcode == AshaService.OPCODE_STATUS:
|
elif opcode == AshaService.OPCODE_STATUS:
|
||||||
logger.info(f'### STATUS: connected={value[1]}')
|
logger.info(f'### STATUS: connected={value[1]}')
|
||||||
|
|
||||||
@@ -131,7 +141,7 @@ class AshaService(TemplateService):
|
|||||||
def on_data(data):
|
def on_data(data):
|
||||||
logging.debug(f'<<< data received:{data}')
|
logging.debug(f'<<< data received:{data}')
|
||||||
|
|
||||||
self.emit(self.emitted_data_name, data)
|
self.emit('data', data)
|
||||||
self.audio_out_data += data
|
self.audio_out_data += data
|
||||||
|
|
||||||
channel.sink = on_data
|
channel.sink = on_data
|
||||||
|
|||||||
Reference in New Issue
Block a user