@Test public void copyApaColorData_throwsIfNullArray() { mExpectedException.expect(IllegalArgumentException.class); Apa102.copyApaColorData((byte) 0, 0, Mode.BGR, null, 0); }
@VisibleForTesting static void copyApaColorData(byte brightness, int color, Mode ledMode, byte[] dest, int pos) { if (dest == null || dest.length < pos + 4) { throw new IllegalArgumentException("Destination length must be at least " + (pos + 4)); } dest[pos] = brightness; int r = Color.red(color); int g = Color.green(color); int b = Color.blue(color); switch(ledMode) { case RBG: dest[++pos] = (byte) r; dest[++pos] = (byte) b; dest[++pos] = (byte) g; break; case BGR: dest[++pos] = (byte) b; dest[++pos] = (byte) g; dest[++pos] = (byte) r; break; case BRG: dest[++pos] = (byte) b; dest[++pos] = (byte) r; dest[++pos] = (byte) g; break; case GRB: dest[++pos] = (byte) g; dest[++pos] = (byte) r; dest[++pos] = (byte) b; break; case GBR: dest[++pos] = (byte) g; dest[++pos] = (byte) b; dest[++pos] = (byte) r; break; default: dest[++pos] = (byte) r; dest[++pos] = (byte) g; dest[++pos] = (byte) b; break; } }
Apa102 implements AutoCloseable { @VisibleForTesting static void copyApaColorData(byte brightness, int color, Mode ledMode, byte[] dest, int pos) { if (dest == null || dest.length < pos + 4) { throw new IllegalArgumentException("Destination length must be at least " + (pos + 4)); } dest[pos] = brightness; int r = Color.red(color); int g = Color.green(color); int b = Color.blue(color); switch(ledMode) { case RBG: dest[++pos] = (byte) r; dest[++pos] = (byte) b; dest[++pos] = (byte) g; break; case BGR: dest[++pos] = (byte) b; dest[++pos] = (byte) g; dest[++pos] = (byte) r; break; case BRG: dest[++pos] = (byte) b; dest[++pos] = (byte) r; dest[++pos] = (byte) g; break; case GRB: dest[++pos] = (byte) g; dest[++pos] = (byte) r; dest[++pos] = (byte) b; break; case GBR: dest[++pos] = (byte) g; dest[++pos] = (byte) b; dest[++pos] = (byte) r; break; default: dest[++pos] = (byte) r; dest[++pos] = (byte) g; dest[++pos] = (byte) b; break; } } }
Apa102 implements AutoCloseable { @VisibleForTesting static void copyApaColorData(byte brightness, int color, Mode ledMode, byte[] dest, int pos) { if (dest == null || dest.length < pos + 4) { throw new IllegalArgumentException("Destination length must be at least " + (pos + 4)); } dest[pos] = brightness; int r = Color.red(color); int g = Color.green(color); int b = Color.blue(color); switch(ledMode) { case RBG: dest[++pos] = (byte) r; dest[++pos] = (byte) b; dest[++pos] = (byte) g; break; case BGR: dest[++pos] = (byte) b; dest[++pos] = (byte) g; dest[++pos] = (byte) r; break; case BRG: dest[++pos] = (byte) b; dest[++pos] = (byte) r; dest[++pos] = (byte) g; break; case GRB: dest[++pos] = (byte) g; dest[++pos] = (byte) r; dest[++pos] = (byte) b; break; case GBR: dest[++pos] = (byte) g; dest[++pos] = (byte) b; dest[++pos] = (byte) r; break; default: dest[++pos] = (byte) r; dest[++pos] = (byte) g; dest[++pos] = (byte) b; break; } } Apa102(String spiBusPort, Mode ledMode);  Apa102(String spiBusPort, Mode ledMode, Direction direction);  Apa102(String spiBusPort, Mode ledMode, Direction direction, int spiMode); @VisibleForTesting  Apa102(SpiDevice device, Mode ledMode, Direction direction); }
Apa102 implements AutoCloseable { @VisibleForTesting static void copyApaColorData(byte brightness, int color, Mode ledMode, byte[] dest, int pos) { if (dest == null || dest.length < pos + 4) { throw new IllegalArgumentException("Destination length must be at least " + (pos + 4)); } dest[pos] = brightness; int r = Color.red(color); int g = Color.green(color); int b = Color.blue(color); switch(ledMode) { case RBG: dest[++pos] = (byte) r; dest[++pos] = (byte) b; dest[++pos] = (byte) g; break; case BGR: dest[++pos] = (byte) b; dest[++pos] = (byte) g; dest[++pos] = (byte) r; break; case BRG: dest[++pos] = (byte) b; dest[++pos] = (byte) r; dest[++pos] = (byte) g; break; case GRB: dest[++pos] = (byte) g; dest[++pos] = (byte) r; dest[++pos] = (byte) b; break; case GBR: dest[++pos] = (byte) g; dest[++pos] = (byte) b; dest[++pos] = (byte) r; break; default: dest[++pos] = (byte) r; dest[++pos] = (byte) g; dest[++pos] = (byte) b; break; } } Apa102(String spiBusPort, Mode ledMode);  Apa102(String spiBusPort, Mode ledMode, Direction direction);  Apa102(String spiBusPort, Mode ledMode, Direction direction, int spiMode); @VisibleForTesting  Apa102(SpiDevice device, Mode ledMode, Direction direction); void setBrightness(int ledBrightness); int getBrightness(); void setDirection(Direction direction); Direction getDirection(); void write(int[] colors); @Override void close(); }
Apa102 implements AutoCloseable { @VisibleForTesting static void copyApaColorData(byte brightness, int color, Mode ledMode, byte[] dest, int pos) { if (dest == null || dest.length < pos + 4) { throw new IllegalArgumentException("Destination length must be at least " + (pos + 4)); } dest[pos] = brightness; int r = Color.red(color); int g = Color.green(color); int b = Color.blue(color); switch(ledMode) { case RBG: dest[++pos] = (byte) r; dest[++pos] = (byte) b; dest[++pos] = (byte) g; break; case BGR: dest[++pos] = (byte) b; dest[++pos] = (byte) g; dest[++pos] = (byte) r; break; case BRG: dest[++pos] = (byte) b; dest[++pos] = (byte) r; dest[++pos] = (byte) g; break; case GRB: dest[++pos] = (byte) g; dest[++pos] = (byte) r; dest[++pos] = (byte) b; break; case GBR: dest[++pos] = (byte) g; dest[++pos] = (byte) b; dest[++pos] = (byte) r; break; default: dest[++pos] = (byte) r; dest[++pos] = (byte) g; dest[++pos] = (byte) b; break; } } Apa102(String spiBusPort, Mode ledMode);  Apa102(String spiBusPort, Mode ledMode, Direction direction);  Apa102(String spiBusPort, Mode ledMode, Direction direction, int spiMode); @VisibleForTesting  Apa102(SpiDevice device, Mode ledMode, Direction direction); void setBrightness(int ledBrightness); int getBrightness(); void setDirection(Direction direction); Direction getDirection(); void write(int[] colors); @Override void close(); static final int MAX_BRIGHTNESS; }