Skip to content

RaftCoreLEDPixels

Rob Dobson edited this page Oct 12, 2024 · 1 revision

Raft Core LEDPixels

The LEDPixels module is responsible for managing and controlling LED strips and segments (arbitrary groupings of LEDs). It handles the setup, management of LED patterns, and updates to LED states. The module also includes functionality for starting/stopping patterns, showing pixels, and handling per-pixel settings.

Features

  • LED Strip Management: Supports multiple LED strips with individual drivers.
  • Segmented Control: Allows for dividing the pixel array into logical segments.
  • Pattern Support: Allows custom patterns to be applied to the LEDs.
  • Callbacks: Pre and post-show callbacks for additional control during pixel updates.

Configuration

Configuration is generally done via JSON although a LEDPixelConfig object can also be constructed directly and setup in this way. For JSON configuration see LEDPixels JSON Configuration

Constructor and Destructor

LEDPixels::LEDPixels()

The constructor initializes the LEDPixels object.

LEDPixels::~LEDPixels()

The destructor is responsible for cleaning up resources used by the LEDPixels object.

Setup

bool setup(const RaftJsonIF& config)

This setup function configures the LED pixels based on a provided configuration in JSON format. It initializes the number of pixels, the LED strip drivers, and the segments.

Parameters:

  • config: The configuration object (RaftJsonIF) that contains the settings for the LED pixel setup.

Returns:

  • bool: Returns true if the setup was successful, false otherwise.

bool setup(LEDPixelConfig& config)

An alternative setup method that directly accepts a LEDPixelConfig object. It initializes the pixel array, LED strip drivers, and LED segments.

Parameters:

  • config: A configuration object containing the LED pixel settings (LEDPixelConfig).

Returns:

  • bool: Returns true if the setup was successful, false otherwise.

Main Loop

void loop()

The main loop function that updates the LED strips and segments. It processes each segment, updating patterns and handling stop requests.

Adding Patterns

void addPattern(const String& patternName, LEDPatternCreateFn createFn)

This function adds a custom pattern to the LED system. If a pattern with the same name exists, it replaces the old pattern with the new one.

Parameters:

  • patternName: The name of the new pattern to add.
  • createFn: The function that creates the pattern (LEDPatternCreateFn).

Retrieving Pattern Names

void getPatternNames(std::vector<String>& patternNames) const

This function retrieves the names of all available patterns.

Parameters:

  • patternNames: A vector to store the names of all available patterns.

Segments

int32_t getSegmentIdx(const String& segmentName) const

Retrieves the index of a segment by its name.

Parameters:

  • segmentName: The name of the segment to find.

Returns:

  • int32_t: The index of the segment, or -1 if the segment is not found.

Pixel Control

bool show()

Updates the LEDs by sending the current pixel values to the hardware drivers. It also triggers pre and post-show callbacks if defined.

Returns:

  • bool: Always returns true after showing the pixels.

void waitUntilShowComplete()

Waits until the hardware drivers finish updating the LEDs.

void clear(bool showAfterClear)

Clears all pixels by setting their color values to zero. Optionally, it can call show() after clearing.

Parameters:

  • showAfterClear: If true, the show() function is called after clearing the pixels.

Debugging

Several compile-time debug options are available to log pixel and segment data:

  • DEBUG_LED_PIXEL_VALUES: Logs the color values of each pixel during the show() process.
  • DEBUG_LED_PIXELS_LOOP_SHOW: Logs information about segment updates and stop requests during the loop() process.

Clone this wiki locally