Seeed Grove ++  v0.0.1-2019
Linux C++ Library For Seeed Grove Devices
SG::ChainableRGBLED Class Reference

RGB LED which can be set programatically to any of 16.7 million colours. More...

#include <sg_104030006_ChainableRGBLED.hpp>

Inheritance diagram for SG::ChainableRGBLED:
Collaboration diagram for SG::ChainableRGBLED:

Public Member Functions

virtual ~ChainableRGBLED (void)
 Destructor. More...
 
 ChainableRGBLED (const size_t i=0, const std::string &n="", const bool turn_off_at_destruction=false)
 Constructor. More...
 
ChainableRGBLEDset_RGB (const int r, const int g, const int b)
 Sets the LED to the specified colour, and updates the red, green, and blue internal variables. More...
 
ChainableRGBLEDset_RGB (const size_t r, const size_t g, const size_t b)
 Sets the LED to the specified colour, and updates the red, green, and blue internal variables. More...
 
ChainableRGBLEDset_RGB (const double r, const double g, const double b)
 Sets the LED to the specified colour, and updates the red, green, and blue internal variables. More...
 
ChainableRGBLEDset_RGB (std::string html_colour)
 Sets the LED to the specified colour, and updates the red, green, and blue internal variables. More...
 
ChainableRGBLEDturn_off (void)
 Sets the LED to [0,0,0] effectively turning off the LED, but doesn't alter the red, green, and blue members of this class. More...
 
ChainableRGBLEDturn_on (void)
 Sets the LED to the previously set values red, green, and blue defined above. More...
 
ChainableRGBLEDturn_on (const int r, const int g, const int b, const bool reserved=true)
 Set the LED to the specified colours, but doesn't alter the values red, green, or blue defined above. More...
 
ChainableRGBLEDstart_pulse_thread (const int r1=255, const int g1=255, const int b1=255, const int r2=0, const int g2=0, const int b2=0, const size_t length_of_pulse_in_milliseconds=1500)
 Start a thread to pulse the LED between two sets of colours. More...
 
ChainableRGBLEDstop_pulse_thread (void)
 Stop any existing pulse thread. More...
 
void run_pulse_thread (int r1=255, int g1=255, int b1=255, int r2=0, int g2=0, int b2=0, size_t length_of_pulse_in_milliseconds=1500)
 Runs a loop which causes the LED to pulse. More...
 
virtual GroveGPIOsend_2_bytes (uint16_t bits)
 Send 16 bits (2 bytes). More...
 
virtual GroveGPIOsend_byte (uint8_t byte)
 Send a single byte. More...
 
virtual bool is_grove_uart (void) const
 Determine if this is a Grove UART device. More...
 
virtual bool is_grove_i2c (void) const
 Determine if this is a Grove I2C device. More...
 
virtual bool is_grove_gpio (void) const
 Determine if this is a Grove GPIO device. More...
 
virtual uint32_t get_sku (void) const
 Return a guess as to the Seeed SKU number based on the grove type. More...
 
virtual std::string get_type_name (void) const
 Return a short text string representing the grove type. More...
 
virtual EGroveType get_type (void) const
 Return the grove type. More...
 
virtual std::string get_name (void) const
 Return the user-supplied name. More...
 
virtual std::string get_description (void) const
 Return a multi-word 1-line description of this object. More...
 
bool operator== (const GroveBase &rhs) const
 Test object equality. More...
 
bool operator!= (const GroveBase &rhs) const
 Test object equality. More...
 

Public Attributes

size_t idx
 The index of the LED into the chain. More...
 
int red
 Red component. Must be in the range 0-255. This is the internal value for red stored in the C++ object, and may not be the same as the actual LED's red intensity. More...
 
int green
 Green component. Must be in the range 0-255. This is the internal value for green stored in the C++ object, and may not be the same as the actual LED's green intensity. More...
 
int blue
 Blue component. Must be in the range 0-255. This is the internal value for blue stored in the C++ object, and may not be the same as the actual LED's blue intensity. More...
 
