|
@@ -3,9 +3,20 @@
|
|
|
int frameCount = 0;
|
|
|
char previousAnicode = 'a';
|
|
|
|
|
|
+//delay with early breakout if current animation code changed
|
|
|
+void delayWithEarlyBreakout(int delayDuration) {
|
|
|
+ delayDuration = delayDuration / 100;
|
|
|
+ for (int i = 0; i < delayDuration; i++) {
|
|
|
+ delay(100);
|
|
|
+ if (getAnimationCode() != previousAnicode) {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
//Handle animation rendering
|
|
|
void handleAnimationRendering(char anicode) {
|
|
|
- if (previousAnicode != anicode){
|
|
|
+ if (previousAnicode != anicode) {
|
|
|
previousAnicode = anicode;
|
|
|
frameCount = 0;
|
|
|
}
|
|
@@ -14,7 +25,8 @@ void handleAnimationRendering(char anicode) {
|
|
|
if (SD.exists(targetFrame)) {
|
|
|
//This is a static frame. Load and render it
|
|
|
loadFrameAndRender(targetFrame);
|
|
|
- delay(getFrameDuration(anicode,0));
|
|
|
+ int delayDuration = getFrameDuration(anicode, 0);
|
|
|
+ delayWithEarlyBreakout(delayDuration);
|
|
|
return;
|
|
|
}
|
|
|
|
|
@@ -23,13 +35,15 @@ void handleAnimationRendering(char anicode) {
|
|
|
if (SD.exists(targetFrame)) {
|
|
|
loadFrameAndRender(targetFrame);
|
|
|
frameCount++;
|
|
|
- delay(getFrameDuration(anicode,frameCount));
|
|
|
+ int delayDuration = getFrameDuration(anicode, frameCount);
|
|
|
+ delayWithEarlyBreakout(delayDuration);
|
|
|
return;
|
|
|
} else {
|
|
|
//Not found.
|
|
|
if (frameCount != 0) {
|
|
|
loadFrameAndRender("/" + String(anicode) + "0.bin");
|
|
|
- delay(getFrameDuration(anicode,0));
|
|
|
+ int delayDuration = getFrameDuration(anicode, 0);
|
|
|
+ delayWithEarlyBreakout(delayDuration);
|
|
|
frameCount = 1;
|
|
|
return;
|
|
|
} else {
|
|
@@ -41,11 +55,15 @@ void handleAnimationRendering(char anicode) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-//Get how long the frame shd last.
|
|
|
+//Get how long the frame shd last.
|
|
|
//Default 500 unless specially programmed
|
|
|
-int getFrameDuration(char anicode, int framecount){
|
|
|
- if ((anicode == 'a' || anicode == 'b') && framecount == 0){
|
|
|
- return 2500;
|
|
|
+int getFrameDuration(char anicode, int framecount) {
|
|
|
+ if ((anicode == 'a' || anicode == 'b' || anicode == 'g')) {
|
|
|
+ //Blinking
|
|
|
+ if (framecount == 0) {
|
|
|
+ return 3000;
|
|
|
+ }
|
|
|
+ return 300;
|
|
|
}
|
|
|
return 500;
|
|
|
}
|