changed randomness and added optimizations
-added fully random palette function ('the old way', currently just used for initialization)
-changed randomness values to make it a little less random
-added 10% chance for pastel color palette
-now using swap() from std library for shuffeling
-changed function name
-moved update check from loadPalette() to handleRandomPalette() saving CPU cycles
This commit is contained in:
@@ -77,8 +77,8 @@ uint16_t Segment::_usedSegmentData = 0U; // amount of RAM all segments use for t
|
||||
uint16_t Segment::maxWidth = DEFAULT_LED_COUNT;
|
||||
uint16_t Segment::maxHeight = 1;
|
||||
|
||||
CRGBPalette16 Segment::_randomPalette = generateRandomPalette(_randomPalette);
|
||||
CRGBPalette16 Segment::_newRandomPalette = generateRandomPalette(_randomPalette);
|
||||
CRGBPalette16 Segment::_randomPalette = generateRandomPalette();
|
||||
CRGBPalette16 Segment::_newRandomPalette = generateRandomPalette();
|
||||
uint16_t Segment::_lastPaletteChange = 0; // perhaps it should be per segment
|
||||
uint16_t Segment::_lastPaletteBlend = 0; //in millis (lowest 16 bits only)
|
||||
|
||||
@@ -222,13 +222,7 @@ CRGBPalette16 IRAM_ATTR &Segment::loadPalette(CRGBPalette16 &targetPalette, uint
|
||||
case 0: //default palette. Exceptions for specific effects above
|
||||
targetPalette = PartyColors_p; break;
|
||||
case 1: {//periodically replace palette with a random one
|
||||
if ((millis()/1000U) - _lastPaletteChange > randomPaletteChangeTime) {
|
||||
_newRandomPalette = generateRandomPalette(_randomPalette);
|
||||
_lastPaletteChange = millis()/1000U;
|
||||
_lastPaletteBlend = (uint16_t)(millis()&0xFFFF)-512; //starts blending immediately
|
||||
handleRandomPalette(); // do a 1st pass of blend
|
||||
}
|
||||
targetPalette = _randomPalette;
|
||||
targetPalette = _randomPalette; //random palette is generated at intervals in handleRandomPalette()
|
||||
break;}
|
||||
case 2: {//primary color only
|
||||
CRGB prim = gamma32(colors[0]);
|
||||
@@ -463,11 +457,17 @@ void Segment::handleRandomPalette() {
|
||||
// just do a blend; if the palettes are identical it will just compare 48 bytes (same as _randomPalette == _newRandomPalette)
|
||||
// this will slowly blend _newRandomPalette into _randomPalette every 15ms or 8ms (depending on MIN_SHOW_DELAY)
|
||||
// if palette transitions is enabled, blend it according to Transition Time (if longer than minimum given by service calls)
|
||||
if(strip.paletteFade)
|
||||
|
||||
if ((millis()/1000U) - _lastPaletteChange > randomPaletteChangeTime) {
|
||||
_newRandomPalette = generateHarmonicRandomPalette(_randomPalette);
|
||||
_lastPaletteChange = millis()/1000U;
|
||||
_lastPaletteBlend = (uint16_t)(millis()&0xFFFF)-512; //starts blending immediately
|
||||
}
|
||||
|
||||
if (strip.paletteFade)
|
||||
{
|
||||
if((millis()&0xFFFF) - _lastPaletteBlend < strip.getTransition()>>7) //assumes that 128 updates are needed to blend a palette, so shift by 7 (can be more, can be less)
|
||||
{
|
||||
return; //not time to fade yet
|
||||
if ((millis() & 0xFFFF) - _lastPaletteBlend < strip.getTransition() >> 7) {//assumes that 128 updates are needed to blend a palette, so shift by 7 (can be more, can be less)
|
||||
return; //not time to fade yet, delay the update
|
||||
}
|
||||
_lastPaletteBlend = millis();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user