Sylib
A C++ Library For V5
Loading...
Searching...
No Matches
sylib::Addrled Class Reference

WS2812B Addressable LED Strip Controller. More...

#include <addrled.hpp>

Inheritance diagram for sylib::Addrled:
sylib::Device

Public Member Functions

 Addrled (const std::uint8_t smart_port, const std::uint8_t adi_port, const std::uint8_t strip_length, const std::vector< std::uint32_t > colors=std::vector< std::uint32_t >())
 Creates an Addrled object for the given port and specifications. More...
 
 ~Addrled ()
 
void set_all (std::uint32_t color)
 Sets every pixel to a single color. More...
 
void set_pixel (std::uint32_t color, std::uint8_t index)
 Sets a specific pixel to a specific color. More...
 
void set_buffer (std::vector< uint32_t > colors)
 Sets the entire light strip to the provided vector of hex codes. More...
 
void update () override
 Addrled update loop. More...
 
void turn_off ()
 Sets the light control mode to OFF without changing the saved buffer. More...
 
void turn_on ()
 Sets the light control mode to MANUAL without changing the saved buffer. More...
 
void clear ()
 Resets the buffer. More...
 
void pulse (std::uint32_t color, int pulse_width, int speed=1, int start_pos=0, bool reverse=false, int end_pixel=-1)
 Sends a single pulse of color down the strip. More...
 
void gradient (std::uint32_t start_color, std::uint32_t end_color, int fade_width=0, int start_pos=0, bool reverse=false, bool hsv_mode=false)
 Sets the strip to a static color gradient. More...
 
void cycle (std::vector< uint32_t > pattern, int speed=1, int start_pos=0, bool reverse=false)
 Automatically rotates the colors of a provided buffer through the light strip periodically. More...
 
void rotate (int pixels=0, bool reverse=false)
 Rotates pixel colors up or down the strip. More...
 
void color_shift (int red, int green, int blue)
 Adds the provided red, green, and blue values to the colors sent to the lights. More...
 
int get_smart_port ()
 Gets smart port number used by the ADI expander for the light strip. More...
 
int get_adi_port ()
 Gets adi port number used by the light strip. More...
 
uint32_t & operator[] (std::uint32_t index)
 Operator overload to retrieve a pixel color. More...
 
std::vector< uint32_t > & operator* ()
 Operator overload to retrieve the current saved buffer. More...
 
sylib::SylibAddrledControlMode getControlMode ()
 Gets which control mode the light is using. More...
 

Static Public Member Functions

static std::uint32_t interpolate_hsv (std::uint32_t start_color, std::uint32_t end_color, int step, int fade_width)
 Finds a color between two provided color values. More...
 
static std::uint32_t interpolate_rgb (std::uint32_t start_color, std::uint32_t end_color, int step, int fade_width)
 Finds a color between two provided color values. More...
 
static std::uint32_t hsv_to_rgb (hsv in)
 Converts an HSV color to an RGB hex code. More...
 
static hsv rgb_to_hsv (std::uint32_t in)
 Converts RGB values to an HSV color. More...
 
static std::uint32_t rgb_to_hex (int r, int g, int b)
 Converts RGB values to an RGB hex code. More...
 
static rgb hex_to_rgb (std::uint32_t color)
 Converts an RGB hex code to RGB values. More...
 

Static Public Attributes

static bool addrled_enabled
 A flag that when set to false turns off all lights on all addrled objects. More...
 

Detailed Description

WS2812B Addressable LED Strip Controller.

Constructor & Destructor Documentation

◆ Addrled()

sylib::Addrled::Addrled ( const std::uint8_t  smart_port,
const std::uint8_t  adi_port,
const std::uint8_t  strip_length,
const std::vector< std::uint32_t >  colors = std::vector< std::uint32_t >() 
)

Creates an Addrled object for the given port and specifications.

Parameters
smart_portThe V5 port number from 1-22
adi_portThe ADI port number from 1-8
strip_lengthThe number of pixels on the light strip
colorsVector of hex codes to initialize the strip to

◆ ~Addrled()

sylib::Addrled::~Addrled ( )

Member Function Documentation

◆ clear()

void sylib::Addrled::clear ( )

Resets the buffer.

Turns off the lights

◆ color_shift()

void sylib::Addrled::color_shift ( int  red,
int  green,
int  blue 
)

Adds the provided red, green, and blue values to the colors sent to the lights.

Does not modify the saved buffer, can be used over other control modes

Parameters
redA number from -255 to 255 describing how much red to add
greenA number from -255 to 255 describing how much green to add
blueA number from -255 to 255 describing how much blue to add

◆ cycle()

void sylib::Addrled::cycle ( std::vector< uint32_t >  pattern,
int  speed = 1,
int  start_pos = 0,
bool  reverse = false 
)

Automatically rotates the colors of a provided buffer through the light strip periodically.

Sets the control mode to CYCLE

Parameters
colorBuffer to rotate, use *<Addrled object name> to use the current saved buffer
speedA value from 1-100 describing the speed of the pulse. 1 is slow, 100 is fast
start_posHow many pixels down the strip to start
reverseA flag that when true reverses the direction of the rotation

◆ get_adi_port()

int sylib::Addrled::get_adi_port ( )

Gets adi port number used by the light strip.

Returns
Value from 1-8 describing an adi port.

◆ get_smart_port()

int sylib::Addrled::get_smart_port ( )

Gets smart port number used by the ADI expander for the light strip.

Returns
Value from 1-22 describing a smart port. 22 is the built-in three wire ports.

