Esempio n. 1
0
    def __init__(self, address=0xc, **kwargs):
        """Initialise the AD5321 device.

        :param address: address of the AD5321 on the I2C bus
        :param kwargs: keyword arguments to be passed to the underlying I2CDevice
        """
        # Initialise the I2CDevice superclass instance
        I2CDevice.__init__(self, address, **kwargs)
Esempio n. 2
0
    def __init__(self, address=0xc, **kwargs):
        """Initialise the AD5321 device.

        :param address: address of the AD5321 on the I2C bus
        :param kwargs: keyword arguments to be passed to the underlying I2CDevice
        """
        # Initialise the I2CDevice superclass instance
        I2CDevice.__init__(self, address, **kwargs)
Esempio n. 3
0
    def __init__(self, address=0x20, **kwargs):
        """Initialise the AD7998 device.

        :param address: address of the AD7998 device on the I2C bus
        :param kwargs: keyword arguments to be passed to the underlying I2CDevice
        """
        # Initialise the I2CDevice superclass instance
        I2CDevice.__init__(self, address, **kwargs)

        # Set cycle register to fastest conversion mode
        self.write8(3, 1)
Esempio n. 4
0
    def __init__(self, address=0x20, **kwargs):
        """Initialise the MCP23008 device.

        :param address: address of the MCP23008 deviceon the I2C bus
        :param kwargs: keyword arguments to be passed to the underlying I2CDevice
        """
        # Initialise the I2CDevice superclass instance
        I2CDevice.__init__(self, address, **kwargs)

        # Synchronise local buffered register values with state of device
        self.__iodir = self.readU8(self.IODIR)
        self.__gppu = self.readU8(self.GPPU)
        self.__gpio = self.readU8(self.GPIO)
Esempio n. 5
0
    def __init__(self, address=0x70, allowMultiple=True, **kwargs):
        """Initialise the the TCA9548 device.

        :param address: address of TCA9548 on the I2C bus
        :param kwargs: keyword arguments to be passed to underlying I2CDevice
        """
        # Initialise the I2CDevice superclass instance
        I2CDevice.__init__(self, address, **kwargs)

        # Clear attached devices and currently enabled channel
        self._attached_devices = {}
        self._selected_channel = None

        # Disable any already enabled devices by clearing output bus selection
        self.write8(0, 0)
Esempio n. 6
0
    def test_remove_missing_device(self):

        device = I2CDevice(0x24)

        with assert_raises_regexp(
            I2CException, 'Device %s was not attached to this I2CContainer' % device
        ):
            self.container.remove_device(device)
Esempio n. 7
0
    def test_remove_missing_device(self):

        device_not_attached = I2CDevice(0x20)

        with assert_raises_regexp(
                I2CException,
                'Device %s is not attached to this TCA' % device_not_attached):
            self.tca.remove_device(device_not_attached)
Esempio n. 8
0
    def setup_class(cls):

        cls.device_busnum = 1
        cls.device_address = 0x70
        cls.device_debug = True
        cls.device = I2CDevice(cls.device_address, cls.device_busnum,
                               cls.device_debug)
        cls.device.pre_access = Mock()
Esempio n. 9
0
    def test_attach_existing_device(self):

        device = I2CDevice(0x21)
        self.container.attach_device(device)
        assert_true(device in self.container._attached_devices)
