Sylib
A C++ Library For V5
|
WS2812B Addressable LED Strip Controller. More...
#include <addrled.hpp>
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... | |
WS2812B Addressable LED Strip Controller.
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.
smart_port | The V5 port number from 1-22 |
adi_port | The ADI port number from 1-8 |
strip_length | The number of pixels on the light strip |
colors | Vector of hex codes to initialize the strip to |
sylib::Addrled::~Addrled | ( | ) |
void sylib::Addrled::clear | ( | ) |
Resets the buffer.
Turns off the lights
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
red | A number from -255 to 255 describing how much red to add |
green | A number from -255 to 255 describing how much green to add |
blue | A number from -255 to 255 describing how much blue to add |
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
color | Buffer to rotate, use *<Addrled object name> to use the current saved buffer |
speed | A value from 1-100 describing the speed of the pulse. 1 is slow, 100 is fast |
start_pos | How many pixels down the strip to start |
reverse | A flag that when true reverses the direction of the rotation |
int sylib::Addrled::get_adi_port | ( | ) |
Gets adi port number used by the light strip.
int sylib::Addrled::get_smart_port | ( | ) |
Gets smart port number used by the ADI expander for the light strip.
sylib::SylibAddrledControlMode sylib::Addrled::getControlMode | ( | ) |
Gets which control mode the light is using.
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
start_color | Hex code for one endpoint of the gradient |
end_color | Hex code for the other endpoint of the gradient |
fade_width | A value describing how many pixels long to make the transition between colors. |
reverse | How many pixels down the strip to start |
reverse | A flag that when true reverses the direction of the gradient |
hsv_mode | A flag that enables the gradient to work in HSV space rather than RGB |
|
static |
Converts an RGB hex code to RGB values.
r | Red amount |
g | Green amount |
b | Blue amount |
|
static |
Converts an HSV color to an RGB hex code.
in | HSV color to translate |
|
static |
Finds a color between two provided color values.
Uses the HSV color space
start_color | The color at the start of the gradient |
end_color | The color at the end of the gradient |
step | The number of steps of size (1/fade_width) from the start value towards the end value |
fade_width | The number of pixels between the two endpoints |
|
static |
Finds a color between two provided color values.
Uses the RGB color space
start_color | The color at the start of the gradient |
end_color | The color at the end of the gradient |
step | The number of steps of size (1/fade_width) from the start value towards the end value |
fade_width | The number of pixels between the two endpoints |
std::vector< uint32_t > & sylib::Addrled::operator* | ( | ) |
Operator overload to retrieve the current saved buffer.
uint32_t & sylib::Addrled::operator[] | ( | std::uint32_t | index | ) |
Operator overload to retrieve a pixel color.
index | Zero-indexed pixel number |
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.
color | Hex code for the desired pulse color |
pulse_width | The number of pixels wide the pulse should be |
speed | A value from 1-100 describing the speed of the pulse. 1 is slow, 100 is fast |
start_pos | How many pixels down the strip to start |
reverse | A flag that when true reverses the direction of the pulse |
end_pixel | The pixel number to end the pulse on. If this unset it defaults to the end of the strip |
|
static |
Converts RGB values to an RGB hex code.
r | Red amount |
g | Green amount |
b | Blue amount |
|
static |
Converts RGB values to an HSV color.
r | Red amount |
g | Green amount |
b | Blue amount |
void sylib::Addrled::rotate | ( | int | pixels = 0 , |
bool | reverse = false |
||
) |
Rotates pixel colors up or down the strip.
pixels | The number of pixels to augment the buffer by |
reverse | A flag that when true reverses the direction of the rotation |
void sylib::Addrled::set_all | ( | std::uint32_t | color | ) |
Sets every pixel to a single color.
color | Hex color code |
void sylib::Addrled::set_buffer | ( | std::vector< uint32_t > | colors | ) |
Sets the entire light strip to the provided vector of hex codes.
colors | A buffer containing hex codes |
void sylib::Addrled::set_pixel | ( | std::uint32_t | color, |
std::uint8_t | index | ||
) |
Sets a specific pixel to a specific color.
color | Hex color code |
index | Zero-indexed pixel number |
void sylib::Addrled::turn_off | ( | ) |
Sets the light control mode to OFF without changing the saved buffer.
void sylib::Addrled::turn_on | ( | ) |
Sets the light control mode to MANUAL without changing the saved buffer.
|
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.
|
static |
A flag that when set to false turns off all lights on all addrled objects.