Seeed Grove ++  v0.0.1-2386
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 RGB8 &colour)
 Sets the LED to the specified colour, and updates the rgb internal colour value. More...
 
ChainableRGBLEDset_RGB (const double r, const double g, const double b)
 Sets the LED to the specified colour, and updates the rgb internal colour value. 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 rgb8 member of this class. More...
 
ChainableRGBLEDturn_on (void)
 Sets the LED to the previously set value rgb8 defined above. More...
 
ChainableRGBLEDturn_on (const RGB8 &rgb, const bool reserved=true)
 Set the LED to the specified colours, but doesn't alter the rgb8 variable defined above. More...
 
ChainableRGBLEDstart_pulse_thread (const uint8_t r1=255, const uint8_t g1=255, const uint8_t b1=255, const uint8_t r2=0, const uint8_t g2=0, const uint8_t b2=0, const size_t length_of_pulse_in_milliseconds=1500)
 Start a thread to pulse the LED between two sets of colours. More...
 
ChainableRGBLEDstart_pulse_thread (const Colours8 &colours, size_t length_of_pulse_in_milliseconds=1500)
 
ChainableRGBLEDstop_pulse_thread (void)
 Stop any existing pulse thread. More...
 
void run_pulse_thread (uint8_t r1=255, uint8_t g1=255, uint8_t b1=255, uint8_t r2=0, uint8_t g2=0, uint8_t b2=0, size_t length_of_pulse_in_milliseconds=1500)
 Runs a loop which causes the LED to pulse. More...
 
void run_pulse_thread (const Colours8 &colours, size_t length_of_pulse_in_milliseconds=1500)
 
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...
 
RGB8 rgb8
 8-bit RGB colour. 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

◆ ~ChainableRGBLED()

SG::ChainableRGBLED::~ChainableRGBLED ( void  )
virtual

◆ ChainableRGBLED()

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

◆ get_description()

◆ get_name()

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:

◆ get_sku()

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:

◆ get_type()

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:

◆ get_type_name()

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:

◆ is_grove_gpio()

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.

◆ is_grove_i2c()

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.

◆ is_grove_uart()

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.

◆ operator!=()

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

Test object equality.

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

Here is the call graph for this function:

◆ operator==()

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:

◆ run_pulse_thread() [1/2]

void SG::ChainableRGBLED::run_pulse_thread ( uint8_t  r1 = 255,
uint8_t  g1 = 255,
uint8_t  b1 = 255,
uint8_t  r2 = 0,
uint8_t  g2 = 0,
uint8_t  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().

Here is the call graph for this function:

◆ run_pulse_thread() [2/2]

void SG::ChainableRGBLED::run_pulse_thread ( const Colours8 colours,
size_t  length_of_pulse_in_milliseconds = 1500 
)

◆ send_2_bytes()

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:

◆ send_byte()

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:

◆ set_RGB() [1/3]

SG::ChainableRGBLED & SG::ChainableRGBLED::set_RGB ( const RGB8 colour)

Sets the LED to the specified colour, and updates the rgb internal colour value.

References rgb8, and turn_on().

Referenced by chainable_rgb_led(), and set_RGB().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ set_RGB() [2/3]

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 rgb internal colour value.

The range of r, g, and b is between 0.0 and 1.0 which is scaled up to a value between 0 and 255.

References set_RGB().

Here is the call graph for this function:

◆ set_RGB() [3/3]

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 SG::RGB8::b, SG::RGB8::g, SG::RGB8::r, rgb8, and turn_on().

Here is the call graph for this function:

◆ start_pulse_thread() [1/2]

SG::ChainableRGBLED & SG::ChainableRGBLED::start_pulse_thread ( const uint8_t  r1 = 255,
const uint8_t  g1 = 255,
const uint8_t  b1 = 255,
const uint8_t  r2 = 0,
const uint8_t  g2 = 0,
const uint8_t  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_must_quit, 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:

◆ start_pulse_thread() [2/2]

ChainableRGBLED& SG::ChainableRGBLED::start_pulse_thread ( const Colours8 colours,
size_t  length_of_pulse_in_milliseconds = 1500 
)

◆ stop_pulse_thread()

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:

◆ turn_off()

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

Sets the LED to [0,0,0] effectively turning off the LED, but doesn't alter the rgb8 member 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:

◆ turn_on() [1/2]

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

Sets the LED to the previously set value rgb8 defined above.

References SG::RGB8::b, SG::RGB8::g, SG::RGB8::r, and rgb8.

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

Here is the caller graph for this function:

◆ turn_on() [2/2]

SG::ChainableRGBLED & SG::ChainableRGBLED::turn_on ( const RGB8 rgb,
const bool  reserved = true 
)

Set the LED to the specified colours, but doesn't alter the rgb8 variable defined above.

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

Parameters
[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 SG::RGB8::b, SG::RGB8::g, SG::RGB8::r, SG::GroveGPIO::send_byte(), and stop_pulse_thread().

Here is the call graph for this function:

Member Data Documentation

◆ grove_name

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

User-supplied name.

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

◆ grove_type

◆ idx

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.

◆ pulse_thread

std::thread SG::ChainableRGBLED::pulse_thread
protected

Referenced by stop_pulse_thread().

◆ pulse_thread_must_quit

std::atomic<bool> SG::ChainableRGBLED::pulse_thread_must_quit
protected

◆ rgb8

RGB8 SG::ChainableRGBLED::rgb8

8-bit RGB colour.

This is an internal value stored in the C++ object, and may not be the same as the actual LED's intensity.

For example, see turn_off() which alters the colour of the LED, but does not change the rgb8 variable. This way, calling turn_on() will return the LED to the previous colour.

Referenced by set_RGB(), and turn_on().

◆ turn_off_LED_when_destructing

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: