LED stuff

This commit is contained in:
Kevin Santo Cappuccio 2023-05-31 16:01:50 -07:00
parent 9f8499d4b0
commit 8fac38881a
4 changed files with 180 additions and 240 deletions

View File

@ -1,46 +1,42 @@
#include "LEDs.h"
#include <Adafruit_NeoPixel.h>
Adafruit_NeoPixel leds(LED_COUNT, LED_PIN, NEO_GRB + NEO_KHZ800);
void initLEDs(void)
{
leds.begin(); // INITIALIZE NeoPixel strip object (REQUIRED)
leds.show(); // Turn OFF all pixels ASAP
leds.begin(); // INITIALIZE NeoPixel strip object (REQUIRED)
leds.show(); // Turn OFF all pixels ASAP
leds.setBrightness(BRIGHTNESS);
}
void colorWipe(uint32_t color, int wait) {
void colorWipe(uint32_t color, int wait)
{
for (int i = 0; i < leds.numPixels(); i++)
{ // For each pixel in strip...
for(int i=0; i<leds.numPixels(); i++) { // For each pixel in strip...
leds.setPixelColor(i, color); // Set pixel's color (in RAM)
leds.show(); // Update strip to match
delay(wait); // Pause for a moment
}
leds.setPixelColor(i, color); // Set pixel's color (in RAM)
leds.show(); // Update strip to match
delay(wait); // Pause for a moment
}
}
void rainbowy(int saturation, int brightness, int wait)
{
void rainbowy(int saturation, int brightness, int wait) {
for(long firstPixelHue = 0; firstPixelHue < 5*65536; firstPixelHue += 256) {
// strip.rainbow() can take a single argument (first pixel hue) or
// optionally a few extras: number of rainbow repetitions (default 1),
// saturation and value (brightness) (both 0-255, similar to the
// ColorHSV() function, default 255), and a true/false flag for whether
// to apply gamma correction to provide 'truer' colors (default true).
leds.rainbow(firstPixelHue, 1, saturation, 220, true);
// Above line is equivalent to:
// strip.rainbow(firstPixelHue, 1, 255, 255, true);
leds.show(); // Update strip with new contents
delay(wait); // Pause for a moment
}
for (long firstPixelHue = 0; firstPixelHue < 5 * 65536; firstPixelHue += 256)
{
// strip.rainbow() can take a single argument (first pixel hue) or
// optionally a few extras: number of rainbow repetitions (default 1),
// saturation and value (brightness) (both 0-255, similar to the
// ColorHSV() function, default 255), and a true/false flag for whether
// to apply gamma correction to provide 'truer' colors (default true).
leds.rainbow(firstPixelHue, 1, saturation, 220, true);
// Above line is equivalent to:
// strip.rainbow(firstPixelHue, 1, 255, 255, true);
leds.show(); // Update strip with new contents
delay(wait); // Pause for a moment
}
}

View File

@ -9,16 +9,9 @@
#define LED_COUNT 80
#define BRIGHTNESS 50
extern Adafruit_NeoPixel leds;
const int bbPixelToNodesMap[62] = { 1, 2, 3, 4, 5, 6, 7, 8, 9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,
32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61};

View File

@ -6,16 +6,16 @@
#include "NetManager.h"
#include "NetsToChipConnections.h"
//don't try to understand this, it's still a mess
// don't try to understand this, it's still a mess
int startEndChip[2] = {-1, -1};
int startEndChip[2] = {-1, -1};
int bothNodes[2] = {-1, -1};
int endChip;
int chipCandidates[2][4] = {{-1, -1, -1, -1}, {-1, -1, -1, -1}}; // nano and sf nodes have multiple possible chips they could be connected to, so we need to store them all and check them all
int chipsLeastToMostCrowded[12] = {0,1,2,3,4,5,6,7,8,9,10,11}; //this will be sorted from most to least crowded, and will be used to determine which chip to use for each node
int sfChipsLeastToMostCrowded[4] = {8,9,10,11}; //this will be sorted from most to least crowded, and will be used to determine which chip to use for each node
int bbToSfLanes[8][4] = {{0}}; // [Chip A - H][CHIP I-K] 0 = free 1 = used
int chipsLeastToMostCrowded[12] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}; // this will be sorted from most to least crowded, and will be used to determine which chip to use for each node
int sfChipsLeastToMostCrowded[4] = {8, 9, 10, 11}; // this will be sorted from most to least crowded, and will be used to determine which chip to use for each node
int bbToSfLanes[8][4] = {{0}}; // [Chip A - H][CHIP I-K] 0 = free 1 = used
int numberOfUniqueNets = 0;
int numberOfNets = 0;
@ -129,7 +129,7 @@ void bridgesToPaths(void)
printPathArray();
sortAllChipsLeastToMostCrowded();
resolveChipCandidates();
resolveChipCandidates();
}
void findStartAndEndChips(int node1, int node2, int pathIdx)
@ -234,7 +234,7 @@ void findStartAndEndChips(int node1, int node2, int pathIdx)
break;
}
}
//Serial.print("\n\r");
// Serial.print("\n\r");
}
if (startEndChip[0] == -1 || startEndChip[1] == -1)
@ -242,23 +242,18 @@ void findStartAndEndChips(int node1, int node2, int pathIdx)
}
else
{
}
}
void resolveChipCandidates(void)
{
int nodesToResolve[2] = {0,0}; // {node1,node2} 0 = already found, 1 = needs resolving
int nodesToResolve[2] = {0, 0}; // {node1,node2} 0 = already found, 1 = needs resolving
for (int pathIndex = 0; pathIndex < numberOfPaths; pathIndex++)
{
nodesToResolve[0] = 0;
nodesToResolve[1] = 0;
if (path[pathIndex].chip[0] == -1)
{
nodesToResolve[0] = 1;
@ -276,89 +271,66 @@ void resolveChipCandidates(void)
{
nodesToResolve[1] = 0;
}
for (int nodeOneOrTwo = 0; nodeOneOrTwo < 2; nodeOneOrTwo++)
{
if(nodesToResolve[nodeOneOrTwo] == 1)
if (nodesToResolve[nodeOneOrTwo] == 1)
{
path[pathIndex].chip[nodeOneOrTwo] = moreAvailableChip(path[pathIndex].candidates[nodeOneOrTwo][0], path[pathIndex].candidates[nodeOneOrTwo][1]);
path[pathIndex].chip[nodeOneOrTwo] = moreAvailableChip(path[pathIndex].candidates[nodeOneOrTwo][0], path[pathIndex].candidates[nodeOneOrTwo][1]);
Serial.print("path[");
Serial.print(pathIndex);
Serial.print("] chip from ");
Serial.print(chipNumToChar(path[pathIndex].chip[(1+nodeOneOrTwo)%2]));
Serial.print(" to chip ");
Serial.print(chipNumToChar(path[pathIndex].chip[nodeOneOrTwo]));
Serial.print(" chosen\n\n\r");
Serial.print("path[");
Serial.print(pathIndex);
Serial.print("] chip from ");
Serial.print(chipNumToChar(path[pathIndex].chip[(1 + nodeOneOrTwo) % 2]));
Serial.print(" to chip ");
Serial.print(chipNumToChar(path[pathIndex].chip[nodeOneOrTwo]));
Serial.print(" chosen\n\n\r");
}
}
}
}
void bbToSfConnections (void)
void bbToSfConnections(void)
{
for (int i = 0 ; i < numberOfPaths; i++)
for (int i = 0; i < numberOfPaths; i++)
{
if (path[i].chip[0] > 7 && path[i].chip[1] <= 7 && path[i].chip[1] >= 0)
{
bbToSfLanes[path[i].chip[1]][path[i].chip[0] - 8] ++; //why is this happening every loop
Serial.print (i);
Serial.print (" ");
Serial.print (chipNumToChar((path[i].chip[1])));
Serial.print ("-");
Serial.println (chipNumToChar((path[i].chip[0])));
} else if (path[i].chip[1] > 7 && path[i].chip[0] <= 7 && path[i].chip[0] >= 0)
bbToSfLanes[path[i].chip[0]][path[i].chip[1] - 8] ++;
Serial.print (i);
Serial.print (" ");
Serial.print (chipNumToChar((path[i].chip[0])));
Serial.print ("-");
Serial.println (chipNumToChar((path[i].chip[1])));
bbToSfLanes[path[i].chip[1]][path[i].chip[0] - 8]++; // why is this happening every loop
Serial.print(i);
Serial.print(" ");
Serial.print(chipNumToChar((path[i].chip[1])));
Serial.print("-");
Serial.println(chipNumToChar((path[i].chip[0])));
}
else if (path[i].chip[1] > 7 && path[i].chip[0] <= 7 && path[i].chip[0] >= 0)
for (int i = 0; i < 8; i++)
{
Serial.print(chipNumToChar(i));
Serial.print(": ");
for (int j = 0; j < 4; j++)
{
Serial.print(chipNumToChar(j + 8));
Serial.print(bbToSfLanes[i][j]);
Serial.print(" ");
bbToSfLanes[path[i].chip[0]][path[i].chip[1] - 8]++;
Serial.print(i);
Serial.print(" ");
Serial.print(chipNumToChar((path[i].chip[0])));
Serial.print("-");
Serial.println(chipNumToChar((path[i].chip[1])));
}
for (int i = 0; i < 8; i++)
{
Serial.print(chipNumToChar(i));
Serial.print(": ");
for (int j = 0; j < 4; j++)
{
Serial.print(chipNumToChar(j + 8));
Serial.print(bbToSfLanes[i][j]);
Serial.print(" ");
}
Serial.println("\n\r");
}
Serial.println("\n\r");
}
}
int moreAvailableChip (int chip1 , int chip2)
int moreAvailableChip(int chip1, int chip2)
{
int chipChosen = -1;
sortAllChipsLeastToMostCrowded();
@ -371,15 +343,12 @@ int moreAvailableChip (int chip1 , int chip2)
break;
}
}
return chipChosen;
return chipChosen;
}
void sortSFchipsLeastToMostCrowded(void)
{
int numberOfConnectionsPerSFchip[4] = {0,0,0,0};
int numberOfConnectionsPerSFchip[4] = {0, 0, 0, 0};
for (int i = 0; i < numberOfPaths; i++)
{
@ -390,39 +359,28 @@ void sortSFchipsLeastToMostCrowded(void)
numberOfConnectionsPerSFchip[path[i].chip[j] - 8]++;
}
}
}
for (int i = 0; i < 4; i++)
{
Serial.print("sf connections: ");
Serial.print (chipNumToChar(i + 8));
Serial.print(numberOfConnectionsPerSFchip[i]);
Serial.print("\n\r");
}
for (int i = 0; i < 4; i++)
{
Serial.print("sf connections: ");
Serial.print(chipNumToChar(i + 8));
Serial.print(numberOfConnectionsPerSFchip[i]);
Serial.print("\n\r");
}
}
void sortAllChipsLeastToMostCrowded(void)
{
debugNTCC = false;
int numberOfConnectionsPerChip[12] = {0,0,0,0,0,0,0,0,0,0,0,0}; //this will be used to determine which chip is most crowded
int numberOfConnectionsPerChip[12] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; // this will be used to determine which chip is most crowded
for (int i = 0; i < 12; i++)
for (int i = 0; i < 12; i++)
{
chipsLeastToMostCrowded[i] = i;
}
Serial.println("\n\r");
for (int i = 0; i < numberOfPaths; i++)
{
for (int j = 0; j < 2; j++)
@ -432,19 +390,18 @@ void sortAllChipsLeastToMostCrowded(void)
numberOfConnectionsPerChip[path[i].chip[j]]++;
}
}
}
if (debugNTCC)
{
for (int i = 0; i < 12; i++)
if (debugNTCC)
{
Serial.print(chipNumToChar(i));
Serial.print(": ");
Serial.println(numberOfConnectionsPerChip[i]);
}
for (int i = 0; i < 12; i++)
{
Serial.print(chipNumToChar(i));
Serial.print(": ");
Serial.println(numberOfConnectionsPerChip[i]);
}
Serial.println("\n\r");
}
Serial.println("\n\r");
}
int temp = 0;
for (int i = 0; i < 12; i++)
@ -454,7 +411,7 @@ if (debugNTCC)
if (numberOfConnectionsPerChip[j] > numberOfConnectionsPerChip[j + 1])
{
temp = numberOfConnectionsPerChip[j];
//chipsLeastToMostCrowded[j] = chipsLeastToMostCrowded[j + 1];
// chipsLeastToMostCrowded[j] = chipsLeastToMostCrowded[j + 1];
numberOfConnectionsPerChip[j] = numberOfConnectionsPerChip[j + 1];
numberOfConnectionsPerChip[j + 1] = temp;
@ -473,28 +430,26 @@ if (debugNTCC)
sfChipsLeastToMostCrowded[i - 8] = chipsLeastToMostCrowded[i];
}
if (debugNTCC)
{
Serial.print(chipNumToChar(chipsLeastToMostCrowded[i]));
Serial.print(": ");
Serial.println(numberOfConnectionsPerChip[i]);
}
{
Serial.print(chipNumToChar(chipsLeastToMostCrowded[i]));
Serial.print(": ");
Serial.println(numberOfConnectionsPerChip[i]);
}
}
if (debugNTCC)
{
for (int i = 0; i < 4; i++)
if (debugNTCC)
{
Serial.print("\n\n\r");
Serial.print(chipNumToChar(sfChipsLeastToMostCrowded[i]));
Serial.print(": ");
Serial.print("\n\n\r");
for (int i = 0; i < 4; i++)
{
Serial.print("\n\n\r");
Serial.print(chipNumToChar(sfChipsLeastToMostCrowded[i]));
Serial.print(": ");
Serial.print("\n\n\r");
}
}
debugNTCC = true;
bbToSfConnections();
}
debugNTCC = true;
bbToSfConnections();
}
void printPathArray(void) // this also prints candidates and x y
{
@ -585,7 +540,7 @@ void clearChipsOnPathToNegOne(void)
path[i].net = -1;
}
for (int c = 0; c < 3; c++)
for (int c = 0; c < 3; c++)
{
path[i].chip[c] = -1;
path[i].x[c] = -1;
@ -593,7 +548,7 @@ void clearChipsOnPathToNegOne(void)
path[i].candidates[c][0] = -1;
path[i].candidates[c][1] = -1;
path[i].candidates[c][2] = -1; //CEEEEEEEE!!!!!! i had this set to 3 and it was clearing everything, but no im not using rust
path[i].candidates[c][2] = -1; // CEEEEEEEE!!!!!! i had this set to 3 and it was clearing everything, but no im not using rust
}
}
}

