Fixed several buffer overflow issues
This commit is contained in:
@@ -39,7 +39,7 @@ 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);
|
||||
void SetColumnColors(const V3D &column, const V3D *color, uint32_t numColors);
|
||||
|
||||
|
||||
/**
|
||||
@@ -64,15 +64,13 @@ class BoardManager{
|
||||
/**
|
||||
* @brief Get the board occupation state returned in the format a,b,c,d....
|
||||
*/
|
||||
String &Board2StackString();
|
||||
void Board2StackString(String& messageBuffer);
|
||||
|
||||
private:
|
||||
BoardDriver<BOARD_WIDTH*BOARD_LENGTH> &driver;
|
||||
Board<BOARD_DIMS> board{};
|
||||
|
||||
bool hasBoardChanged{false};
|
||||
|
||||
void updateBoardColors(const V3D &column);
|
||||
void updateStackColors(const V3D &column);
|
||||
|
||||
uint32_t getColumnHeight(BOARD_TYPES::PLANE_NORMAL normal){
|
||||
switch(normal){
|
||||
@@ -110,17 +108,30 @@ void BoardManager<BOARD_DIMS>::Update(){
|
||||
uint32_t numCubes{this->driver.GetNumberCubes(stackIndex)};
|
||||
for(uint32_t z = 0; z < BOARD_DIMS.z; z++){
|
||||
V3D cubePosition{x, y, z};
|
||||
// update the cube's occupation
|
||||
this->board.SetCubeOccupation(cubePosition, z < numCubes);
|
||||
cubePosition.z = BOARD_TYPES::PLANE_NORMAL::Z;
|
||||
this->driver.UpdateStackLEDs(stackIndex, this->board.SliceBoard(cubePosition), BOARD_DIMS.z);
|
||||
}
|
||||
|
||||
// create the column vector for the slice direction
|
||||
V3D 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
|
||||
this->board.SliceBoard(sliceVector, sliceBuffer);
|
||||
// send the board slice to the driver to update its LED colors
|
||||
this->driver.UpdateStackLEDs(stackIndex, sliceBuffer, BOARD_DIMS.z);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template <const V3D &BOARD_DIMS>
|
||||
void BoardManager<BOARD_DIMS>::updateBoardColors(const V3D &column){
|
||||
BOARD_TYPES::Cube ** cubeSlice{this->board.SliceBoard(column)};
|
||||
void BoardManager<BOARD_DIMS>::updateStackColors(const V3D &column){
|
||||
// the only column type allowed here is z.
|
||||
V3D 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);
|
||||
|
||||
uint32_t numCubes{this->getColumnHeight(static_cast<BOARD_TYPES::PLANE_NORMAL>(column.z))};
|
||||
this->driver.UpdateStackLEDs(BOARD_DIMS.x, cubeSlice, numCubes);
|
||||
}
|
||||
@@ -129,45 +140,45 @@ template <const V3D &BOARD_DIMS>
|
||||
void BoardManager<BOARD_DIMS>::SetCubeColor(const V3D &position, const V3D &color){
|
||||
this->board.SetCubeColor(position, color);
|
||||
V3D slice{position.x, position.y, BOARD_TYPES::PLANE_NORMAL::Z};
|
||||
this->updateBoardColors(slice);
|
||||
this->updateStackColors(slice);
|
||||
}
|
||||
|
||||
template <const V3D &BOARD_DIMS>
|
||||
void BoardManager<BOARD_DIMS>::SetColumnColors(const V3D &column, const V3D *color){
|
||||
void BoardManager<BOARD_DIMS>::SetColumnColors(const V3D &column, const V3D *color, uint32_t numColors){
|
||||
uint32_t columnHeight{this->getColumnHeight(static_cast<BOARD_TYPES::PLANE_NORMAL>(column.z))};
|
||||
|
||||
V3D position = column;
|
||||
for(uint32_t z = 0; z < columnHeight; z++){
|
||||
position.z = z;
|
||||
this->board.SetCubeColor(position, color[z]);
|
||||
// create a cube pointer buffer and store a board slice into it
|
||||
BOARD_TYPES::Cube * slicedBoard[columnHeight];
|
||||
Serial.println("moments before slicing");
|
||||
uint32_t sliceLength{this->board.SliceBoard(column, slicedBoard)};
|
||||
|
||||
Serial.println("setting colors");
|
||||
uint32_t maxIndex{std::min(numColors, columnHeight)};
|
||||
for(uint32_t i = 0; i < columnHeight; i++){
|
||||
slicedBoard[i]->color = color[i];
|
||||
}
|
||||
|
||||
this->updateBoardColors(column);
|
||||
Serial.println("End of SetColumnColors");
|
||||
}
|
||||
|
||||
template <const V3D &BOARD_DIMS>
|
||||
void BoardManager<BOARD_DIMS>::FillColumnColor(const V3D &column, const V3D &color){
|
||||
uint32_t columnHeight{this->getColumnHeight(column.z)};
|
||||
|
||||
V3D position = column;
|
||||
for(uint32_t z = 0; z < columnHeight; z++){
|
||||
position.z = z;
|
||||
this->board.SetCubeColor(position, color);
|
||||
V3D colors[columnHeight];
|
||||
for(uint32_t i = 0; i < columnHeight; i++){
|
||||
colors[i] = color;
|
||||
}
|
||||
|
||||
this->updateBoardColors(column);
|
||||
this->SetColumnColors(column, colors);
|
||||
}
|
||||
|
||||
template <const V3D &BOARD_DIMS>
|
||||
bool BoardManager<BOARD_DIMS>::HasBoardChanged(){return this->hasBoardChanged;}
|
||||
bool BoardManager<BOARD_DIMS>::HasBoardChanged(){return this->board.BoardStateChanged();}
|
||||
|
||||
template <const V3D &BOARD_DIMS>
|
||||
void BoardManager<BOARD_DIMS>::ClearBoardChanged(){this->hasBoardChanged = false;}
|
||||
void BoardManager<BOARD_DIMS>::ClearBoardChanged(){this->board.SetStateChanged(false);}
|
||||
|
||||
template <const V3D &BOARD_DIMS>
|
||||
String &BoardManager<BOARD_DIMS>::Board2StackString(){
|
||||
String message{};
|
||||
this->board.ToStackString(message);
|
||||
return message;
|
||||
void BoardManager<BOARD_DIMS>::Board2StackString(String& messageBuffer){
|
||||
this->board.ToStackString(messageBuffer);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user