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); delayMicroseconds(40);
} }
int probeHalfPeriodus = 10;
int readFloatingOrState(int pin, int rowBeingScanned) int readFloatingOrState(int pin, int rowBeingScanned)
{ {
@ -263,21 +265,21 @@ int readFloatingOrState(int pin, int rowBeingScanned)
pinMode(pin, INPUT_PULLUP); pinMode(pin, INPUT_PULLUP);
delayMicroseconds(200); delayMicroseconds(100);
readingPullup = digitalRead(pin); readingPullup = digitalRead(pin);
delayMicroseconds(10); delayMicroseconds(probeHalfPeriodus);
readingPullup2 = digitalRead(pin); readingPullup2 = digitalRead(pin);
delayMicroseconds(5); delayMicroseconds(probeHalfPeriodus / 2);
readingPullup3 = digitalRead(pin); readingPullup3 = digitalRead(pin);
pinMode(pin, INPUT_PULLDOWN); pinMode(pin, INPUT_PULLDOWN);
delayMicroseconds(200); delayMicroseconds(100);
readingPulldown = digitalRead(pin); readingPulldown = digitalRead(pin);
delayMicroseconds(10); delayMicroseconds(probeHalfPeriodus);
readingPulldown2 = digitalRead(pin); readingPulldown2 = digitalRead(pin);
delayMicroseconds(5); delayMicroseconds(probeHalfPeriodus / 2);
readingPulldown3 = digitalRead(pin); readingPulldown3 = digitalRead(pin);
if (readingPullup != readingPullup2 || readingPullup2 != readingPullup3 && rowBeingScanned != -1) if (readingPullup != readingPullup2 || readingPullup2 != readingPullup3 && rowBeingScanned != -1)
@ -286,9 +288,10 @@ int readFloatingOrState(int pin, int rowBeingScanned)
{ {
state = probe; 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"); // Serial.print("probe");
leds.show(); //
} }
} }
else else
@ -326,26 +329,60 @@ int readFloatingOrState(int pin, int rowBeingScanned)
return state; return state;
} }
void startProbe(void) void startProbe(int probeSpeed)
{ {
probeHalfPeriodus = 1000000 / probeSpeed / 2;
pinMode(19, OUTPUT); pinMode(19, OUTPUT);
analogWriteFreq(50000); analogWriteFreq(probeSpeed);
analogWrite(19, 128); 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) int scanRows(int pin, bool clearLastFound)
{ {
static int lastFound = -1;
int found = -1; int found = -1;
if (clearLastFound) 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; return -1;
} }
digitalWrite(RESETPIN, HIGH); digitalWrite(RESETPIN, HIGH);
delayMicroseconds(10); delayMicroseconds(10);
digitalWrite(RESETPIN, LOW); digitalWrite(RESETPIN, LOW);
@ -390,30 +427,41 @@ int scanRows(int pin, bool clearLastFound)
// analogRead(ADC0_PIN); // analogRead(ADC0_PIN);
rowBeingScanned = ch[chipScan].yMap[yToScan]; rowBeingScanned = ch[chipScan].yMap[yToScan];
if (readFloatingOrState(pin, rowBeingScanned) == probe && rowBeingScanned != lastFound) if (readFloatingOrState(pin, rowBeingScanned) == probe && rowBeingScanned != lastFound[0])
{ {
found = rowBeingScanned; 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, 0, 0);
sendXYraw(chipScan, 0, yToScan, 0); sendXYraw(chipScan, 0, yToScan, 0);
// if (found != -1) if (found != -1)
// { {
// break; break;
// } }
} }
sendXYraw(CHIP_L, 2, chipScan, 0); sendXYraw(CHIP_L, 2, chipScan, 0);
if (found != -1)
{
return found;
}
} }
int corners[4] = {1, 30, 31, 60}; int corners[4] = {1, 30, 31, 60};
@ -426,36 +474,103 @@ int scanRows(int pin, bool clearLastFound)
// analogRead(ADC0_PIN); // analogRead(ADC0_PIN);
rowBeingScanned = corners[cornerScan]; rowBeingScanned = corners[cornerScan];
if (readFloatingOrState(pin, rowBeingScanned) == probe && rowBeingScanned != lastFound) if (readFloatingOrState(pin, rowBeingScanned) == probe && rowBeingScanned != lastFound[0])
{ {
found = rowBeingScanned; 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); sendXYraw(CHIP_L, cornerScan + 8, 0, 0);
// if (found != -1) if (found != -1)
// { {
// break; break;
// } }
} }
sendXYraw(CHIP_L, xMapRead, 0, 0); sendXYraw(CHIP_L, xMapRead, 0, 0);
int gp18read = readFloatingOrState(18, -1);
if (gp18read == probe)
{
return -18;
}
pinMode(19, INPUT); pinMode(19, INPUT);
delayMicroseconds(400); delayMicroseconds(400);
int probeRead = readFloatingOrState(19, -1); int probeRead = readFloatingOrState(19, -1);
if (probeRead == high && lastFound != SUPPLY_3V3) if (probeRead == high && ((lastFound[0] != SUPPLY_3V3 )))
{ {
found = SUPPLY_3V3; found = SUPPLY_3V3;
lastFound = found; if (justCleared)
{
nextIsSupply = 1;
//justCleared = 0;
} }
else if (probeRead == low && lastFound != GND) 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; found = GND;
lastFound = found; 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;
}
return found; return found;
// return 0; // return 0;

