@Test public void readDifferential_returnsCorrectValue() throws IOException { Mcp3008Device mockDevice = new Mcp3008Device(); mockDevice.setChannelValues(512, 256); Mcp300x driver = new Mcp300x(mockDevice, Mcp300x.Configuration.MCP3008); int result = driver.readDifferentialInput(Mcp300x.MODE_DIFF_0P_1N); assertEquals("Normal differential should return 256", 256, result); result = driver.readDifferentialInput(Mcp300x.MODE_DIFF_1P_0N); assertEquals("Inverted differential should return 0", 0, result); }
public int readDifferentialInput(@DifferentialMode int mode) throws IOException { byte config = MODE_DIFFERENTIAL; config |= mode; byte[] command = { 0x01, config, 0x00 }; byte[] response = new byte[3]; mDevice.transfer(command, response, 3); return ((response[1] & 0x3) << 8) | (response[2] & 0xFF); }
Mcp300x implements AutoCloseable { public int readDifferentialInput(@DifferentialMode int mode) throws IOException { byte config = MODE_DIFFERENTIAL; config |= mode; byte[] command = { 0x01, config, 0x00 }; byte[] response = new byte[3]; mDevice.transfer(command, response, 3); return ((response[1] & 0x3) << 8) | (response[2] & 0xFF); } }
Mcp300x implements AutoCloseable { public int readDifferentialInput(@DifferentialMode int mode) throws IOException { byte config = MODE_DIFFERENTIAL; config |= mode; byte[] command = { 0x01, config, 0x00 }; byte[] response = new byte[3]; mDevice.transfer(command, response, 3); return ((response[1] & 0x3) << 8) | (response[2] & 0xFF); } Mcp300x(String spiName, Configuration chip); @VisibleForTesting  Mcp300x(SpiDevice spiDevice, Configuration chip); }
Mcp300x implements AutoCloseable { public int readDifferentialInput(@DifferentialMode int mode) throws IOException { byte config = MODE_DIFFERENTIAL; config |= mode; byte[] command = { 0x01, config, 0x00 }; byte[] response = new byte[3]; mDevice.transfer(command, response, 3); return ((response[1] & 0x3) << 8) | (response[2] & 0xFF); } Mcp300x(String spiName, Configuration chip); @VisibleForTesting  Mcp300x(SpiDevice spiDevice, Configuration chip); int readSingleEndedInput(int channel); int readDifferentialInput(@DifferentialMode int mode); @Override void close(); }
Mcp300x implements AutoCloseable { public int readDifferentialInput(@DifferentialMode int mode) throws IOException { byte config = MODE_DIFFERENTIAL; config |= mode; byte[] command = { 0x01, config, 0x00 }; byte[] response = new byte[3]; mDevice.transfer(command, response, 3); return ((response[1] & 0x3) << 8) | (response[2] & 0xFF); } Mcp300x(String spiName, Configuration chip); @VisibleForTesting  Mcp300x(SpiDevice spiDevice, Configuration chip); int readSingleEndedInput(int channel); int readDifferentialInput(@DifferentialMode int mode); @Override void close(); static final int MODE_DIFF_0P_1N; static final int MODE_DIFF_1P_0N; static final int MODE_DIFF_2P_3N; static final int MODE_DIFF_3P_2N; static final int MODE_DIFF_4P_5N; static final int MODE_DIFF_5P_4N; static final int MODE_DIFF_6P_7N; static final int MODE_DIFF_7P_6N; }