Skip to content

Commit

Permalink
added initial values
Browse files Browse the repository at this point in the history
  • Loading branch information
evalott100 committed Nov 11, 2024
1 parent 609e0ad commit 5a3f2ec
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 25 deletions.
6 changes: 5 additions & 1 deletion src/fastcs_pandablocks/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,14 @@ def main():
level = getattr(logging, parsed_args.log_level.upper(), None)
logging.basicConfig(format="%(levelname)s:%(message)s", level=level)

screens_directory = (
Path(parsed_args.screens_dir) if parsed_args.screens_dir else None
)

ioc(
parsed_args.prefix,
parsed_args.hostname,
screens_directory=Path(parsed_args.screens_dir),
screens_directory=screens_directory,
clear_bobfiles=parsed_args.clear_bobfiles,
poll_period=parsed_args.poll_period,
naming_convention=PvNamingConvention(parsed_args.pv_naming_convention),
Expand Down
71 changes: 47 additions & 24 deletions src/fastcs_pandablocks/panda/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ def __init__(
handler=DefaultFieldHandler(panda_name),
description=_strip_description(field_info.description),
group=WidgetGroup.PARAMETERS.value,
initial_value=float(initial_values[panda_name]),
)
self._additional_attributes["units"] = AttrW(
String(),
Expand All @@ -148,6 +149,7 @@ def __init__(
),
description=_strip_description(field_info.description),
group=WidgetGroup.OUTPUTS.value,
initial_value=float(initial_values[panda_name]),
)
self._additional_attributes["units"] = AttrW(
String(),
Expand Down Expand Up @@ -191,6 +193,7 @@ def __init__(
Bool(znam="0", onam="1"),
description=_strip_description(field_info.description),
group=WidgetGroup.OUTPUTS.value,
initial_value=bool(int(initial_values[panda_name])),
)


Expand All @@ -206,6 +209,7 @@ def __init__(
Float(),
description=_strip_description(field_info.description),
group=WidgetGroup.OUTPUTS.value,
initial_value=bool(int(initial_values[panda_name])),
)

scaled = AttrR(
Expand Down Expand Up @@ -349,7 +353,10 @@ def __init__(
super().__init__(panda_name)
self.top_level_attribute = AttrRW(
String(),
description=_strip_description(pos_mux_field_info.description),
group=WidgetGroup.INPUTS.value,
allowed_values=pos_mux_field_info.labels,
initial_value=initial_values[panda_name],
)


Expand All @@ -363,9 +370,13 @@ def __init__(
super().__init__(panda_name)
self.top_level_attribute = AttrR(
Float(prec=0),
description=_strip_description(uint_param_field_info.description),
group=WidgetGroup.PARAMETERS.value,
initial_value=float(initial_values[panda_name]),
)

# TODO: set DRVL, DRVH, HOPR (new fastcs feature)


class UintReadFieldController(FieldController):
def __init__(
Expand All @@ -377,9 +388,9 @@ def __init__(
super().__init__(panda_name)
self.top_level_attribute = AttrR(
Float(prec=0),
description=_strip_description(uint_read_field_info.description),
group=WidgetGroup.READBACKS.value,
# To be added once we have a pvxs backend
# description=uint_read_field_info.description,
initial_value=float(initial_values[panda_name]),
)


Expand All @@ -393,6 +404,7 @@ def __init__(
super().__init__(panda_name)
self.top_level_attribute = AttrW(
Float(prec=0),
description=_strip_description(uint_write_field_info.description),
group=WidgetGroup.OUTPUTS.value,
)

Expand All @@ -406,8 +418,10 @@ def __init__(
):
super().__init__(panda_name)
self.top_level_attribute = AttrRW(
Float(prec=0),
Int(),
description=_strip_description(int_param_field_info.description),
group=WidgetGroup.PARAMETERS.value,
initial_value=int(initial_values[panda_name]),
)


Expand All @@ -421,7 +435,9 @@ def __init__(
super().__init__(panda_name)
self.top_level_attribute = AttrR(
Int(),
description=_strip_description(int_read_field_info.description),
group=WidgetGroup.READBACKS.value,
initial_value=int(initial_values[panda_name]),
)


Expand All @@ -435,6 +451,7 @@ def __init__(
super().__init__(panda_name)
self.top_level_attribute = AttrW(
Int(),
description=_strip_description(int_write_field_info.description),
group=WidgetGroup.PARAMETERS.value,
)

Expand All @@ -449,7 +466,10 @@ def __init__(
super().__init__(panda_name)
self.top_level_attribute = AttrRW(
Float(),
description=_strip_description(scalar_param_field_info.description),
# TODO: allow EGU (fastcs feature)
group=WidgetGroup.PARAMETERS.value,
initial_value=float(initial_values[panda_name]),
)


Expand All @@ -463,7 +483,9 @@ def __init__(
super().__init__(panda_name)
self.top_level_attribute = AttrR(
Float(),
description=_strip_description(scalar_read_field_info.description),
group=WidgetGroup.READBACKS.value,
initial_value=float(initial_values[panda_name]),
)


Expand All @@ -477,6 +499,7 @@ def __init__(
super().__init__(panda_name)
self.top_level_attribute = AttrR(
Float(),
description=_strip_description(scalar_write_field_info.description),
group=WidgetGroup.PARAMETERS.value,
)

Expand All @@ -491,7 +514,11 @@ def __init__(
super().__init__(panda_name)
self.top_level_attribute = AttrRW(
Bool(znam="0", onam="1"),
description=_strip_description(bit_param_field_info.description),
group=WidgetGroup.PARAMETERS.value,
# Initial value is string "0"/"1".
# TODO: Equip each read/readwrite field with a converter
initial_value=bool(int(initial_values[panda_name])),
)


Expand All @@ -505,7 +532,9 @@ def __init__(
super().__init__(panda_name)
self.top_level_attribute = AttrR(
Bool(znam="0", onam="1"),
description=_strip_description(bit_read_field_info.description),
group=WidgetGroup.READBACKS.value,
initial_value=bool(int(initial_values[panda_name])),
)


Expand All @@ -519,24 +548,11 @@ def __init__(
super().__init__(panda_name)
self.top_level_attribute = AttrW(
Bool(znam="0", onam="1"),
description=_strip_description(bit_write_field_info.description),
group=WidgetGroup.OUTPUTS.value,
)


class ActionReadFieldController(FieldController):
def __init__(
self,
panda_name: PandaName,
action_read_field_info: FieldInfo,
initial_values: RawInitialValuesType,
):
super().__init__(panda_name)
self.top_level_attribute = AttrR(
Bool(znam="0", onam="1"),
group=WidgetGroup.READBACKS.value,
)


class ActionWriteFieldController(FieldController):
def __init__(
self,
Expand All @@ -547,6 +563,7 @@ def __init__(
super().__init__(panda_name)
self.top_level_attribute = AttrW(
Bool(znam="0", onam="1"),
description=_strip_description(action_write_field_info.description),
group=WidgetGroup.OUTPUTS.value,
)

Expand All @@ -561,7 +578,9 @@ def __init__(
super().__init__(panda_name)
self.top_level_attribute = AttrRW(
String(),
description=_strip_description(lut_param_field_info.description),
group=WidgetGroup.PARAMETERS.value,
initial_value=initial_values[panda_name],
)


Expand All @@ -575,7 +594,9 @@ def __init__(
super().__init__(panda_name)
self.top_level_attribute = AttrR(
String(),
description=_strip_description(lut_read_field_info.description),
group=WidgetGroup.READBACKS.value,
initial_value=initial_values[panda_name],
)


Expand All @@ -589,6 +610,7 @@ def __init__(
super().__init__(panda_name)
self.top_level_attribute = AttrR(
String(),
description=_strip_description(lut_read_field_info.description),
group=WidgetGroup.OUTPUTS.value,
)

Expand All @@ -601,10 +623,12 @@ def __init__(
initial_values: RawInitialValuesType,
):
super().__init__(panda_name)
self.allowed_values = enum_param_field_info.labels
self.top_level_attribute = AttrRW(
String(),
description=_strip_description(enum_param_field_info.description),
allowed_values=enum_param_field_info.labels,
group=WidgetGroup.PARAMETERS.value,
initial_value=initial_values[panda_name],
)


Expand All @@ -618,7 +642,10 @@ def __init__(
super().__init__(panda_name)
self.top_level_attribute = AttrR(
String(),
description=_strip_description(enum_read_field_info.description),
allowed_values=enum_read_field_info.labels,
group=WidgetGroup.READBACKS.value,
initial_value=initial_values[panda_name],
)


Expand All @@ -632,6 +659,8 @@ def __init__(
super().__init__(panda_name)
self.top_level_attribute = AttrW(
String(),
description=_strip_description(enum_write_field_info.description),
allowed_values=enum_write_field_info.labels,
group=WidgetGroup.OUTPUTS.value,
)

Expand All @@ -656,7 +685,6 @@ def __init__(
| BitParamFieldController
| BitReadFieldController
| BitWriteFieldController
| ActionReadFieldController
| ActionWriteFieldController
| LutParamFieldController
| LutReadFieldController
Expand Down Expand Up @@ -737,11 +765,6 @@ def get_field_controller_from_field_info(
return IntWriteFieldController(panda_name, field_info, initial_values)

# Action types
case FieldInfo(
type="read",
subtype="action",
):
return ActionReadFieldController(panda_name, field_info, initial_values)
case FieldInfo(
type="write",
subtype="action",
Expand Down

0 comments on commit 5a3f2ec

Please sign in to comment.