bool turn_off_LED_when_destructing
 Determines whether the destructor attempts to turn off the light. This can be specified in the constructor. More...
 
EGroveType grove_type
 Grove type. More...
 
std::string grove_name
 User-supplied name. More...
 

Protected Attributes

std::thread pulse_thread
 
std::atomic< bool > pulse_thread_must_quit
 

Detailed Description

RGB LED which can be set programatically to any of 16.7 million colours.

Each component (red, green blue) can be set in intensity to any value between 0 and 255. Setting the colour to (0, 0, 0) will turn off the light, while (255, 255, 255) will result in bright white.

Description Image
Chainable RGB LED connected to the Grove UART interface.
The light in this example was enabled from the command-line with "sudo seeedgrove chainable_rgb_led 255 128 0".
ChainableRGBLED_1.jpg
GROVE cable connects to the 'in' side of the chainable RGB LED.
ChainableRGBLED_2.jpg
See also
http://www.seeedstudio.com/wiki/images/b/be/P9813_datasheet.pdf
http://www.seeedstudio.com/wiki/Grove_-_Chainable_RGB_LED
http://www.seeedstudio.com/depot/Grove-Chainable-RGB-LED-p-850.html
Note
This is not the same as the variable colour LED, SKU #104020001, SG::VariableColorLED. The colour on the chainable RGB LED can be set programmatically. The colour on the variable colour LED can only be set by turning tiny screws on the back of the twig.

Constructor & Destructor Documentation

SG::ChainableRGBLED::~ChainableRGBLED ( void  )
virtual
SG::ChainableRGBLED::ChainableRGBLED ( const size_t  i = 0,
const std::string &  n = "",
const bool  turn_off_at_destruction = false 
)

Constructor.

Parameters
[in]iSince the LEDs are chainable, i is the index of the LED into the chain. The first LED is idx zero.
[in]nUser-supplied name which can be used to identify this LED. The name can be anything, it isn't parsed by SG++.
[in]turn_off_at_destructionNormally when an object of this class is destructed, the LED retains the very last state ("colour"). If turn_off_at_destruction is set to true, then the LED will be turned off by the destructor.

References SG::SGpp::get(), SG::SGpp::gpio, SG::GpioManagement::gpio_export(), and SG::GpioManagement::kOutput.

Here is the call graph for this function:

Member Function Documentation

virtual std::string SG::GroveBase::get_name ( void  ) const
inlinevirtualinherited

Return the user-supplied name.

References SG::GroveBase::get_description(), SG::GroveBase::grove_name, SG::GroveBase::is_grove_gpio(), SG::GroveBase::is_grove_i2c(), and SG::GroveBase::is_grove_uart().

Referenced by SG::GroveBase::get_description(), SG::GroveBase::operator=(), and SG::GroveBase::operator==().

Here is the call graph for this function:

Here is the caller graph for this function:

virtual uint32_t SG::GroveBase::get_sku ( void  ) const
inlinevirtualinherited

Return a guess as to the Seeed SKU number based on the grove type.

References SG::get_sku_from_grove_type(), and SG::GroveBase::grove_type.

Referenced by SG::GroveBase::get_description().

Here is the call graph for this function:

Here is the caller graph for this function:

virtual EGroveType SG::GroveBase::get_type ( void  ) const
inlinevirtualinherited

Return the grove type.

References SG::GroveBase::grove_type.

Referenced by SG::GroveI2CDigital::get_address_from_type(), SG::GroveBase::operator=(), and SG::GroveBase::operator==().

Here is the caller graph for this function:

virtual std::string SG::GroveBase::get_type_name ( void  ) const
inlinevirtualinherited

Return a short text string representing the grove type.

References SG::GroveBase::grove_type, and SG::to_string().

Referenced by SG::GroveBase::get_description().

Here is the call graph for this function:

Here is the caller graph for this function:

virtual bool SG::GroveGPIO::is_grove_gpio ( void  ) const
inlinevirtualinherited

Determine if this is a Grove GPIO device.

See also
SG::GroveGPIO

Implements SG::GroveBase.

