This repository has been archived by the owner on Apr 11, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 124
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Time handling was being insane on the second core. Switched to using …
…PICO SDK time handlers that are nicer anyway. Added CHASE animation.
- Loading branch information
Showing
11 changed files
with
135 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
#include "Chase.hpp" | ||
#include "Helpers.hpp" | ||
|
||
void Chase::Animate(uint32_t (&frame)[100]) { | ||
if (!time_reached(this->nextRunTime)) { | ||
return; | ||
} | ||
|
||
for (int i = this->firstPixel; i < this->lastPixel + 1; ++i) { | ||
if (this->IsChasePixel(i)) { | ||
frame[i] = Helpers::Wheel(this->WheelFrame(i)); | ||
} else { | ||
frame[i] = 0; | ||
} | ||
} | ||
|
||
currentPixel++; | ||
|
||
if (currentPixel > this->lastPixel) { | ||
currentPixel = this->firstPixel; | ||
} | ||
|
||
if (reverse) { | ||
currentFrame--; | ||
|
||
if (currentFrame < 0) { | ||
currentFrame = 1; | ||
reverse = false; | ||
} | ||
} | ||
else { | ||
currentFrame++; | ||
|
||
if (currentFrame > 255) { | ||
currentFrame = 254; | ||
reverse = true; | ||
} | ||
} | ||
|
||
this->nextRunTime = make_timeout_time_ms(this->cycleTime); | ||
} | ||
|
||
bool Chase::IsChasePixel(int i) { | ||
if (i == this->currentPixel || i == (this->currentPixel - 1) % this->totalPixels || i == (this->currentPixel - 2) % this->totalPixels) { | ||
return true; | ||
} | ||
|
||
return false; | ||
} | ||
|
||
int Chase::WheelFrame(int i) { | ||
int frame = this->currentFrame; | ||
|
||
if (i == (this->currentPixel - 1) % totalPixels) { | ||
if (this->reverse) { | ||
frame = frame + 16; | ||
} | ||
else { | ||
frame = frame - 16; | ||
} | ||
} | ||
|
||
if (i == (this->currentPixel - 2) % totalPixels) { | ||
if (this->reverse) { | ||
frame = frame + 32; | ||
} | ||
else { | ||
frame = frame - 32; | ||
} | ||
} | ||
|
||
if (frame < 0) { | ||
return 0; | ||
} | ||
|
||
return frame; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#ifndef _CHASE_H_ | ||
#define _CHASE_H_ | ||
|
||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include "../Animation.hpp" | ||
|
||
class Chase : public Animation { | ||
public: | ||
Chase() : Animation() { | ||
} | ||
Chase(int firstPixel, int lastPixel, int cycleTime = 50, bool defaultAnimation = false) : Animation(firstPixel, lastPixel, defaultAnimation) { | ||
this->cycleTime = cycleTime; | ||
this->currentPixel = firstPixel; | ||
this->totalPixels = this->lastPixel - this->firstPixel + 1; | ||
} | ||
void Animate(uint32_t (&frame)[100]); | ||
protected: | ||
bool IsChasePixel(int i); | ||
int WheelFrame(int i); | ||
|
||
int cycleTime; | ||
int currentFrame = 0; | ||
int currentPixel = 0; | ||
int totalPixels; | ||
bool reverse = false; | ||
absolute_time_t nextRunTime = 0; | ||
}; | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters