def get_terminal_config(self, channel=None): """Get the terminal configuration for the specified channel. :param DeviceControlChannel channel: The channel to get the terminal configuration for. :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.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) # Read the current config. tcon = self._read(channel.term_control_address) # Build result chan_enabled = (tcon & channel.hardware_config_ctrl_bit) > 0 pin_a_enabled = (tcon & channel.term_a_connection_ctrl_bit) > 0 pin_w_enabled = (tcon & channel.wiper_connection_ctrl_bit) > 0 pin_b_enabled = (tcon & channel.term_b_connection_ctrl_bit) > 0 return DeviceControllerTermConfig(channel, chan_enabled, pin_a_enabled, pin_w_enabled, pin_b_enabled)
def set_terminal_config(self, config=None): """Set the device's terminal configuration. :param DeviceControllerTermConfig config: The configuration to set. :raises: raspy.object_disposed_exception.ObjectDisposedException if this instance has been disposed. :raises: raspy.argument_null_exception.ArgumentNullException if the 'config' param is None. :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 config is None: raise ArgumentNullException("'config' param cannot be None.") if not isinstance(config, DeviceControllerTermConfig): msg = "'config' param must be of type DeviceControllerTermConfig." raise IllegalArgumentException(msg) chan = config.channel if chan is None: msg = "A configuration with a null channel is not permitted." raise ArgumentNullException(msg) # Read current config. mem_addr = config.channel.term_control_address tcon = self._read(mem_addr) # Modify config. ctrl_bit = chan.hardware_config_ctrl_bit tcon = self._set_bit(tcon, ctrl_bit, config.channel_enabled) ctrl_bit = chan.term_a_connection_ctrl_bit tcon = self._set_bit(tcon, ctrl_bit, config.pin_a_enabled) ctrl_bit = chan.wiper_connection_ctrl_bit tcon = self._set_bit(tcon, ctrl_bit, config.pin_w_enabled) ctrl_bit = chan.term_b_connection_ctrl_bit tcon = self._set_bit(tcon, ctrl_bit, config.pin_b_enabled) # Write new config to device. self._write(mem_addr, tcon)
def __init__(self, pwm_pin): """Initialize a new instance of BuzzerComponent. :param raspy.io.gpio.Gpio pwm_pin: The pin the buzzer is attached to. :raise: raspy.argument_null_exception.ArgumentNullException if pin is None. """ Buzzer.__init__(self) if pwm_pin is None: raise ArgumentNullException("'pwm_pin' cannot be None.") self.__pwmPin = pwm_pin self.__isBuzzing = False self.__pwmPin.provision() self.__buzzTimer = None
def set_value(self, channel=None, value=0, non_vol=False): """Set the wiper's value in the device. :param DeviceControlChannel channel: The device channel the wiper is on. :param int value: The wiper's value. :param bool non_vol: Set True to write to non-volatile memory, or False to write to volatile memory. :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 - or - if 'value' param is a negative number. :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) if value < 0: msg = "Only positive integer values are permitted. Got value: '" msg += str(value) + "' for writing to channel '" msg += channel.name 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 # Write value to device. self._write(mem_addr, value)
def __init__(self, device, bus_address=-1): """Initialize a new instance of MCPDeviceController. :param raspy.io.i2c.i2c_interface.I2CInterface device: The I2C bus device this instance is connected to. :param int bus_address: The bus address of the device. :raises: raspy.argument_null_exception.ArgumentNullException if param 'device' is None. :raises: raspy.illegal_argument_exception.IllegalArgumentException if param 'device' is not of type I2CInterface. """ Disposable.__init__(self) if device is None: raise ArgumentNullException("Param 'device' cannot be None.") if not isinstance(device, I2CInterface): msg = "Param 'device' must be of I2CInterface." raise IllegalArgumentException(msg) self.__busAddress = bus_address self.__device = device if not self.__device.is_open: self.__device.open()