Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/FastLED/FastLED.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkriegsman@gmail.com <kriegsman@gmail.com@4ad4ec5c-605d-bd5c-5796-512c9b60011b>2013-07-16 07:34:48 +0400
committerkriegsman@gmail.com <kriegsman@gmail.com@4ad4ec5c-605d-bd5c-5796-512c9b60011b>2013-07-16 07:34:48 +0400
commitaa79052de296c87cad9f4912c4fba9efbc88b4a4 (patch)
treeecd6caab99310c58928f79f8f7b7112c9b27aa05 /pixeltypes.h
parent9cb79c4ab8d9be7e0cac2801bfed930ae7c4f7ba (diff)
MEK: added HSV setters on CRGB pixels - woo! Exposed getting the current random16 seed, for later 'playback'.
Diffstat (limited to 'pixeltypes.h')
-rw-r--r--pixeltypes.h42
1 files changed, 38 insertions, 4 deletions
diff --git a/pixeltypes.h b/pixeltypes.h
index 3a6e7f5e..949b7fc7 100644
--- a/pixeltypes.h
+++ b/pixeltypes.h
@@ -4,9 +4,16 @@
#include <stdint.h>
#include "lib8tion.h"
+struct CRGB;
+struct CHSV;
+
+// Forward declaration of hsv2rgb_rainbow here,
+// to avoid circular dependencies.
+extern void hsv2rgb_rainbow( const CHSV& hsv, CRGB& rgb);
+
struct CHSV {
- union {
+ union {
struct {
union {
uint8_t hue;
@@ -100,7 +107,7 @@ struct CRGB {
{
}
- // allow construction from 32 (24) bit color code
+ // allow construction from 32-bit (really 24-bit) bit 0xRRGGBB color code
inline CRGB( uint32_t colorcode) __attribute__((always_inline))
: r((colorcode >> 16) & 0xFF), g((colorcode >> 8) & 0xFF), b((colorcode >> 0) & 0xFF)
{
@@ -114,6 +121,12 @@ struct CRGB {
b = rhs.b;
}
+ // allow construction from HSV color
+ inline CRGB(const CHSV& rhs) __attribute__((always_inline))
+ {
+ hsv2rgb_rainbow( rhs, *this);
+ }
+
// allow assignment from one RGB struct to another
inline CRGB& operator= (const CRGB& rhs) __attribute__((always_inline))
{
@@ -123,7 +136,7 @@ struct CRGB {
return *this;
}
- // allow assignment from one RGB struct to another
+ // allow assignment from 32-bit (really 24-bit) 0xRRGGBB color code
inline CRGB& operator= (const uint32_t colorcode) __attribute__((always_inline))
{
r = (colorcode >> 16) & 0xFF;
@@ -141,7 +154,28 @@ struct CRGB {
return *this;
}
- // allow assignment from 32 (24) bit color code
+ // allow assignment from H, S, and V
+ inline CRGB& setHSV (uint8_t hue, uint8_t sat, uint8_t val) __attribute__((always_inline))
+ {
+ hsv2rgb_rainbow( CHSV(hue, sat, val), *this);
+ return *this;
+ }
+
+ // allow assignment from just a Hue, saturation and value automatically at max.
+ inline CRGB& setHue (uint8_t hue) __attribute__((always_inline))
+ {
+ hsv2rgb_rainbow( CHSV(hue, 255, 255), *this);
+ return *this;
+ }
+
+ // allow assignment from HSV color
+ inline CRGB& operator= (const CHSV& rhs) __attribute__((always_inline))
+ {
+ hsv2rgb_rainbow( rhs, *this);
+ return *this;
+ }
+
+ // allow assignment from 32-bit (really 24-bit) 0xRRGGBB color code
inline CRGB& setColorCode (uint32_t colorcode) __attribute__((always_inline))
{
r = (colorcode >> 16) & 0xFF;