output drivers: add option to generate a separate output range reversing param

Makes it a bit easier to configure. Reversing by setting MIN > MAX is still
supported.
This commit is contained in:
Beat Küng
2021-12-24 20:06:13 -05:00
committed by Daniel Agar
parent 1901edf13c
commit d1abdd0f8d
12 changed files with 68 additions and 4 deletions
@@ -130,7 +130,8 @@ def get_actuator_output(yaml_config, output_functions, timer_config_file, verbos
return None
output_groups = yaml_config['actuator_output']['output_groups']
actuator_output_yaml = yaml_config['actuator_output']
output_groups = actuator_output_yaml['output_groups']
module_name = process_module_name(yaml_config['module_name'])
group_idx = 0
@@ -139,8 +140,9 @@ def get_actuator_output(yaml_config, output_functions, timer_config_file, verbos
actuator_output = {
'label': module_name
}
if 'show_subgroups_if' in yaml_config['actuator_output']:
actuator_output['show-subgroups-if'] = yaml_config['actuator_output']['show_subgroups_if']
if 'show_subgroups_if' in actuator_output_yaml:
actuator_output['show-subgroups-if'] = actuator_output_yaml['show_subgroups_if']
add_reverse_range_param = actuator_output_yaml.get('add_reverse_range_param', False)
# config parameters
def get_config_params(param_list):
@@ -159,7 +161,7 @@ def get_actuator_output(yaml_config, output_functions, timer_config_file, verbos
parameters.append(param)
return parameters
parameters = get_config_params(yaml_config['actuator_output'].get('config_parameters', []))
parameters = get_config_params(actuator_output_yaml.get('config_parameters', []))
if len(parameters) > 0:
actuator_output['parameters'] = parameters
@@ -254,6 +256,16 @@ def get_actuator_output(yaml_config, output_functions, timer_config_file, verbos
if show_if: param['show-if'] = show_if
per_channel_params.append(param)
if add_reverse_range_param:
param = {
'label': 'Rev Range\n(for Servos)',
'name': param_prefix+'_REV',
'index-offset': -1,
'show-as': 'bitset',
}
per_channel_params.append(param)
# TODO: support non-standard per-channel parameters
subgroup['per-channel-parameters'] = per_channel_params
+32
View File
@@ -178,6 +178,9 @@ def get_actuator_output_params(yaml_config, output_functions,
all_params = {}
group_idx = 0
add_reverse_range_param = yaml_config['actuator_output'].get('add_reverse_range_param', False)
all_param_prefixes = {}
def add_local_param(param_name, param_def):
nonlocal all_params
# add as a list, as there can be multiple entries with the same param_name
@@ -259,6 +262,11 @@ def get_actuator_output_params(yaml_config, output_functions,
for i in range(count):
output_function_values[start+i] = function_name_label+' '+str(i+1)
if param_prefix not in all_param_prefixes:
all_param_prefixes[param_prefix] = []
all_param_prefixes[param_prefix].append((instance_start,
instance_start_label, num_channels, channel_label))
# function param
param = {
'description': {
@@ -338,6 +346,30 @@ When set to -1 (default), the value depends on the function (see {:}).
}
add_local_param(param_prefix+'_'+param_suffix+'${i}', param)
if add_reverse_range_param:
for param_prefix in all_param_prefixes:
groups = all_param_prefixes[param_prefix]
# collect the bits
channel_bits = {}
for instance_start, instance_start_label, num_instances, label in groups:
for instance in range(instance_start, instance_start+num_instances):
instance_label = instance - instance_start + instance_start_label
channel_bits[instance-1] = label + ' ' + str(instance_label)
param = {
'description': {
'short': 'Reverse Output Range for '+module_name,
'long':
'''Allows to reverse the output range for each channel.
Note: this is only useful for servos.
'''.format(channel_label),
},
'type': 'bitmask',
'default': 0,
'bit': channel_bits
}
add_local_param(param_prefix+'_REV', param)
if verbose: print('adding actuator params: {:}'.format(all_params))
return all_params