Esempio n. 10
0
    def __init__(self, quad_enable_interval=DEFAULT_QUAD_ENABLE_INTERVAL,
                 detector_position_offset=DEFAULT_DETECTOR_POSITION_OFFSET):
        """Initialise the PSCU instance.

        The constructor initialises the PSCU instance, setting up all the I2C
        devices on the PSCU, intialising and attached the quads, and setting up the
        front panel display and buttons.

        :param quad_enable_interval: time interval between quad enable commands
        """
        # Turn off exception raising in the I2C device class
        I2CDevice.disable_exceptions()

        # Set up the quad enable interval with the specified value
        self.quad_enable_interval = quad_enable_interval
        self.detector_position_offset = detector_position_offset

        # Create the TCA I2C bus multiplexer instance
        self.tca = TCA9548(0x70)

        # Attach the quads to the TCA
        self.num_quads = 4
        self.quad = []
        for i in range(self.num_quads):
            self.quad.append(self.tca.attach_device(i, Quad))

        # Attach the internal I2C bus 4 sensor and IO devices
        # Temperature monitor ADC channels
        self.adc_temp_mon = []
        self.adc_temp_mon.append(self.tca.attach_device(4, AD7998, 0x21))
        self.adc_temp_mon.append(self.tca.attach_device(4, AD7998, 0x22))
        self.adc_temp_mon.append(self.tca.attach_device(4, AD7998, 0x23))

        # Temperature monitor GPIO channels
        self.mcp_temp_mon = []
        self.mcp_temp_mon.append(self.tca.attach_device(4, MCP23008, 0x24))
        for i in range(8):
            self.mcp_temp_mon[0].setup(i, MCP23008.IN if i < 7 else MCP23008.IN)

        self.mcp_temp_mon.append(self.tca.attach_device(4, MCP23008, 0x25))
        for i in range(8):
            self.mcp_temp_mon[1].setup(i, MCP23008.IN)

        self.mcp_temp_mon.append(self.tca.attach_device(4, MCP23008, 0x26))
        for i in range(8):
            self.mcp_temp_mon[2].setup(i, MCP23008.IN)

        self.mcp_temp_mon.append(self.tca.attach_device(4, MCP23008, 0x27))
        for i in range(8):
            self.mcp_temp_mon[3].setup(i, MCP23008.IN)

        # Attach the miscellaneous I2C bus 5 devices
        # Miscellaneous ADC channels
        self.adc_misc = []
        self.adc_misc.append(self.tca.attach_device(5, AD7998, 0x21))
        self.adc_misc.append(self.tca.attach_device(5, AD7998, 0x22))

        # Miscellaneous monitor GPIO channels
        self.mcp_misc = []
        self.mcp_misc.append(self.tca.attach_device(5, MCP23008, 0x24))
        for i in range(8):
            self.mcp_misc[0].setup(i, MCP23008.OUT if i < 2 else MCP23008.IN)
        self.mcp_misc.append(self.tca.attach_device(5, MCP23008, 0x25))
        for i in range(8):
            self.mcp_misc[1].setup(i, MCP23008.IN)
        self.mcp_misc.append(self.tca.attach_device(5, MCP23008, 0x26))
        for i in range(8):
            self.mcp_misc[2].setup(i, MCP23008.IN)
        self.mcp_misc.append(self.tca.attach_device(5, MCP23008, 0x27))
        for i in range(8):
            self.mcp_misc[3].setup(i, MCP23008.IN)

        # Attach the fan speed DAC device
        self.fan_speed_dac = self.tca.attach_device(5, AD5321, 0x0c)

        # Create internal buffer variables for all sensor parameters
        # Temperature
        self.num_temperatures = 11
        self.__temperature_values = [0.0] * self.num_temperatures
        self.__temperature_values_raw = [0.0] * self.num_temperatures
        self.__temperature_set_points = [0.0] * self.num_temperatures
        self.__temperature_set_points_raw = [0.0] * self.num_temperatures
        self.__temperature_trips = [False] * self.num_temperatures
        self.__temperature_traces = [False] * self.num_temperatures
        self.__temperature_disabled = [False] * self.num_temperatures
        self.__temperature_mode = ['Over'] * 8 + ['Under'] * 3

        # Humidity
        self.num_humidities = 2
        self.__humidity_values = [0.0] * self.num_humidities
        self.__humidity_values_raw = [0.0] * self.num_humidities
        self.__humidity_set_points = [0.0] * self.num_humidities
        self.__humidity_set_points_raw = [0.0] * self.num_humidities
        self.__humidity_trips = [False] * self.num_humidities
        self.__humidity_traces = [False] * self.num_humidities
        self.__humidity_disabled = [False] * self.num_humidities
        self.__humidity_mode = ['Over'] * self.num_humidities

        # Pump
        self.__pump_flow = 0.0
        self.__pump_flow_raw = 0.0
        self.__pump_set_point = 0.0
        self.__pump_set_point_raw = 0.0
        self.__pump_trip = False
        self.__pump_mode = 'Under'

        # Fan
        self.__fan_speed = 0.0
        self.__fan_speed_raw = 0.0
        self.__fan_target = 100.0
        self.__fan_set_point = 0.0
        self.__fan_set_point_raw = 0.0
        self.__fan_trip = False
        self.__fan_mode = 'Under'

        # Position
        self.__position = 0.0
        self.__position_raw = 0.0

        # Quad traces
        self.__quad_traces = [False] * self.num_quads

        # Overall
        self.__armed = False
        self.__healthy = False
        self.__sensor_states = [False] * 5  # Tmp, F, P, H, T
        self.__latched_states = [False] * 5  # Tmp, F, P, T, H

        # Initialise the front panel LCD
        try:
            self.lcd = LcdDisplay(self, "/dev/ttyACM0", 57600, rows=4, cols=20)
            self.lcd_display_error = False
        except LcdDisplayError as e:
            logging.warning(e)
            self.lcd_display_error = True

        # Intialise the front panel push buttons on GPIO pins and enable rising edge detection
        GPIO.setup("P9_11", GPIO.IN)
        GPIO.setup("P9_12", GPIO.IN)
        GPIO.add_event_detect("P9_11", GPIO.RISING)
        GPIO.add_event_detect("P9_12", GPIO.RISING)

        # Internal flag tracking state of quads 'enable all' command
        self.__all_enabled = False

        self.deferred_executor = DeferredExecutor()