From 43a8d674dc723e491f90499696a4d6cfe3ba16a0 Mon Sep 17 00:00:00 2001 From: Kevin Santo Cappuccio Date: Fri, 12 Jan 2024 14:23:16 -0800 Subject: [PATCH] Add "load last net" if connected to a power bank with no USB host --- JumperlessNano/src/FileParsing.cpp | 27 ++ JumperlessNano/src/FileParsing.h | 2 +- JumperlessNano/src/LEDs.cpp | 2 +- JumperlessNano/src/main.cpp | 688 ++++++++++++++++------------- 4 files changed, 399 insertions(+), 320 deletions(-) diff --git a/JumperlessNano/src/FileParsing.cpp b/JumperlessNano/src/FileParsing.cpp index aab7446..0e6b6e7 100644 --- a/JumperlessNano/src/FileParsing.cpp +++ b/JumperlessNano/src/FileParsing.cpp @@ -84,6 +84,33 @@ void savePreformattedNodeFile(int source) nodeFile.close(); } + +void printNodeFile(void) +{ + 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"); + } + nodeFileString.clear(); + + nodeFileString.read(nodeFile); + + nodeFile.close(); + + Serial.println(nodeFileString); + + nodeFileString.clear(); +} + + void parseWokwiFileToNodeFile(void) { diff --git a/JumperlessNano/src/FileParsing.h b/JumperlessNano/src/FileParsing.h index 366e128..8427e86 100644 --- a/JumperlessNano/src/FileParsing.h +++ b/JumperlessNano/src/FileParsing.h @@ -29,7 +29,7 @@ void openNodeFile(); void splitStringToFields(); void replaceSFNamesWithDefinedInts(); - +void printNodeFile(void); void replaceNanoNamesWithDefinedInts(); void parseStringToBridges(); diff --git a/JumperlessNano/src/LEDs.cpp b/JumperlessNano/src/LEDs.cpp index 27ade7e..6ce4d0d 100644 --- a/JumperlessNano/src/LEDs.cpp +++ b/JumperlessNano/src/LEDs.cpp @@ -1578,7 +1578,7 @@ struct rgbColor unpackRgb(uint32_t color) } void clearLEDs(void) { - for (int i = 0; i <= 254; i++) + for (int i = 0; i <= 116; i++) { // For each pixel in strip... leds.setPixelColor(i, 0); // Set pixel's color (in RAM) diff --git a/JumperlessNano/src/main.cpp b/JumperlessNano/src/main.cpp index 1c61e80..ac4ab60 100644 --- a/JumperlessNano/src/main.cpp +++ b/JumperlessNano/src/main.cpp @@ -94,7 +94,65 @@ void setup() setDac1_8Vvoltage(1.9); clearAllNTCC(); - delay(4); + while (tud_connected() == 0 && millis() < 500); + + if (tud_connected() == 0 ) + { + + int bootselPressed = 0; + openNodeFile(); + getNodesToConnect(); + // Serial.print("openNF\n\r"); + digitalWrite(RESETPIN, HIGH); + bridgesToPaths(); + clearLEDs(); + assignNetColors(); + + sendAllPathsCore2 = 1; + + delay(250); + if (BOOTSEL) + { + bootselPressed = 1; + + } + + while (tud_connected() == 0 ) + { + if (BOOTSEL) bootselPressed = 1; + clearLEDs(); + showLEDsCore2 = 1; + if (BOOTSEL) bootselPressed = 1; + delay(250); + sendAllPathsCore2 = 1; + if (BOOTSEL) bootselPressed = 1; + delay(250); + + if (bootselPressed == 1) + { + unsigned long longPressTimer = millis(); + while (BOOTSEL) + { + if (millis() - longPressTimer > 1500) + { + clearAllNTCC(); + clearLEDs(); + sendAllPathsCore2 = 1; + break; + } + + } + + digitalWrite(RESETPIN, LOW); + sendAllPathsCore2 = 1; + break; + } + + } + } + + + } void setup1() @@ -130,370 +188,365 @@ void loop() menu: // showMeasurements(); + // unsigned long connecttimer = 0; + // // while (tud_connected() == 0) + // // { + // // connecttimer = millis(); + + // // } +Serial.print("\n\n\r\t\t\tMenu\n\n\r"); +Serial.print("\tn = show netlist\n\r"); +Serial.print("\tb = show bridge array\n\r"); +Serial.print("\tw = waveGen\n\r"); +Serial.print("\tv = toggle show current/voltage\n\r"); +Serial.print("\tf = load formatted nodeFile\n\r"); +Serial.print("\tu = set baud rate for USB-Serial\n\r"); +Serial.print("\tl = LED brightness / test\n\r"); +Serial.print("\td = toggle debug flags\n\r"); +Serial.print("\tr = reset Arduino\n\r"); +Serial.print("\n\n\r"); - Serial.print("\n\n\r\t\t\tMenu\n\n\r"); - Serial.print("\tn = show netlist\n\r"); - Serial.print("\tb = show bridge array\n\r"); - Serial.print("\tw = waveGen\n\r"); - Serial.print("\tv = toggle show current/voltage\n\r"); - Serial.print("\tf = load formatted nodeFile\n\r"); - Serial.print("\tu = set baud rate for USB-Serial\n\r"); - Serial.print("\tl = LED brightness / test\n\r"); - Serial.print("\td = toggle debug flags\n\r"); - Serial.print("\tr = reset Arduino\n\r"); - Serial.print("\n\n\r"); +dontshowmenu : connectFromArduino = '\0'; -dontshowmenu: - connectFromArduino = '\0'; - - while (Serial.available() == 0 && connectFromArduino == '\0') +while (Serial.available() == 0 && connectFromArduino == '\0') +{ + if (showReadings >= 1) { - if (showReadings >= 1) - { - showMeasurements(); - } + showMeasurements(); + } +} + +if (connectFromArduino != '\0') +{ + input = 'f'; + // connectFromArduino = '\0'; +} +else +{ + input = Serial.read(); + Serial.print("\n\r"); +} + +// Serial.print(input); +skipinput : switch (input) +{ +case 'v': + + if (showReadings >= 3 || (inaConnected == 0 && showReadings >= 1)) + { + showReadings = 0; + break; + } + else + { + showReadings++; + + chooseShownReadings(); + // Serial.println(showReadings); + + // Serial.write("\033"); //these VT100/ANSI commands work on some terminals and not others so I took it out + // Serial.write("\x1B\x5B"); + // Serial.write("1F");//scroll up one line + // Serial.write("\x1B\x5B"); + // Serial.write("\033"); + // Serial.write("2K");//clear line + // Serial.write("\033"); + // Serial.write("\x1B\x5B"); + // Serial.write("1F");//scroll up one line + // Serial.write("\x1B\x5B"); + // Serial.write("\033"); + // Serial.write("2K");//clear line + + goto dontshowmenu; + // break; + } + +case 'n': + + Serial.print("\n\n\rnetlist\n\n\r"); + listSpecialNets(); + listNets(); + + break; +case 'b': + Serial.print("\n\n\rBridge Array\n\r"); + printBridgeArray(); + Serial.print("\n\n\n\rPaths\n\r"); + printPathsCompact(); + Serial.print("\n\n\rChip Status\n\r"); + printChipStatus(); + Serial.print("\n\n\r"); + Serial.print("Revision "); + Serial.print(revisionNumber); + Serial.print("\n\n\r"); + break; + +case 'm': + + break; + +case '!': + printNodeFile(); + break; + +case 'w': + + if (waveGen() == 1) + { + break; + } + + // case 'a': + // { + // resetArduino(); // reset works + // // uploadArduino(); //this is unwritten + // } + +case 'f': + readInNodesArduino = 1; + clearAllNTCC(); + + // sendAllPathsCore2 = 1; + timer = millis(); + + clearNodeFile(); + + if (connectFromArduino != '\0') + { + serSource = 1; + } + else + { + serSource = 0; + } + + savePreformattedNodeFile(serSource); + + // Serial.print("savePFNF\n\r"); + openNodeFile(); + getNodesToConnect(); + // Serial.print("openNF\n\r"); + digitalWrite(RESETPIN, HIGH); + bridgesToPaths(); + clearLEDs(); + assignNetColors(); + // Serial.print("bridgesToPaths\n\r"); + digitalWrite(RESETPIN, LOW); + // showNets(); + + sendAllPathsCore2 = 1; + + if (debugNMtime) + { + Serial.print("\n\n\r"); + Serial.print("took "); + Serial.print(millis() - timer); + Serial.print("ms"); } if (connectFromArduino != '\0') { - input = 'f'; - // connectFromArduino = '\0'; - } - else - { - input = Serial.read(); - Serial.print("\n\r"); - } - - // Serial.print(input); -skipinput: - switch (input) - { - case 'v': - - if (showReadings >= 3 || (inaConnected == 0 && showReadings >= 1)) - { - showReadings = 0; - break; - } - else - { - showReadings++; - - chooseShownReadings(); - //Serial.println(showReadings); - - - - // Serial.write("\033"); //these VT100/ANSI commands work on some terminals and not others so I took it out - // Serial.write("\x1B\x5B"); - // Serial.write("1F");//scroll up one line - // Serial.write("\x1B\x5B"); - // Serial.write("\033"); - // Serial.write("2K");//clear line - // Serial.write("\033"); - // Serial.write("\x1B\x5B"); - // Serial.write("1F");//scroll up one line - // Serial.write("\x1B\x5B"); - // Serial.write("\033"); - // Serial.write("2K");//clear line - - goto dontshowmenu; - // break; - } - - case 'n': - - Serial.print("\n\n\rnetlist\n\n\r"); - listSpecialNets(); - listNets(); - - break; - case 'b': - Serial.print("\n\n\rBridge Array\n\r"); - printBridgeArray(); - Serial.print("\n\n\n\rPaths\n\r"); - printPathsCompact(); - Serial.print("\n\n\rChip Status\n\r"); - printChipStatus(); - Serial.print("\n\n\r"); - Serial.print("Revision "); - Serial.print(revisionNumber); - Serial.print("\n\n\r"); - break; - - case 'm': - - break; - - case 'w': - - if (waveGen() == 1) - { - break; - } - - // case 'a': - // { - // resetArduino(); // reset works - // // uploadArduino(); //this is unwritten - // } - - case 'f': - readInNodesArduino = 1; - clearAllNTCC(); - - // sendAllPathsCore2 = 1; - timer = millis(); - - clearNodeFile(); - - if (connectFromArduino != '\0') - { - serSource = 1; - } - else - { - serSource = 0; - } - - savePreformattedNodeFile(serSource); - - // Serial.print("savePFNF\n\r"); - openNodeFile(); - getNodesToConnect(); - // Serial.print("openNF\n\r"); - digitalWrite(RESETPIN, HIGH); - bridgesToPaths(); - clearLEDs(); - assignNetColors(); - // Serial.print("bridgesToPaths\n\r"); - digitalWrite(RESETPIN, LOW); - // showNets(); - - sendAllPathsCore2 = 1; - - if (debugNMtime) - { - Serial.print("\n\n\r"); - Serial.print("took "); - Serial.print(millis() - timer); - Serial.print("ms"); - } - - if (connectFromArduino != '\0') - { - connectFromArduino = '\0'; - // Serial.print("connectFromArduino\n\r"); - // delay(2000); - input = ' '; - readInNodesArduino = 0; - goto dontshowmenu; - } - + connectFromArduino = '\0'; + // Serial.print("connectFromArduino\n\r"); + // delay(2000); + input = ' '; readInNodesArduino = 0; - break; + goto dontshowmenu; + } - case '\n': - goto menu; - break; + readInNodesArduino = 0; + break; - case 'p': +case '\n': + goto menu; + break; - // case '{': //I had this so you could paste a wokwi diagram from the main menu but it kinda makes a mess of other things +case 'p': - digitalWrite(RESETPIN, HIGH); - delay(1); + // 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(); + clearNodeFile(); #endif - digitalWrite(RESETPIN, LOW); - clearAllNTCC(); - clearLEDs(); + digitalWrite(RESETPIN, LOW); + clearAllNTCC(); + clearLEDs(); - timer = millis(); + timer = millis(); #ifdef FSSTUFF - parseWokwiFileToNodeFile(); + parseWokwiFileToNodeFile(); - openNodeFile(); - getNodesToConnect(); + openNodeFile(); + getNodesToConnect(); #endif - Serial.println("\n\n\rnetlist\n\n\r"); + Serial.println("\n\n\rnetlist\n\n\r"); - bridgesToPaths(); - assignNetColors(); + bridgesToPaths(); + assignNetColors(); #ifdef PIOSTUFF - sendAllPaths(); + sendAllPaths(); #endif - if (debugNMtime) - { - Serial.print("\n\n\r"); - Serial.print("took "); - Serial.print(millis() - timer); - Serial.print("ms"); - } - break; + if (debugNMtime) + { + Serial.print("\n\n\r"); + Serial.print("took "); + Serial.print(millis() - timer); + Serial.print("ms"); + } + break; - case 't': +case 't': #ifdef FSSTUFF - clearNodeFile(); + clearNodeFile(); #endif #ifdef EEPROMSTUFF - lastCommandWrite(input); + lastCommandWrite(input); - runCommandAfterReset('t'); + runCommandAfterReset('t'); #endif #ifdef FSSTUFF - openNodeFile(); - getNodesToConnect(); + openNodeFile(); + getNodesToConnect(); #endif - Serial.println("\n\n\rnetlist\n\n\r"); + Serial.println("\n\n\rnetlist\n\n\r"); - bridgesToPaths(); + bridgesToPaths(); - listSpecialNets(); - listNets(); - printBridgeArray(); - Serial.print("\n\n\r"); - Serial.print(numberOfNets); + listSpecialNets(); + listNets(); + printBridgeArray(); + Serial.print("\n\n\r"); + Serial.print(numberOfNets); - Serial.print("\n\n\r"); - Serial.print(numberOfPaths); + Serial.print("\n\n\r"); + Serial.print(numberOfPaths); - assignNetColors(); + assignNetColors(); #ifdef PIOSTUFF - sendAllPaths(); + sendAllPaths(); #endif - break; + break; - case 'l': - if (LEDbrightnessMenu() == '!') - { - clearLEDs(); - delayMicroseconds(9200); - sendAllPathsCore2 = 1; - } - break; - - case 'r': - - resetArduino(); - - break; - - - case 'u': - Serial.print("\n\r"); - Serial.print("enter baud rate\n\r"); - while (Serial.available() == 0) - ; - baudRate = Serial.parseInt(); - Serial.print("\n\r"); - Serial.print("setting baud rate to "); - Serial.print(baudRate); - Serial.print("\n\r"); - - - - - - - - - setBaudRate(baudRate); - break; - - - - case 'd': +case 'l': + if (LEDbrightnessMenu() == '!') { - debugFlagInit(); - - debugFlags: - - Serial.print("\n\r0. all off"); - Serial.print("\n\r9. all on"); - Serial.print("\n\ra-z. exit\n\r"); - - Serial.print("\n\r1. file parsing = "); - Serial.print(debugFP); - Serial.print("\n\r2. file parsing time = "); - Serial.print(debugFPtime); - - Serial.print("\n\r3. net manager = "); - Serial.print(debugNM); - Serial.print("\n\r4. net manager time = "); - Serial.print(debugNMtime); - - Serial.print("\n\r5. chip connections = "); - Serial.print(debugNTCC); - Serial.print("\n\r6. chip conns alt paths = "); - Serial.print(debugNTCC2); - Serial.print("\n\r7. LEDs = "); - Serial.print(debugLEDs); - - Serial.print("\n\n\r"); - - while (Serial.available() == 0) - ; - - int toggleDebug = Serial.read(); - Serial.write(toggleDebug); - toggleDebug -= '0'; - - if (toggleDebug >= 0 && toggleDebug <= 9) - { - - debugFlagSet(toggleDebug); - - delay(10); - - goto debugFlags; - } - else - { - break; - } + clearLEDs(); + delayMicroseconds(9200); + sendAllPathsCore2 = 1; } + break; - case ':': +case 'r': - if (Serial.read() == ':') - { - // Serial.print("\n\r"); - // Serial.print("entering machine mode\n\r"); - machineMode(); - showLEDsCore2 = 1; - goto dontshowmenu; - break; - } - else - { - break; - } + resetArduino(); - default: - while (Serial.available() > 0) - { - int f = Serial.read(); - delayMicroseconds(50); - } + break; +case 'u': + Serial.print("\n\r"); + Serial.print("enter baud rate\n\r"); + while (Serial.available() == 0) + ; + baudRate = Serial.parseInt(); + Serial.print("\n\r"); + Serial.print("setting baud rate to "); + Serial.print(baudRate); + Serial.print("\n\r"); + + setBaudRate(baudRate); + break; + +case 'd': +{ + debugFlagInit(); + +debugFlags: + + Serial.print("\n\r0. all off"); + Serial.print("\n\r9. all on"); + Serial.print("\n\ra-z. exit\n\r"); + + Serial.print("\n\r1. file parsing = "); + Serial.print(debugFP); + Serial.print("\n\r2. file parsing time = "); + Serial.print(debugFPtime); + + Serial.print("\n\r3. net manager = "); + Serial.print(debugNM); + Serial.print("\n\r4. net manager time = "); + Serial.print(debugNMtime); + + Serial.print("\n\r5. chip connections = "); + Serial.print(debugNTCC); + Serial.print("\n\r6. chip conns alt paths = "); + Serial.print(debugNTCC2); + Serial.print("\n\r7. LEDs = "); + Serial.print(debugLEDs); + + Serial.print("\n\n\r"); + + while (Serial.available() == 0) + ; + + int toggleDebug = Serial.read(); + Serial.write(toggleDebug); + toggleDebug -= '0'; + + if (toggleDebug >= 0 && toggleDebug <= 9) + { + + debugFlagSet(toggleDebug); + + delay(10); + + goto debugFlags; + } + else + { + break; + } +} + +case ':': + + if (Serial.read() == ':') + { + // Serial.print("\n\r"); + // Serial.print("entering machine mode\n\r"); + machineMode(); + showLEDsCore2 = 1; + goto dontshowmenu; + break; + } + else + { break; } - goto menu; +default: + while (Serial.available() > 0) + { + int f = Serial.read(); + delayMicroseconds(50); + } + + break; +} + +goto menu; } // #include // Include the necessary header file @@ -554,16 +607,16 @@ void machineMode(void) // read in commands in machine readable format case lightnet: lightUpNetsFromInputBuffer(); // lightUpNet(); - //assignNetColors(); - //showLEDsCore2 = 1; - break; + // assignNetColors(); + // showLEDsCore2 = 1; + break; // case getmeasurement: // showMeasurements(); // break; case setsupplyswitch: - + supplySwitchPosition = setSupplySwitch(); showLEDsCore2 = 1; break; @@ -572,8 +625,8 @@ void machineMode(void) // read in commands in machine readable format printSupplySwitch(supplySwitchPosition); break; - // case gpio: - // break; + // case gpio: + // break; case unknown: machineModeRespond(sequenceNumber, false); @@ -647,7 +700,6 @@ void loop1() // core 2 handles the LEDs and the CH446Q8 char ch = USBSer1.read(); Serial1.write(ch); - } if (Serial1.available()) @@ -670,14 +722,14 @@ void loop1() // core 2 handles the LEDs and the CH446Q8 char ch = USBSer1.read(); Serial1.write(ch); - // Serial.print(ch); + // Serial.print(ch); } if (Serial1.available()) { char ch = Serial1.read(); USBSer1.write(ch); - //Serial.print(ch); + // Serial.print(ch); if (ch == 'f' && connectFromArduino == '\0') {