Skip to content

Commit

Permalink
Merge pull request #786 from MartinMueller2003/main
Browse files Browse the repository at this point in the history
Added option to the Transition effect to control the number of steps between colors
  • Loading branch information
forkineye authored Sep 26, 2024
2 parents 972841d + 0fd78b3 commit efb8049
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 49 deletions.
96 changes: 52 additions & 44 deletions ESPixelStick/src/input/InputEffectEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ c_InputEffectEngine::c_InputEffectEngine (c_InputMgr::e_InputChannelIds NewInput

SetBufferInfo (BufferSize);

TransitionTargetColorIterator = TransitionColorTable.begin();
TransitionInfo.TargetColorIterator = TransitionColorTable.begin();

// DEBUG_END;
} // c_InputEffectEngine
Expand All @@ -104,7 +104,7 @@ c_InputEffectEngine::c_InputEffectEngine () :

SetBufferInfo (0);

TransitionTargetColorIterator = TransitionColorTable.begin();
TransitionInfo.TargetColorIterator = TransitionColorTable.begin();

// DEBUG_END;

Expand Down Expand Up @@ -159,6 +159,7 @@ void c_InputEffectEngine::GetConfig (JsonObject& jsonConfig)
jsonConfig["FlashMaxDelay"] = FlashInfo.MaxDelayMS;
jsonConfig["FlashMinDur"] = FlashInfo.MinDurationMS;
jsonConfig["FlashMaxDur"] = FlashInfo.MaxDurationMS;
jsonConfig["TransCount"] = TransitionInfo.StepsToTarget;

// DEBUG_V ("");

Expand Down Expand Up @@ -429,24 +430,31 @@ bool c_InputEffectEngine::SetConfig (ArduinoJson::JsonObject& jsonConfig)
String effectName;
String effectColor;

setFromJSON (EffectSpeed, jsonConfig, CN_EffectSpeed);
setFromJSON (EffectReverse, jsonConfig, CN_EffectReverse);
setFromJSON (EffectMirror, jsonConfig, CN_EffectMirror);
setFromJSON (EffectAllLeds, jsonConfig, CN_EffectAllLeds);
setFromJSON (EffectBrightness, jsonConfig, CN_EffectBrightness);
setFromJSON (EffectSpeed, jsonConfig, CN_EffectSpeed);
setFromJSON (EffectReverse, jsonConfig, CN_EffectReverse);
setFromJSON (EffectMirror, jsonConfig, CN_EffectMirror);
setFromJSON (EffectAllLeds, jsonConfig, CN_EffectAllLeds);
setFromJSON (EffectBrightness, jsonConfig, CN_EffectBrightness);
setFromJSON (EffectWhiteChannel, jsonConfig, CN_EffectWhiteChannel);
setFromJSON (effectName, jsonConfig, CN_currenteffect);
setFromJSON (effectColor, jsonConfig, CN_EffectColor);
setFromJSON (effectName, jsonConfig, CN_currenteffect);
setFromJSON (effectColor, jsonConfig, CN_EffectColor);
// DEBUG_V (String ("effectColor: ") + effectColor);
setFromJSON (effectMarqueePixelAdvanceCount, jsonConfig, CN_pixel_count);

setFromJSON (FlashInfo.Enable, jsonConfig, "FlashEnable");
setFromJSON (FlashInfo.MinIntensity, jsonConfig, "FlashMinInt");
setFromJSON (FlashInfo.MaxIntensity, jsonConfig, "FlashMaxInt");
setFromJSON (FlashInfo.MinDelayMS, jsonConfig, "FlashMinDelay");
setFromJSON (FlashInfo.MaxDelayMS, jsonConfig, "FlashMaxDelay");
setFromJSON (FlashInfo.MinDurationMS, jsonConfig, "FlashMinDur");
setFromJSON (FlashInfo.MaxDurationMS, jsonConfig, "FlashMaxDur");
setFromJSON (FlashInfo.Enable, jsonConfig, "FlashEnable");
setFromJSON (FlashInfo.MinIntensity, jsonConfig, "FlashMinInt");
setFromJSON (FlashInfo.MaxIntensity, jsonConfig, "FlashMaxInt");
setFromJSON (FlashInfo.MinDelayMS, jsonConfig, "FlashMinDelay");
setFromJSON (FlashInfo.MaxDelayMS, jsonConfig, "FlashMaxDelay");
setFromJSON (FlashInfo.MinDurationMS, jsonConfig, "FlashMinDur");
setFromJSON (FlashInfo.MaxDurationMS, jsonConfig, "FlashMaxDur");

setFromJSON (TransitionInfo.StepsToTarget, jsonConfig, "TransCount");

// avoid divide by zero errors later in the processing.
TransitionInfo.StepsToTarget = max(double(1.0), TransitionInfo.StepsToTarget);
// Pretend we reached the currnt color.
TransitionInfo.CurrentColor = *TransitionInfo.TargetColorIterator;

// make sure max is really max
if(FlashInfo.MinIntensity >= FlashInfo.MaxIntensity)
Expand Down Expand Up @@ -923,44 +931,44 @@ uint16_t c_InputEffectEngine::effectTransition ()
// DEBUG_V("need to calculate a new target color");

// remove any calculation errors
dCRGB TransitionCurrentColor = *TransitionTargetColorIterator;
TransitionInfo.CurrentColor = *TransitionInfo.TargetColorIterator;

++TransitionTargetColorIterator;
++TransitionInfo.TargetColorIterator;

// wrap the index
if(TransitionTargetColorIterator == TransitionColorTable.end())
if(TransitionInfo.TargetColorIterator == TransitionColorTable.end())
{
// DEBUG_V("Wrap Transition iterator");
TransitionTargetColorIterator = TransitionColorTable.begin();
TransitionInfo.TargetColorIterator = TransitionColorTable.begin();
}

CalculateTransitionStepValue (TransitionTargetColorIterator->r, TransitionCurrentColor.r, TransitionStepValue.r);
CalculateTransitionStepValue (TransitionTargetColorIterator->g, TransitionCurrentColor.g, TransitionStepValue.g);
CalculateTransitionStepValue (TransitionTargetColorIterator->b, TransitionCurrentColor.b, TransitionStepValue.b);

// DEBUG_V(String(" TransitionStepValue.r: ") + String(TransitionStepValue.r));
// DEBUG_V(String(" TransitionStepValue.g: ") + String(TransitionStepValue.g));
// DEBUG_V(String(" TransitionStepValue.b: ") + String(TransitionStepValue.b));
// DEBUG_V(String(" TargetColor.r: ") + String(TransitionTargetColorIterator->r));
// DEBUG_V(String(" TargetColor.g: ") + String(TransitionTargetColorIterator->g));
// DEBUG_V(String(" TargetColor.b: ") + String(TransitionTargetColorIterator->b));
// DEBUG_V(String("TransitionCurrentColor.r: ") + String(TransitionCurrentColor.r));
// DEBUG_V(String("TransitionCurrentColor.g: ") + String(TransitionCurrentColor.g));
// DEBUG_V(String("TransitionCurrentColor.b: ") + String(TransitionCurrentColor.b));
CalculateTransitionStepValue (TransitionInfo.TargetColorIterator->r, TransitionInfo.CurrentColor.r, TransitionInfo.StepValue.r);
CalculateTransitionStepValue (TransitionInfo.TargetColorIterator->g, TransitionInfo.CurrentColor.g, TransitionInfo.StepValue.g);
CalculateTransitionStepValue (TransitionInfo.TargetColorIterator->b, TransitionInfo.CurrentColor.b, TransitionInfo.StepValue.b);

// DEBUG_V(String(" TransitionInfo.StepValue.r: ") + String(TransitionInfo.StepValue.r));
// DEBUG_V(String(" TransitionInfo.StepValue.g: ") + String(TransitionInfo.StepValue.g));
// DEBUG_V(String(" TransitionInfo.StepValue.b: ") + String(TransitionInfo.StepValue.b));
// DEBUG_V(String(" TargetColor.r: ") + String(TransitionInfo.TargetColorIterator->r));
// DEBUG_V(String(" TargetColor.g: ") + String(TransitionInfo.TargetColorIterator->g));
// DEBUG_V(String(" TargetColor.b: ") + String(TransitionInfo.TargetColorIterator->b));
// DEBUG_V(String("TransitionInfo.CurrentColor.r: ") + String(TransitionInfo.CurrentColor.r));
// DEBUG_V(String("TransitionInfo.CurrentColor.g: ") + String(TransitionInfo.CurrentColor.g));
// DEBUG_V(String("TransitionInfo.CurrentColor.b: ") + String(TransitionInfo.CurrentColor.b));
}
else
{
// DEBUG_V("need to calculate next transition color");

ConditionalIncrementColor(TransitionTargetColorIterator->r, TransitionCurrentColor.r, TransitionStepValue.r);
ConditionalIncrementColor(TransitionTargetColorIterator->g, TransitionCurrentColor.g, TransitionStepValue.g);
ConditionalIncrementColor(TransitionTargetColorIterator->b, TransitionCurrentColor.b, TransitionStepValue.b);
ConditionalIncrementColor(TransitionInfo.TargetColorIterator->r, TransitionInfo.CurrentColor.r, TransitionInfo.StepValue.r);
ConditionalIncrementColor(TransitionInfo.TargetColorIterator->g, TransitionInfo.CurrentColor.g, TransitionInfo.StepValue.g);
ConditionalIncrementColor(TransitionInfo.TargetColorIterator->b, TransitionInfo.CurrentColor.b, TransitionInfo.StepValue.b);
}

CRGB TempColor;
TempColor.r = uint8_t(TransitionCurrentColor.r);
TempColor.g = uint8_t(TransitionCurrentColor.g);
TempColor.b = uint8_t(TransitionCurrentColor.b);
TempColor.r = uint8_t(TransitionInfo.CurrentColor.r);
TempColor.g = uint8_t(TransitionInfo.CurrentColor.g);
TempColor.b = uint8_t(TransitionInfo.CurrentColor.b);

// DEBUG_V(String("r: ") + String(TempColor.r));
// DEBUG_V(String("g: ") + String(TempColor.g));
Expand Down Expand Up @@ -1070,9 +1078,9 @@ uint16_t c_InputEffectEngine::effectMarquee ()
void c_InputEffectEngine::CalculateTransitionStepValue(double tc, double cc, double & step)
{
// DEBUG_START;
step = (tc - cc) / NumStepsToTarget;
step = (tc - cc) / TransitionInfo.StepsToTarget;

#define MinStepValue (1.0 / NumStepsToTarget)
#define MinStepValue (1.0 / TransitionInfo.StepsToTarget)
if(MinStepValue > fabs(step))
{
if(step < 0.0)
Expand Down Expand Up @@ -1152,9 +1160,9 @@ bool c_InputEffectEngine::ColorHasReachedTarget()
{
// DEBUG_START;

bool response = ( ColorHasReachedTarget(TransitionTargetColorIterator->r, TransitionCurrentColor.r, TransitionStepValue.r) &&
ColorHasReachedTarget(TransitionTargetColorIterator->g, TransitionCurrentColor.g, TransitionStepValue.g) &&
ColorHasReachedTarget(TransitionTargetColorIterator->b, TransitionCurrentColor.b, TransitionStepValue.b));
bool response = ( ColorHasReachedTarget(TransitionInfo.TargetColorIterator->r, TransitionInfo.CurrentColor.r, TransitionInfo.StepValue.r) &&
ColorHasReachedTarget(TransitionInfo.TargetColorIterator->g, TransitionInfo.CurrentColor.g, TransitionInfo.StepValue.g) &&
ColorHasReachedTarget(TransitionInfo.TargetColorIterator->b, TransitionInfo.CurrentColor.b, TransitionInfo.StepValue.b));

if(response)
{
Expand Down
13 changes: 8 additions & 5 deletions ESPixelStick/src/input/InputEffectEngine.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class c_InputEffectEngine : public c_InputCommon
CRGB color;
} MQTTConfiguration_s;

struct MarqueeGroup
struct MarqueeGroup
{
uint32_t NumPixelsInGroup;
CRGB Color;
Expand Down Expand Up @@ -176,10 +176,13 @@ class c_InputEffectEngine : public c_InputCommon

const EffectDescriptor_t * ActiveEffect = nullptr;

dCRGB TransitionCurrentColor = {0.0, 0.0, 0.0};
std::vector<c_InputEffectEngine::dCRGB>::iterator TransitionTargetColorIterator;
dCRGB TransitionStepValue = {2.0, 2.0, 2.0};
#define NumStepsToTarget 300.0
struct Transition_t
{
dCRGB CurrentColor = {0.0, 0.0, 0.0};
std::vector<c_InputEffectEngine::dCRGB>::iterator TargetColorIterator;
dCRGB StepValue = {2.0, 2.0, 2.0};
double StepsToTarget = 300; // number of NumStepsToTarget
} TransitionInfo;
bool ColorHasReachedTarget ();
bool ColorHasReachedTarget (double tc, double cc, double step);
void ConditionalIncrementColor(double tc, double & cc, double step);
Expand Down
10 changes: 10 additions & 0 deletions html/effects.html
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,16 @@
</div>

<div class="form-group hidden" id="TransitionsConfig">
<label class="control-label col-sm-2" for="TransCount">Steps Between Colors</label>
<div class="col-sm-4">
<input type="number" class="form-control is-valid" id="TransCount" step="1" min="1" max="10000"
value="0" required title="Steps between Colors">
</div>
<label class="control-label col-sm-2" for="TransDelay">Seconds to stay at color</label>
<div class="col-sm-4">
<input type="number" class="form-control is-valid" id="TransDelay" step="1" min="1" max="1000"
value="0" required title="Seconds to stay at color.">
</div>
<label class="control-label col-sm-2" for="TransitionColorTable">Transitions</label>
<div class="form-group " style="height:200px; overflow:auto;">
<div class="col-sm-offset-0 col-sm-2" id="d_transition">
Expand Down

0 comments on commit efb8049

Please sign in to comment.