Finished commenting code changes

This commit is contained in:
2024-08-24 14:07:12 -04:00
parent 5caa0a8a61
commit a59a6657e8
5 changed files with 85 additions and 28 deletions

View File

@@ -9,7 +9,7 @@
#include <array>
#include <WString.h>
#include "Cube.h"
#include "BoardTypes.h"
#include "Vector3D.h"
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)
* @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<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;
};
@@ -145,7 +145,7 @@ void Board<BOARD_DIMS>::SetCubeOccupation(const V3D &position, bool occupation){
}
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};
V3D indexIncriment{};
V3D position{};
@@ -172,7 +172,7 @@ Cube ** Board<BOARD_DIMS>::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]);

View File

@@ -11,7 +11,7 @@
#include <Adafruit_NeoPixel.h>
#include <Arduino.h>
#include "Cube.h"
#include "BoardTypes.h"
#include "BoardTypes.h"
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 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;
/**
@@ -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<NUM_STACKS>::Init(){
}
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),
pixelController(pixelController)
{
@@ -94,12 +110,22 @@ pixelController(pixelController)
}
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);
}
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);
for(int i = 0; i < numCubes; i++){
V3D color{cubes[i]->color};
@@ -110,7 +136,11 @@ void BoardDriver<NUM_STACKS>::UpdateStackLEDs(uint32_t stackIndex, Cube* cubes[]
}
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));
}

View File

@@ -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<BOARD_DIMS>::Update(){
template <const V3D &BOARD_DIMS>
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))};
this->driver.UpdateStackLEDs(BOARD_DIMS.x, cubeSlice, numCubes);
}

View File

@@ -1,6 +1,11 @@
/**
* @file BoardTypes.h
* @brief Some types to that you'll need to define and control the board
*/
#pragma once
#include <cstdint>
#include "Vector3D.h"
namespace BOARD_TYPES{
struct CubeStack{
@@ -13,4 +18,9 @@ namespace BOARD_TYPES{
Y,
Z
};
struct Cube{
V3D color;
bool isOccupied{false};
};
};

View File

@@ -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};
};