Beispiel #1
0
    def x_or(self, b_set):
        """Perform a logical XOR of this BitSet with the specified BitSet.

        This BitSet is modified so that the bits in it have the value True if
        (and only if) one of the following statements hold true:
        - The bit initially has the value True, and the corresponding bit in
        the specified BitSet has the value False.
        - The bit initially has the value False, and the corresponding bit in
        the specified BitSet has the value True.

        :param BitSet b_set: A BitSet.
        :raises: ArgumentNullException if bs is None.
        :raises: IllegalArgumentException if bs is not a BitSet.
        """
        if b_set is None:
            raise ArgumentNullException("param 'b_set' cannot be None.")

        if not isinstance(b_set, BitSet):
            raise IllegalArgumentException("param 'b_set' must be a BitSet.")

        # Calculate how many words which have in common with the other BitSet.
        words_in_common = min(self.__words_in_use, b_set.get_words_in_use())
        if self.__words_in_use < b_set.get_words_in_use():
            self._ensure_capacity(b_set.get_words_in_use())
            self.__words_in_use = b_set.get_words_in_use()

        # Perform logical XOR on words in common.
        for i in range(0, words_in_common - 1):
            self.__bits[i] ^= b_set.get_bits()[i]

        # Copy any remaining words.
        if words_in_common < b_set.get_words_in_use():
            self.__bits = self.__bits[0:b_set.get_words_in_use() -
                                      words_in_common]

        self.recalculate_words_in_use()
        self._check_invariants()
Beispiel #2
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)
Beispiel #3
0
    def get_value(self, channel=None, non_vol=False):
        """Receive the current wiper's value from the device.

        :param DeviceControlChannel channel: The device channel the wiper
        is on.
        :param bool non_vol: Set True to read from non-volatile memory, or
        False to read from volatile memory.
        :returns: The wiper's value.
        :rtype: int
        :raises: raspy.object_disposed_exception.ObjectDisposedException if
        this instance has been disposed.
        :raises: raspy.argument_null_exception.ArgumentNullException if the
        'channel' param is None.
        :raises: raspy.illegal_argument_exception.IllegalArgumentException if
        param 'channel' is not of type DeviceControlChannel.
        :raises: raspy.io.io_exception.IOException if an I/O error occurred.
        The specified address is inaccessible or the I2C transaction failed.
        """
        if self.is_disposed:
            return ObjectDisposedException("MCPDeviceController")

        if channel is None:
            raise ArgumentNullException("'channel' param cannot be None.")

        if not isinstance(channel, device_control_channel.DeviceControlChannel):
            msg = "'channel' param must be of type DeviceControlChannel."
            raise IllegalArgumentException(msg)

        # Choose proper mem address.
        if non_vol is None:
            non_vol = False

        mem_addr = channel.volatile_mem_address
        if non_vol:
            mem_addr = channel.non_volatile_mem_address
        return self._read(mem_addr)
Beispiel #4
0
    def __init__(self, pn, initial_val, name):
        """Initialize a new instance of the raspy.io.PiFaceGPIO class.

        :param raspy.io.pi_face_pin.PiFacePin pn: The underlying PiFace pin.
        :param int initial_val: The initial pin value (state).
        :param string name: The pin name.
        :raises: raspy.argument_null_exception.ArgumentNullException if the
        specified pin is NonePin.
        :raises: raspy.illegal_argument_exception.IllegalArgumentException if
        the specified pin is not of type raspy.io.pi_face_pins.PiFacePin.
        """
        gpio.Gpio.__init__(self, pn, pin_mode.IN, initial_val)
        self.__pwm = 0
        self.__pwmRange = 0

        if pn is None:
            raise ArgumentNullException("pn param cannot be NonePin.")

        if not isinstance(pn, pi_face_pins.PiFacePin):
            err_msg = "pn param must be a PiFacePins member."
            raise IllegalArgumentException(err_msg)

        self.pin_name = name
        if string_utils.is_null_or_empty(self.pin_name):
            self.pin_name = pn.name

        if (pn == pi_face_pins.Input00 or pn == pi_face_pins.Input01
                or pn == pi_face_pins.Input02 or pn == pi_face_pins.Input03
                or pn == pi_face_pins.Input04 or pn == pi_face_pins.Input05
                or pn == pi_face_pins.Input06 or pn == pi_face_pins.Input07):
            self.mode = pin_mode.IN
        elif (pn == pi_face_pins.Output00 or pn == pi_face_pins.Output01
              or pn == pi_face_pins.Output02 or pn == pi_face_pins.Output03
              or pn == pi_face_pins.Output04 or pn == pi_face_pins.Output05
              or pn == pi_face_pins.Output06 or pn == pi_face_pins.Output07):
            self.mode = pin_mode.OUT
Beispiel #5
0
    def set_wiper_lock(self, channel=None, locked=False):
        """Enable or disable the wiper's lock.

        :param device_control_channel.DeviceControlChannel channel: The
        channel of the wiper to set the lock for.
        :param bool locked: Set True to enable the lock or False to disable.
        :raises: raspy.object_disposed_exception.ObjectDisposedException if
        this instance has been disposed.
        :raises: raspy.argument_null_exception.ArgumentNullException if
        channel is None.
        """
        if self.is_disposed:
            raise ObjectDisposedException("MCPDeviceController")

        if channel is None:
            raise ArgumentNullException("channel param cannot be None.")

        # Increasing or decreasing on non-volatile wipers enables or
        # disables the wiper lock.
        mem_addr = channel.non_volatile_mem_address
        flag = False
        if locked is not None:
            flag = locked
        self._increase_or_decrease(mem_addr, flag, 1)