Added probing!!!

This commit is contained in:
Kevin Santo Cappuccio 2024-02-13 21:19:57 -08:00
parent 844b0a0f55
commit 2a274928a9
5 changed files with 453 additions and 185 deletions

View File

@ -249,6 +249,8 @@ void sendXYraw(int chip, int x, int y, int setOrClear)
delayMicroseconds(40);
}
int probeHalfPeriodus = 10;
int readFloatingOrState(int pin, int rowBeingScanned)
{
@ -263,21 +265,21 @@ int readFloatingOrState(int pin, int rowBeingScanned)
pinMode(pin, INPUT_PULLUP);
delayMicroseconds(200);
delayMicroseconds(100);
readingPullup = digitalRead(pin);
delayMicroseconds(10);
delayMicroseconds(probeHalfPeriodus);
readingPullup2 = digitalRead(pin);
delayMicroseconds(5);
delayMicroseconds(probeHalfPeriodus / 2);
readingPullup3 = digitalRead(pin);
pinMode(pin, INPUT_PULLDOWN);
delayMicroseconds(200);
delayMicroseconds(100);
readingPulldown = digitalRead(pin);
delayMicroseconds(10);
delayMicroseconds(probeHalfPeriodus);
readingPulldown2 = digitalRead(pin);
delayMicroseconds(5);
delayMicroseconds(probeHalfPeriodus / 2);
readingPulldown3 = digitalRead(pin);
if (readingPullup != readingPullup2 || readingPullup2 != readingPullup3 && rowBeingScanned != -1)
@ -286,9 +288,10 @@ int readFloatingOrState(int pin, int rowBeingScanned)
{
state = probe;
leds.setPixelColor(nodesToPixelMap[rowBeingScanned], 45, 0, 45);
// leds.setPixelColor(nodesToPixelMap[rowBeingScanned], rainbowList[rainbowIndex][0], rainbowList[rainbowIndex][1], rainbowList[rainbowIndex][2]);
// Serial.print("probe");
leds.show();
//
}
}
else
@ -305,13 +308,13 @@ int readFloatingOrState(int pin, int rowBeingScanned)
else if (readingPullup == 1 && readingPulldown == 1)
{
// Serial.print("HIGH");
//leds.setPixelColor(nodesToPixelMap[rowBeingScanned], 45, 0, 0);
// leds.setPixelColor(nodesToPixelMap[rowBeingScanned], 45, 0, 0);
state = high;
}
else if (readingPullup == 0 && readingPulldown == 0)
{
// Serial.print("LOW");
//leds.setPixelColor(nodesToPixelMap[rowBeingScanned], 0, 45, 0);
// leds.setPixelColor(nodesToPixelMap[rowBeingScanned], 0, 45, 0);
state = low;
}
else if (readingPullup == 0 && readingPulldown == 1)
@ -321,31 +324,65 @@ int readFloatingOrState(int pin, int rowBeingScanned)
}
// Serial.print("\n");
leds.show();
//delayMicroseconds(100);
// delayMicroseconds(100);
return state;
}
void startProbe(void)
void startProbe(int probeSpeed)
{
probeHalfPeriodus = 1000000 / probeSpeed / 2;
pinMode(19, OUTPUT);
analogWriteFreq(50000);
analogWriteFreq(probeSpeed);
analogWrite(19, 128);
delayMicroseconds(100);
// delayMicroseconds(10);
pinMode(18, INPUT);
}
int rainbowList[12][3] = {
{45, 35, 8},
{10, 45, 30},
{30, 15, 45},
{8, 27, 45},
{45, 18, 19},
{35, 42, 5},
{02, 45, 35},
{18, 25, 45},
{40, 12, 45},
{10, 32, 45},
{18, 5, 43},
{45, 28, 13}};
int rainbowIndex = 0;
int lastFound[5] = {-1, -1, -1, -1, -1};
int nextIsSupply = 0;
int nextIsGnd = 0;
int justCleared = 1;
int scanRows(int pin, bool clearLastFound)
{
static int lastFound = -1;
int found = -1;
if (clearLastFound)
{
lastFound = -1;
// for (int i = 0; i < 5; i++)
// {
// lastFound[i] = -1;
// }
rainbowIndex++;
if (rainbowIndex > 11)
{
rainbowIndex = 0;
}
justCleared = 1;
nextIsGnd = 0;
nextIsSupply = 0;
return -1;
}
digitalWrite(RESETPIN, HIGH);
delayMicroseconds(10);
digitalWrite(RESETPIN, LOW);
@ -390,30 +427,41 @@ int scanRows(int pin, bool clearLastFound)
// analogRead(ADC0_PIN);
rowBeingScanned = ch[chipScan].yMap[yToScan];
if (readFloatingOrState(pin, rowBeingScanned) == probe && rowBeingScanned != lastFound)
if (readFloatingOrState(pin, rowBeingScanned) == probe && rowBeingScanned != lastFound[0])
{
found = rowBeingScanned;
lastFound = found;
if (nextIsSupply)
{
leds.setPixelColor(nodesToPixelMap[rowBeingScanned], 65, 10, 10);
}
else if (nextIsGnd)
{
leds.setPixelColor(nodesToPixelMap[rowBeingScanned], 10, 65, 10);
}
else
{
leds.setPixelColor(nodesToPixelMap[rowBeingScanned], rainbowList[rainbowIndex][0], rainbowList[rainbowIndex][1], rainbowList[rainbowIndex][2]);
}
leds.show();
for (int i = 4; i > 0; i--)
{
lastFound[i] = lastFound[i - 1];
}
lastFound[0] = found;
}
sendXYraw(chipScan, 0, 0, 0);
sendXYraw(chipScan, 0, yToScan, 0);
// if (found != -1)
// {
// break;
// }
if (found != -1)
{
break;
}
}
sendXYraw(CHIP_L, 2, chipScan, 0);
if (found != -1)
{
return found;
}
}
int corners[4] = {1, 30, 31, 60};
@ -426,39 +474,106 @@ int scanRows(int pin, bool clearLastFound)
// analogRead(ADC0_PIN);
rowBeingScanned = corners[cornerScan];
if (readFloatingOrState(pin, rowBeingScanned) == probe && rowBeingScanned != lastFound)
if (readFloatingOrState(pin, rowBeingScanned) == probe && rowBeingScanned != lastFound[0])
{
found = rowBeingScanned;
lastFound = found;
if (nextIsSupply)
{
leds.setPixelColor(nodesToPixelMap[rowBeingScanned], 65, 10, 10);
}
else if (nextIsGnd)
{
leds.setPixelColor(nodesToPixelMap[rowBeingScanned], 10, 65, 10);
}
else
{
leds.setPixelColor(nodesToPixelMap[rowBeingScanned], rainbowList[rainbowIndex][0], rainbowList[rainbowIndex][1], rainbowList[rainbowIndex][2]);
}
leds.show();
for (int i = 4; i > 0; i--)
{
lastFound[i] = lastFound[i - 1];
}
lastFound[0] = found;
}
sendXYraw(CHIP_L, cornerScan + 8, 0, 0);
// if (found != -1)
// {
// break;
// }
if (found != -1)
{
break;
}
}
sendXYraw(CHIP_L, xMapRead, 0, 0);
int gp18read = readFloatingOrState(18, -1);
if (gp18read == probe)
{
return -18;
}
pinMode(19, INPUT);
delayMicroseconds(400);
int probeRead = readFloatingOrState(19, -1);
delayMicroseconds(400);
int probeRead = readFloatingOrState(19, -1);
if (probeRead == high && ((lastFound[0] != SUPPLY_3V3 )))
{
found = SUPPLY_3V3;
if (justCleared)
{
nextIsSupply = 1;
//justCleared = 0;
}
else
{
leds.setPixelColor(nodesToPixelMap[lastFound[0]], 65, 10, 10);
nextIsSupply = 0;
}
for (int i = 4; i > 0; i--)
{
lastFound[i] = lastFound[i - 1];
}
lastFound[0] = found;
}
else if (probeRead == low && ((lastFound[0] != GND )))
{
found = GND;
if (justCleared)
{
// leds.setPixelColor(nodesToPixelMap[lastFound[0]], 0, 0, 0);
nextIsGnd = 1;
//justCleared = 0;
}
else
{
leds.setPixelColor(nodesToPixelMap[lastFound[0]], 10, 65, 10);
nextIsGnd = 0;
}
for (int i = 4; i > 0; i--)
{
lastFound[i] = lastFound[i - 1];
}
lastFound[0] = found;
}
if (justCleared && found != -1)
{
Serial.print("\n\rjustCleared: ");
Serial.println(justCleared);
Serial.print("nextIsSupply: ");
Serial.println(nextIsSupply);
Serial.print("nextIsGnd: ");
Serial.println(nextIsGnd);
justCleared = 0;
}
if (probeRead == high && lastFound != SUPPLY_3V3)
{
found = SUPPLY_3V3;
lastFound = found;
}
else if (probeRead == low && lastFound != GND)
{
found = GND;
lastFound = found;
}
return found;
//return 0;
// return 0;
}
void sendPath(int i, int setOrClear)