View File

@ -7,97 +7,93 @@
#include "NetsToChipConnections.h"
#include "LEDs.h"
// nanoStatus nano;
const char *definesToChar(int); // i really need to find a way to not need to forward declare fuctions with this setup, i hate it
//nanoStatus nano;
const char* definesToChar (int); //i really need to find a way to not need to forward declare fuctions with this setup, i hate it
// void printConnections();
//void printConnections();
void setup() {
void setup()
{
Serial.begin(115200);
pinMode(25, OUTPUT);
LittleFS.begin();
delay(3000);
openNodeFile();
initLEDs();
LittleFS.begin();
delay(3000);
openNodeFile();
initLEDs();
}
void loop() {
//digitalWrite(LED_BUILTIN,HIGH);
//delay(100);
//digitalWrite(LED_BUILTIN,LOW);
rainbowy(180 ,55 , 20); // Red
//delay(800);
getNodesToConnect();
//delay(800);
Serial.println("\n\n\rfinal netlist\n\n\r");
listSpecialNets();
listNets();
//printBridgeArray();
bridgesToPaths();
while(1);
//Serial.println("\n\r");
//writeJSONtoFile();
//delay(1000);
/*
for (int i = 0; i < 9; i++) //this is just to check that the structs are being set up correctly
void loop()
{
Serial.print("\n\r");
Serial.print (net[i].name);
Serial.print ("\t");
Serial.print (net[i].number);
Serial.print ("\t");
Serial.print (definesToChar(net[i].specialFunction));
if (i == 1) Serial.print ("\t"); //padding for "GND"
Serial.print ("\t{");
// digitalWrite(LED_BUILTIN,HIGH);
// delay(100);
// digitalWrite(LED_BUILTIN,LOW);
for (int k = 0; k < 8; k++)
{
if (net[i].doNotIntersectNodes[k] != 0)
{
Serial.print (definesToChar(net[i].doNotIntersectNodes[k]));
Serial.print (",");
}
rainbowy(180, 55, 20); // Red
}
Serial.print ("}\t");
// delay(800);
for (int j = 0 ; j < MAX_NODES; j++)
getNodesToConnect();
// delay(800);
Serial.println("\n\n\rfinal netlist\n\n\r");
listSpecialNets();
listNets();
// printBridgeArray();
bridgesToPaths();
while (1)
;
// Serial.println("\n\r");
// writeJSONtoFile();
// delay(1000);
/*
for (int i = 0; i < 9; i++) //this is just to check that the structs are being set up correctly
{
if (net[i].nodes[j] != 0)
{
Serial.print (definesToChar(net[i].nodes[j]));
Serial.print (",");
}
Serial.print("\n\r");
Serial.print (net[i].name);
Serial.print ("\t");
Serial.print (net[i].number);
Serial.print ("\t");
Serial.print (definesToChar(net[i].specialFunction));
if (i == 1) Serial.print ("\t"); //padding for "GND"
Serial.print ("\t{");
for (int k = 0; k < 8; k++)
{
if (net[i].doNotIntersectNodes[k] != 0)
{
Serial.print (definesToChar(net[i].doNotIntersectNodes[k]));
Serial.print (",");
}
}
Serial.println("\n\n\n\n\r");
Serial.print ("}\t");
}*/
delay(100);
for (int j = 0 ; j < MAX_NODES; j++)
{
if (net[i].nodes[j] != 0)
{
Serial.print (definesToChar(net[i].nodes[j]));
Serial.print (",");
}
}
Serial.println("\n\n\n\n\r");
}*/
delay(100);
}
/*
void printConnections(void) {
@ -210,7 +206,7 @@ void printConnections(void) {
}
Serial.println(" ");
Serial.println("\n\n");
*/
/*