M5Unit-RGB 0.0.2 git rev:51dfbe6
Loading...
Searching...
No Matches
m5::unit::UnitLED Class Reference

LED base unit. More...

#include <unit_LED.hpp>

Inheritance diagram for m5::unit::UnitLED:
m5::unit::UnitSK6812 m5::unit::UnitWS2812 m5::unit::UnitSK6812GRB m5::unit::UnitSK6812GRBW m5::unit::UnitHexLED37< UnitWS2812 > m5::unit::UnitRectLED< 18, 7, UnitWS2812 > m5::unit::UnitRectLED< 5, 5, UnitWS2812 > m5::unit::UnitRectLED< 8, 8, UnitWS2812 > m5::unit::UnitNeco m5::unit::UnitHexLED37< UnitSK6812GRB > m5::unit::UnitRGB m5::unit::UnitRGBLED144 m5::unit::UnitRGBLED15 m5::unit::UnitRGBLED288 m5::unit::UnitRGBLED29 m5::unit::UnitRGBLED72 m5::unit::UnitRGBLEDStrip120 m5::unit::UnitRGBLEDStrip30 m5::unit::UnitRGBLEDStrip300 m5::unit::UnitRGBLEDStrip60 m5::unit::UnitHex m5::unit::HatNeoFlash m5::unit::UnitAtomMatrixRGB m5::unit::UnitPuzzle

Classes

struct  config_t
 Settings for begin. More...
 

Public Types

using container_type = std::vector<uint8_t>
 pixel container
 
using item_container_type = std::vector<gpio::m5_rmt_item_t>
 item container
 

Public Member Functions

virtual ~UnitLED ()
 Destructor.
 
bool add (UnitLED &c, const int16_t channel)
 Connect an LED unit as a daisy-chained child.
 
virtual bool begin () override
 Begin the unit.
 
Configuration for begin
config_t config ()
 Gets the configuration.
 
void config (const config_t &cfg)
 Set the configuration.
 
Properties
uint16_t numPixels () const
 Number of the pixels.
 
uint8_t brightness () const
 Brightness.
 
virtual uint16_t width () const
 Logical width in pixels.
 
virtual uint16_t height () const
 Logical height in pixels.
 
bool hasWhite () const
 Has white data?
 
rgb::Order order () const
 Color order.
 
int8_t offsetR () const
 Offset of red.
 
int8_t offsetG () const
 Offset of green.
 
int8_t offsetB () const
 Offset of blue.
 
int8_t offsetW () const
 Offset of white.
 
const container_typepixels () const
 pixels container
 
rgb::Color color (const uint16_t n) const
 Get the Color.
 
rgb::Color absoluteColor (const uint16_t n) const
 Get the Color.
 
Apply
bool writePixels ()
 Write pixel color to LED.
 
bool show ()
 Write pixel color to LED (alias)
 
Modifiers
Note
Calling writePixels() or show() is reflected in LEDs
void setBrightness (const uint8_t b)
 Set the brightness.
 
bool setPixelColor (const uint16_t n, const uint8_t r, const uint8_t g, const uint8_t b)
 Set pixel color (RGB)
 
bool setPixelColor (const uint16_t n, const uint8_t r, const uint8_t g, const uint8_t b, const uint8_t w)
 Set pixel color (RGBW)
 
bool setPixelColor (const uint16_t n, const rgb::wrgb32_color_t c)
 Set pixel color.
 
bool setPixelColor (const uint16_t n, const rgb::Color &c)
 Set pixel color.
 
bool fill (const rgb::Color &c, const uint16_t first=0, const uint16_t count=0)
 Fill the specified range with the specified color.
 
void clear (void)
 Clear pixels.
 
bool fillRainbow (const uint16_t first=0, const uint16_t count=0, const uint8_t firstHue=0)
 Fill the specified range to rainbow.
 
bool fillGradation (const rgb::Color &firstClr, const rgb::Color &lastClr, const uint16_t first=0, const uint16_t count=0)
 Fill the specified range to gradation pixels.
 
bool fillRandom (const uint16_t first=0, const uint16_t count=0)
 Fill the specified range to random color pixels.
 
void shiftLeft (const uint16_t count=1)
 Shift pixels left.
 
void shiftRight (const uint16_t count=1)
 Shift pixels right.
 
void rotateLeft (const uint16_t count=1)
 Rotate pixels left.
 
void rotateRight (const uint16_t count=1)
 Rotate pixels right.
 
Rotation
Note
Calling writePixels() or show() is reflected in LEDs
1 rot angle varies from unit to unit (e.g. Puzzle 90 deg Hex 60 deg)
Rotation direction is clockwise
virtual uint8_t maxRotation () const
 Get the max rotation.
 
float rotationDegree () const
 Get the rotation angle per 1.
 
int8_t rotation () const
 Get the rotation.
 
void setRotation (const int8_t rot)
 Set the rotation.
 
