improvements for flame

- frappy_psi.channelswitcher: use isBusy instead of checking value and target
- frappy_psi.ls372: remove underflow mechanism
- frappy_psi.parmod.SwitchDriv: switch the controlled module also when not buys
This commit is contained in:
l_samenv
2023-07-11 13:24:41 +02:00
committed by Markus Zolliker
parent 44c59bd818
commit cf10590245
3 changed files with 65 additions and 39 deletions

View File

@ -134,7 +134,12 @@ def get_value(obj, default):
"""get the value of given module. if not valid, return the limit (min_high or max_low)"""
if not getattr(obj, 'enabled', True):
return default
return obj.value if IDLE <= obj.status[0] < ERROR else default
# consider also that a value 0 is invalid
return (obj.value if IDLE <= obj.status[0] < ERROR else 0) or default
LOW = 0
HIGH = 1
class SwitchDriv(HasConvergence, Drivable):
@ -143,14 +148,32 @@ class SwitchDriv(HasConvergence, Drivable):
min_high = Parameter('minimum high target', FloatRange(unit='$'), readonly=False)
max_low = Parameter('maximum low target', FloatRange(unit='$'), readonly=False)
# disable_other = Parameter('whether to disable unused channel', BoolType(), readonly=False)
selected = Parameter('selected module', EnumType(low=0, high=1), readonly=False, default=0)
selected = Parameter('selected module', EnumType(low=LOW, high=HIGH), readonly=False, default=0)
_switch_target = None # if not None, switch to selection mhen mid range is reached
# TODO: copy units from attached module
# TODO: callbacks for updates
def doPoll(self):
super().doPoll()
if not self.isBusy():
if self.isBusy():
if self._switch_target is not None:
mid = (self.min_high + self.max_low) * 0.5
if self._switch_target == HIGH:
low = get_value(self.low, mid) # returns mid when low is invalid
if low > mid:
self.value = self.low.value
self._switch_target = None
self.write_target(self.target)
return
else:
high = get_value(self.high, mid) # return mid then high is invalid
if high < mid:
self.value = self.high.value
self._switch_target = None
self.write_target(self.target)
return
else:
low = get_value(self.low, self.max_low)
high = get_value(self.high, self.min_high)
low_valid = low < self.max_low
@ -167,28 +190,36 @@ class SwitchDriv(HasConvergence, Drivable):
set_enabled(self.high, True)
def read_value(self):
return self.low.value if self.selected == self.selected.low else self.high.value
return self.low.value if self.selected == LOW else self.high.value
def read_status(self):
status = self.low.status if self.selected == self.selected.low else self.high.status
status = self.low.status if self.selected == LOW else self.high.status
if status[0] >= ERROR:
return status
return super().read_status() # convergence status
def read_target(self):
if self.selected == self.selected.low:
return self.low.target
return self.high.target
def write_target(self, target):
this, other = self.low, self.high
selected = self.selected
target1 = target
self._switch_target = None
if target > self.max_low:
this, other = other, this
selected = self.selected.high
if self.value < self.min_high:
target1 = self.max_low
self._switch_target = HIGH
selected = LOW
else:
this, other = other, this
selected = HIGH
elif target < self.min_high:
selected = self.selected.low
elif self.selected == self.selected.high:
if self.value > self.max_low:
target1 = self.min_high
self._switch_target = LOW
this, other = other, this
selected = HIGH
else:
selected = LOW
elif self.selected == HIGH:
this, other = other, this
if hasattr(other, 'control_off'):
other.control_off()
@ -197,4 +228,5 @@ class SwitchDriv(HasConvergence, Drivable):
self.write_selected(selected)
self.convergence_start()
self.log.info('target=%g (%s)', target, this.name)
return this.write_target(target)
this.write_target(target1)
return target