Finished commenting code changes
This commit is contained in:
@@ -9,7 +9,7 @@
|
|||||||
#include <array>
|
#include <array>
|
||||||
#include <WString.h>
|
#include <WString.h>
|
||||||
|
|
||||||
#include "Cube.h"
|
#include "BoardTypes.h"
|
||||||
#include "Vector3D.h"
|
#include "Vector3D.h"
|
||||||
|
|
||||||
template <const V3D &BOARD_DIMS>
|
template <const V3D &BOARD_DIMS>
|
||||||
@@ -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)
|
* 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
|
* @returns an array of cubes along that column
|
||||||
*/
|
*/
|
||||||
Cube ** SliceBoard(const V3D &column);
|
BOARD_TYPES::Cube ** SliceBoard(const V3D &column);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// this is a 3d array of cubes to represent the board. Good luck visualizing it
|
// this is a 3d array of cubes to represent the board. Good luck visualizing it
|
||||||
@@ -90,7 +90,7 @@ class Board{
|
|||||||
| | /
|
| | /
|
||||||
|____________|/
|
|____________|/
|
||||||
*/
|
*/
|
||||||
std::array<std::array<std::array<Cube, BOARD_DIMS.z>, BOARD_DIMS.y>, BOARD_DIMS.x> cubes;
|
std::array<std::array<std::array<BOARD_TYPES::Cube, BOARD_DIMS.z>, BOARD_DIMS.y>, BOARD_DIMS.x> cubes;
|
||||||
|
|
||||||
bool boardStateHasChanged;
|
bool boardStateHasChanged;
|
||||||
};
|
};
|
||||||
@@ -145,7 +145,7 @@ void Board<BOARD_DIMS>::SetCubeOccupation(const V3D &position, bool occupation){
|
|||||||
}
|
}
|
||||||
|
|
||||||
template <const V3D &BOARD_DIMS>
|
template <const V3D &BOARD_DIMS>
|
||||||
Cube ** Board<BOARD_DIMS>::SliceBoard(const V3D &column){
|
BOARD_TYPES::Cube ** Board<BOARD_DIMS>::SliceBoard(const V3D &column){
|
||||||
uint32_t columnLength{0};
|
uint32_t columnLength{0};
|
||||||
V3D indexIncriment{};
|
V3D indexIncriment{};
|
||||||
V3D position{};
|
V3D position{};
|
||||||
@@ -172,7 +172,7 @@ Cube ** Board<BOARD_DIMS>::SliceBoard(const V3D &column){
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
Cube* columnSlice[columnLength];
|
BOARD_TYPES::Cube* columnSlice[columnLength];
|
||||||
for(uint32_t i = 0; i < columnLength; i++){
|
for(uint32_t i = 0; i < columnLength; i++){
|
||||||
V3D cubePosition = indexIncriment * i + position;
|
V3D cubePosition = indexIncriment * i + position;
|
||||||
columnSlice[i] = &(this->cubes[cubePosition.x][cubePosition.y][cubePosition.z]);
|
columnSlice[i] = &(this->cubes[cubePosition.x][cubePosition.y][cubePosition.z]);
|
||||||
|
|||||||
@@ -11,7 +11,7 @@
|
|||||||
#include <Adafruit_NeoPixel.h>
|
#include <Adafruit_NeoPixel.h>
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
|
|
||||||
#include "Cube.h"
|
#include "BoardTypes.h"
|
||||||
#include "BoardTypes.h"
|
#include "BoardTypes.h"
|
||||||
|
|
||||||
template <uint32_t NUM_STACKS>
|
template <uint32_t NUM_STACKS>
|
||||||
@@ -22,7 +22,10 @@ public:
|
|||||||
* @param stacks a reference to an array which contains information about the pins which control each cube stack.
|
* @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
|
* @param pixelController a reference to a pre-constructed neopixel controller which will allow this driver to control neopixels
|
||||||
*/
|
*/
|
||||||
BoardDriver(std::array<BOARD_TYPES::CubeStack, NUM_STACKS> &stacks, Adafruit_NeoPixel &pixelController);
|
BoardDriver(
|
||||||
|
std::array<BOARD_TYPES::CubeStack, NUM_STACKS> &stacks,
|
||||||
|
Adafruit_NeoPixel &pixelController
|
||||||
|
);
|
||||||
~BoardDriver() = default;
|
~BoardDriver() = default;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -52,7 +55,13 @@ public:
|
|||||||
* @param cubes an array of cube pointers which contain the color data you want to stream
|
* @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
|
* @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
|
* @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 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
|
* @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:
|
private:
|
||||||
@@ -84,7 +97,10 @@ void BoardDriver<NUM_STACKS>::Init(){
|
|||||||
}
|
}
|
||||||
|
|
||||||
template<uint32_t NUM_STACKS>
|
template<uint32_t NUM_STACKS>
|
||||||
BoardDriver<NUM_STACKS>::BoardDriver(std::array<BOARD_TYPES::CubeStack, NUM_STACKS> &stacks, Adafruit_NeoPixel &pixelController):
|
BoardDriver<NUM_STACKS>::BoardDriver(
|
||||||
|
std::array<BOARD_TYPES::CubeStack, NUM_STACKS> &stacks,
|
||||||
|
Adafruit_NeoPixel &pixelController
|
||||||
|
):
|
||||||
stacks(stacks),
|
stacks(stacks),
|
||||||
pixelController(pixelController)
|
pixelController(pixelController)
|
||||||
{
|
{
|
||||||
@@ -94,12 +110,22 @@ pixelController(pixelController)
|
|||||||
}
|
}
|
||||||
|
|
||||||
template<uint32_t NUM_STACKS>
|
template<uint32_t NUM_STACKS>
|
||||||
void BoardDriver<NUM_STACKS>::UpdateStackLEDs(uint32_t numXStacks, uint32_t X_COORD, uint32_t Y_COORD, Cube* cubes[], uint32_t numCubes){
|
void BoardDriver<NUM_STACKS>::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);
|
this->UpdateStackLEDs(this->xy2StackIndex(X_COORD, Y_COORD, numXStacks), cubes, numCubes);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<uint32_t NUM_STACKS>
|
template<uint32_t NUM_STACKS>
|
||||||
void BoardDriver<NUM_STACKS>::UpdateStackLEDs(uint32_t stackIndex, Cube* cubes[], uint32_t numCubes){
|
void BoardDriver<NUM_STACKS>::UpdateStackLEDs(
|
||||||
|
uint32_t stackIndex,
|
||||||
|
BOARD_TYPES::Cube* cubes[],
|
||||||
|
uint32_t numCubes
|
||||||
|
){
|
||||||
this->pixelController.setPin(this->stacks[stackIndex].ledPin);
|
this->pixelController.setPin(this->stacks[stackIndex].ledPin);
|
||||||
for(int i = 0; i < numCubes; i++){
|
for(int i = 0; i < numCubes; i++){
|
||||||
V3D color{cubes[i]->color};
|
V3D color{cubes[i]->color};
|
||||||
@@ -110,7 +136,11 @@ void BoardDriver<NUM_STACKS>::UpdateStackLEDs(uint32_t stackIndex, Cube* cubes[]
|
|||||||
}
|
}
|
||||||
|
|
||||||
template<uint32_t NUM_STACKS>
|
template<uint32_t NUM_STACKS>
|
||||||
uint32_t BoardDriver<NUM_STACKS>::GetNumberCubes(uint32_t numXStacks, uint32_t X_COORD, uint32_t Y_COORD){
|
uint32_t BoardDriver<NUM_STACKS>::GetNumberCubes(
|
||||||
|
uint32_t numXStacks,
|
||||||
|
uint32_t X_COORD,
|
||||||
|
uint32_t Y_COORD
|
||||||
|
){
|
||||||
return this->GetNumberCubes(this->xy2StackIndex(X_COORD, Y_COORD, numXStacks));
|
return this->GetNumberCubes(this->xy2StackIndex(X_COORD, Y_COORD, numXStacks));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,7 @@
|
|||||||
|
/**
|
||||||
|
* @file BoardManager.h
|
||||||
|
* @brief Provides an easy way to manage a board
|
||||||
|
*/
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "Board.h"
|
#include "Board.h"
|
||||||
@@ -11,12 +15,30 @@ class BoardManager{
|
|||||||
|
|
||||||
~BoardManager() = default;
|
~BoardManager() = default;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Initialize the board control. This hsould be called during setup
|
||||||
|
*/
|
||||||
void Init();
|
void Init();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Read the board state and update the LED colors
|
||||||
|
*/
|
||||||
void Update();
|
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);
|
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);
|
void SetColumnColors(const V3D &column, const V3D *color);
|
||||||
|
|
||||||
|
|
||||||
@@ -29,10 +51,19 @@ class BoardManager{
|
|||||||
*/
|
*/
|
||||||
void FillColumnColor(const V3D &column, const V3D &color);
|
void FillColumnColor(const V3D &column, const V3D &color);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @returns true if the board has changed state
|
||||||
|
*/
|
||||||
bool HasBoardChanged();
|
bool HasBoardChanged();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Clear the board state changed flag
|
||||||
|
*/
|
||||||
void ClearBoardChanged();
|
void ClearBoardChanged();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Get the board occupation state returned in the format a,b,c,d....
|
||||||
|
*/
|
||||||
String &Board2StackString();
|
String &Board2StackString();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@@ -89,7 +120,7 @@ void BoardManager<BOARD_DIMS>::Update(){
|
|||||||
|
|
||||||
template <const V3D &BOARD_DIMS>
|
template <const V3D &BOARD_DIMS>
|
||||||
void BoardManager<BOARD_DIMS>::updateBoardColors(const V3D &column){
|
void BoardManager<BOARD_DIMS>::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<BOARD_TYPES::PLANE_NORMAL>(column.z))};
|
uint32_t numCubes{this->getColumnHeight(static_cast<BOARD_TYPES::PLANE_NORMAL>(column.z))};
|
||||||
this->driver.UpdateStackLEDs(BOARD_DIMS.x, cubeSlice, numCubes);
|
this->driver.UpdateStackLEDs(BOARD_DIMS.x, cubeSlice, numCubes);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,11 @@
|
|||||||
|
/**
|
||||||
|
* @file BoardTypes.h
|
||||||
|
* @brief Some types to that you'll need to define and control the board
|
||||||
|
*/
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
#include "Vector3D.h"
|
||||||
|
|
||||||
namespace BOARD_TYPES{
|
namespace BOARD_TYPES{
|
||||||
struct CubeStack{
|
struct CubeStack{
|
||||||
@@ -13,4 +18,9 @@ namespace BOARD_TYPES{
|
|||||||
Y,
|
Y,
|
||||||
Z
|
Z
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct Cube{
|
||||||
|
V3D color;
|
||||||
|
bool isOccupied{false};
|
||||||
|
};
|
||||||
};
|
};
|
||||||
@@ -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};
|
|
||||||
};
|
|
||||||
Reference in New Issue
Block a user