minor bug fixes and a new animation
This commit is contained in:
221
lib/Animator/Animation.h
Normal file
221
lib/Animator/Animation.h
Normal file
@@ -0,0 +1,221 @@
|
||||
#pragma once
|
||||
|
||||
#include "AnimationTypes.h"
|
||||
#include "Vector3D.h"
|
||||
#include "Animator.h"
|
||||
|
||||
using namespace ANIMATION_TYPES;
|
||||
|
||||
namespace AnimationHelpers{
|
||||
V3D<uint8_t> red{255,0,0};
|
||||
V3D<uint8_t> green{0,255,0};
|
||||
V3D<uint8_t> blue{0,0,255};
|
||||
V3D<uint8_t> cyan{0,255,255};
|
||||
V3D<uint8_t> magenta{255,0,255};
|
||||
|
||||
Cell CreateCell(float x_percent, float y_percent, float z_percent, V3D<uint8_t> &color){
|
||||
float continuousMaxValue{static_cast<float>(std::numeric_limits<uint32_t>::max())};
|
||||
Cell cell{
|
||||
.position = V3D<uint32_t>{
|
||||
static_cast<uint32_t>(continuousMaxValue*x_percent),
|
||||
static_cast<uint32_t>(continuousMaxValue*y_percent),
|
||||
static_cast<uint32_t>(continuousMaxValue*z_percent)
|
||||
},
|
||||
.color = color
|
||||
};
|
||||
|
||||
return cell;
|
||||
}
|
||||
}
|
||||
|
||||
namespace RotatingCubes{
|
||||
using namespace AnimationHelpers;
|
||||
|
||||
AnimationFrame frame1{
|
||||
.frame = {
|
||||
CreateCell(0,0,0,red),
|
||||
CreateCell(1,0.5,0,green),
|
||||
CreateCell(0,1,0,blue)
|
||||
},
|
||||
.fillInterpolation = FillInterpolation::CLOSEST_COLOR,
|
||||
.frameInterpolation = FrameInterpolation::FADE,
|
||||
.delay = std::chrono::milliseconds(1000)
|
||||
};
|
||||
|
||||
AnimationFrame frame2{
|
||||
.frame = {
|
||||
CreateCell(0,0.5,0,red),
|
||||
CreateCell(1,0,0,green),
|
||||
CreateCell(0.5,1,0,blue)
|
||||
},
|
||||
.fillInterpolation = FillInterpolation::CLOSEST_COLOR,
|
||||
.frameInterpolation = FrameInterpolation::FADE,
|
||||
.delay = std::chrono::milliseconds(500)
|
||||
};
|
||||
|
||||
AnimationFrame frame3{
|
||||
.frame = {
|
||||
CreateCell(0,1,0,red),
|
||||
CreateCell(0.5,0,0,green),
|
||||
CreateCell(1,1,0,blue)
|
||||
},
|
||||
.fillInterpolation = FillInterpolation::CLOSEST_COLOR,
|
||||
.frameInterpolation = FrameInterpolation::FADE,
|
||||
.delay = std::chrono::milliseconds(1000)
|
||||
};
|
||||
|
||||
AnimationFrame frame4{
|
||||
.frame = {
|
||||
CreateCell(0.5,1,0,red),
|
||||
CreateCell(0,0,0,green),
|
||||
CreateCell(1,0.5,0,blue)
|
||||
},
|
||||
.fillInterpolation = FillInterpolation::CLOSEST_COLOR,
|
||||
.frameInterpolation = FrameInterpolation::FADE,
|
||||
.delay = std::chrono::milliseconds(500)
|
||||
};
|
||||
|
||||
AnimationFrame frame5{
|
||||
.frame = {
|
||||
CreateCell(1,1,0,red),
|
||||
CreateCell(0,0.5,0,green),
|
||||
CreateCell(1,0,0,blue)
|
||||
},
|
||||
.fillInterpolation = FillInterpolation::CLOSEST_COLOR,
|
||||
.frameInterpolation = FrameInterpolation::FADE,
|
||||
.delay = std::chrono::milliseconds(1000)
|
||||
};
|
||||
|
||||
AnimationFrame frame6{
|
||||
.frame = {
|
||||
CreateCell(1,0.5,0,red),
|
||||
CreateCell(0,1,0,green),
|
||||
CreateCell(0.5,0,0,blue)
|
||||
},
|
||||
.fillInterpolation = FillInterpolation::CLOSEST_COLOR,
|
||||
.frameInterpolation = FrameInterpolation::FADE,
|
||||
.delay = std::chrono::milliseconds(500)
|
||||
};
|
||||
|
||||
AnimationFrame frame7{
|
||||
.frame = {
|
||||
CreateCell(1,0,0,red),
|
||||
CreateCell(0.5,1,0,green),
|
||||
CreateCell(0,0,0,blue)
|
||||
},
|
||||
.fillInterpolation = FillInterpolation::CLOSEST_COLOR,
|
||||
.frameInterpolation = FrameInterpolation::FADE,
|
||||
.delay = std::chrono::milliseconds(1000)
|
||||
};
|
||||
|
||||
AnimationFrame frame8{
|
||||
.frame = {
|
||||
CreateCell(0.5,0,0,red),
|
||||
CreateCell(1,1,0,green),
|
||||
CreateCell(0,0.5,0,blue)
|
||||
},
|
||||
.fillInterpolation = FillInterpolation::CLOSEST_COLOR,
|
||||
.frameInterpolation = FrameInterpolation::FADE,
|
||||
.delay = std::chrono::milliseconds(500)
|
||||
};
|
||||
|
||||
AnimationFrame frame9{
|
||||
.frame = {
|
||||
CreateCell(0,0,0,red),
|
||||
CreateCell(1,0.5,0,green),
|
||||
CreateCell(0,1,0,blue)
|
||||
},
|
||||
.fillInterpolation = FillInterpolation::CLOSEST_COLOR,
|
||||
.frameInterpolation = FrameInterpolation::FADE,
|
||||
.delay = std::chrono::milliseconds(1)
|
||||
};
|
||||
|
||||
std::vector<AnimationFrame> rotating{
|
||||
frame1, // 0
|
||||
frame2, // 1
|
||||
frame3, // 2
|
||||
frame4, // 3
|
||||
frame5, // 4
|
||||
frame6, // 5
|
||||
frame7, // 6
|
||||
frame8, // 7
|
||||
frame9, // 8
|
||||
};
|
||||
}
|
||||
|
||||
namespace RisingCubes{
|
||||
using namespace AnimationHelpers;
|
||||
|
||||
AnimationFrame frame1{
|
||||
.frame = {
|
||||
CreateCell(0,0,0,cyan),
|
||||
CreateCell(0,1,0.5,green),
|
||||
CreateCell(1,0,1,blue),
|
||||
CreateCell(0.5,0.5,0.5,red),
|
||||
CreateCell(1,1,0,magenta)
|
||||
},
|
||||
.fillInterpolation = FillInterpolation::LINEAR_WEIGHTED_DISTANCE,
|
||||
.frameInterpolation = FrameInterpolation::FADE,
|
||||
.delay = std::chrono::milliseconds(800)
|
||||
};
|
||||
|
||||
AnimationFrame frame2{
|
||||
.frame = {
|
||||
CreateCell(0,0,0.5,cyan),
|
||||
CreateCell(0,1,1,green),
|
||||
CreateCell(1,0,0.5,blue),
|
||||
CreateCell(0.5,0.5,0,red),
|
||||
CreateCell(1,1,0.5,magenta)
|
||||
},
|
||||
.fillInterpolation = FillInterpolation::LINEAR_WEIGHTED_DISTANCE,
|
||||
.frameInterpolation = FrameInterpolation::FADE,
|
||||
.delay = std::chrono::milliseconds(800)
|
||||
};
|
||||
|
||||
AnimationFrame frame3{
|
||||
.frame = {
|
||||
CreateCell(0,0,1,cyan),
|
||||
CreateCell(0,1,0.5,green),
|
||||
CreateCell(1,0,0,blue),
|
||||
CreateCell(0.5,0.5,0.5,red),
|
||||
CreateCell(1,1,1,magenta)
|
||||
},
|
||||
.fillInterpolation = FillInterpolation::LINEAR_WEIGHTED_DISTANCE,
|
||||
.frameInterpolation = FrameInterpolation::FADE,
|
||||
.delay = std::chrono::milliseconds(800)
|
||||
};
|
||||
|
||||
AnimationFrame frame4{
|
||||
.frame = {
|
||||
CreateCell(0,0,0.5,cyan),
|
||||
CreateCell(0,1,0,green),
|
||||
CreateCell(1,0,0.5,blue),
|
||||
CreateCell(0.5,0.5,1,red),
|
||||
CreateCell(1,1,0.5,magenta)
|
||||
},
|
||||
.fillInterpolation = FillInterpolation::LINEAR_WEIGHTED_DISTANCE,
|
||||
.frameInterpolation = FrameInterpolation::FADE,
|
||||
.delay = std::chrono::milliseconds(800)
|
||||
};
|
||||
|
||||
AnimationFrame frame5{
|
||||
.frame = {
|
||||
CreateCell(0,0,0,cyan),
|
||||
CreateCell(0,1,0.5,green),
|
||||
CreateCell(1,0,1,blue),
|
||||
CreateCell(0.5,0.5,0.5,red),
|
||||
CreateCell(1,1,0,magenta)
|
||||
},
|
||||
.fillInterpolation = FillInterpolation::LINEAR_WEIGHTED_DISTANCE,
|
||||
.frameInterpolation = FrameInterpolation::FADE,
|
||||
.delay = std::chrono::milliseconds(1)
|
||||
};
|
||||
|
||||
std::vector<AnimationFrame> rising{
|
||||
frame1, // 0
|
||||
frame2, // 1
|
||||
frame3, // 2
|
||||
frame4, // 3
|
||||
frame5
|
||||
};
|
||||
}
|
||||
@@ -121,7 +121,7 @@ void Board<BOARD_DIMS>::ToStackString(String &stringBuffer) const{
|
||||
|
||||
stringBuffer += String(linearizedBoard[0]);
|
||||
|
||||
for(uint32_t i = 0; i < BOARD_DIMS.x * BOARD_DIMS.y; i++){
|
||||
for(uint32_t i = 1; i < BOARD_DIMS.x * BOARD_DIMS.y; i++){
|
||||
stringBuffer += "," + String(linearizedBoard[i]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -68,6 +68,7 @@ class BoardManager{
|
||||
void Board2StackString(String& messageBuffer);
|
||||
|
||||
void FillColor(const V3D<uint32_t> &color){this->board.FillColor(color);}
|
||||
void PrintColorState(){this->board.PrintEntireBoard();}
|
||||
|
||||
private:
|
||||
BoardDriver<BOARD_WIDTH*BOARD_LENGTH> &driver;
|
||||
@@ -167,7 +168,7 @@ void BoardManager<BOARD_DIMS>::SetColumnColors(const V3D<uint32_t> &column, cons
|
||||
uint32_t sliceLength{this->board.SliceBoard(column, slicedBoard)};
|
||||
|
||||
uint32_t maxIndex{std::min(numColors, columnHeight)};
|
||||
for(uint32_t i = 0; i < columnHeight; i++){
|
||||
for(uint32_t i = 0; i < maxIndex; i++){
|
||||
slicedBoard[i]->color = color[i];
|
||||
}
|
||||
}
|
||||
|
||||
31
src/main.cpp
31
src/main.cpp
@@ -4,6 +4,7 @@
|
||||
#include <FreeRTOS.h>
|
||||
#include <Adafruit_NeoPixel.h>
|
||||
#include <chrono>
|
||||
#include <array>
|
||||
|
||||
// Static Defines
|
||||
#include "PINOUT.h"
|
||||
@@ -21,6 +22,7 @@
|
||||
|
||||
#include "Animator.h"
|
||||
#include "TestFrames.h"
|
||||
#include "Animation.h"
|
||||
|
||||
// --------------------------------------------------
|
||||
// ----------------- VARIABLES ----------------------
|
||||
@@ -28,6 +30,11 @@
|
||||
TaskHandle_t updateCommunicaitonTask;
|
||||
TaskHandle_t updateBoardTask;
|
||||
|
||||
std::array<std::vector<AnimationFrame>*, 2> animations = {
|
||||
&RisingCubes::rising,
|
||||
&RotatingCubes::rotating,
|
||||
};
|
||||
|
||||
// BluetoothSerial SerialBT;
|
||||
// BluetoothSerialMessage serialMessageBT(&SerialBT);
|
||||
SerialMessage<SERIAL_CHAR_LENGTH, SERIAL_ARG_LENGTH> serialMessage(&Serial);
|
||||
@@ -158,17 +165,33 @@ void UpdateBoard(void * params){
|
||||
auto boardStateTimer{std::chrono::milliseconds(0)};
|
||||
auto boardStateMaxUpdatePeriod{std::chrono::milliseconds(34)}; // this is a little slower than 30fps
|
||||
unsigned long accurateTimer{millis()};
|
||||
auto changeAnimationTimer{std::chrono::milliseconds(0)};
|
||||
uint8_t currentAnimation{0};
|
||||
|
||||
for(;;){
|
||||
auto actualTimePassed{std::chrono::milliseconds(millis() - accurateTimer)};
|
||||
accurateTimer = millis();
|
||||
|
||||
if(boardStateTimer >= boardStateMaxUpdatePeriod && boardManager.HasBoardChanged()){
|
||||
printBoardState();
|
||||
boardManager.ClearBoardChanged();
|
||||
boardStateTimer = std::chrono::milliseconds(0);
|
||||
}
|
||||
|
||||
animator.RunAnimation(std::chrono::milliseconds(millis() - accurateTimer));
|
||||
accurateTimer = millis();
|
||||
if(changeAnimationTimer >= std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::minutes(1))){
|
||||
changeAnimationTimer = std::chrono::milliseconds(0);
|
||||
currentAnimation++;
|
||||
if(currentAnimation >= animations.size()){
|
||||
currentAnimation = 0;
|
||||
}
|
||||
animator.StartAnimation(animations[currentAnimation]);
|
||||
}
|
||||
|
||||
animator.RunAnimation(actualTimePassed);
|
||||
boardManager.Update();
|
||||
|
||||
boardStateTimer += updateTickRate;
|
||||
boardStateTimer += actualTimePassed;
|
||||
changeAnimationTimer += actualTimePassed;
|
||||
vTaskDelay(updateTickRate.count());
|
||||
}
|
||||
Serial.println("UpdateBoard task has ended unexpectedly!");
|
||||
@@ -197,7 +220,7 @@ void setup() {
|
||||
Serial.println("Beginning Board Initializaiton");
|
||||
boardManager.Init();
|
||||
animator.SetLoop(true);
|
||||
animator.StartAnimation(&(TestFrames::testAnimationSequence2));
|
||||
animator.StartAnimation(animations[0]);
|
||||
xTaskCreate(UpdateBoard, "UpdateBoard", 10000, NULL, 0, &updateBoardTask);
|
||||
|
||||
Serial.println("Setup Complete");
|
||||
|
||||
Reference in New Issue
Block a user