def test_revision_1(self):
     with patch('__builtin__.open') as mock_open:
         handle = mock_open.return_value.__enter__.return_value
         handle.__iter__.return_value = iter(['Revision : 0000'])
         rev = Platform.pi_revision()
         self.assertEquals(rev, 1)
     with patch('__builtin__.open') as mock_open:
         handle = mock_open.return_value.__enter__.return_value
         handle.__iter__.return_value = iter(['Revision : 0002'])
         rev = Platform.pi_revision()
         self.assertEquals(rev, 1)
     with patch('__builtin__.open') as mock_open:
         handle = mock_open.return_value.__enter__.return_value
         handle.__iter__.return_value = iter(['Revision : 0003'])
         rev = Platform.pi_revision()
         self.assertEquals(rev, 1)
Ejemplo n.º 2
0
def get_default_bus():
    """Return the default bus number based on the device platform.  For a
    Raspberry Pi either bus 0 or 1 (based on the Pi revision) will be returned.
    For a Beaglebone Black the first user accessible bus, 1, will be returned.
    """
    plat = Platform.platform_detect()
    if plat == Platform.RASPBERRY_PI:
        if Platform.pi_revision() == 1:
            # Revision 1 Pi uses I2C bus 0.
            return 0
        else:
            # Revision 2 Pi uses I2C bus 1.
            return 1
    elif plat == Platform.BEAGLEBONE_BLACK:
        # Beaglebone Black has multiple I2C buses, default to 1 (P9_19 and P9_20).
        return 1
    else:
        raise RuntimeError('Could not determine default I2C bus for platform.')