Skip to content

Commit

Permalink
Remove duplicate code in hysteresis_threshold_factors
Browse files Browse the repository at this point in the history
  • Loading branch information
ulikoehler committed Nov 24, 2016
1 parent 9fc92a1 commit 16fd5b8
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 19 deletions.
35 changes: 17 additions & 18 deletions UliEngineering/Electronics/Hysteresis.py
Expand Up @@ -132,6 +132,19 @@ def hysteresis_threshold_voltages_opendrain(r1, r2, rh, vcc):
return (thl * vcc, thu * vcc)


def __hysteresis_threshold_factors(r1, r2, rh, fn):
"""Internal push-pull & open-drain common code"""
# Normalize inputs
r1 = normalize_numeric(r1)
r2 = normalize_numeric(r2)
rh = normalize_numeric(rh)
# Compute thresholds
thl, thu = fn(r1, r2, rh)
# Compute factors
thnom = unloaded_ratio(r1, r2)
return (thl / thnom, thu / thnom)


def hysteresis_threshold_factors(r1, r2, rh):
"""
Same as hysteresis_threshold_ratios(), but calculates the
Expand All @@ -151,15 +164,8 @@ def hysteresis_threshold_factors(r1, r2, rh):
rh : float or EngineerIO string
The hysteresis resistor of the divider
"""
# Normalize inputs
r1 = normalize_numeric(r1)
r2 = normalize_numeric(r2)
rh = normalize_numeric(rh)
# Compute thresholds
thl, thu = hysteresis_threshold_ratios(r1, r2, rh)
# Compute factors
thnom = unloaded_ratio(r1, r2)
return (thl / thnom, thu / thnom)
return __hysteresis_threshold_factors(
r1, r2, rh, hysteresis_threshold_ratios)


def hysteresis_threshold_factors_opendrain(r1, r2, rh):
Expand All @@ -181,15 +187,8 @@ def hysteresis_threshold_factors_opendrain(r1, r2, rh):
rh : float or EngineerIO string
The hysteresis resistor of the divider
"""
# Normalize inputs
r1 = normalize_numeric(r1)
r2 = normalize_numeric(r2)
rh = normalize_numeric(rh)
# Compute thresholds
thl, thu = hysteresis_threshold_ratios_opendrain(r1, r2, rh)
# Compute factors
thnom = unloaded_ratio(r1, r2)
return (thl / thnom, thu / thnom)
return __hysteresis_threshold_factors(
r1, r2, rh, hysteresis_threshold_ratios_opendrain)


def hysteresis_resistor(r1, r2, fh=0.05):
Expand Down
1 change: 0 additions & 1 deletion UliEngineering/Electronics/VoltageDivider.py
Expand Up @@ -111,4 +111,3 @@ def feedback_actual_voltage(rtop, rbot, vfb) -> Quantity("V"):
ratio = unloaded_ratio(rtop, rbot)
return normalize_numeric(vfb) / ratio


0 comments on commit 16fd5b8

Please sign in to comment.