◆ getControlMode()

sylib::SylibAddrledControlMode sylib::Addrled::getControlMode ( )

Gets which control mode the light is using.

Returns
Control mode

◆ gradient()

void sylib::Addrled::gradient ( std::uint32_t  start_color,
std::uint32_t  end_color,
int  fade_width = 0,
int  start_pos = 0,
bool  reverse = false,
bool  hsv_mode = false 
)

Sets the strip to a static color gradient.

Does not modify the saved buffer, can be used over other control modes

Parameters
start_colorHex code for one endpoint of the gradient
end_colorHex code for the other endpoint of the gradient
fade_widthA value describing how many pixels long to make the transition between colors.
reverseHow many pixels down the strip to start
reverseA flag that when true reverses the direction of the gradient
hsv_modeA flag that enables the gradient to work in HSV space rather than RGB

◆ hex_to_rgb()

static rgb sylib::Addrled::hex_to_rgb ( std::uint32_t  color)
static

Converts an RGB hex code to RGB values.

Parameters
rRed amount
gGreen amount
bBlue amount
Returns
RGB color

◆ hsv_to_rgb()

static std::uint32_t sylib::Addrled::hsv_to_rgb ( hsv  in)
static

Converts an HSV color to an RGB hex code.

Parameters
inHSV color to translate
Returns
Hex code describing an RGB color

◆ interpolate_hsv()

static std::uint32_t sylib::Addrled::interpolate_hsv ( std::uint32_t  start_color,
std::uint32_t  end_color,
int  step,
int  fade_width 
)
static

Finds a color between two provided color values.

Uses the HSV color space

Parameters
start_colorThe color at the start of the gradient
end_colorThe color at the end of the gradient
stepThe number of steps of size (1/fade_width) from the start value towards the end value
fade_widthThe number of pixels between the two endpoints
Returns
Hex code describing pixel color

◆ interpolate_rgb()

static std::uint32_t sylib::Addrled::interpolate_rgb ( std::uint32_t  start_color,
std::uint32_t  end_color,
int  step,
int  fade_width 
)
static

Finds a color between two provided color values.

Uses the RGB color space

Parameters
start_colorThe color at the start of the gradient
end_colorThe color at the end of the gradient
stepThe number of steps of size (1/fade_width) from the start value towards the end value
fade_widthThe number of pixels between the two endpoints
Returns
Hex code describing pixel color

◆ operator*()

std::vector< uint32_t > & sylib::Addrled::operator* ( )

Operator overload to retrieve the current saved buffer.

Returns
Vector of hex codes describing pixel colors

◆ operator[]()

uint32_t & sylib::Addrled::operator[] ( std::uint32_t  index)

Operator overload to retrieve a pixel color.

Parameters
indexZero-indexed pixel number
Returns
Hex code describing pixel color

◆ pulse()

void sylib::Addrled::pulse ( std::uint32_t  color,
int  pulse_width,
int  speed = 1,
int  start_pos = 0,
bool  reverse = false,
int  end_pixel = -1 
)

Sends a single pulse of color down the strip.

Parameters
colorHex code for the desired pulse color
pulse_widthThe number of pixels wide the pulse should be
speedA value from 1-100 describing the speed of the pulse. 1 is slow, 100 is fast
start_posHow many pixels down the strip to start
reverseA flag that when true reverses the direction of the pulse
end_pixelThe pixel number to end the pulse on. If this unset it defaults to the end of the strip

◆ rgb_to_hex()

static std::uint32_t sylib::Addrled::rgb_to_hex ( int  r,
int  g,
int  b 
)
static

Converts RGB values to an RGB hex code.

Parameters
rRed amount
gGreen amount
bBlue amount
Returns
Hex code describing an RGB color

◆ rgb_to_hsv()

static hsv sylib::Addrled::rgb_to_hsv ( std::uint32_t  in)
static

Converts RGB values to an HSV color.

Parameters
rRed amount
gGreen amount
bBlue amount
Returns
HSV color

◆ rotate()

void sylib::Addrled::rotate ( int  pixels = 0,
bool  reverse = false 
)

Rotates pixel colors up or down the strip.

Parameters
pixelsThe number of pixels to augment the buffer by
reverseA flag that when true reverses the direction of the rotation

◆ set_all()

void sylib::Addrled::set_all ( std::uint32_t  color)

Sets every pixel to a single color.

Parameters
colorHex color code

◆ set_buffer()

void sylib::Addrled::set_buffer ( std::vector< uint32_t >  colors)

Sets the entire light strip to the provided vector of hex codes.

Parameters
colorsA buffer containing hex codes

◆ set_pixel()

void sylib::Addrled::set_pixel ( std::uint32_t  color,
std::uint8_t  index 
)

Sets a specific pixel to a specific color.

Parameters
colorHex color code
indexZero-indexed pixel number

◆ turn_off()

void sylib::Addrled::turn_off ( )

Sets the light control mode to OFF without changing the saved buffer.

◆ turn_on()

void sylib::Addrled::turn_on ( )

Sets the light control mode to MANUAL without changing the saved buffer.

◆ update()

void sylib::Addrled::update ( )
overridevirtual

Addrled update loop.

Updates the light strip to the most recently set values

Users do not need to call this function, it is handled by the sylib daemon. Don't use this. It won't help.

Implements sylib::Device.

Member Data Documentation

◆ addrled_enabled

bool sylib::Addrled::addrled_enabled
static

A flag that when set to false turns off all lights on all addrled objects.