View File

@ -22,7 +22,7 @@ enum measuredState
void initCH446Q(void);
void sendXYraw(int chip, int x, int y, int setorclear);
int readFloatingOrState (int pin = 0, int row = 0);
void startProbe (void);
void startProbe (int probeSpeed = 50000);
int scanRows(int pin = 0, bool clearLastFound = false);
void sendAllPaths(void); // should we sort them by chip? for now, no
void resetArduino (void);

View File

@ -402,8 +402,79 @@ void changeWokwiDefinesToJumperless(void)
void clearNodeFile(void)
{
LittleFS.remove("nodeFile.txt");
nodeFile = LittleFS.open("nodeFile.txt", "w+");
nodeFile.print("!");
nodeFile.close();
}
void addBridgeToNodeFile(int node1, int node2)
{
nodeFile = LittleFS.open("nodeFile.txt", "r+");
if (!nodeFile)
{
if (debugFP)
Serial.println("Failed to open nodeFile");
return;
}
else
{
if (debugFP)
Serial.println("\n\ropened nodeFile.txt\n\n\rloading bridges from file\n\r");
}
int nodeFileBraceIndex = 0;
while (nodeFile.available())
{
char c = nodeFile.read();
// Serial.print(c);
if (c == '}')
{
break;
} else {
nodeFileBraceIndex++;
}
if (c == '!')
{
nodeFile.seek(0);
nodeFile.print("{\n\r");
nodeFile.print(node1);
nodeFile.print("-");
nodeFile.print(node2);
nodeFile.print(",\n\r}\n\r{\n\r}\n\r");
nodeFile.close();
return;
}
}
//Serial.println(nodeFileBraceIndex);
nodeFile.seek(nodeFileBraceIndex);
nodeFile.print(node1);
nodeFile.print("-");
nodeFile.print(node2);
nodeFile.print(",\n\r}\n\r{\n\r}\n\r");
if (debugFP)
{
Serial.println("wrote to nodeFile.txt");
Serial.println("nodeFile.txt contents:\n\r");
nodeFile.seek(0);
while (nodeFile.available())
{
Serial.write(nodeFile.read());
}
Serial.println("\n\r");
}
nodeFile.close();
}
void writeToNodeFile(void)
{

View File

@ -22,7 +22,7 @@ extern bool debugMM;
void parseWokwiFileToNodeFile();
void changeWokwiDefinesToJumperless ();
void writeToNodeFile(void);
void addBridgeToNodeFile(int node1, int node2);
void savePreformattedNodeFile (int source = 0);
void openNodeFile();

View File

@ -1,6 +1,5 @@
// SPDX-License-Identifier: MIT
#include <Arduino.h>
#define USE_TINYUSB 1
@ -53,7 +52,6 @@ int supplySwitchPosition = 0;
void machineMode(void);
void lastNetConfirm(int forceLastNet = 0);
unsigned long lastNetConfirmTimer = 0;
// int machineMode = 0;
@ -77,7 +75,6 @@ void setup()
USBSer1.setStringDescriptor("Jumperless USB Serial");
USBSer1.begin(115200);
#ifdef EEPROMSTUFF
@ -104,9 +101,7 @@ void setup()
clearAllNTCC();
lastNetConfirm(0);
// lastNetConfirm(0);
}
void setup1()
@ -134,8 +129,10 @@ char input;
int serSource = 0;
int readInNodesArduino = 0;
int baudRate = 115200;
unsigned long probingTimer = 0;
int restoredNodeFile = 0;
const char firmwareVersion[] = "1.2.0"; //// remember to update this
const char firmwareVersion[] = "1.3.0"; //// remember to update this
void loop()
{
@ -150,7 +147,7 @@ menu:
// // connecttimer = millis();
// // }
//Serial.print("Updated!\n\r");
// Serial.print("Updated!\n\r");
Serial.print("\n\n\r\t\t\tMenu\n\n\r");
Serial.print("\tn = show netlist\n\r");
@ -173,13 +170,31 @@ dontshowmenu:
if (showReadings >= 1)
{
showMeasurements();
//Serial.print("\n\n\r");
//showLEDsCore2 = 1;
// Serial.print("\n\n\r");
// showLEDsCore2 = 1;
}
if (BOOTSEL)
{
lastNetConfirm(1);
}
// if (tud_connected() == 0 && millis() > 1000)
// {
// input = 'p';
// //clearNodeFile();
// goto skipinput;
// }
if (millis() % 100 == 0)
{
startProbe();
if (readFloatingOrState(18) == 3)
{
input = 'p';
probingTimer = millis();
// delay(500);
goto skipinput;
}
pinMode(19, INPUT);
}
}
if (connectFromArduino != '\0')
@ -235,43 +250,154 @@ skipinput:
}
case 'p':
{
//clearLEDs();
int lastRow[10];
int pokedNumber = 0;
Serial.print("Press any key to exit\n\n\r");
while(Serial.available() == 0){
int row = scanRows(0);
// clearLEDs();
int lastRow[10];
int pokedNumber = 0;
Serial.print("Press any key to exit and commit paths (or touch probe to gpio 18)\n\n\r");
rawOtherColors[1] = 0x3500A8;
// Serial.print(numberOfNets);
if (row != -1 )
{
if (numberOfNets == 0)
{
clearNodeFile();
}
clearAllNTCC();
openNodeFile();
getNodesToConnect();
delay(10);
lastRow[pokedNumber] = row;
pokedNumber++;
bridgesToPaths();
// clearLEDs();
assignNetColors();
delay(18);
showLEDsCore2 = 1;
delay(28);
int probedNodes[40][2];
int probedNodesIndex = 0;
printNodeOrName(row);
Serial.print("\r\t");
if (pokedNumber >= 2)
int row = 0;
while (Serial.available() == 0)
{
delayMicroseconds(9700);
row = scanRows(0);
if (row != -1)
{
if (row == -18 && millis() - probingTimer > 800)
{
Serial.print("\r \r");
printNodeOrName(lastRow[0]);
Serial.print(" - ");
printNodeOrName(lastRow[1]);
Serial.print("\n\r");
scanRows(0, true);
delay(18);
pokedNumber = 0;
Serial.print("\n\rCommitting paths!\n\r");
break;
}
}
delayMicroseconds(1000);
else if (row == -18)
{
continue;
}
delay(10);
lastRow[pokedNumber] = row;
probedNodes[probedNodesIndex][pokedNumber] = row;
}
pinMode(19, INPUT);
pokedNumber++;
printNodeOrName(row);
Serial.print("\r\t");
if (pokedNumber >= 2)
{
Serial.print("\r \r");
printNodeOrName(probedNodes[probedNodesIndex][0]);
Serial.print(" - ");
printNodeOrName(probedNodes[probedNodesIndex][1]);
Serial.print("\n\r");
Serial.print("\n\r");
for (int i = 0; i < probedNodesIndex; i++)
{
/// Serial.print("\n\r");
if ((probedNodes[i][0] == probedNodes[probedNodesIndex][0] && probedNodes[i][1] == probedNodes[probedNodesIndex][1]) || (probedNodes[i][0] == probedNodes[probedNodesIndex][1] && probedNodes[i][1] == probedNodes[probedNodesIndex][0]))
{
probedNodes[probedNodesIndex][0] = 0;
probedNodes[probedNodesIndex][1] = 0;
leds.setPixelColor(nodesToPixelMap[probedNodes[i][0]], 0);
leds.setPixelColor(nodesToPixelMap[probedNodes[i][1]], 0);
for (int j = i; j < probedNodesIndex; j++)
{
probedNodes[j][0] = probedNodes[j + 1][0];
probedNodes[j][1] = probedNodes[j + 1][1];
}
// probedNodes[i][0] = -1;
// probedNodes[i][1] = -1;
pokedNumber = 0;
showLEDsCore2 = 1;
probedNodesIndex--;
probedNodesIndex--;
break;
}
}
// Serial.print("\n\n\n\r");
// Serial.print("\r \r");
// printNodeOrName(probedNodes[probedNodesIndex][0]);
// Serial.print(" - ");
// printNodeOrName(probedNodes[probedNodesIndex][1]);
// Serial.print("\n\r");
for (int i = probedNodesIndex; i >= 0; i--)
{
// Serial.print (" ");
// Serial.print (i);
Serial.print("\t");
printNodeOrName(probedNodes[i][0]);
Serial.print(" - ");
printNodeOrName(probedNodes[i][1]);
Serial.print("\n\r");
}
Serial.print("\n\n\r");
// delay(18);
pokedNumber = 0;
probedNodesIndex++;
// clearLEDs();
// openNodeFile();
// getNodesToConnect();
// bridgesToPaths();
/// assignNetColors();
delay(8);
// showLEDsCore2 = 1;
// delay(18);
scanRows(0, true);
}
}
}
for (int i = 0; i < probedNodesIndex; i++)
{
addBridgeToNodeFile(probedNodes[i][0], probedNodes[i][1]);
}
clearAllNTCC();
openNodeFile();
getNodesToConnect();
bridgesToPaths();
// clearLEDs();
assignNetColors();
// Serial.print("bridgesToPaths\n\r");
delay(18);
// showNets();
rawOtherColors[1] = 0x550008;
sendAllPathsCore2 = 1;
delay(25);
pinMode(19, INPUT);
delay(300);
break;
}
case 'n':
@ -374,47 +500,6 @@ skipinput:
goto menu;
break;
// case 'p':
// // case '{': //I had this so you could paste a wokwi diagram from the main menu but it kinda makes a mess of other things
// digitalWrite(RESETPIN, HIGH);
// delay(1);
// #ifdef FSSTUFF
// clearNodeFile();
// #endif
// digitalWrite(RESETPIN, LOW);
// clearAllNTCC();
// clearLEDs();
// timer = millis();
// #ifdef FSSTUFF
// parseWokwiFileToNodeFile();
// openNodeFile();
// getNodesToConnect();
// #endif
// Serial.println("\n\n\rnetlist\n\n\r");
// bridgesToPaths();
// assignNetColors();
// #ifdef PIOSTUFF
// sendAllPaths();
// #endif
// if (debugNMtime)
// {
// Serial.print("\n\n\r");
// Serial.print("took ");
// Serial.print(millis() - timer);
// Serial.print("ms");
// }
// break;
case 't':
#ifdef FSSTUFF
clearNodeFile();
@ -561,21 +646,20 @@ skipinput:
// #include <string> // Include the necessary header file
void lastNetConfirm(int forceLastNet)
{
while (tud_connected() == 0 && millis() < 500)
;
// while (tud_connected() == 0 && millis() < 500)
// ;
if (millis() - lastNetConfirmTimer < 3000 && tud_connected() == 1)
{
//Serial.println(lastNetConfirmTimer);
// if (millis() - lastNetConfirmTimer < 3000 && tud_connected() == 1)
// {
// // Serial.println(lastNetConfirmTimer);
//lastNetConfirmTimer = millis();
return;
}
// // lastNetConfirmTimer = millis();
// return;
// }
if (tud_connected() == 0 || forceLastNet == 1)
if (forceLastNet == 1)
{
int bootselPressed = 0;
@ -595,7 +679,7 @@ void lastNetConfirm(int forceLastNet)
bootselPressed = 1;
}
while (tud_connected() == 0 || forceLastNet == 1)
while (forceLastNet == 1)
{
if (BOOTSEL)
bootselPressed = 1;
@ -607,7 +691,7 @@ void lastNetConfirm(int forceLastNet)
sendAllPathsCore2 = 1;
if (BOOTSEL)
bootselPressed = 1;
//delay(250);
// delay(250);
if (bootselPressed == 1)
{
@ -616,7 +700,6 @@ void lastNetConfirm(int forceLastNet)
while (BOOTSEL)
{
sendAllPathsCore2 = 1;
delay(250);
clearLEDs();
@ -627,18 +710,20 @@ void lastNetConfirm(int forceLastNet)
clearAllNTCC();
clearLEDs();
startupColors();
clearNodeFile();
sendAllPathsCore2 = 1;
lastNetConfirmTimer = millis();
//delay(1000);
restoredNodeFile = 0;
// delay(1000);
return;
}
delay(fade * 10);
fade--;
}
digitalWrite(RESETPIN, LOW);
restoredNodeFile = 1;
sendAllPathsCore2 = 1;
return;
}
@ -653,23 +738,18 @@ void machineMode(void) // read in commands in machine readable format
{
int sequenceNumber = -1;
lastTimeCommandRecieved = millis();
lastTimeCommandRecieved = millis();
if (millis() - lastTimeCommandRecieved > 100)
{
machineModeRespond(sequenceNumber, true);
return;
}
if (millis() - lastTimeCommandRecieved > 100)
{
machineModeRespond(sequenceNumber, true);
return;
}
enum machineModeInstruction receivedInstruction = parseMachineInstructions(&sequenceNumber);
// Serial.print("receivedInstruction: ");
// Serial.print(receivedInstruction);
// Serial.print("\n\r");
// Serial.print("receivedInstruction: ");
// Serial.print(receivedInstruction);
// Serial.print("\n\r");
switch (receivedInstruction)
{
@ -690,15 +770,17 @@ if (millis() - lastTimeCommandRecieved > 100)
break;
case getnetlist:
if (millis() - lastTimeNetlistLoaded > 300)
{
if (millis() - lastTimeNetlistLoaded > 300)
{
listNetsMachine();
} else {
machineModeRespond(0, true);
//Serial.print ("too soon bro\n\r");
return;
}
listNetsMachine();
}
else
{
machineModeRespond(0, true);
// Serial.print ("too soon bro\n\r");
return;
}
break;
case bridgelist:
@ -742,24 +824,24 @@ if (millis() - lastTimeCommandRecieved > 100)
case setsupplyswitch:
supplySwitchPosition = setSupplySwitch();
//printSupplySwitch(supplySwitchPosition);
// printSupplySwitch(supplySwitchPosition);
machineModeRespond(sequenceNumber, true);
showLEDsCore2 = 1;
break;
case getsupplyswitch:
//if (millis() - lastTimeNetlistLoaded > 100)
//{
// if (millis() - lastTimeNetlistLoaded > 100)
//{
printSupplySwitch(supplySwitchPosition);
//machineModeRespond(sequenceNumber, true);
// machineModeRespond(sequenceNumber, true);
// }else {
//Serial.print ("\n\rtoo soon bro\n\r");
// machineModeRespond(0, true);
// return;
// }
// }else {
// Serial.print ("\n\rtoo soon bro\n\r");
// machineModeRespond(0, true);
// return;
// }
break;
case getchipstatus:
@ -876,8 +958,8 @@ void loop1() // core 2 handles the LEDs and the CH446Q8
{
input = 'f';
//connectFromArduino = 'f';
// Serial.print("!!!!");
// connectFromArduino = 'f';
// Serial.print("!!!!");
}
else
{