View File

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

View File

@ -402,8 +402,79 @@ void changeWokwiDefinesToJumperless(void)
void clearNodeFile(void) void clearNodeFile(void)
{ {
LittleFS.remove("nodeFile.txt"); 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) void writeToNodeFile(void)
{ {

View File

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

View File

@ -1,6 +1,5 @@
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
#include <Arduino.h> #include <Arduino.h>
#define USE_TINYUSB 1 #define USE_TINYUSB 1
@ -53,7 +52,6 @@ int supplySwitchPosition = 0;
void machineMode(void); void machineMode(void);
void lastNetConfirm(int forceLastNet = 0); void lastNetConfirm(int forceLastNet = 0);
unsigned long lastNetConfirmTimer = 0; unsigned long lastNetConfirmTimer = 0;
// int machineMode = 0; // int machineMode = 0;
@ -77,7 +75,6 @@ void setup()
USBSer1.setStringDescriptor("Jumperless USB Serial"); USBSer1.setStringDescriptor("Jumperless USB Serial");
USBSer1.begin(115200); USBSer1.begin(115200);
#ifdef EEPROMSTUFF #ifdef EEPROMSTUFF
@ -104,9 +101,7 @@ void setup()
clearAllNTCC(); clearAllNTCC();
lastNetConfirm(0); // lastNetConfirm(0);
} }
void setup1() void setup1()
@ -134,8 +129,10 @@ char input;
int serSource = 0; int serSource = 0;
int readInNodesArduino = 0; int readInNodesArduino = 0;
int baudRate = 115200; 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() void loop()
{ {
@ -180,6 +177,24 @@ dontshowmenu:
{ {
lastNetConfirm(1); 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') if (connectFromArduino != '\0')
@ -238,40 +253,151 @@ skipinput:
// clearLEDs(); // clearLEDs();
int lastRow[10]; int lastRow[10];
int pokedNumber = 0; int pokedNumber = 0;
Serial.print("Press any key to exit\n\n\r"); Serial.print("Press any key to exit and commit paths (or touch probe to gpio 18)\n\n\r");
while(Serial.available() == 0){ rawOtherColors[1] = 0x3500A8;
int row = scanRows(0); // Serial.print(numberOfNets);
if (numberOfNets == 0)
{
clearNodeFile();
}
clearAllNTCC();
openNodeFile();
getNodesToConnect();
bridgesToPaths();
// clearLEDs();
assignNetColors();
delay(18);
showLEDsCore2 = 1;
delay(28);
int probedNodes[40][2];
int probedNodesIndex = 0;
int row = 0;
while (Serial.available() == 0)
{
delayMicroseconds(9700);
row = scanRows(0);
if (row != -1) if (row != -1)
{ {
if (row == -18 && millis() - probingTimer > 800)
{
Serial.print("\n\rCommitting paths!\n\r");
break;
}
else if (row == -18)
{
continue;
}
delay(10); delay(10);
lastRow[pokedNumber] = row; lastRow[pokedNumber] = row;
probedNodes[probedNodesIndex][pokedNumber] = row;
pokedNumber++; pokedNumber++;
printNodeOrName(row); printNodeOrName(row);
Serial.print("\r\t"); Serial.print("\r\t");
if (pokedNumber >= 2) if (pokedNumber >= 2)
{ {
Serial.print("\r \r"); Serial.print("\r \r");
printNodeOrName(lastRow[0]); printNodeOrName(probedNodes[probedNodesIndex][0]);
Serial.print(" - "); Serial.print(" - ");
printNodeOrName(lastRow[1]); printNodeOrName(probedNodes[probedNodesIndex][1]);
Serial.print("\n\r"); Serial.print("\n\r");
scanRows(0, true);
delay(18);
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; pokedNumber = 0;
}
}
delayMicroseconds(1000);
}
pinMode(19, INPUT);
showLEDsCore2 = 1;
probedNodesIndex--;
probedNodesIndex--;
break; 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': case 'n':
@ -374,47 +500,6 @@ skipinput:
goto menu; goto menu;
break; 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': case 't':
#ifdef FSSTUFF #ifdef FSSTUFF
clearNodeFile(); clearNodeFile();
@ -561,21 +646,20 @@ skipinput:
// #include <string> // Include the necessary header file // #include <string> // Include the necessary header file
void lastNetConfirm(int forceLastNet) void lastNetConfirm(int forceLastNet)
{ {
while (tud_connected() == 0 && millis() < 500) // while (tud_connected() == 0 && millis() < 500)
; // ;
if (millis() - lastNetConfirmTimer < 3000 && tud_connected() == 1) // if (millis() - lastNetConfirmTimer < 3000 && tud_connected() == 1)
{ // {
//Serial.println(lastNetConfirmTimer); // // Serial.println(lastNetConfirmTimer);
//lastNetConfirmTimer = millis(); // // lastNetConfirmTimer = millis();
return; // return;
} // }
if (tud_connected() == 0 || forceLastNet == 1) if (forceLastNet == 1)
{ {
int bootselPressed = 0; int bootselPressed = 0;
@ -595,7 +679,7 @@ void lastNetConfirm(int forceLastNet)
bootselPressed = 1; bootselPressed = 1;
} }
while (tud_connected() == 0 || forceLastNet == 1) while (forceLastNet == 1)
{ {
if (BOOTSEL) if (BOOTSEL)
bootselPressed = 1; bootselPressed = 1;
@ -616,7 +700,6 @@ void lastNetConfirm(int forceLastNet)
while (BOOTSEL) while (BOOTSEL)
{ {
sendAllPathsCore2 = 1; sendAllPathsCore2 = 1;
delay(250); delay(250);
clearLEDs(); clearLEDs();
@ -627,18 +710,20 @@ void lastNetConfirm(int forceLastNet)
clearAllNTCC(); clearAllNTCC();
clearLEDs(); clearLEDs();
startupColors(); startupColors();
clearNodeFile();
sendAllPathsCore2 = 1; sendAllPathsCore2 = 1;
lastNetConfirmTimer = millis(); lastNetConfirmTimer = millis();
restoredNodeFile = 0;
// delay(1000); // delay(1000);
return; return;
} }
delay(fade * 10); delay(fade * 10);
fade--; fade--;
} }
digitalWrite(RESETPIN, LOW); digitalWrite(RESETPIN, LOW);
restoredNodeFile = 1;
sendAllPathsCore2 = 1; sendAllPathsCore2 = 1;
return; return;
} }
@ -662,15 +747,10 @@ if (millis() - lastTimeCommandRecieved > 100)
} }
enum machineModeInstruction receivedInstruction = parseMachineInstructions(&sequenceNumber); enum machineModeInstruction receivedInstruction = parseMachineInstructions(&sequenceNumber);
// Serial.print("receivedInstruction: "); // Serial.print("receivedInstruction: ");
// Serial.print(receivedInstruction); // Serial.print(receivedInstruction);
// Serial.print("\n\r"); // Serial.print("\n\r");
switch (receivedInstruction) switch (receivedInstruction)
{ {
case netlist: case netlist:
@ -694,7 +774,9 @@ if (millis() - lastTimeCommandRecieved > 100)
{ {
listNetsMachine(); listNetsMachine();
} else { }
else
{
machineModeRespond(0, true); machineModeRespond(0, true);
// Serial.print ("too soon bro\n\r"); // Serial.print ("too soon bro\n\r");
return; return;