Pixels element access
Note
Affected by rotation
rgb::Color operator[] (const uint16_t i) const
 rvalue
 
PixelProxy operator[] (const uint16_t i)
 lvalue
 

Protected Member Functions

virtual types::category_t unit_category () const override
 
virtual gpio::adapter_config_t rmt_config ()
 
virtual gpio::m5_rmt_item_t rmt_item_one ()
 
virtual gpio::m5_rmt_item_t rmt_item_zero ()
 
virtual gpio::m5_rmt_item_t rmt_item_reset ()
 
container_typepixels ()
 
rgb::Color get_pixel_color (const uint16_t n) const
 
bool set_pixel_color (const uint16_t n, const rgb::Color &c)
 
uint8_t rotation_of (const int8_t r) const
 
virtual uint16_t index_of (const uint16_t n) const
 
container_type rgb888_items ()
 
item_container_type items ()
 
void shift_left (const uint16_t count, const bool wrap)
 
void shift_right (const uint16_t count, const bool wrap)
 
 UnitLED (const uint16_t num_of_pixels, const rgb::Order order)
 

Friends

class InterfaceGPIO
 
class InterfacePbHub
 

Detailed Description

LED base unit.

Member Function Documentation

◆ absoluteColor()

rgb::Color m5::unit::UnitLED::absoluteColor ( const uint16_t n) const
inline

Get the Color.

Parameters
nPosition of the pixels
Returns
Color if exists
Note
Not affected by rotation

◆ add()

bool m5::unit::UnitLED::add ( UnitLED & c,
const int16_t channel )

Connect an LED unit as a daisy-chained child.

Parameters
cChild LED unit
channelChannel number
Returns
True if successful
Note
Shadows Component::add so only UnitLED subtypes are accepted as children of an LED daisy chain.

◆ begin()

bool m5::unit::UnitLED::begin ( )
overridevirtual

Begin the unit.

Returns
True if successful

Reimplemented in m5::unit::UnitAtomMatrixRGB, and m5::unit::UnitNeco.

◆ brightness()

uint8_t m5::unit::UnitLED::brightness ( ) const
inline

Brightness.

Returns
Current brightness (255 = 100%)
Note
Scaling factor (255 = 100%)

◆ clear()

void m5::unit::UnitLED::clear ( void )
inline

Clear pixels.

Note
All pixel color to WRGB 0,0,0,0

◆ color()

rgb::Color m5::unit::UnitLED::color ( const uint16_t n) const
inline

Get the Color.

Parameters
nPosition of the pixels
Returns
Color if exists
Note
Affected by rotation

◆ config() [1/2]

config_t m5::unit::UnitLED::config ( )
inline

Gets the configuration.

Returns
config_t

◆ config() [2/2]

void m5::unit::UnitLED::config ( const config_t & cfg)
inline

Set the configuration.

Parameters
cfgconfig_t

◆ fill()

bool m5::unit::UnitLED::fill ( const rgb::Color & c,
const uint16_t first = 0,
const uint16_t count = 0 )

Fill the specified range with the specified color.

Parameters
crgb::Color
firstFirst position of the pixels
countNumber of pixels to fill (To the end if zero)
Returns
True if successful
Note
Affected by rotation
Warning
If white is not supported, white is ignored

◆ fillGradation()

bool m5::unit::UnitLED::fillGradation ( const rgb::Color & firstClr,
const rgb::Color & lastClr,
const uint16_t first = 0,
const uint16_t count = 0 )

Fill the specified range to gradation pixels.

Parameters
firstClrFirst Color
lastClrLast Color
firstFirst position of the pixels
countNumber of pixels to fill (To the end if zero)
Returns
True if successful
Note
Affected by rotation

◆ fillRainbow()

bool m5::unit::UnitLED::fillRainbow ( const uint16_t first = 0,
const uint16_t count = 0,
const uint8_t firstHue = 0 )

Fill the specified range to rainbow.

Parameters
firstFirst position of the pixels
countNumber of pixels to fill (To the end if zero)
firstHueThe first hue value
Returns
True if successful
Note
Affected by rotation

◆ fillRandom()

bool m5::unit::UnitLED::fillRandom ( const uint16_t first = 0,
const uint16_t count = 0 )

Fill the specified range to random color pixels.

Parameters
firstFirst position of the pixels
countNumber of pixels to fill (To the end if zero)
Returns
True if successful
Note
Affected by rotation

◆ hasWhite()

bool m5::unit::UnitLED::hasWhite ( ) const
inline

Has white data?

Returns
True if the color order includes a white channel

◆ height()

virtual uint16_t m5::unit::UnitLED::height ( ) const
inlinevirtual

◆ maxRotation()

virtual uint8_t m5::unit::UnitLED::maxRotation ( ) const
inlinevirtual

◆ numPixels()

uint16_t m5::unit::UnitLED::numPixels ( ) const
inline

