Пример #1
0
class LEDTest():
    """Test for LED on FT232H board"""
    def __init__(self):
        self._gpio = GpioController()
        self._state = 0  # SW cache of the GPIO output lines
        
    def pins(self):
        print(self._gpio.direction)
    
    def open(self, out_pins):
        """Open a GPIO connection, defining which pins are configured as
           output and input"""
        out_pins &= 0xFF
        url = environ.get('FTDI_DEVICE', 'ftdi://ftdi:232h/1')
        self._gpio.open_from_url(url, direction=out_pins)
        
    def close(self):
        """Close the GPIO connection"""
        self._gpio.close()
        
    def get_gpio(self, line):
        """Retrieve the level of a GPIO input pin

           :param line: specify which GPIO to read out.
           :return: True for high-level, False for low-level
        """
        value = self._gpio.read_port()
        print(value)
        return bool(value & (1 << line))
        
    def set_gpio(self, line, on):
        """Set the level of a GPIO ouput pin.

           :param line: specify which GPIO to madify.
           :param on: a boolean value, True for high-level, False for low-level
        """
        if on:
            state = self._state | (1 << line)
        else:
            state = self._state & ~(1 << line)
        self._commit_state(state)

        
    def _commit_state(self, state):
        """Update GPIO outputs
        """
        self._gpio.write_port(state)
        # do not update cache on error
        self._state = state
Пример #2
0
 def test(self):
     """Check simple GPIO write and read sequence."""
     gpio = GpioController()
     # access to the virtual GPIO port
     out_pins = 0xAA
     gpio.configure('ftdi://:232h/1', direction=out_pins)
     bus, address, iface = gpio.ftdi.usb_path
     self.assertEqual((bus, address, iface), (4, 5, 0))
     vftdi = self.loader.get_virtual_ftdi(bus, address)
     gpio.write_port(0xF3)
     self.assertEqual(vftdi.gpio, 0xAA & 0xF3)
     vftdi.gpio = 0x0c
     vio = gpio.read_port()
     self.assertEqual(vio, (0xAA & 0xF3) | (~0xAA & 0x0c))
     gpio.close()
Пример #3
0
class GpioTest(object):
    """
    """

    def __init__(self):
        self._gpio = GpioController()
        self._state = 0  # SW cache of the GPIO output lines

    def open(self, out_pins):
        """Open a GPIO connection, defining which pins are configured as 
           output and input"""
        out_pins &= 0xFF
        self._gpio.open(vendor=0x403, product=0x6011, interface=1,
                        direction=out_pins)

    def close(self):
        """Close the GPIO connection"""
        self._gpio.close()

    def set_gpio(self, line, on):
        """Set the level of a GPIO ouput pin.

           :param line: specify which GPIO to madify.
           :param on: a boolean value, True for high-level, False for low-level
        """
        if on:
            state = self._state | (1 << line)
        else:
            state = self._state & ~(1 << line)
        self._commit_state(state)

    def get_gpio(self, line):
        """Retrieve the level of a GPIO input pin

           :param line: specify which GPIO to read out.
           :return: True for high-level, False for low-level
        """
        value = self._gpio.read_port()
        return bool(value & (1 << line))

    def _commit_state(self, state):
        """Update GPIO outputs
        """
        self._gpio.write_port(state)
        # do not update cache on error
        self._state = state
Пример #4
0
 def _test_gpio(self):
     """Check simple GPIO write and read sequence."""
     with open('pyftdi/tests/resources/ft232h.yaml', 'rb') as yfp:
         self.loader.load(yfp)
     gpio = GpioController()
     # access to the virtual GPIO port
     out_pins = 0xAA
     gpio.configure('ftdi://:232h/1', direction=out_pins)
     bus, address, iface = gpio.ftdi.usb_path
     self.assertEqual((bus, address, iface), (4, 5, 0))
     vftdi = self.loader.get_virtual_ftdi(bus, address)
     vport = vftdi.get_port(1)
     gpio.write_port(0xF3)
     self.assertEqual(vport.gpio, 0xAA & 0xF3)
     vport.gpio = 0x0c
     vio = gpio.read_port()
     self.assertEqual(vio, (0xAA & 0xF3) | (~0xAA & 0x0c))
     gpio.close()