From 2acab33faa2088a47bfdf6697acf80468b1bb990 Mon Sep 17 00:00:00 2001 From: Markus Zolliker Date: Tue, 30 Jan 2024 10:56:09 +0100 Subject: [PATCH] add FloatEnumParam for the use case where a parameter is a selection of discrete float parameters declaring a parameter as FloatEnumParam will create effectively two parameters, one with datatype FloatRange and another with datatype Enum, influencing each other automatically. in a later change StructParam should be moved from frappy/structparam.py to frappy/extparams.py Change-Id: Ica3fd8dcaf6e9439e8178390f220dec15e52cc86 Reviewed-on: https://forge.frm2.tum.de/review/c/secop/frappy/+/32975 Tested-by: Jenkins Automated Tests Reviewed-by: Markus Zolliker --- frappy/extparams.py | 164 +++++++++++++++++++ test/{test_ctrlpars.py => test_extparams.py} | 78 ++++++++- 2 files changed, 241 insertions(+), 1 deletion(-) create mode 100644 frappy/extparams.py rename test/{test_ctrlpars.py => test_extparams.py} (61%) diff --git a/frappy/extparams.py b/frappy/extparams.py new file mode 100644 index 0000000..6f7b9dd --- /dev/null +++ b/frappy/extparams.py @@ -0,0 +1,164 @@ +# ***************************************************************************** +# +# This program is free software; you can redistribute it and/or modify it under +# the terms of the GNU General Public License as published by the Free Software +# Foundation; either version 2 of the License, or (at your option) any later +# version. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +# details. +# +# You should have received a copy of the GNU General Public License along with +# this program; if not, write to the Free Software Foundation, Inc., +# 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# Module authors: +# Markus Zolliker +# +# ***************************************************************************** +"""extended parameters + +special parameter classes with some automatic functionality +""" + +import re +from frappy.core import Parameter, Property +from frappy.datatypes import DataType, ValueType, EnumType, \ + StringType, FloatRange, DataTypeType +from frappy.errors import ProgrammingError + + +# TODO: insert StructParam here + + +class FloatEnumParam(Parameter): + """combine enum and float parameter + + Example Usage: + + vrange = FloatEnumParam('sensor range', ['500uV', '20mV', '1V'], 'V') + + The following will be created automatically: + + - the parameter vrange will get a datatype FloatRange(5e-4, 1, unit='V') + - an additional parameter `vrange_idx` will be created with an enum type + {'500uV': 0, '20mV': 1, '1V': 2} + - the method `write_vrange` will be created automatically + + However, the methods `write_vrange_idx` and `read_vrange_idx`, if needed, + have to implemented by the programmer. + + Writing to the float parameter involves 'rounding' to the closest allowed value. + + Customization: + + The individual labels might be customized by defining them as a tuple + (,