Exemple #1
0
    def decrease(self, steps=0):
        """Decrease the wiper's value by the specified number of steps.

        It is not an error if the wiper hits or already hit the lower
        boundary (0). In such situations, the wiper sticks to the lower
        boundary or doesn't change.

        :param int steps: The number of steps to decrease by. If not
        specified or zero, then defaults to 1.
        :raises: raspy.io.io_exception.IOException if communication with the
        device failed.
        """
        if self.__currentValue == 0:
            return

        if steps < 0:
            msg = "Only positive integer values are permitted."
            raise IllegalArgumentException(msg)

        if self.non_volatile_mode != microchip_pot_non_volatile_mode.VOLATILE_ONLY:
            msg = "Decrease is only permitted on volatile-only wipers."
            raise InvalidOperationException(msg)

        # Check bounds:
        actual_steps = steps
        if steps > self.__currentValue:
            actual_steps = self.__currentValue

        new_val = self.__currentValue - actual_steps
        if new_val == 0 or steps > 5:
            self.__currentValue = new_val
        else:
            chan = device_control_channel.value_of(self.__channel)
            self.__controller.decrease(chan, actual_steps)
            self.__currentValue = new_val
Exemple #2
0
    def update_cache_from_device(self):
        """Update the cache from the wiper's value.

        :returns: The wiper's current value.
        :rtype: int
        :raises: raspy.io.io_exception.IOException if communication with
        the device fails.
        """
        chan = device_control_channel.value_of(self.__channel)
        self.__currentValue = self.__controller.get_value(chan, False)
        return self.__currentValue
Exemple #3
0
    def set_wiper_lock(self, enabled=False):
        """Enable or disable the wiper lock.

        :param bool enabled: Set True to enable the wiper lock.
        :raises: raspy.io.io_exception.IOException if communication with
        the device fails.
        :raises: raspy.object_disposed_exception.ObjectDisposedException if
        this instance has been disposed.
        """
        if self.is_disposed:
            raise ObjectDisposedException("MicrochipPotentiometer")
        chan = device_control_channel.value_of(self.__channel)
        self.__controller.set_wiper_lock(chan, enabled)
Exemple #4
0
    def _get_non_volatile_value(self):
        """Get the non-volatile wiper's value.

        :returns: The non-volatile wiper's value.
        :rtype: int
        :raises: raspy.invalid_operation_exception.InvalidOperationException if
        this device is not capable of non-volatile wipers.
        """
        if self.is_non_volatile_wiper_capable:
            msg = "This device is not capable of non-volatile wipers."
            raise InvalidOperationException(msg)
        chan = device_control_channel.value_of(self.__channel)
        return self.__controller.get_value(chan, True)
Exemple #5
0
    def terminal_configuration(self):
        """Get the current terminal configuration.

        :returns: The terminal configuration.
        :rtype: raspy.components.potentiometers.microchip.MCPTerminalConfiguration
        :raises: raspy.io.io_exception.IOException if communication with
        the device fails.
        """
        chan = device_control_channel.value_of(self.__channel)
        tcon = self.__controller.get_terminal_config(chan)
        chan_enable = tcon.channel_enabled
        pin_a = tcon.pin_a_enabled
        pin_w = tcon.pin_w_enabled
        pin_b = tcon.pin_b_enabled
        return MCPTerminalConfiguration(self.__channel, chan_enable, pin_a,
                                        pin_w, pin_b)
Exemple #6
0
    def current_value(self, value):
        """Set the wiper's current value.

        :param int value: The wiper value to set.
        """
        # Check bounds.
        new_val = self._get_value_according_boundaries(value)

        # Set wipers according to mode.
        chan = device_control_channel.value_of(self.channel)
        evt = WiperEvent(chan, self.__controller, new_val)
        self._fire_wiper_action_event(evt)

        # Set value only if volatile wiper is affected.
        if self.__nonVolMode == microchip_pot_non_volatile_mode.NON_VOLATILE_ONLY:
            return
        self.__currentValue = new_val
Exemple #7
0
    def _initialize(self, init_val):
        """Initialize the wiper to a defined status.

        For devices capable of non-volatile wipers, the non-volatile value is
        loaded. For devices not capable, the given value is set in the device.

        :param int init_val: The initial value for devices not capable of
        non-volatile wipers.
        :raises: raspy.io.io_exception.IOException if communication with the
        device failed or a malformed result.
        """
        chan = device_control_channel.value_of(self.__channel)
        if self.is_non_volatile_wiper_capable:
            self.__currentValue = self.__controller.get_value(chan, True)
        else:
            new_init_val = self._get_value_according_boundaries(init_val)
            vol = mcp_device_controller.VOLATILE_WIPER
            self.__controller.set_value(chan, new_init_val, vol)
            self.__currentValue = new_init_val
Exemple #8
0
    def increase(self, steps=0):
        """Increase the wiper's value bye the specified number of steps.

        It is not an error if the wiper hits or already hit the upper
        boundary. In such situations, the wiper sticks to the upper boundary
        or doesn't change.
        :param int steps: How many steps to increase. If not specified or
        zero, then defaults to 1. If the current value is equal to the max
        value, then nothing happens. If steps is less than zero, then an
        exception is thrown.
        :raises: raspy.io.io_exception.IOException if communication with the
        device failed.
        """
        max_val = self.max_value
        if self.__currentValue == max_val:
            return

        if steps < 0:
            msg = "Only positive integer values are permitted."
            raise IllegalArgumentException(msg)

        vol_only = microchip_pot_non_volatile_mode.VOLATILE_ONLY
        if self.non_volatile_mode != vol_only:
            msg = "Increase is only permitted for volatile-only wipers."
            raise InvalidOperationException(msg)

        # Check bounds.
        actual_steps = steps
        if (steps + self.__currentValue) > max_val:
            actual_steps = max_val - self.__currentValue

        new_val = self.__currentValue + actual_steps
        if new_val == max_val or steps > 5:
            self.__currentValue = new_val
        else:
            chan = device_control_channel.value_of(self.__channel)
            self.__controller.increase(chan, actual_steps)
            self.__currentValue = new_val
Exemple #9
0
    def terminal_configuration(self, config):
        """Set the terminal configuration.

        :param MCPTerminalConfiguration config:
        The terminal configuration.
        :raises: raspy.io.io_exception.IOException if communication with
        the device fails.
        """
        if config is None:
            raise ArgumentNullException("config value cannot be None.")

        if config.channel != self.__channel:
            msg = "Setting a configuration with a channel that is not the "
            msg += "potentiometer's channel is not supported."
            raise IllegalArgumentException(msg)

        chan = device_control_channel.value_of(self.__channel)
        chan_enable = config.is_channel_enabled
        pin_a = config.is_pin_a_enabled
        pin_w = config.is_pin_w_enabled
        pin_b = config.is_pin_b_enabled
        dev_con = DeviceControllerTermConfig(chan, chan_enable, pin_a, pin_w,
                                             pin_b)
        self.__controller.set_terminal_config(dev_con)