Class AddressableLEDBufferView

java.lang.Object
org.wpilib.hardware.led.AddressableLEDBufferView
All Implemented Interfaces:
LEDReader, LEDWriter

public class AddressableLEDBufferView extends Object implements LEDReader, LEDWriter
A view of another addressable LED buffer. Views CANNOT be written directly to an LED strip; the backing buffer must be written instead. However, views provide an easy way to split a large LED strip into smaller sections (which may be reversed from the orientation of the LED strip as a whole) that can be animated individually without modifying LEDs outside those sections.
  • Constructor Details

    • AddressableLEDBufferView

      public <B extends LEDReader & LEDWriter> AddressableLEDBufferView(B backingBuffer, int startingIndex, int endingIndex)
      Creates a new view of a buffer. A view will be reversed if the starting index is after the ending index; writing front-to-back in the view will write in the back-to-front direction on the underlying buffer.
      Type Parameters:
      B - the type of the buffer object to create a view for
      Parameters:
      backingBuffer - the backing buffer to view
      startingIndex - the index of the LED in the backing buffer that the view should start from
      endingIndex - the index of the LED in the backing buffer that the view should end on
    • AddressableLEDBufferView

      public AddressableLEDBufferView(LEDReader backingReader, LEDWriter backingWriter, int startingIndex, int endingIndex)
      Creates a new view of a buffer. A view will be reversed if the starting index is after the ending index; writing front-to-back in the view will write in the back-to-front direction on the underlying buffer.
      Parameters:
      backingReader - the backing LED data reader
      backingWriter - the backing LED data writer
      startingIndex - the index of the LED in the backing buffer that the view should start from
      endingIndex - the index of the LED in the backing buffer that the view should end on
  • Method Details

    • reversed

      Creates a view that operates on the same range as this one, but goes in reverse order. This is useful for serpentine runs of LED strips connected front-to-end; simply reverse the view for reversed sections and animations will move in the same physical direction along both strips.
      Returns:
      the reversed view
    • getLength

      public int getLength()
      Description copied from interface: LEDReader
      Gets the length of the buffer.
      Specified by:
      getLength in interface LEDReader
      Returns:
      the buffer length
    • setRGB

      public void setRGB(int index, int r, int g, int b)
      Description copied from interface: LEDWriter
      Sets the RGB value for an LED at a specific index on a LED buffer.
      Specified by:
      setRGB in interface LEDWriter
      Parameters:
      index - the index of the LED to write to
      r - the value of the red channel, in [0, 255]
      g - the value of the green channel, in [0, 255]
      b - the value of the blue channel, in [0, 255]
    • getLED

      public Color getLED(int index)
      Description copied from interface: LEDReader
      Gets the most recently written color for a particular LED in the buffer.
      Specified by:
      getLED in interface LEDReader
      Parameters:
      index - the index of the LED
      Returns:
      the LED color
    • getLED8Bit

      public Color8Bit getLED8Bit(int index)
      Description copied from interface: LEDReader
      Gets the most recently written color for a particular LED in the buffer.
      Specified by:
      getLED8Bit in interface LEDReader
      Parameters:
      index - the index of the LED
      Returns:
      the LED color
    • getRed

      public int getRed(int index)
      Description copied from interface: LEDReader
      Gets the red channel of the color at the specified index.
      Specified by:
      getRed in interface LEDReader
      Parameters:
      index - the index of the LED to read
      Returns:
      the value of the red channel, from [0, 255]
    • getGreen

      public int getGreen(int index)
      Description copied from interface: LEDReader
      Gets the green channel of the color at the specified index.
      Specified by:
      getGreen in interface LEDReader
      Parameters:
      index - the index of the LED to read
      Returns:
      the value of the green channel, from [0, 255]
    • getBlue

      public int getBlue(int index)
      Description copied from interface: LEDReader
      Gets the blue channel of the color at the specified index.
      Specified by:
      getBlue in interface LEDReader
      Parameters:
      index - the index of the LED to read
      Returns:
      the value of the blue channel, from [0, 255]
    • isReversed

      public boolean isReversed()
      Checks if this view is reversed with respect to its backing buffer.
      Returns:
      true if the view is reversed, false otherwise