Sylib
A C++ Library For V5
Loading...
Searching...
No Matches
addrled.hpp
1
11#pragma once
12#include <cstdint>
13#include <vector>
14
15#include "sylib/env.hpp"
16#include "sylib/system.hpp"
17#include "sylib/sylib_apitypes.hpp"
18
19
20namespace sylib {
21
25typedef struct {
26 double r;
27 double g;
28 double b;
29} rgb;
30
34typedef struct {
35 double h;
36 double s;
37 double v;
38} hsv;
39
43class Addrled : private Device {
44 private:
45 static const std::vector<uint32_t> off_buffer;
46 const std::uint8_t smart_port;
47 const std::uint8_t adi_port;
48 const std::uint8_t strip_length;
49 std::vector<uint32_t> buffer;
50 std::vector<uint32_t> template_buffer;
51 std::vector<uint32_t> rotation_buffer;
52 std::vector<uint32_t> buffer_saved;
53 static std::vector<sylib::Addrled*>& getAllAddrleds();
54 const V5_DeviceT device;
55 static void setAddrledUpdateCycles(int count);
56 sylib::SylibAddrledControlMode addrledControlMode;
57 double controlSpeed = 1;
58 double pulseSpeed = 1;
59 int cyclePixelsShifted = 0;
60 int end_pixel = -1;
61 bool pulseControlReversed = false;
62 bool cycleControlReversed = false;
63 int pixelsToMove = 0;
64 int pulseStartMovementTime = 0;
65 int cycleStartMovementTime = 0;
66 bool sendingPulse = false;
67 int controlPulseWidth = 1;
68 int redShift = 0;
69 int greenShift = 0;
70 int blueShift = 0;
71 int pulsePixelsShifted = 0;
72
73 public:
86 Addrled(const std::uint8_t smart_port, const std::uint8_t adi_port,
87 const std::uint8_t strip_length,
88 const std::vector<std::uint32_t> colors = std::vector<std::uint32_t>());
89
91
95 static bool addrled_enabled;
96
103 void set_all(std::uint32_t color);
104
113 void set_pixel(std::uint32_t color, std::uint8_t index);
114
121 void set_buffer(std::vector<uint32_t> colors);
122
131 void update() override;
132
136 void turn_off();
137
141 void turn_on();
142
148 void clear();
149
172 void pulse(std::uint32_t color, int pulse_width, int speed = 1, int start_pos = 0,
173 bool reverse = false, int end_pixel = -1);
174
198 void gradient(std::uint32_t start_color, std::uint32_t end_color, int fade_width = 0,
199 int start_pos = 0, bool reverse = false, bool hsv_mode = false);
200
219 void cycle(std::vector<uint32_t> pattern, int speed = 1, int start_pos = 0,
220 bool reverse = false);
221
231 void rotate(int pixels = 0, bool reverse = false);
232
247 void color_shift(int red, int green, int blue);
248
255
262
271 uint32_t& operator[](std::uint32_t index);
272
278 std::vector<uint32_t>& operator*();
279
286
306 static std::uint32_t interpolate_hsv(std::uint32_t start_color, std::uint32_t end_color,
307 int step, int fade_width);
308
328 static std::uint32_t interpolate_rgb(std::uint32_t start_color, std::uint32_t end_color,
329 int step, int fade_width);
330
339 static std::uint32_t hsv_to_rgb(hsv in);
340
355 static hsv rgb_to_hsv(std::uint32_t in);
356
371 static std::uint32_t rgb_to_hex(int r, int g, int b);
372
387 static rgb hex_to_rgb(std::uint32_t color);
388};
389} // namespace sylib
WS2812B Addressable LED Strip Controller.
Definition: addrled.hpp:43
void set_pixel(std::uint32_t color, std::uint8_t index)
Sets a specific pixel to a specific color.
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.
void turn_on()
Sets the light control mode to MANUAL without changing the saved buffer.
static rgb hex_to_rgb(std::uint32_t color)
Converts an RGB hex code to RGB values.
std::vector< uint32_t > & operator*()
Operator overload to retrieve the current saved buffer.
static std::uint32_t rgb_to_hex(int r, int g, int b)
Converts RGB values to an RGB hex code.
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.
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.
void rotate(int pixels=0, bool reverse=false)
Rotates pixel colors up or down the strip.
void turn_off()
Sets the light control mode to OFF without changing the saved buffer.
void clear()
Resets the buffer.
void update() override
Addrled update loop.
uint32_t & operator[](std::uint32_t index)
Operator overload to retrieve a pixel color.
void color_shift(int red, int green, int blue)
Adds the provided red, green, and blue values to the colors sent to the lights.
static std::uint32_t hsv_to_rgb(hsv in)
Converts an HSV color to an RGB hex code.
void set_all(std::uint32_t color)
Sets every pixel to a single color.
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.
void set_buffer(std::vector< uint32_t > colors)
Sets the entire light strip to the provided vector of hex codes.
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.
int get_smart_port()
Gets smart port number used by the ADI expander for the light strip.
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.
static hsv rgb_to_hsv(std::uint32_t in)
Converts RGB values to an HSV color.
int get_adi_port()
Gets adi port number used by the light strip.
static bool addrled_enabled
A flag that when set to false turns off all lights on all addrled objects.
Definition: addrled.hpp:95
sylib::SylibAddrledControlMode getControlMode()
Gets which control mode the light is using.
Device Parent Class.
Definition: system.hpp:238
Definition: addrled.hpp:20
SylibAddrledControlMode
Definition: sylib_apitypes.hpp:25
HSV Color.
Definition: addrled.hpp:34
double s
Definition: addrled.hpp:36
double v
Definition: addrled.hpp:37
double h
Definition: addrled.hpp:35
RGB Color.
Definition: addrled.hpp:25
double r
Definition: addrled.hpp:26
double g
Definition: addrled.hpp:27
double b
Definition: addrled.hpp:28