Got the animator fades working

This commit is contained in:
2024-08-25 16:11:06 -04:00
parent 240d4866aa
commit 14ac96988a
10 changed files with 164 additions and 139 deletions

View File

@@ -12,13 +12,13 @@
#include "BoardTypes.h"
#include "Vector3D.h"
template <const V3D &BOARD_DIMS>
template <const V3D<uint32_t> &BOARD_DIMS>
class Board{
public:
Board() = default;
~Board() = default;
constexpr const V3D &GetSize() const{return BOARD_DIMS;}
constexpr const V3D<uint32_t> &GetSize() const{return BOARD_DIMS;}
constexpr uint32_t GetNumberCubes() const{return BOARD_DIMS.x * BOARD_DIMS.y * BOARD_DIMS.z;}
constexpr uint32_t GetMaxDimension(){return std::max(std::max(BOARD_DIMS.x, BOARD_DIMS.y), BOARD_DIMS.z);}
@@ -34,7 +34,7 @@ class Board{
* @brief fill the entire board with the given color
* @param color the color to fill the board with
*/
void FillColor(const V3D &color);
void FillColor(const V3D<uint32_t> &color);
/**
* @brief Set the color of the cube at the given position.
@@ -43,7 +43,7 @@ class Board{
* @param position the position of the cube.
* @param color the color you want the cube to be
*/
void SetCubeColor(const V3D &position, const V3D &color);
void SetCubeColor(const V3D<uint32_t> &position, const V3D<uint32_t> &color);
/**
* @brief Set the occupation status of the cube at a given position
@@ -52,7 +52,7 @@ class Board{
* @post if the new occupation status of the cube is different than
* the old occupation status, this will enable boardStateHasChanged.
*/
void SetCubeOccupation(const V3D &position, bool occupation);
void SetCubeOccupation(const V3D<uint32_t> &position, bool occupation);
/**
* @returns true if the board state has changed since this flag was last set to false
@@ -69,18 +69,18 @@ class Board{
* @brief Get a column along any axis read into the sliceBuffer
* @param column .z specifies the normal direction of the plane (see PLANE_NORMAL), and
* the x,y values specify the location of the column in that plane
* to fill. IE To fill one stack at 0,2 I would say give V3D(0,2,PLANE_NORMAL::Z)
* to fill. IE To fill one stack at 0,2 I would say give V3D<uint32_t>(0,2,PLANE_NORMAL::Z)
* @param sliceBuffer an array of pointers to the cubes along that column
* @returns the number of elements written into the slice buffer
* @note That array is stored locally and will be overwritten everytime this function is called.
* Also, any unused spots at the end of the array will be nullptrs
* @warning allocate the size of the slice buffer using GetMaxDimension if you don't know what you're doing!
*/
uint32_t SliceBoard(const V3D &column, BOARD_TYPES::Cube ** sliceBuffer);
uint32_t SliceBoard(const V3D<uint32_t> &column, BOARD_TYPES::Cube ** sliceBuffer);
void PrintEntireBoard() const;
void UpdateAllColors(const std::array<std::array<std::array<V3D, BOARD_DIMS.z>, BOARD_DIMS.y>, BOARD_DIMS.x>& colorFrame){
void UpdateAllColors(const std::array<std::array<std::array<V3D<uint32_t>, BOARD_DIMS.z>, BOARD_DIMS.y>, BOARD_DIMS.x>& colorFrame){
for(uint32_t x = 0; x < BOARD_DIMS.x; x++){
for(uint32_t y = 0; y < BOARD_DIMS.y; y++){
for(uint32_t z = 0; z < BOARD_DIMS.z; z++){
@@ -106,7 +106,7 @@ class Board{
bool boardStateHasChanged;
};
template <const V3D &BOARD_DIMS>
template <const V3D<uint32_t> &BOARD_DIMS>
void Board<BOARD_DIMS>::ToStackString(String &stringBuffer) const{
std::array<uint32_t, BOARD_DIMS.x * BOARD_DIMS.y> linearizedBoard;
for(uint32_t x{0}; x < BOARD_DIMS.x; x++){
@@ -126,8 +126,8 @@ void Board<BOARD_DIMS>::ToStackString(String &stringBuffer) const{
}
}
template <const V3D &BOARD_DIMS>
void Board<BOARD_DIMS>::FillColor(const V3D &color){
template <const V3D<uint32_t> &BOARD_DIMS>
void Board<BOARD_DIMS>::FillColor(const V3D<uint32_t> &color){
for(uint32_t x{0}; x < BOARD_DIMS.x; x++){
for(uint32_t y{0}; y < BOARD_DIMS.y; y++){
for(uint32_t z{0}; z < BOARD_DIMS.z; z++){
@@ -137,23 +137,23 @@ void Board<BOARD_DIMS>::FillColor(const V3D &color){
}
}
template <const V3D &BOARD_DIMS>
void Board<BOARD_DIMS>::SetCubeColor(const V3D &position, const V3D &color){
template <const V3D<uint32_t> &BOARD_DIMS>
void Board<BOARD_DIMS>::SetCubeColor(const V3D<uint32_t> &position, const V3D<uint32_t> &color){
this->cubes[position.x][position.y][position.z].color = color;
}
template <const V3D &BOARD_DIMS>
void Board<BOARD_DIMS>::SetCubeOccupation(const V3D &position, bool occupation){
template <const V3D<uint32_t> &BOARD_DIMS>
void Board<BOARD_DIMS>::SetCubeOccupation(const V3D<uint32_t> &position, bool occupation){
bool oldOccupation{this->cubes[position.x][position.y][position.z].isOccupied};
this->cubes[position.x][position.y][position.z].isOccupied = occupation;
if(occupation != oldOccupation) this->boardStateHasChanged = true;
}
template <const V3D &BOARD_DIMS>
uint32_t Board<BOARD_DIMS>::SliceBoard(const V3D &column, BOARD_TYPES::Cube ** sliceBuffer){
template <const V3D<uint32_t> &BOARD_DIMS>
uint32_t Board<BOARD_DIMS>::SliceBoard(const V3D<uint32_t> &column, BOARD_TYPES::Cube ** sliceBuffer){
uint32_t columnLength{0};
V3D indexIncrimentVector{};
V3D indexVector{};
V3D<uint32_t> indexIncrimentVector{};
V3D<uint32_t> indexVector{};
switch(column.z){
case BOARD_TYPES::PLANE_NORMAL::X:
@@ -189,7 +189,7 @@ uint32_t Board<BOARD_DIMS>::SliceBoard(const V3D &column, BOARD_TYPES::Cube ** s
return columnLength;
}
template <const V3D &BOARD_DIMS>
template <const V3D<uint32_t> &BOARD_DIMS>
void Board<BOARD_DIMS>::PrintEntireBoard() const{
for(uint32_t x = 0; x < BOARD_DIMS.x; x++){
for(uint32_t y = 0; y < BOARD_DIMS.y; y++){

View File

@@ -129,7 +129,7 @@ void BoardDriver<NUM_STACKS>::UpdateStackLEDs(
){
this->pixelController.setPin(this->stacks[stackIndex].ledPin);
for(int i = 0; i < numCubes; i++){
V3D color{cubes[i]->color};
V3D<uint32_t> color{cubes[i]->color};
this->pixelController.setPixelColor(i*2, this->pixelController.Color(color.x, color.y, color.z));
this->pixelController.setPixelColor((i*2 + 1), this->pixelController.Color(color.x, color.y, color.z));
}

View File

@@ -9,7 +9,7 @@
#include "Vector3D.h"
#include "Animator.h"
template <const V3D &BOARD_DIMS>
template <const V3D<uint32_t> &BOARD_DIMS>
class BoardManager{
public:
BoardManager(BoardDriver<BOARD_WIDTH*BOARD_LENGTH> &boardDriver, Animator<BOARD_DIMS> &animator);
@@ -31,7 +31,7 @@ class BoardManager{
* @param position the position of the cube
* @param color the oclor you want the cube to be
*/
void SetCubeColor(const V3D &position, const V3D &color);
void SetCubeColor(const V3D<uint32_t> &position, const V3D<uint32_t> &color);
/**
* @brief Set the color of one column of cubes.
@@ -40,17 +40,17 @@ class BoardManager{
* @param column the column vector
* @param color the color you want the column to be
*/
void SetColumnColors(const V3D &column, const V3D *color, uint32_t numColors);
void SetColumnColors(const V3D<uint32_t> &column, const V3D<uint32_t> *color, uint32_t numColors);
/**
* @brief Fill a column along any axis with a color
* @param column .z specifies the normal direction of the plane (see PLANE_NORMAL), and
* the x,y values specify the location of the column in that plane
* to fill. IE To fill one stack at 0,2 I would say give V3D(0,2,PLANE_NORMAL::Z)
* to fill. IE To fill one stack at 0,2 I would say give V3D<uint32_t>(0,2,PLANE_NORMAL::Z)
* @param color the color you want to fill the column with
*/
void FillColumnColor(const V3D &column, const V3D &color);
void FillColumnColor(const V3D<uint32_t> &column, const V3D<uint32_t> &color);
/**
* @returns true if the board has changed state
@@ -67,14 +67,14 @@ class BoardManager{
*/
void Board2StackString(String& messageBuffer);
void FillColor(const V3D &color){this->board.FillColor(color);}
void FillColor(const V3D<uint32_t> &color){this->board.FillColor(color);}
private:
BoardDriver<BOARD_WIDTH*BOARD_LENGTH> &driver;
Board<BOARD_DIMS> board{};
Animator<BOARD_DIMS> &animator;
void updateStackColors(const V3D &column);
void updateStackColors(const V3D<uint32_t> &column);
uint32_t getColumnHeight(BOARD_TYPES::PLANE_NORMAL normal){
switch(normal){
@@ -95,24 +95,25 @@ class BoardManager{
void updateColorsFromAnimator();
};
template <const V3D &BOARD_DIMS>
template <const V3D<uint32_t> &BOARD_DIMS>
void BoardManager<BOARD_DIMS>::updateColorsFromAnimator(){
if(this->animator.HasInterpolatedFrameChanged()){
if(this->animator.interpolatedFrameHasChanged){
this->board.UpdateAllColors(this->animator.GetInterpolatedFrame());
this->animator.interpolatedFrameHasChanged = false;
}
}
template <const V3D &BOARD_DIMS>
template <const V3D<uint32_t> &BOARD_DIMS>
BoardManager<BOARD_DIMS>::BoardManager(BoardDriver<BOARD_WIDTH*BOARD_LENGTH> &boardDriver, Animator<BOARD_DIMS> &animator):
driver(boardDriver),
animator(animator){}
template <const V3D &BOARD_DIMS>
template <const V3D<uint32_t> &BOARD_DIMS>
void BoardManager<BOARD_DIMS>::Init(){
this->driver.Init();
}
template <const V3D &BOARD_DIMS>
template <const V3D<uint32_t> &BOARD_DIMS>
void BoardManager<BOARD_DIMS>::Update(){
this->updateColorsFromAnimator();
// update the occupied cubes on the board and the cube colors
@@ -121,13 +122,13 @@ void BoardManager<BOARD_DIMS>::Update(){
uint32_t stackIndex{y * BOARD_DIMS.x + x};
uint32_t numCubes{this->driver.GetNumberCubes(stackIndex)};
for(uint32_t z = 0; z < BOARD_DIMS.z; z++){
V3D cubePosition{x, y, z};
V3D<uint32_t> cubePosition{x, y, z};
// update the cube's occupation
this->board.SetCubeOccupation(cubePosition, z < numCubes);
}
// create the column vector for the slice direction
V3D sliceVector{x,y,BOARD_TYPES::PLANE_NORMAL::Z};
V3D<uint32_t> sliceVector{x,y,BOARD_TYPES::PLANE_NORMAL::Z};
// create a cube slice array buffer
BOARD_TYPES::Cube* sliceBuffer[BOARD_DIMS.z];
// have the board slice get read into our buffer
@@ -138,10 +139,10 @@ void BoardManager<BOARD_DIMS>::Update(){
}
}
template <const V3D &BOARD_DIMS>
void BoardManager<BOARD_DIMS>::updateStackColors(const V3D &column){
template <const V3D<uint32_t> &BOARD_DIMS>
void BoardManager<BOARD_DIMS>::updateStackColors(const V3D<uint32_t> &column){
// the only column type allowed here is z.
V3D sliceVector{column.x, column.y, BOARD_TYPES::Z};
V3D<uint32_t> sliceVector{column.x, column.y, BOARD_TYPES::Z};
// create a buffer for slice board to write the cube slice into
BOARD_TYPES::Cube * cubeSlice[BOARD_DIMS.z];
this->board.SliceBoard(column, cubeSlice);
@@ -150,15 +151,15 @@ void BoardManager<BOARD_DIMS>::updateStackColors(const V3D &column){
this->driver.UpdateStackLEDs(BOARD_DIMS.x, cubeSlice, numCubes);
}
template <const V3D &BOARD_DIMS>
void BoardManager<BOARD_DIMS>::SetCubeColor(const V3D &position, const V3D &color){
template <const V3D<uint32_t> &BOARD_DIMS>
void BoardManager<BOARD_DIMS>::SetCubeColor(const V3D<uint32_t> &position, const V3D<uint32_t> &color){
this->board.SetCubeColor(position, color);
V3D slice{position.x, position.y, BOARD_TYPES::PLANE_NORMAL::Z};
V3D<uint32_t> slice{position.x, position.y, BOARD_TYPES::PLANE_NORMAL::Z};
this->updateStackColors(slice);
}
template <const V3D &BOARD_DIMS>
void BoardManager<BOARD_DIMS>::SetColumnColors(const V3D &column, const V3D *color, uint32_t numColors){
template <const V3D<uint32_t> &BOARD_DIMS>
void BoardManager<BOARD_DIMS>::SetColumnColors(const V3D<uint32_t> &column, const V3D<uint32_t> *color, uint32_t numColors){
uint32_t columnHeight{this->getColumnHeight(static_cast<BOARD_TYPES::PLANE_NORMAL>(column.z))};
// create a cube pointer buffer and store a board slice into it
@@ -171,11 +172,11 @@ void BoardManager<BOARD_DIMS>::SetColumnColors(const V3D &column, const V3D *col
}
}
template <const V3D &BOARD_DIMS>
void BoardManager<BOARD_DIMS>::FillColumnColor(const V3D &column, const V3D &color){
template <const V3D<uint32_t> &BOARD_DIMS>
void BoardManager<BOARD_DIMS>::FillColumnColor(const V3D<uint32_t> &column, const V3D<uint32_t> &color){
uint32_t columnHeight{this->getColumnHeight(column.z)};
V3D colors[columnHeight];
V3D<uint32_t> colors[columnHeight];
for(uint32_t i = 0; i < columnHeight; i++){
colors[i] = color;
}
@@ -183,13 +184,13 @@ void BoardManager<BOARD_DIMS>::FillColumnColor(const V3D &column, const V3D &col
this->SetColumnColors(column, colors);
}
template <const V3D &BOARD_DIMS>
template <const V3D<uint32_t> &BOARD_DIMS>
bool BoardManager<BOARD_DIMS>::HasBoardChanged(){return this->board.BoardStateChanged();}
template <const V3D &BOARD_DIMS>
template <const V3D<uint32_t> &BOARD_DIMS>
void BoardManager<BOARD_DIMS>::ClearBoardChanged(){this->board.SetStateChanged(false);}
template <const V3D &BOARD_DIMS>
template <const V3D<uint32_t> &BOARD_DIMS>
void BoardManager<BOARD_DIMS>::Board2StackString(String& messageBuffer){
this->board.ToStackString(messageBuffer);
}

View File

@@ -20,7 +20,7 @@ namespace BOARD_TYPES{
};
struct Cube{
V3D color;
V3D<uint32_t> color;
bool isOccupied{false};
};
};