| 1 |
#!/usr/bin/env python3 |
| 2 |
# SPDX-License-Identifier: GPL-3.0-or-later |
| 3 |
# Copyright (C) 2018 Takashi Sakamoto |
| 4 |
|
| 5 |
from hinawa_utils.misc.cli_kit import CliKit |
| 6 |
from hinawa_utils.oxfw.oxfw_unit import OxfwUnit |
| 7 |
from hinawa_utils.ta1394.audio import AvcAudio |
| 8 |
|
| 9 |
|
| 10 |
def handle_current_status(unit, args): |
| 11 |
print('Current status:') |
| 12 |
print(' Packet Streaming:') |
| 13 |
print(' running: {0}'.format(unit.get_property('is-locked'))) |
| 14 |
fmts = unit.get_current_stream_formats() |
| 15 |
print(' sampling-rate: {0}'.format(fmts['playback']['sampling-rate'])) |
| 16 |
print('Volumes:') |
| 17 |
for ch in range(1, 7): |
| 18 |
data = AvcAudio.get_feature_volume_state(unit.fcp, 0, 'current', 2, ch) |
| 19 |
db = AvcAudio.parse_data_to_db(data) |
| 20 |
print(' {0}: {1}'.format(ch, db)) |
| 21 |
if AvcAudio.get_feature_mute_state(unit.fcp, 0, 'current', 1, 0): |
| 22 |
mute = 'on' |
| 23 |
else: |
| 24 |
mute = 'off' |
| 25 |
print(' mute: {0}'.format(mute)) |
| 26 |
print('ASIC information:') |
| 27 |
print(' type: {0}'.format(unit.hw_info['asic-type'])) |
| 28 |
print(' ID: {0}'.format(unit.hw_info['asic-id'])) |
| 29 |
print(' firmware version: {0}'.format(unit.hw_info['firmware-version'])) |
| 30 |
return True |
| 31 |
|
| 32 |
|
| 33 |
def handle_output_volume(unit, args): |
| 34 |
ops = ('set', 'get') |
| 35 |
if len(args) > 1 and args[0] in ops: |
| 36 |
op = args[0] |
| 37 |
ch = int(args[1]) |
| 38 |
if op == ops[0] and len(args) == 3: |
| 39 |
db = float(args[2]) |
| 40 |
data = AvcAudio.build_data_from_db(db) |
| 41 |
AvcAudio.set_feature_volume_state(unit.fcp, 0, 'current', 1, ch, |
| 42 |
data) |
| 43 |
else: |
| 44 |
data = AvcAudio.get_feature_volume_state(unit.fcp, 0, 'current', |
| 45 |
1, ch) |
| 46 |
print(AvcAudio.parse_data_to_db(data)) |
| 47 |
return True |
| 48 |
print('Arguments for output-volume command:') |
| 49 |
print(' output-volume OPERATION CH [dB]') |
| 50 |
print(' OP: [{0}]'.format('|'.join(ops))) |
| 51 |
print(' CH: [0..6] (0 = all)') |
| 52 |
print(' dB: [-128.0..128.0] if OP=set') |
| 53 |
return False |
| 54 |
|
| 55 |
|
| 56 |
def handle_ouptut_mute(unit, args): |
| 57 |
ops = ('set', 'get') |
| 58 |
if len(args) > 0 and args[0] in ops: |
| 59 |
op = args[0] |
| 60 |
if op == ops[0] and len(args) == 2: |
| 61 |
mute = int(args[1]) |
| 62 |
AvcAudio.set_feature_mute_state(unit.fcp, 0, 'current', 1, 0, mute) |
| 63 |
else: |
| 64 |
print(AvcAudio.get_feature_mute_state( |
| 65 |
unit.fcp, 0, 'current', 1, 0)) |
| 66 |
return True |
| 67 |
print('Arguments for output-mute command:') |
| 68 |
print(' output-mute OPERATION [MUTE]') |
| 69 |
print(' OPERATION: {0}'.format(', '.join(ops))) |
| 70 |
print(' MUTE: 0, 1') |
| 71 |
return False |
| 72 |
|
| 73 |
|
| 74 |
cmds = { |
| 75 |
'current-status': handle_current_status, |
| 76 |
'output-volume': handle_output_volume, |
| 77 |
'output-mute': handle_ouptut_mute, |
| 78 |
} |
| 79 |
|
| 80 |
fullpath = CliKit.seek_snd_unit_path() |
| 81 |
if fullpath: |
| 82 |
with OxfwUnit(fullpath) as unit: |
| 83 |
CliKit.dispatch_command(unit, cmds) |