public Apa102LedDriver(int controller, int chipSelect, int frequency, int numLeds, int brightness) { device = new SpiDevice(controller, chipSelect, frequency, SpiClockMode.MODE_0, SPIConstants.DEFAULT_LSB_FIRST); this.brightness = brightness & 0x1F; leds = new int[numLeds]; // A start frame of 32 zero bits (<0x00> <0x00> <0x00> <0x00>) // A 32 bit LED frame for each LED in the string (<0xE0+brightness> <blue> <green> <red>) // An end frame consisting of at least (n/2) bits of 1, where n is the number of LEDs in the string. // 1-64 LEDs => 32bits // 65-128 LEDs => spiBuffer = new byte[4 + 4*numLeds + ((numLeds+63)/64)*4]; }
@Override public void close() { if (device != null) { device.close(); } }
@Override protected void writeByte(int register, byte value) { byte[] tx = new byte[3]; tx[0] = (byte) (boardAddress | WRITE_FLAG); tx[1] = (byte) register; tx[2] = value; device.write(tx); } }
@Override public String getName() { return type.name() + "-" + spiDevice.getController() + "-" + spiDevice.getChipSelect(); }
@Override protected byte readByte(int register) { byte[] tx = new byte[3]; tx[0] = (byte) (boardAddress | READ_FLAG); tx[1] = (byte) register; tx[2] = (byte) 0; byte[] rx = device.writeAndRead(tx); return rx[2]; }
private byte readRegister(PcdRegister register) { byte[] tx = new byte[2]; // Address Format: 1XXXXXX0, the first "1" indicates a read tx[0] = (byte) (register.getAddress() | 0x80); tx[1] = (byte) 0; byte[] rx = device.writeAndRead(tx); if (logReadsAndWrites) { Logger.debug("(0x{}): 0x{}", Integer.toHexString(register.getValue() & 0xff), Integer.toHexString(rx[1] & 0xff)); } return rx[1]; }
@Override public void render() { device.write(spiBuffer); }
@Override public void close() throws RuntimeIOException { super.close(); device.close(); }
public SsdOled(int controller, int chipSelect, DigitalOutputDevice dcPin, DigitalOutputDevice resetPin, int width, int height, int imageType) { spiDevice = new SpiDevice(controller, chipSelect, SPI_FREQUENCY, SpiClockMode.MODE_0, false); this.dcPin = dcPin; this.resetPin = resetPin; this.width = width; this.height = height; this.imageType = imageType; }
byte[] rx = device.writeAndRead(tx);
@Override public void close() { allOff(); device.close(); }
public MFRC522(int controller, int chipSelect, DigitalOutputDevice resetPin) { device = new SpiDevice(controller, chipSelect, SPI_CLOCK_FREQUENCY, SpiClockMode.MODE_0, false); this.resetPin = resetPin; init(); }
tx[index++] = (byte) 0; byte[] in = spiDevice.writeAndRead(tx);
protected void command(byte... commands) { dcPin.setOn(false); spiDevice.write(commands); }
@Override public void close() { Logger.debug("Turning all off before close"); allOff(); device.close(); }
public McpAdc(Type type, int controller, int chipSelect, float vRef) throws RuntimeIOException { super(type.name() + "-" + controller + "-" + chipSelect); this.type = type; this.vRef = vRef; boardPinInfo = new McpAdcBoardPinInfo(type); spiDevice = new SpiDevice(controller, chipSelect, type.getMaxFreq2v7(), SpiClockMode.MODE_0, false); }
protected void data() { dcPin.setOn(true); spiDevice.write(buffer); }
@Override public void close() { clear(); setDisplayOn(false); spiDevice.close(); }
public WS281xSpi(int controller, int chipSelect, Protocol protocol, StripType stripType, int numLeds, int brightness) { device = new SpiDevice(controller, chipSelect, protocol.getFrequency() * 3, SpiClockMode.MODE_0, SPIConstants.DEFAULT_LSB_FIRST); this.protocol = protocol; this.stripType = stripType; this.numLeds = numLeds; this.brightness = brightness & 0xff; leds = new int[numLeds]; gamma = new byte[256]; // Set default uncorrected gamma table for (int x=0; x<256; x++) { gamma[x] = (byte) x; } // Allocate SPI transmit buffer (same size as PCM) pixelRaw = new byte[PCM_BYTE_COUNT(numLeds, protocol.getFrequency())]; // 1.25us per bit (1250ns) renderWaitTime = numLeds * stripType.getColourCount() * 8 * 1250 + LED_RESET_WAIT_TIME; }