Skip to content

Commit

Permalink
Remove duplicate code in hysteresis_threshold_voltages
Browse files Browse the repository at this point in the history
  • Loading branch information
ulikoehler committed Nov 24, 2016
1 parent 16fd5b8 commit 2d3dd46
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions UliEngineering/Electronics/Hysteresis.py
Expand Up @@ -83,6 +83,12 @@ def hysteresis_threshold_ratios_opendrain(r1, r2, rh):
thu = unloaded_ratio(r1, r2)
return (thl, thu)

def __hysteresis_threshold_voltages(r1, r2, rh, vcc, fn):
"""Internal push-pull & open-drain common code"""
vcc = normalize_numeric(vcc)
thl, thu = fn(r1, r2, rh)
return (thl * vcc, thu * vcc)


def hysteresis_threshold_voltages(r1, r2, rh, vcc):
"""
Expand All @@ -103,10 +109,8 @@ def hysteresis_threshold_voltages(r1, r2, rh, vcc):
The supply voltage that drives the output of the comparator
and the R1/R2 network.
"""
vcc = normalize_numeric(vcc)
thl, thu = hysteresis_threshold_ratios(r1, r2, rh)
return (thl * vcc, thu * vcc)

return __hysteresis_threshold_voltages(
r1, r2, rh, vcc, hysteresis_threshold_ratios)

def hysteresis_threshold_voltages_opendrain(r1, r2, rh, vcc):
"""
Expand All @@ -127,9 +131,8 @@ def hysteresis_threshold_voltages_opendrain(r1, r2, rh, vcc):
The supply voltage that drives the output of the comparator
and the R1/R2 network.
"""
vcc = normalize_numeric(vcc)
thl, thu = hysteresis_threshold_ratios_opendrain(r1, r2, rh)
return (thl * vcc, thu * vcc)
return __hysteresis_threshold_voltages(
r1, r2, rh, vcc, hysteresis_threshold_ratios_opendrain)


def __hysteresis_threshold_factors(r1, r2, rh, fn):
Expand Down

0 comments on commit 2d3dd46

Please sign in to comment.