@Test public void readSingle_returnsCorrectValue() throws IOException { Mcp3008Device mockDevice = new Mcp3008Device(); mockDevice.setChannelValues(0, 256, 512, 1023); Mcp300x driver = new Mcp300x(mockDevice, Mcp300x.Configuration.MCP3008); int result = driver.readSingleEndedInput(0); assertEquals("Channel 0 should return 0", 0, result); result = driver.readSingleEndedInput(1); assertEquals("Channel 1 should return 256", 256, result); result = driver.readSingleEndedInput(2); assertEquals("Channel 2 should return 512", 512, result); result = driver.readSingleEndedInput(3); assertEquals("Channel 3 should return 1023", 1023, result); }
public int readSingleEndedInput(int channel) throws IOException { if (channel >= mChipConfiguration.channelCount) { throw new IllegalArgumentException("Channel cannot be greater than " + mChipConfiguration.channelCount); } byte config = MODE_SINGLE_ENDED; config |= ((channel & 0x7) << 4); 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 readSingleEndedInput(int channel) throws IOException { if (channel >= mChipConfiguration.channelCount) { throw new IllegalArgumentException("Channel cannot be greater than " + mChipConfiguration.channelCount); } byte config = MODE_SINGLE_ENDED; config |= ((channel & 0x7) << 4); 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 readSingleEndedInput(int channel) throws IOException { if (channel >= mChipConfiguration.channelCount) { throw new IllegalArgumentException("Channel cannot be greater than " + mChipConfiguration.channelCount); } byte config = MODE_SINGLE_ENDED; config |= ((channel & 0x7) << 4); 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 readSingleEndedInput(int channel) throws IOException { if (channel >= mChipConfiguration.channelCount) { throw new IllegalArgumentException("Channel cannot be greater than " + mChipConfiguration.channelCount); } byte config = MODE_SINGLE_ENDED; config |= ((channel & 0x7) << 4); 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 readSingleEndedInput(int channel) throws IOException { if (channel >= mChipConfiguration.channelCount) { throw new IllegalArgumentException("Channel cannot be greater than " + mChipConfiguration.channelCount); } byte config = MODE_SINGLE_ENDED; config |= ((channel & 0x7) << 4); 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; }