MicrochipPotentiometerDeviceController { public DeviceControllerDeviceStatus getDeviceStatus() throws IOException { int deviceStatus = read(MEMADDR_STATUS); int reservedValue = deviceStatus & STATUS_RESERVED_MASK; if (reservedValue != STATUS_RESERVED_VALUE) { throw new IOException( "status-bits 4 to 8 must be 1 according to documentation chapter 4.2.2.1. got '" + Integer.toString(reservedValue, 2) + "'!"); } boolean eepromWriteActive = (deviceStatus & STATUS_EEPROM_WRITEACTIVE_BIT) > 0; boolean eepromWriteProtection = (deviceStatus & STATUS_EEPROM_WRITEPROTECTION_BIT) > 0; boolean wiperLock0 = (deviceStatus & STATUS_WIPERLOCK0_BIT) > 0; boolean wiperLock1 = (deviceStatus & STATUS_WIPERLOCK1_BIT) > 0; return new DeviceControllerDeviceStatus( eepromWriteActive, eepromWriteProtection, wiperLock0, wiperLock1); } MicrochipPotentiometerDeviceController(final I2CDevice i2cDevice); DeviceControllerDeviceStatus getDeviceStatus(); void increase(final DeviceControllerChannel channel, final int steps); void decrease(final DeviceControllerChannel channel, final int steps); int getValue(final DeviceControllerChannel channel, final boolean nonVolatile); void setValue(final DeviceControllerChannel channel, final int value,
			final boolean nonVolatile); DeviceControllerTerminalConfiguration getTerminalConfiguration(
			final DeviceControllerChannel channel); void setTerminalConfiguration(final DeviceControllerTerminalConfiguration config); void setWiperLock(final DeviceControllerChannel channel,
			final boolean locked); void setWriteProtection(final boolean enabled); @Override String toString(); @Override boolean equals(final Object obj); static final boolean VOLATILE_WIPER; static final boolean NONVOLATILE_WIPER; }
@Test public void testGetDeviceStatus() throws IOException { try { controller.getDeviceStatus(); fail("Excpected IOException (but there is no) because " + "I2CDevice-mock is not initialized yet!"); } catch (IOException e) { } testForWriteAndRead((byte) 0b1011100); reset(i2cDevice); final int[] length = new int[1]; mockReadResult(i2cDevice, (byte) 0b00011111, (byte) 0b11110101, length); DeviceControllerDeviceStatus deviceStatus1 = controller.getDeviceStatus(); testForWriteAndRead((byte) 0b1011100); assertTrue("On calling 'getDeviceStatus' the method I2CDevice.read(...)" + "is called with a byte-array as first argument. The length of this " + "array must be at least 2 but was " + length[0], length[0] >= 2); assertEquals("Unexpected EEPROM-write-active-flag according to " + "status-bits 0b1111111110101 (see 4.2.2.1)", false, deviceStatus1.isEepromWriteActive()); assertEquals("Unexpected channel-B-locked-flag according to " + "status-bits 0b1111111110101 (see 4.2.2.1)", true, deviceStatus1.isChannelBLocked()); assertEquals("Unexpected channel-A-locked-flag according to " + "status-bits 0b1111111110101 (see 4.2.2.1)", false, deviceStatus1.isChannelALocked()); assertEquals("Unexpected EEPROM-write-protected-flag according to " + "status-bits 0b1111111110101 (see 4.2.2.1)", true, deviceStatus1.isEepromWriteProtected()); reset(i2cDevice); mockReadResult(i2cDevice, (byte) 0b00011111, (byte) 0b11111010, length); DeviceControllerDeviceStatus deviceStatus2 = controller.getDeviceStatus(); testForWriteAndRead((byte) 0b1011100); assertTrue("On calling 'getDeviceStatus' the method I2CDevice.read(...)" + "is called with a byte-array as first argument. The length of this " + "array must be at least 2 but was " + length[0], length[0] >= 2); assertEquals("Unexpected EEPROM-write-active-flag according to " + "status-bits 0b1111111111010 (see 4.2.2.1)", true, deviceStatus2.isEepromWriteActive()); assertEquals("Unexpected channel-B-locked-flag according to " + "status-bits 0b1111111111010 (see 4.2.2.1)", false, deviceStatus2.isChannelBLocked()); assertEquals("Unexpected channel-A-locked-flag according to " + "status-bits 0b1111111111010 (see 4.2.2.1)", true, deviceStatus2.isChannelALocked()); assertEquals("Unexpected EEPROM-write-protected-flag according to " + "status-bits 0b1111111111010 (see 4.2.2.1)", false, deviceStatus2.isEepromWriteProtected()); reset(i2cDevice); mockReadResult(i2cDevice, (byte) 0b00000000, (byte) 0b000000000, length); try { controller.getDeviceStatus(); fail("Excpected IOException (but there is no) because " + "I2CDevice-mock returns malformed device-status!"); } catch (IOException e) { } testForWriteAndRead((byte) 0b1011100); assertTrue("On calling 'getDeviceStatus' the method I2CDevice.read(...)" + "is called with a byte-array as first argument. The length of this " + "array must be at least 2 but was " + length[0], length[0] >= 2); }