# Path: nanpy/util.py
# def constrain(value, xmin, xmax):
#     if value < xmin:
#         return xmin
#     if value > xmax:
#         return xmax
#     return value


from nanpy.util import constrain
LOW, HIGH = 0, 1
INPUT, OUTPUT = 0, 1


class DigiPot():
    _udLastValue = None
    _currentValue = None
    range = (0, DIGIPOT_MAX_AMOUNT)

    def __init__(self, incPin, udPin, csPin):
        self._incPin = incPin
        self._udPin = udPin
        self._csPin = csPin

        self._incPin.write_mode(OUTPUT)
        self._incPin.write_digital_value(HIGH)

        self._udPin.write_mode(OUTPUT)

        self._csPin.write_mode(OUTPUT)
        self._csPin.write_digital_value(LOW)

        self.set(0)

    def reset(self):
        # change down maximum number of times to ensure the value is 0
        self.decrease(DIGIPOT_MAX_AMOUNT)
        self._currentValue = 0

    def set(self, value):

# Path: nanpy/util.py
# def constrain(value, xmin, xmax):
#     if value < xmin:
#         return xmin
#     if value > xmax:
#         return xmax
#     return value


# Path: nanpy/DigiPotX9Cxxx.py
from nanpy.util import constrain

LOW, HIGH = 0, 1
INPUT, OUTPUT = 0, 1


class DigiPot():
    _udLastValue = None
    _currentValue = None
    range = (0, DIGIPOT_MAX_AMOUNT)

    def __init__(self, incPin, udPin, csPin):
        self._incPin = incPin
        self._udPin = udPin
        self._csPin = csPin

        self._incPin.write_mode(OUTPUT)
        self._incPin.write_digital_value(HIGH)

        self._udPin.write_mode(OUTPUT)

        self._csPin.write_mode(OUTPUT)
        self._csPin.write_digital_value(LOW)

        self.set(0)

    def reset(self):
        # change down maximum number of times to ensure the value is 0
        self.decrease(DIGIPOT_MAX_AMOUNT)
        self._currentValue = 0

    def set(self, value):

        value = constrain(value, 0, DIGIPOT_MAX_AMOUNT)