Permalink
Browse files

Merge branch 'FastLED3.1' into d21

  • Loading branch information...
focalintent committed Aug 9, 2015
2 parents c1285ef + 9b047b5 commit 1d77874dd34eceec382aa6ea22db1df4aa912d9c
View
@@ -23,7 +23,6 @@ CFastLED::CFastLED() {
// m_nControllers = 0;
m_Scale = 255;
m_nFPS = 0;
setMaxRefreshRate(400);
}
CLEDController &CFastLED::addLeds(CLEDController *pLed,
@@ -34,6 +33,7 @@ CLEDController &CFastLED::addLeds(CLEDController *pLed,
pLed->init();
pLed->setLeds(data + nOffset, nLeds);
FastLED.setMaxRefreshRate(pLed->getMaxRefreshRate(),true);
return *pLed;
}
@@ -199,12 +199,18 @@ void CFastLED::countFPS(int nFrames) {
}
}
void CFastLED::setMaxRefreshRate(uint16_t refresh) {
if(refresh > 0) {
m_nMinMicros = 1000000 / refresh;
} else {
m_nMinMicros = 0;
}
void CFastLED::setMaxRefreshRate(uint16_t refresh, bool constrain) {
if(constrain) {
// if we're constraining, the new value of m_nMinMicros _must_ be higher than previously (because we're only
// allowed to slow things down if constraining)
if(refresh > 0) {
m_nMinMicros = ( (1000000/refresh) > m_nMinMicros) ? (1000000/refresh) : m_nMinMicros;
}
} else if(refresh > 0) {
m_nMinMicros = 1000000 / refresh;
} else {
m_nMinMicros = 0;
}
}
View
@@ -40,6 +40,7 @@
#include "./dmx.h"
#include "platforms.h"
#include "fastled_progmem.h"
#include "lib8tion.h"
#include "hsv2rgb.h"
@@ -434,10 +435,13 @@ class CFastLED {
void setDither(uint8_t ditherMode = BINARY_DITHER);
/// Set the maximum refresh rate. This is global for all leds. Attempts to
/// call show faster than this rate will simply wait. Defaults to 400Hz. Set
/// to 0 to have no maximum rate.
/// call show faster than this rate will simply wait. Note that the refresh rate
/// defaults to the slowest refresh rate of all the leds added through addLeds. If
/// you wish to set/override this rate, be sure to call setMaxRefreshRate _after_
/// adding all of your leds.
/// @param refresh - maximum refresh rate in hz
void setMaxRefreshRate(uint16_t refresh);
/// @param constrain - constrain refresh rate to the slowest speed yet set
void setMaxRefreshRate(uint16_t refresh, bool constrain=false);
/// for debugging, will keep track of time between calls to countFPS, and every
/// nFrames calls, it will update an internal counter for the current FPS.
View
@@ -1,17 +1,17 @@
IMPORTANT NOTE: For AVR based systems, avr-gcc 4.8.x is supported, as is avr-gcc 4.3 and earlier. There are known issues with avr-gcc 4.7 and timing based chipsets like the WS2812B. If you are using a linux system make sure you are using avr-gcc 4.8.x not avr-gcc 4.7.x.
[![Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/FastLED/public)
IMPORTANT NOTE: For AVR based systems, avr-gcc 4.8.x is supported, as is avr-gcc 4.3 and earlier. There are known issues with avr-gcc 4.7 and timing based chipsets like the WS2812B. If you are using a linux system make sure you are using avr-gcc 4.8.x not avr-gcc 4.7.x.
FastLED 3.0
FastLED 3.1
===========
IMPORTANT NOTE: If you are building for AVR based systems, please do not use any version of the arduino
IDE 1.5.7 or later yet. It messes with some of the asm output which will cause you problems.
This is a library for easily & efficiently controlling a wide variety of LED chipsets, like the ones
sold by adafruit (Neopixel, LPD8806), Sparkfun (WS2801), and aliexpress. In addition to writing to the
leds, this library also includes a number of functions for high-performing 8bit math for manipulating
your RGB values, as well as low level classes for abstracting out access to pins and SPI hardware, while
still keeping things as fast as possible.
still keeping things as fast as possible. Tested with Arduino up to 1.6.5 from arduino.cc.
Quick note for people installing from GitHub repo zips, rename the folder FastLED before copying it to your Arduino/libraries folder. Github likes putting -branchname into the name of the folder, which unfortunately, makes Arduino cranky!
@@ -43,7 +43,7 @@ How quickly can you get up and running with the library? Here's a simple blink
Here's a list of all the LED chipsets are supported. More details on the led chipsets are included *TODO: Link to wiki page*
* Adafruit's DotStars - AKA the APA102
* Adafruit's Neopixel - aka the WS2812B (also WS2811/WS2812, also suppored in lo-speed mode) - a 3 wire addressable led chipset
* Adafruit's Neopixel - aka the WS2812B (also WS2811/WS2812, also supported in lo-speed mode) - a 3 wire addressable led chipset
* TM1809/4 - 3 wire chipset, cheaply available on aliexpress.com
* TM1803 - 3 wire chipset, sold by radio shack
* UCS1903 - another 3 wire led chipset, cheap
@@ -64,7 +64,7 @@ LPD6803, HL1606, and "595"-style shift registers are no longer supported by the
Right now the library is supported on a variety of arduino compatable platforms. If it's ARM or AVR and uses the arduino software (or a modified version of it to build) then it is likely supported. Note that we have a long list of upcoming platforms to support, so if you don't see what you're looking for here, ask, it may be on the roadmap (or may already be supported). N.B. at the moment we are only supporting the stock compilers that ship with the arduino software. Support for upgraded compilers, as well as using AVR studio and skipping the arduino entirely, should be coming in a near future release.
* Arduino & compatibles - straight up arduino devices, uno, duo, leonardo, mega, nano, etc... NOTE: On the mega, you can't use pins 42,43,44,45,46,47,48, and 49 with 3-wire chipsets.
* Arduino & compatibles - straight up arduino devices, uno, duo, leonardo, mega, nano, etc...
* Adafruit Trinket & Gemma - Trinket Pro may be supported, but haven't tested to confirm yet
* Teensy 2, Teensy++ 2, Teensy 3.0, Teensy 3.1, Teensy LC - arduino compataible from pjrc.com with some extra goodies (note the teensy 3 is ARM, not AVR!)
* Arduino Due and the digistump DigiX
View
@@ -178,7 +178,11 @@ class APA102Controller : public CLEDController {
startBoundary();
for(int i = 0; i < nLeds; i++) {
writeLed(pixels.loadAndScale0(), pixels.loadAndScale1(), pixels.loadAndScale2());
uint8_t b = pixels.loadAndScale0();
mSPI.writeWord(0xFF00 | b);
uint16_t w = pixels.loadAndScale1() << 8;
w |= pixels.loadAndScale2();
mSPI.writeWord(w);
pixels.stepDithering();
}
endBoundary(nLeds);
@@ -194,7 +198,11 @@ class APA102Controller : public CLEDController {
startBoundary();
for(int i = 0; i < nLeds; i++) {
writeLed(pixels.loadAndScale0(), pixels.loadAndScale1(), pixels.loadAndScale2());
uint16_t b = 0xFF00 | (uint16_t)pixels.loadAndScale0();
mSPI.writeWord(b);
uint16_t w = pixels.loadAndScale1() << 8;
w |= pixels.loadAndScale2();
mSPI.writeWord(w);
pixels.advanceData();
pixels.stepDithering();
}
@@ -211,7 +219,10 @@ class APA102Controller : public CLEDController {
startBoundary();
for(int i = 0; i < nLeds; i++) {
writeLed(pixels.loadAndScale0(), pixels.loadAndScale1(), pixels.loadAndScale2());
mSPI.writeByte(0xFF);
uint8_t b = pixels.loadAndScale0(); mSPI.writeByte(b);
b = pixels.loadAndScale1(); mSPI.writeByte(b);
b = pixels.loadAndScale2(); mSPI.writeByte(b);
pixels.advanceData();
pixels.stepDithering();
}
View
@@ -7,15 +7,6 @@
FASTLED_USING_NAMESPACE
// Workaround for http://gcc.gnu.org/bugzilla/show_bug.cgi?id=34734
#ifdef FASTLED_AVR
#ifdef PROGMEM
#undef PROGMEM
#define PROGMEM __attribute__((section(".progmem.data")))
#endif
#endif
// Preset color schemes, such as they are.
@@ -26,7 +17,7 @@ FASTLED_USING_NAMESPACE
// use each one, so you only 'pay for' those you actually use.
extern const TProgmemRGBPalette16 CloudColors_p PROGMEM =
extern const TProgmemRGBPalette16 CloudColors_p FL_PROGMEM =
{
CRGB::Blue,
CRGB::DarkBlue,
@@ -49,7 +40,7 @@ extern const TProgmemRGBPalette16 CloudColors_p PROGMEM =
CRGB::SkyBlue
};
extern const TProgmemRGBPalette16 LavaColors_p PROGMEM =
extern const TProgmemRGBPalette16 LavaColors_p FL_PROGMEM =
{
CRGB::Black,
CRGB::Maroon,
@@ -72,7 +63,7 @@ extern const TProgmemRGBPalette16 LavaColors_p PROGMEM =
};
extern const TProgmemRGBPalette16 OceanColors_p PROGMEM =
extern const TProgmemRGBPalette16 OceanColors_p FL_PROGMEM =
{
CRGB::MidnightBlue,
CRGB::DarkBlue,
@@ -95,7 +86,7 @@ extern const TProgmemRGBPalette16 OceanColors_p PROGMEM =
CRGB::LightSkyBlue
};
extern const TProgmemRGBPalette16 ForestColors_p PROGMEM =
extern const TProgmemRGBPalette16 ForestColors_p FL_PROGMEM =
{
CRGB::DarkGreen,
CRGB::DarkGreen,
@@ -119,7 +110,7 @@ extern const TProgmemRGBPalette16 ForestColors_p PROGMEM =
};
/// HSV Rainbow
extern const TProgmemRGBPalette16 RainbowColors_p PROGMEM =
extern const TProgmemRGBPalette16 RainbowColors_p FL_PROGMEM =
{
0xFF0000, 0xD52A00, 0xAB5500, 0xAB7F00,
0xABAB00, 0x56D500, 0x00FF00, 0x00D52A,
@@ -129,7 +120,7 @@ extern const TProgmemRGBPalette16 RainbowColors_p PROGMEM =
/// HSV Rainbow colors with alternatating stripes of black
#define RainbowStripesColors_p RainbowStripeColors_p
extern const TProgmemRGBPalette16 RainbowStripeColors_p PROGMEM =
extern const TProgmemRGBPalette16 RainbowStripeColors_p FL_PROGMEM =
{
0xFF0000, 0x000000, 0xAB5500, 0x000000,
0xABAB00, 0x000000, 0x00FF00, 0x000000,
@@ -141,7 +132,7 @@ extern const TProgmemRGBPalette16 RainbowStripeColors_p PROGMEM =
/// Basically, everything but the greens, which tend to make
/// people's skin look unhealthy. This palette is good for
/// lighting at a club or party, where it'll be shining on people.
extern const TProgmemRGBPalette16 PartyColors_p PROGMEM =
extern const TProgmemRGBPalette16 PartyColors_p FL_PROGMEM =
{
0x5500AB, 0x84007C, 0xB5004B, 0xE5001B,
0xE81700, 0xB84700, 0xAB7700, 0xABAB00,
@@ -155,7 +146,7 @@ extern const TProgmemRGBPalette16 PartyColors_p PROGMEM =
/// the usual 0-255, as the last 15 colors will be
/// 'wrapping around' from the hot end to the cold end,
/// which looks wrong.
extern const TProgmemRGBPalette16 HeatColors_p PROGMEM =
extern const TProgmemRGBPalette16 HeatColors_p FL_PROGMEM =
{
0x000000,
0x330000, 0x660000, 0x990000, 0xCC0000, 0xFF0000,
View
@@ -15,34 +15,34 @@ FASTLED_NAMESPACE_BEGIN
///@{
/// Cloudy color pallete
extern const TProgmemRGBPalette16 CloudColors_p PROGMEM;
extern const TProgmemRGBPalette16 CloudColors_p FL_PROGMEM;
/// Lava colors
extern const TProgmemRGBPalette16 LavaColors_p PROGMEM;
extern const TProgmemRGBPalette16 LavaColors_p FL_PROGMEM;
/// Ocean colors, blues and whites
extern const TProgmemRGBPalette16 OceanColors_p PROGMEM;
extern const TProgmemRGBPalette16 OceanColors_p FL_PROGMEM;
/// Forest colors, greens
extern const TProgmemRGBPalette16 ForestColors_p PROGMEM;
extern const TProgmemRGBPalette16 ForestColors_p FL_PROGMEM;
/// HSV Rainbow
extern const TProgmemRGBPalette16 RainbowColors_p PROGMEM;
extern const TProgmemRGBPalette16 RainbowColors_p FL_PROGMEM;
#define RainbowStripesColors_p RainbowStripeColors_p
/// HSV Rainbow colors with alternatating stripes of black
extern const TProgmemRGBPalette16 RainbowStripeColors_p PROGMEM;
extern const TProgmemRGBPalette16 RainbowStripeColors_p FL_PROGMEM;
/// HSV color ramp: blue purple ping red orange yellow (and back)
/// Basically, everything but the greens, which tend to make
/// people's skin look unhealthy. This palette is good for
/// lighting at a club or party, where it'll be shining on people.
extern const TProgmemRGBPalette16 PartyColors_p PROGMEM;
extern const TProgmemRGBPalette16 PartyColors_p FL_PROGMEM;
/// Approximate "black body radiation" palette, akin to
/// the FastLED 'HeatColor' function.
/// Recommend that you use values 0-240 rather than
/// the usual 0-255, as the last 15 colors will be
/// 'wrapping around' from the hot end to the cold end,
/// which looks wrong.
extern const TProgmemRGBPalette16 HeatColors_p PROGMEM;
extern const TProgmemRGBPalette16 HeatColors_p FL_PROGMEM;
FASTLED_NAMESPACE_END
View
@@ -69,10 +69,10 @@ void fill_gradient_RGB( CRGB* leds,
if( endpos < startpos ) {
uint16_t t = endpos;
CRGB tc = endcolor;
startpos = t;
startcolor = tc;
endcolor = startcolor;
endpos = startpos;
startpos = t;
startcolor = tc;
}
saccum87 rdistance87;
@@ -538,7 +538,7 @@ CRGB ColorFromPalette( const TProgmemRGBPalette16& pal, uint8_t index, uint8_t b
uint8_t lo4 = index & 0x0F;
// CRGB rgb1 = pal[ hi4];
CRGB entry = pgm_read_dword_near( &(pal[0]) + hi4 );
CRGB entry = FL_PGM_READ_DWORD_NEAR( &(pal[0]) + hi4 );
uint8_t red1 = entry.red;
uint8_t green1 = entry.green;
@@ -549,9 +549,9 @@ CRGB ColorFromPalette( const TProgmemRGBPalette16& pal, uint8_t index, uint8_t b
if( blend ) {
if( hi4 == 15 ) {
entry = pgm_read_dword_near( &(pal[0]) );
entry = FL_PGM_READ_DWORD_NEAR( &(pal[0]) );
} else {
entry = pgm_read_dword_near( &(pal[1]) + hi4 );
entry = FL_PGM_READ_DWORD_NEAR( &(pal[1]) + hi4 );
}
uint8_t f2 = lo4 << 4;
@@ -736,7 +736,7 @@ void nblendPaletteTowardPalette( CRGBPalette16& current, CRGBPalette16& target,
p2 = (uint8_t*)target.entries;
const uint8_t totalChannels = sizeof(CRGBPalette16);
for( byte i = 0; i < totalChannels; i++) {
for( uint8_t i = 0; i < totalChannels; i++) {
// if the values are equal, no changes are needed
if( p1[i] == p2[i] ) { continue; }
@@ -755,4 +755,63 @@ void nblendPaletteTowardPalette( CRGBPalette16& current, CRGBPalette16& target,
}
}
uint8_t applyGamma_video( uint8_t brightness, float gamma)
{
float orig;
float adj;
orig = (float)(brightness) / (255.0);
adj = pow( orig, gamma) * (255.0);
uint8_t result = (uint8_t)(adj);
if( (brightness > 0) && (result == 0)) {
result = 1; // never gamma-adjust a positive number down to zero
}
return result;
}
CRGB applyGamma_video( const CRGB& orig, float gamma)
{
CRGB adj;
adj.r = applyGamma_video( orig.r, gamma);
adj.g = applyGamma_video( orig.g, gamma);
adj.b = applyGamma_video( orig.b, gamma);
return adj;
}
CRGB applyGamma_video( const CRGB& orig, float gammaR, float gammaG, float gammaB)
{
CRGB adj;
adj.r = applyGamma_video( orig.r, gammaR);
adj.g = applyGamma_video( orig.g, gammaG);
adj.b = applyGamma_video( orig.b, gammaB);
return adj;
}
CRGB& napplyGamma_video( CRGB& rgb, float gamma)
{
rgb = applyGamma_video( rgb, gamma);
return rgb;
}
CRGB& napplyGamma_video( CRGB& rgb, float gammaR, float gammaG, float gammaB)
{
rgb = applyGamma_video( rgb, gammaR, gammaG, gammaB);
return rgb;
}
void napplyGamma_video( CRGB* rgbarray, uint16_t count, float gamma)
{
for( uint16_t i = 0; i < count; i++) {
rgbarray[i] = applyGamma_video( rgbarray[i], gamma);
}
}
void napplyGamma_video( CRGB* rgbarray, uint16_t count, float gammaR, float gammaG, float gammaB)
{
for( uint16_t i = 0; i < count; i++) {
rgbarray[i] = applyGamma_video( rgbarray[i], gammaR, gammaG, gammaB);
}
}
FASTLED_NAMESPACE_END
Oops, something went wrong.

0 comments on commit 1d77874

Please sign in to comment.