Number of the pixels.

Returns
Number of pixels

◆ offsetB()

int8_t m5::unit::UnitLED::offsetB ( ) const
inline

Offset of blue.

Returns
Byte offset of Blue (-1 if not present)

◆ offsetG()

int8_t m5::unit::UnitLED::offsetG ( ) const
inline

Offset of green.

Returns
Byte offset of Green (-1 if not present)

◆ offsetR()

int8_t m5::unit::UnitLED::offsetR ( ) const
inline

Offset of red.

Returns
Byte offset of Red (-1 if not present)

◆ offsetW()

int8_t m5::unit::UnitLED::offsetW ( ) const
inline

Offset of white.

Returns
Byte offset of White (-1 if not present)

◆ operator[]() [1/2]

PixelProxy m5::unit::UnitLED::operator[] ( const uint16_t i)
inline

lvalue

Parameters
iPosition of the pixels
Returns
Proxy that writes back on assignment

◆ operator[]() [2/2]

rgb::Color m5::unit::UnitLED::operator[] ( const uint16_t i) const
inline

rvalue

Parameters
iPosition of the pixels
Returns
Color at position i

◆ order()

rgb::Order m5::unit::UnitLED::order ( ) const
inline

Color order.

Returns
rgb::Order

◆ pixels()

const container_type & m5::unit::UnitLED::pixels ( ) const
inline

pixels container

Returns
Reference to the internal packed pixel buffer

◆ rotateLeft()

void m5::unit::UnitLED::rotateLeft ( const uint16_t count = 1)
inline

Rotate pixels left.

Parameters
countNumber of rotates
Note
Affected by rotation

◆ rotateRight()

void m5::unit::UnitLED::rotateRight ( const uint16_t count = 1)
inline

Rotate pixels right.

Parameters
countNumber of rotates
Note
Affected by rotation

◆ rotation()

int8_t m5::unit::UnitLED::rotation ( ) const
inline

Get the rotation.

Returns
Current rotation step

◆ rotationDegree()

float m5::unit::UnitLED::rotationDegree ( ) const
inline

Get the rotation angle per 1.

Returns
Angle per rotation step (degree)

◆ setBrightness()

void m5::unit::UnitLED::setBrightness ( const uint8_t b)
inline

Set the brightness.

Parameters
bbrightness (255 = 100%)
Note
Behaves similar to FastLED
Internal pixels's color is not changed
The brightness applied on writePixels()

◆ setPixelColor() [1/4]

bool m5::unit::UnitLED::setPixelColor ( const uint16_t n,
const rgb::Color & c )
inline

Set pixel color.

Parameters
nPosition of the pixels
crgb::Color
Returns
True if successful
Note
Affected by rotation
Warning
If white is not supported, white is ignored

◆ setPixelColor() [2/4]

bool m5::unit::UnitLED::setPixelColor ( const uint16_t n,
const rgb::wrgb32_color_t c )
inline

Set pixel color.

Parameters
nPosition of the pixels
cWRGB 32bits color
Returns
True if successful
Note
Affected by rotation
Warning
If white is not supported, white is ignored

◆ setPixelColor() [3/4]

bool m5::unit::UnitLED::setPixelColor ( const uint16_t n,
const uint8_t r,
const uint8_t g,
const uint8_t b )

Set pixel color (RGB)

Parameters
nPosition of the pixels
rRed
gGreen
bBlue
Returns
True if successful
Note
If white is supported, white value does not change
Affected by rotation

◆ setPixelColor() [4/4]

bool m5::unit::UnitLED::setPixelColor ( const uint16_t n,
const uint8_t r,
const uint8_t g,
const uint8_t b,
const uint8_t w )
inline

Set pixel color (RGBW)

Parameters
nPosition of the pixels
rRed
gGreen
bBlue
wWhite
Returns
True if successful
Note
Affected by rotation
Warning
If white is not supported, white is ignored

◆ setRotation()

void m5::unit::UnitLED::setRotation ( const int8_t rot)

Set the rotation.

Parameters
rotRotation step

◆ shiftLeft()

void m5::unit::UnitLED::shiftLeft ( const uint16_t count = 1)
inline

Shift pixels left.

Parameters
countNumber of shifts
Note
The empty space will be WRGB 0,0,0,0
Affected by rotation

◆ shiftRight()

void m5::unit::UnitLED::shiftRight ( const uint16_t count = 1)
inline

Shift pixels right.

Parameters
countNumber of shifts
Note
The empty space will be WRGB 0,0,0,0
Affected by rotation

◆ show()

bool m5::unit::UnitLED::show ( )
inline

Write pixel color to LED (alias)

Returns
True if successful

◆ width()

virtual uint16_t m5::unit::UnitLED::width ( ) const
inlinevirtual

◆ writePixels()

bool m5::unit::UnitLED::writePixels ( void )

Write pixel color to LED.

Returns
True if successful