def has_changed(self, to_value=None):
if len(self._shift_register) > 1:
if to_value is not None:
# if we are comparing to a given value (that matches the data class)...
if to_value.__class__ != self._data_class:
return None
if self._data_class == float:
# compare with isclose, for floats
return math.isclose(self._shift_register[-1], to_value, rel_tol=1.0e-6) and self.has_changed()
else:
# compare with equality, otherwise
return (self._shift_register[-1] == to_value) and self.has_changed()
else:
# if we are just checking if the latest value changed at all
if self._data_class == float:
# compare with isclose, for floats
return not math.isclose(self._shift_register[-1], self._shift_register[-2])
else:
# compare with equality, otherwise
return (self._shift_register[-1] != self._shift_register[-2])
else:
return False
#--- Basic PID controller class
#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-
评论列表
文章目录