diff --git a/lib/Board/Board.h b/lib/Board/Board.h index d705b58..f3b51d8 100644 --- a/lib/Board/Board.h +++ b/lib/Board/Board.h @@ -9,7 +9,7 @@ #include #include -#include "Cube.h" +#include "BoardTypes.h" #include "Vector3D.h" template @@ -76,7 +76,7 @@ class Board{ * to fill. IE To fill one stack at 0,2 I would say give V3D(0,2,PLANE_NORMAL::Z) * @returns an array of cubes along that column */ - Cube ** SliceBoard(const V3D &column); + BOARD_TYPES::Cube ** SliceBoard(const V3D &column); private: // this is a 3d array of cubes to represent the board. Good luck visualizing it @@ -90,7 +90,7 @@ class Board{ | | / |____________|/ */ - std::array, BOARD_DIMS.y>, BOARD_DIMS.x> cubes; + std::array, BOARD_DIMS.y>, BOARD_DIMS.x> cubes; bool boardStateHasChanged; }; @@ -145,7 +145,7 @@ void Board::SetCubeOccupation(const V3D &position, bool occupation){ } template -Cube ** Board::SliceBoard(const V3D &column){ +BOARD_TYPES::Cube ** Board::SliceBoard(const V3D &column){ uint32_t columnLength{0}; V3D indexIncriment{}; V3D position{}; @@ -172,7 +172,7 @@ Cube ** Board::SliceBoard(const V3D &column){ break; } - Cube* columnSlice[columnLength]; + BOARD_TYPES::Cube* columnSlice[columnLength]; for(uint32_t i = 0; i < columnLength; i++){ V3D cubePosition = indexIncriment * i + position; columnSlice[i] = &(this->cubes[cubePosition.x][cubePosition.y][cubePosition.z]); diff --git a/lib/Board/BoardDriver.h b/lib/Board/BoardDriver.h index 4b200a7..6180620 100644 --- a/lib/Board/BoardDriver.h +++ b/lib/Board/BoardDriver.h @@ -11,7 +11,7 @@ #include #include -#include "Cube.h" +#include "BoardTypes.h" #include "BoardTypes.h" template @@ -22,7 +22,10 @@ public: * @param stacks a reference to an array which contains information about the pins which control each cube stack. * @param pixelController a reference to a pre-constructed neopixel controller which will allow this driver to control neopixels */ - BoardDriver(std::array &stacks, Adafruit_NeoPixel &pixelController); + BoardDriver( + std::array &stacks, + Adafruit_NeoPixel &pixelController + ); ~BoardDriver() = default; /** @@ -52,7 +55,13 @@ public: * @param cubes an array of cube pointers which contain the color data you want to stream * @param numCubes the number of cubes in the cubes array */ - void UpdateStackLEDs(uint32_t numXStacks, uint32_t X_COORD, uint32_t Y_COORD, Cube* cubes[], uint32_t numCubes); + void UpdateStackLEDs( + uint32_t numXStacks, + uint32_t X_COORD, + uint32_t Y_COORD, + BOARD_TYPES::Cube* cubes[], + uint32_t numCubes + ); /** * @brief stream data to a single cube stack on the board @@ -60,7 +69,11 @@ public: * @param cubes an array of cube pointers which contain the color data you want to stream * @param numCubes the number of cubes in the cubes array */ - void UpdateStackLEDs(uint32_t stackIndex, Cube* cubes[], uint32_t numCubes); + void UpdateStackLEDs( + uint32_t stackIndex, + BOARD_TYPES::Cube* cubes[], + uint32_t numCubes + ); private: @@ -84,7 +97,10 @@ void BoardDriver::Init(){ } template -BoardDriver::BoardDriver(std::array &stacks, Adafruit_NeoPixel &pixelController): +BoardDriver::BoardDriver( + std::array &stacks, + Adafruit_NeoPixel &pixelController + ): stacks(stacks), pixelController(pixelController) { @@ -94,12 +110,22 @@ pixelController(pixelController) } template -void BoardDriver::UpdateStackLEDs(uint32_t numXStacks, uint32_t X_COORD, uint32_t Y_COORD, Cube* cubes[], uint32_t numCubes){ +void BoardDriver::UpdateStackLEDs( + uint32_t numXStacks, + uint32_t X_COORD, + uint32_t Y_COORD, + BOARD_TYPES::Cube* cubes[], + uint32_t numCubes + ){ this->UpdateStackLEDs(this->xy2StackIndex(X_COORD, Y_COORD, numXStacks), cubes, numCubes); } template -void BoardDriver::UpdateStackLEDs(uint32_t stackIndex, Cube* cubes[], uint32_t numCubes){ +void BoardDriver::UpdateStackLEDs( + uint32_t stackIndex, + BOARD_TYPES::Cube* cubes[], + uint32_t numCubes + ){ this->pixelController.setPin(this->stacks[stackIndex].ledPin); for(int i = 0; i < numCubes; i++){ V3D color{cubes[i]->color}; @@ -110,7 +136,11 @@ void BoardDriver::UpdateStackLEDs(uint32_t stackIndex, Cube* cubes[] } template -uint32_t BoardDriver::GetNumberCubes(uint32_t numXStacks, uint32_t X_COORD, uint32_t Y_COORD){ +uint32_t BoardDriver::GetNumberCubes( + uint32_t numXStacks, + uint32_t X_COORD, + uint32_t Y_COORD + ){ return this->GetNumberCubes(this->xy2StackIndex(X_COORD, Y_COORD, numXStacks)); } diff --git a/lib/Board/BoardManager.h b/lib/Board/BoardManager.h index 9a0d78a..2527057 100644 --- a/lib/Board/BoardManager.h +++ b/lib/Board/BoardManager.h @@ -1,3 +1,7 @@ +/** + * @file BoardManager.h + * @brief Provides an easy way to manage a board + */ #pragma once #include "Board.h" @@ -11,12 +15,30 @@ class BoardManager{ ~BoardManager() = default; + /** + * @brief Initialize the board control. This hsould be called during setup + */ void Init(); + /** + * @brief Read the board state and update the LED colors + */ void Update(); + /** + * @brief Set the color of one cube + * @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); + /** + * @brief Set the color of one column of cubes. + * A column is defined as x,y,z where z is the normal vector direction to a plane. + * x,y is the column coordinate on the plane. + * @param column the column vector + * @param color the color you want the column to be + */ void SetColumnColors(const V3D &column, const V3D *color); @@ -29,10 +51,19 @@ class BoardManager{ */ void FillColumnColor(const V3D &column, const V3D &color); + /** + * @returns true if the board has changed state + */ bool HasBoardChanged(); + /** + * @brief Clear the board state changed flag + */ void ClearBoardChanged(); + /** + * @brief Get the board occupation state returned in the format a,b,c,d.... + */ String &Board2StackString(); private: @@ -89,7 +120,7 @@ void BoardManager::Update(){ template void BoardManager::updateBoardColors(const V3D &column){ - Cube ** cubeSlice{this->board.SliceBoard(column)}; + BOARD_TYPES::Cube ** cubeSlice{this->board.SliceBoard(column)}; uint32_t numCubes{this->getColumnHeight(static_cast(column.z))}; this->driver.UpdateStackLEDs(BOARD_DIMS.x, cubeSlice, numCubes); } diff --git a/lib/Board/BoardTypes.h b/lib/Board/BoardTypes.h index e83e1a1..812c341 100644 --- a/lib/Board/BoardTypes.h +++ b/lib/Board/BoardTypes.h @@ -1,6 +1,11 @@ +/** + * @file BoardTypes.h + * @brief Some types to that you'll need to define and control the board + */ #pragma once #include +#include "Vector3D.h" namespace BOARD_TYPES{ struct CubeStack{ @@ -13,4 +18,9 @@ namespace BOARD_TYPES{ Y, Z }; + + struct Cube{ + V3D color; + bool isOccupied{false}; + }; }; \ No newline at end of file diff --git a/lib/Board/Cube.h b/lib/Board/Cube.h deleted file mode 100644 index 8e2bc57..0000000 --- a/lib/Board/Cube.h +++ /dev/null @@ -1,14 +0,0 @@ -/** - * @file Cube.h - * @brief An object to store the data of one cube - */ - -#pragma once - -#include "Vector3D.h" - -class Cube{ - public: - V3D color; - bool isOccupied{false}; -}; \ No newline at end of file