virtual bool SG::GroveGPIO::is_grove_i2c ( void  ) const
inlinevirtualinherited

Determine if this is a Grove I2C device.

See also
SG::GroveI2C

Implements SG::GroveBase.

virtual bool SG::GroveGPIO::is_grove_uart ( void  ) const
inlinevirtualinherited

Determine if this is a Grove UART device.

See also
SG::GroveUART

Implements SG::GroveBase.

bool SG::GroveBase::operator!= ( const GroveBase rhs) const
inlineinherited

Test object equality.

References SG::GroveBase::operator==().

Here is the call graph for this function:

bool SG::GroveBase::operator== ( const GroveBase rhs) const
inherited

Test object equality.

References SG::GroveBase::get_name(), and SG::GroveBase::get_type().

Referenced by SG::GroveBase::operator!=(), SG::Buzzer::operator==(), SG::TemperatureAndHumiditySensor::operator==(), SG::TemperatureSensor::operator==(), and SG::I2CADC::operator==().

Here is the call graph for this function:

Here is the caller graph for this function:

void SG::ChainableRGBLED::run_pulse_thread ( int  r1 = 255,
int  g1 = 255,
int  b1 = 255,
int  r2 = 0,
int  g2 = 0,
int  b2 = 0,
size_t  length_of_pulse_in_milliseconds = 1500 
)

Runs a loop which causes the LED to pulse.

Normally, this is started on a secondary thread by start_pulse_thread(), though it can also be called directly. Call stop_pulse_thread() to force the loop to end.

References pulse_thread_must_quit, and turn_on().

Referenced by start_pulse_thread().

Here is the call graph for this function:

Here is the caller graph for this function:

SG::GroveGPIO & SG::GroveGPIO::send_2_bytes ( uint16_t  bits)
virtualinherited

Send 16 bits (2 bytes).

References SG::GroveGPIO::send_byte().

Here is the call graph for this function:

SG::GroveGPIO & SG::GroveGPIO::send_byte ( uint8_t  byte)
virtualinherited

Send a single byte.

References SG::SGpp::get(), SG::SGpp::gpio, SG::GpioManagement::set_high(), and SG::GpioManagement::set_low().

Referenced by SG::GroveGPIO::send_2_bytes(), and turn_on().

Here is the call graph for this function:

Here is the caller graph for this function:

SG::ChainableRGBLED & SG::ChainableRGBLED::set_RGB ( const int  r,
const int  g,
const int  b 
)

Sets the LED to the specified colour, and updates the red, green, and blue internal variables.

The range of r, g, and b is 0 to 255. Values outside that range will automatically be brought within range.

References blue, green, red, and turn_on().

Referenced by chainable_rgb_led().

Here is the call graph for this function:

Here is the caller graph for this function:

SG::ChainableRGBLED & SG::ChainableRGBLED::set_RGB ( const size_t  r,
const size_t  g,
const size_t  b 
)

Sets the LED to the specified colour, and updates the red, green, and blue internal variables.

The range of r, g, and b is 0 to 255.

References blue, green, red, and turn_on().

Here is the call graph for this function:

SG::ChainableRGBLED & SG::ChainableRGBLED::set_RGB ( const double  r,
const double  g,
const double  b 
)

Sets the LED to the specified colour, and updates the red, green, and blue internal variables.

The range of r, g, and b is 0.0 to 1.0.

References blue, green, red, and turn_on().

Here is the call graph for this function:

SG::ChainableRGBLED & SG::ChainableRGBLED::set_RGB ( std::string  html_colour)

Sets the LED to the specified colour, and updates the red, green, and blue internal variables.

Parameters
[in]html_colourThe string must be formatted like an HTML colour entry, such as #00ff88 or #0f8. Colour names are not recognized. Values that cannot be parsed will be set to 0xff.

References blue, green, red, and turn_on().

Here is the call graph for this function:

SG::ChainableRGBLED & SG::ChainableRGBLED::start_pulse_thread ( const int  r1 = 255,
const int  g1 = 255,
const int  b1 = 255,
const int  r2 = 0,
const int  g2 = 0,
const int  b2 = 0,
const size_t  length_of_pulse_in_milliseconds = 1500 
)

Start a thread to pulse the LED between two sets of colours.

If a pulse thread is already running, it will be stopped before starting a new one. Calling any of the set_RGB(), turn_off(), or turn_on() will also automatically stop any running pulse threads. If this method is called multiple times, only the last colour values will be used.

References pulse_thread, pulse_thread_must_quit, run_pulse_thread(), and stop_pulse_thread().

Referenced by chainable_rgb_led().

Here is the call graph for this function:

Here is the caller graph for this function:

SG::ChainableRGBLED & SG::ChainableRGBLED::stop_pulse_thread ( void  )

Stop any existing pulse thread.

References pulse_thread, and pulse_thread_must_quit.

Referenced by start_pulse_thread(), turn_on(), and ~ChainableRGBLED().

Here is the caller graph for this function:

SG::ChainableRGBLED & SG::ChainableRGBLED::turn_off ( void  )

Sets the LED to [0,0,0] effectively turning off the LED, but doesn't alter the red, green, and blue members of this class.

This way, calling turn_on() will re-activate the LED to the previous preset colour.

References turn_on().

Referenced by ~ChainableRGBLED().

Here is the call graph for this function:

Here is the caller graph for this function:

SG::ChainableRGBLED & SG::ChainableRGBLED::turn_on ( void  )

Sets the LED to the previously set values red, green, and blue defined above.

References blue, green, and red.

Referenced by run_pulse_thread(), set_RGB(), and turn_off().

Here is the caller graph for this function:

SG::ChainableRGBLED & SG::ChainableRGBLED::turn_on ( const int  r,
const int  g,
const int  b,
const bool  reserved = true 
)

Set the LED to the specified colours, but doesn't alter the values red, green, or blue defined above.

Normally you'd call set_RGB(), unless you want to temporarily change the LED colour without altering the original saved colour values.

Parameters
[in]rRed component. Values below zero will be interpreted as zero. Values above 255 will be interpreted as 255.
[in]gGreen component. Values below zero will be interpreted as zero. Values above 255 will be interpreted as 255.
[in]bBlue component. Values below zero will be interpreted as zero. Values above 255 will be interpreted as 255.
[in]reservedUsed internally to determine if the pulse thread must be stopped. From an external API point of view, leave this parameter to true.
Todo:
How to set multiple RGB LEDs if they are chained?

References blue, green, red, SG::GroveGPIO::send_byte(), and stop_pulse_thread().

Here is the call graph for this function:

Member Data Documentation

int SG::ChainableRGBLED::blue

Blue component. Must be in the range 0-255. This is the internal value for blue stored in the C++ object, and may not be the same as the actual LED's blue intensity.

Referenced by set_RGB(), and turn_on().

int SG::ChainableRGBLED::green

Green component. Must be in the range 0-255. This is the internal value for green stored in the C++ object, and may not be the same as the actual LED's green intensity.

Referenced by set_RGB(), and turn_on().

std::string SG::GroveBase::grove_name
inherited

User-supplied name.

Referenced by SG::GroveBase::get_name(), and SG::GroveBase::operator=().

size_t SG::ChainableRGBLED::idx

The index of the LED into the chain.

The first LED is index zero. Normally, idx should be zero. Only set this if you have multiple chainable LEDs connected together.

std::thread SG::ChainableRGBLED::pulse_thread
protected
std::atomic<bool> SG::ChainableRGBLED::pulse_thread_must_quit
protected
int SG::ChainableRGBLED::red

Red component. Must be in the range 0-255. This is the internal value for red stored in the C++ object, and may not be the same as the actual LED's red intensity.

Referenced by set_RGB(), and turn_on().

bool SG::ChainableRGBLED::turn_off_LED_when_destructing

Determines whether the destructor attempts to turn off the light. This can be specified in the constructor.

Referenced by ~ChainableRGBLED().


The documentation for this class was generated from the following files: