Skip to content

Commit

Permalink
Fix sequence logic
Browse files Browse the repository at this point in the history
  • Loading branch information
bportaluri committed Nov 25, 2018
1 parent c9d9b8e commit bd2c85a
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 15 deletions.
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=ALA
version=2.3.7
version=2.3.8
author=bportaluri
maintainer=Bruno Portaluri <[email protected]>
sentence=Arduino Light Animation (ALA) library
Expand Down
17 changes: 13 additions & 4 deletions src/AlaLed.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,17 @@ void AlaLed::setRefreshRate(int refreshRate)
}


void AlaLed::setAnimation(int animation, long speed)
void AlaLed::setAnimation(int animation, long speed, bool isSeq)
{
if (this->animation == animation && this->speed == speed)
return;

this->animation = animation;
this->speed = speed;

setAnimationFunc(animation);
if (!isSeq)
animSeqLen=0;
setAnimationFunc(animation);
animStartTime = millis();
}

Expand All @@ -95,9 +97,16 @@ void AlaLed::setAnimation(AlaSeq animSeq[])
animSeqDuration = animSeqDuration + animSeq[animSeqLen].duration;
}
animSeqStartTime = millis();
setAnimation(animSeq[0].animation, animSeq[0].speed);
setAnimation(animSeq[0].animation, animSeq[0].speed, true);
}

void AlaLed::setSpeed(long speed)
{
this->speed = speed;
animStartTime = millis();
}


int AlaLed::getAnimation()
{
return animation;
Expand Down Expand Up @@ -128,7 +137,7 @@ bool AlaLed::runAnimation()
{
if (t>=c && t<(c+animSeq[i].duration))
{
setAnimation(animSeq[i].animation, animSeq[i].speed);
setAnimation(animSeq[i].animation, animSeq[i].speed, true);
break;
}
c = c + animSeq[i].duration;
Expand Down
3 changes: 2 additions & 1 deletion src/AlaLed.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,9 @@ class AlaLed

int getRefreshRate();

void setAnimation(int animation, long speed);
void setAnimation(int animation, long speed, bool isSeq=false);
void setAnimation(AlaSeq animSeq[]);
void setSpeed(long speed);
int getAnimation();

bool runAnimation();
Expand Down
29 changes: 22 additions & 7 deletions src/AlaLedRgb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ int AlaLedRgb::getCurrentRefreshRate()
}


void AlaLedRgb::setAnimation(int animation, long speed, AlaColor color)
void AlaLedRgb::setAnimation(int animation, long speed, AlaColor color, bool isSeq)
{
// is there any change?
if (this->animation == animation && this->speed == speed && this->palette.numColors == 1 && this->palette.colors[0] == color)
Expand All @@ -115,15 +115,18 @@ void AlaLedRgb::setAnimation(int animation, long speed, AlaColor color)
this->speed = speed;

this->palette.numColors = 1;
this->palette.colors = (AlaColor*)malloc(3);
// TODO is this a memory leak?
this->palette.colors = (AlaColor*)malloc(3);
this->palette.colors[0] = color;

animSeqLen=0;
if (!isSeq)
animSeqLen=0;
setAnimationFunc(animation);
animStartTime = millis();
}

void AlaLedRgb::setAnimation(int animation, long speed, AlaPalette palette)

void AlaLedRgb::setAnimation(int animation, long speed, AlaPalette palette, bool isSeq)
{
// is there any change?
if (this->animation == animation && this->speed == speed && this->palette == palette)
Expand All @@ -139,7 +142,8 @@ void AlaLedRgb::setAnimation(int animation, long speed, AlaPalette palette)
this->speed = speed;
this->palette = palette;

animSeqLen=0;
if (!isSeq)
animSeqLen=0;
setAnimationFunc(animation);
animStartTime = millis();
}
Expand All @@ -156,7 +160,18 @@ void AlaLedRgb::setAnimation(AlaSeq animSeq[])
animSeqDuration = animSeqDuration + animSeq[animSeqLen].duration;
}
animSeqStartTime = millis();
setAnimation(animSeq[0].animation, animSeq[0].speed, animSeq[0].palette);
setAnimation(animSeq[0].animation, animSeq[0].speed, animSeq[0].palette, true);
}

void AlaLedRgb::setSpeed(long speed)
{
this->speed = speed;
animStartTime = millis();
}

void AlaLedRgb::setColor(AlaColor color)
{
this->palette.colors[0] = color;
}

int AlaLedRgb::getAnimation()
Expand Down Expand Up @@ -189,7 +204,7 @@ bool AlaLedRgb::runAnimation()
{
if (t>=c && t<(c+animSeq[i].duration))
{
setAnimation(animSeq[i].animation, animSeq[i].speed, animSeq[i].palette);
setAnimation(animSeq[i].animation, animSeq[i].speed, animSeq[i].palette, true);
break;
}
c = c + animSeq[i].duration;
Expand Down
6 changes: 4 additions & 2 deletions src/AlaLedRgb.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,11 @@ class AlaLedRgb
int getCurrentRefreshRate();


void setAnimation(int animation, long speed, AlaColor color);
void setAnimation(int animation, long speed, AlaPalette palette);
void setAnimation(int animation, long speed, AlaColor color, bool isSeq=false);
void setAnimation(int animation, long speed, AlaPalette palette, bool isSeq=false);
void setAnimation(AlaSeq animSeq[]);
void setSpeed(long speed);
void setColor(AlaColor color);
int getAnimation();

bool runAnimation();
Expand Down

0 comments on commit bd2c85a

Please sign in to comment.