@Test public void copyApaColorData() { ColorMock.mockStatic(); final byte brightness = 15; final byte r = (byte) 0x33; final byte g = (byte) 0xB5; final byte b = (byte) 0xE5; final int color = Color.argb(0xFF, r & 0xFF, g & 0xFF, b & 0xFF); final byte[] dest = new byte[4]; Apa102.copyApaColorData(brightness, color, Mode.BGR, dest, 0); assertArrayEquals(new byte[]{brightness, b, g, r}, dest); Apa102.copyApaColorData(brightness, color, Mode.BRG, dest, 0); assertArrayEquals(new byte[]{brightness, b, r, g}, dest); Apa102.copyApaColorData(brightness, color, Mode.GBR, dest, 0); assertArrayEquals(new byte[]{brightness, g, b, r}, dest); Apa102.copyApaColorData(brightness, color, Mode.GRB, dest, 0); assertArrayEquals(new byte[]{brightness, g, r, b}, dest); Apa102.copyApaColorData(brightness, color, Mode.RBG, dest, 0); assertArrayEquals(new byte[]{brightness, r, b, g}, dest); Apa102.copyApaColorData(brightness, color, Mode.RGB, dest, 0); assertArrayEquals(new byte[]{brightness, r, g, b}, dest); }
@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; }