From f7b4bd7552e3eeea2cc48e39cb49384a37bee2fb Mon Sep 17 00:00:00 2001 From: Kevin Santo Cappuccio Date: Mon, 11 Nov 2024 10:02:25 -0800 Subject: [PATCH] Made last connections load on startup --- .../JumperlessRev3point1.kicad_prl | 3 +- .../KiCAD/JumperlessRev3point1/fp-info-cache | 252 -- .../~JumperlessRev3point1.kicad_pcb.lck | 1 + JumperlessNano/.vscode/settings.json | 7 +- JumperlessNano/boards/pico.json | 4 +- JumperlessNano/platformio.ini | 2 +- JumperlessNano/src/FileParsing.cpp | 3259 ++++++++--------- JumperlessNano/src/Peripherals.cpp | 658 ++-- JumperlessNano/src/Peripherals.h | 7 +- JumperlessNano/src/Probing.cpp | 4 +- JumperlessNano/src/main.cpp | 435 +-- .../JumperlessWokwiBridge.py | 1940 ---------- .../JumperlessWokwiBridge/Packager.py | 141 - 13 files changed, 2036 insertions(+), 4677 deletions(-) create mode 100644 Hardware/KiCAD/JumperlessRev3point1/~JumperlessRev3point1.kicad_pcb.lck delete mode 100644 Jumperless_Wokwi_Bridge_App/JumperlessWokwiBridge/JumperlessWokwiBridge.py delete mode 100644 Jumperless_Wokwi_Bridge_App/JumperlessWokwiBridge/Packager.py diff --git a/Hardware/KiCAD/JumperlessRev3point1/JumperlessRev3point1.kicad_prl b/Hardware/KiCAD/JumperlessRev3point1/JumperlessRev3point1.kicad_prl index 5b23bff..c5ea004 100644 --- a/Hardware/KiCAD/JumperlessRev3point1/JumperlessRev3point1.kicad_prl +++ b/Hardware/KiCAD/JumperlessRev3point1/JumperlessRev3point1.kicad_prl @@ -38,7 +38,6 @@ 9, 10, 11, - 12, 13, 15, 16, @@ -64,7 +63,7 @@ 39, 40 ], - "visible_layers": "fffffff_ffffffff", + "visible_layers": "fffffcf_ffffffff", "zone_display_mode": 1 }, "git": { diff --git a/Hardware/KiCAD/JumperlessRev3point1/fp-info-cache b/Hardware/KiCAD/JumperlessRev3point1/fp-info-cache index be62790..573541a 100644 --- a/Hardware/KiCAD/JumperlessRev3point1/fp-info-cache +++ b/Hardware/KiCAD/JumperlessRev3point1/fp-info-cache @@ -1,253 +1 @@ -60677951824539 -JumperlessFootprints -Arduino_Nano -Arduino Nano, http://www.mouser.com/pdfdocs/Gravitech_Arduino_Nano3_0.pdf -Arduino Nano 0 -30 -30 -JumperlessFootprints -Breadboard_CustomClips_Fallback - - -0 -320 -64 -JumperlessFootprints -CP_EIA-6032-20_AVX-F_Pad2.25x2.35mm_HandSolder -Tantalum Capacitor SMD AVX-F (6032-20 Metric), IPC_7351 nominal, (Body size from: http://www.kemet.com/Lists/ProductCatalog/Attachments/253/KEM_TC101_STD.pdf), generated with kicad-footprint-generator -capacitor tantalum -0 -2 -2 -JumperlessFootprints -C_0402_1005Metric -Capacitor SMD 0402 (1005 Metric), square (rectangular) end terminal, IPC_7351 nominal, (Body size source: IPC-SM-782 page 76, https://www.pcb-3d.com/wordpress/wp-content/uploads/ipc-sm-782a_amendment_1_and_2.pdf), generated with kicad-footprint-generator -capacitor -0 -2 -2 -JumperlessFootprints -C_0603_1608Metric -Capacitor SMD 0603 (1608 Metric), square (rectangular) end terminal, IPC_7351 nominal, (Body size source: IPC-SM-782 page 76, https://www.pcb-3d.com/wordpress/wp-content/uploads/ipc-sm-782a_amendment_1_and_2.pdf), generated with kicad-footprint-generator -capacitor -0 -2 -2 -JumperlessFootprints -C_1206_3216Metric_Pad1.33x1.80mm_HandSolder -Capacitor SMD 1206 (3216 Metric), square (rectangular) end terminal, IPC_7351 nominal with elongated pad for handsoldering. (Body size source: IPC-SM-782 page 76, https://www.pcb-3d.com/wordpress/wp-content/uploads/ipc-sm-782a_amendment_1_and_2.pdf), generated with kicad-footprint-generator -capacitor handsolder -0 -2 -2 -JumperlessFootprints -Crystal_SMD_3225-4Pin_3.2x2.5mm -SMD Crystal SERIES SMD3225/4 http://www.txccrystal.com/images/pdf/7m-accuracy.pdf, 3.2x2.5mm^2 package -SMD SMT crystal -0 -4 -4 -JumperlessFootprints -DIP-8_W7.62mm -8-lead though-hole mounted DIP package, row spacing 7.62 mm (300 mils) -THT DIP DIL PDIP 2.54mm 7.62mm 300mil -0 -8 -8 -JumperlessFootprints -D_SOD-323 -SOD-323 -SOD-323 -0 -2 -2 -JumperlessFootprints -Fiducial_1mm_Mask2mm -Circular Fiducial, 1mm bare copper, 2mm soldermask opening (Level A) -fiducial -0 -1 -0 -JumperlessFootprints -Fuse_1206_3216Metric_Pad1.42x1.75mm_HandSolder -Fuse SMD 1206 (3216 Metric), square (rectangular) end terminal, IPC_7351 nominal with elongated pad for handsoldering. (Body size source: http://www.tortai-tech.com/upload/download/2011102023233369053.pdf), generated with kicad-footprint-generator -fuse handsolder -0 -2 -2 -JumperlessFootprints -GPIO_header - - -0 -4 -4 -JumperlessFootprints -LED_1206_REVERSEMOUNT_OVAL - - -0 -2 -2 -JumperlessFootprints -LED_WS2812B-2020_PLCC4_2.0x2.0mm -Addressable RGB LED NeoPixel Nano, 12 mA, https://cdn-shop.adafruit.com/product-files/4684/4684_WS2812B-2020_V1.3_EN.pdf -LED RGB NeoPixel Nano 2020 -0 -4 -4 -JumperlessFootprints -LQFP44_Tight - - -0 -44 -44 -JumperlessFootprints -PINHEADER-1x1_vertical - - -0 -1 -1 -JumperlessFootprints -PinHeader_1x02_P2.54mm_Vertical -Through hole straight pin header, 1x02, 2.54mm pitch, single row -Through hole pin header THT 1x02 2.54mm single row -0 -2 -2 -JumperlessFootprints -PinHeader_1x03_P2.54mm_Vertical -Through hole straight pin header, 1x03, 2.54mm pitch, single row -Through hole pin header THT 1x03 2.54mm single row -0 -3 -3 -JumperlessFootprints -PinHeader_1x06_P2.54mm_Vertical -Through hole straight pin header, 1x06, 2.54mm pitch, single row -Through hole pin header THT 1x06 2.54mm single row -0 -6 -6 -JumperlessFootprints -RP2040-QFN-56 -QFN, 56 Pin (http://www.cypress.com/file/416486/download#page=40), generated with kicad-footprint-generator ipc_dfn_qfn_generator.py -QFN DFN_QFN -0 -70 -57 -JumperlessFootprints -R_0402_1005Metric -Resistor SMD 0402 (1005 Metric), square (rectangular) end terminal, IPC_7351 nominal, (Body size source: IPC-SM-782 page 72, https://www.pcb-3d.com/wordpress/wp-content/uploads/ipc-sm-782a_amendment_1_and_2.pdf), generated with kicad-footprint-generator -resistor -0 -2 -2 -JumperlessFootprints -R_0603_1608Metric -Resistor SMD 0603 (1608 Metric), square (rectangular) end terminal, IPC_7351 nominal, (Body size source: IPC-SM-782 page 72, https://www.pcb-3d.com/wordpress/wp-content/uploads/ipc-sm-782a_amendment_1_and_2.pdf), generated with kicad-footprint-generator -resistor -0 -2 -2 -JumperlessFootprints -SOIC-8_3.9x4.9mm_P1.27mm -SOIC, 8 Pin (JEDEC MS-012AA, https://www.analog.com/media/en/package-pcb-resources/package/pkg_pdf/soic_narrow-r/r_8.pdf), generated with kicad-footprint-generator ipc_gullwing_generator.py -SOIC SO -0 -8 -8 -JumperlessFootprints -SOIC-8_5.23x5.23mm_P1.27mm -SOIC, 8 Pin (http://www.winbond.com/resource-files/w25q32jv%20revg%2003272018%20plus.pdf#page=68), generated with kicad-footprint-generator ipc_gullwing_generator.py -SOIC SO -0 -8 -8 -JumperlessFootprints -SOIC-14_3.9x8.7mm_P1.27mm -SOIC, 14 Pin (JEDEC MS-012AB, https://www.analog.com/media/en/package-pcb-resources/package/pkg_pdf/soic_narrow-r/r_14.pdf), generated with kicad-footprint-generator ipc_gullwing_generator.py -SOIC SO -0 -14 -14 -JumperlessFootprints -SOIC-16_3.9x9.9mm_P1.27mm -SOIC, 16 Pin (JEDEC MS-012AC, https://www.analog.com/media/en/package-pcb-resources/package/pkg_pdf/soic_narrow-r/r_16.pdf), generated with kicad-footprint-generator ipc_gullwing_generator.py -SOIC SO -0 -16 -16 -JumperlessFootprints -SOT-23-6 -SOT, 6 Pin (https://www.jedec.org/sites/default/files/docs/Mo-178c.PDF variant AB), generated with kicad-footprint-generator ipc_gullwing_generator.py -SOT TO_SOT_SMD -0 -6 -6 -JumperlessFootprints -SOT-223-3_TabPin2 -module CMS SOT223 4 pins -CMS SOT -0 -4 -3 -JumperlessFootprints -SW_SPST_TL3342 -Low-profile SMD Tactile Switch, https://www.e-switch.com/system/asset/product_line/data_sheet/165/TL3342.pdf -SPST Tactile Switch -0 -4 -2 -JumperlessFootprints -Slide_Switch_SSSS223600 - - -0 -8 -8 -JumperlessFootprints -SolderJumper_2_Bridged_Small - - -0 -2 -2 -JumperlessFootprints -SolderJumper_2_Open_Small - - -0 -2 -2 -JumperlessFootprints -TestPoint_D0.75mm - - -0 -1 -1 -JumperlessFootprints -TestPoint_Pad_D1.0mm -SMD pad as test Point, diameter 1.0mm -test point SMD pad -0 -1 -1 -JumperlessFootprints -USB_Mini-B_Wuerth_65100516121_Horizontal -Mini USB 2.0 Type B SMT Horizontal 5 Contacts (https://katalog.we-online.de/em/datasheet/65100516121.pdf) -Mini USB 2.0 Type B -0 -9 -6 -JumperlessFootprints -ws2812c-2020-noSolk - - -0 -4 -4 diff --git a/Hardware/KiCAD/JumperlessRev3point1/~JumperlessRev3point1.kicad_pcb.lck b/Hardware/KiCAD/JumperlessRev3point1/~JumperlessRev3point1.kicad_pcb.lck new file mode 100644 index 0000000..e9336e2 --- /dev/null +++ b/Hardware/KiCAD/JumperlessRev3point1/~JumperlessRev3point1.kicad_pcb.lck @@ -0,0 +1 @@ +{"hostname":"Kevins-MacBook-Pro","username":"kevinsanto"} \ No newline at end of file diff --git a/JumperlessNano/.vscode/settings.json b/JumperlessNano/.vscode/settings.json index 065ac84..c43cd37 100644 --- a/JumperlessNano/.vscode/settings.json +++ b/JumperlessNano/.vscode/settings.json @@ -13,6 +13,11 @@ "cmath": "cpp" }, "cortex-debug.registerUseNaturalFormat": false, - "C_Cpp.errorSquiggles": "disabled" + "C_Cpp.errorSquiggles": "disabled", + "prettier.printWidth": 200, + "python.analysis.fixAll": [ + + ], + "platformio-ide.reopenSerialMonitorDelay": 1000 } \ No newline at end of file diff --git a/JumperlessNano/boards/pico.json b/JumperlessNano/boards/pico.json index c0ff9e9..67931ac 100644 --- a/JumperlessNano/boards/pico.json +++ b/JumperlessNano/boards/pico.json @@ -35,8 +35,8 @@ "name": "Jumperless", "upload": { - "maximum_ram_size": 270336, - "maximum_size": 2097152, + "maximum_ram_size": 262144, + "maximum_size": 16777216, "require_upload_port": true, "native_usb": true, "use_1200bps_touch": true, diff --git a/JumperlessNano/platformio.ini b/JumperlessNano/platformio.ini index de42509..6a7072c 100644 --- a/JumperlessNano/platformio.ini +++ b/JumperlessNano/platformio.ini @@ -33,5 +33,5 @@ lib_deps = adafruit/Adafruit NeoPixel@^1.11.0 robtillaart/MCP_DAC@^0.2.0 adafruit/Adafruit SSD1306@^2.5.9 - https://github.com/pschatzmann/logic-analyzer.git + ;https://github.com/pschatzmann/logic-analyzer.git diff --git a/JumperlessNano/src/FileParsing.cpp b/JumperlessNano/src/FileParsing.cpp index 4970e3c..db758d4 100644 --- a/JumperlessNano/src/FileParsing.cpp +++ b/JumperlessNano/src/FileParsing.cpp @@ -1,17 +1,17 @@ // SPDX-License-Identifier: MIT #include "FileParsing.h" -#include "RotaryEncoder.h" -#include -#include "LittleFS.h" -#include "MatrixStateRP2040.h" -#include "SafeString.h" #include "ArduinoJson.h" -#include "NetManager.h" #include "JumperlessDefinesRP2040.h" #include "LEDs.h" -#include +#include "LittleFS.h" #include "MachineCommands.h" +#include "MatrixStateRP2040.h" +#include "NetManager.h" #include "Probing.h" +#include "RotaryEncoder.h" +#include "SafeString.h" +#include +#include bool debugFP = EEPROM.read(DEBUG_FILEPARSINGADDRESS); bool debugFPtime = EEPROM.read(TIME_FILEPARSINGADDRESS); @@ -35,1776 +35,1635 @@ File nodeFileBuffer; unsigned long timeToFP = 0; -const char rotaryConnectionString[] = "{AREF-GND,D11-GND,D10-UART_TX,D12-UART_RX,D13-GPIO_0, "; - -void createSlots(int slot, int addRotaryConnections) -{ - if (slot == -1) - { - for (int i = 0; i < NUM_SLOTS; i++) - { - int index = 0; - // int length = 0; - // nodeFile = LittleFS.open("nodeFileSlot" + String(i) + ".txt", "r+"); - // //nodeFile.seek(0); - // if (addRotaryConnections == 0) - // { - // while(nodeFile.available()) - // { - // if (rotaryConnectionString[index] == nodeFile.read()) - // { - // //nodeFile.write(' '); - // index++; - - // } else - // length++; - // } - // } - // nodeFile.seek(0); - // nodeFile.write("f { "); - // for (int i = 0; i < (index-length); i++) - // { - // nodeFile.seek(index+i); - // uint8_t c = nodeFile.read(); - // nodeFile.seek(i); - // nodeFile.print('t'); - // } - // Serial.println(index); - - // Serial.println(length); - // nodeFile.seek(0); - // while(nodeFile.available()) - // { - // Serial.write(nodeFile.read()); - // } - - // nodeFile.close(); - - nodeFile = LittleFS.open("nodeFileSlot" + String(i) + ".txt", "w"); - if (i >= 0) - { - // nodeFile.print("{ 83-103, 81-100, 82-110, 117-110, 85-111, 114-111, 80-112, 116-112, "); - // nodeFile.print("{ D5-GND, A3-GND, A5-GPIO_0, D4-UART_TX, D6-UART_RX, "); - // nodeFile.print("{ AREF-D8, D8-ADC0, ADC0-GPIO_0, D11-GND, D10-ADC2, ADC2-UART_TX, D12-ADC1, ADC1-UART_RX, D13-GND, "); - if (addRotaryConnections > 0) - { - nodeFile.print("{AREF-GND,D11-GND,D10-UART_TX,D12-UART_RX,D13-GPIO_0,"); - nodeFile.print(i * 4 + 1); - nodeFile.print("-"); - nodeFile.print(i * 4 + 2); - nodeFile.print(",}"); - } - else - { - nodeFile.print("{ \n\r } \n\r"); - } - } - nodeFile.close(); - } - } - else - { - nodeFile = LittleFS.open("nodeFileSlot" + String(slot) + ".txt", "w"); - - // nodeFile.print("{ D12-D7, D7-ADC0, ADC0-UART_RX, D11-GND, D10-ADC2, ADC2-UART_TX, AREF-ADC1, ADC1-GPIO_0, D13-GND, "); - if (addRotaryConnections > 0) - { - nodeFile.print("{AREF-GND,D11-GND,D10-UART_TX,D12-UART_RX,D13-GPIO_0,} "); - // nodeFile.print(slot * 4 + 1); - // nodeFile.print("-"); - // nodeFile.print(slot * 4 + 2); - // nodeFile.print(", } "); - } - nodeFile.close(); - } -} -void inputNodeFileList(int addRotaryConnections) -{ - // addRotaryConnections = 1; - // Serial.println("Paste the nodeFile list here\n\n\r"); - - unsigned long humanTime = millis(); - - int shown = 0; - while (Serial.available() == 0) - { - if (millis() - humanTime == 400 && shown == 0) - { - Serial.println("Paste the nodeFile list here\n\n\r"); - shown = 1; - } - } - nodeFileString.clear(); - // if (addRotaryConnections > 0) - // { - // for (int i = 0; i < 59 ; i++) - // { - // nodeFileString.write(rotaryConnectionString[i]); - // Serial.print(rotaryConnectionString[i]); - // } - // } - int startInsertion = 0; - while (Serial.available() > 0) - { - uint8_t c = Serial.read(); - if (c == '{' && addRotaryConnections > 0) - { - // startInsertion = 1; - for (int i = 0; i < 53; i++) - { - nodeFileString.write(rotaryConnectionString[i]); - // Serial.print(rotaryConnectionString[i]); - } - continue; - } - nodeFileString.write(c); - delayMicroseconds(100); - } - // nodeFileString.read(Serial); - // Serial.println("nodeFileString"); - // Serial.println(nodeFileString); - int lastTokenIndex = 0; - int tokenFound = 0; - uint8_t lastReads[8] = {' ', ' ', ' ', ' '}; - uint8_t slotText[8] = {'S', 'l', 'o', 't', ' '}; - uint8_t searchFor[3] = {'f', ' ', '{'}; - - createSafeString(nodeFileStringSlot, 1200); - nodeFileBuffer = LittleFS.open("nodeFileBuffer.txt", "w+"); - nodeFileString.trim(); - if (nodeFileString.endsWith("}") == 0) - { - nodeFileString.concat(" } \n\r"); - } - - nodeFileString.printTo(nodeFileBuffer); - - int index = 0; - - int inFileMeat = 0; - - int numberOfSlotsFound = 0; - int firstSlotNumber = 0; - int firstSlotFound = 0; - - // nodeFileBuffer.seek(nodeFileBuffer.size()); - // nodeFileBuffer.print("fuck \n\r"); - nodeFileBuffer.seek(0); - // Serial.println(" \n\n\n\r"); - // while (nodeFileBuffer.available()) - // { - // Serial.write(nodeFileBuffer.read()); - // } - - for (int i = 0; i < NUM_SLOTS; i++) // this just searches for how many slots are in the pasted list - { - tokenFound = 0; - nodeFileBuffer.seek(index); - inFileMeat = 0; - - while (nodeFileBuffer.available()) - { - uint8_t c = nodeFileBuffer.read(); - lastReads[0] = lastReads[1]; - lastReads[1] = lastReads[2]; - lastReads[2] = lastReads[3]; - lastReads[3] = lastReads[4]; - lastReads[4] = lastReads[5]; - lastReads[5] = c; - - if (lastReads[0] == slotText[0] && lastReads[1] == slotText[1] && lastReads[2] == slotText[2] && lastReads[3] == slotText[3] && lastReads[4] == slotText[4] && firstSlotFound == 0) - { - - firstSlotFound = 1; - firstSlotNumber = lastReads[5] - '0'; - - // break; - } - - if (lastReads[3] == searchFor[0] && lastReads[4] == searchFor[1] && lastReads[5] == searchFor[2]) - { - inFileMeat = 1; - numberOfSlotsFound++; - } - if (lastReads[2] == '}') - { - inFileMeat = 0; - - index++; - break; - } - - if (inFileMeat == 1) - { - - // Serial.println(numberOfSlotsFound); - } - index++; - } - } - - index = 0; - int lastSlotNumber = firstSlotNumber + numberOfSlotsFound - 1; - - for (int i = firstSlotNumber; i <= lastSlotNumber; i++) // this takes the pasted list fron the serial monitor and saves it to the nodeFileSlot files - { - - if (i >= firstSlotNumber && i <= lastSlotNumber) - { - // Serial.println(i); - nodeFile = LittleFS.open("nodeFileSlot" + String(i) + ".txt", "w"); - } - - // nodeFileStringSlot.clear(); - nodeFileBuffer.seek(index); - - inFileMeat = 0; - - while (nodeFileBuffer.available()) - { - uint8_t c = nodeFileBuffer.read(); - lastReads[0] = lastReads[1]; - lastReads[1] = lastReads[2]; - lastReads[2] = c; - - // nodeFile.write(c); - - if (lastReads[0] == searchFor[0] && lastReads[1] == searchFor[1] && lastReads[2] == searchFor[2]) - { - inFileMeat = 1; - } - if (lastReads[1] == '}') - { - inFileMeat = 0; - break; - } - - if (inFileMeat == 1 && i >= firstSlotNumber && i <= lastSlotNumber) - { - nodeFile.write(c); - // Serial.print(index); - } - index++; - } - if (i >= firstSlotNumber && i <= lastSlotNumber) - { - nodeFile.seek(0); - nodeFile.close(); - } - } - // uint8_t trash = Serial.read(); - // Serial.write(trash); - // delay(10); - - // while(Serial.available() > 0) - // { - // trash = Serial.read(); - // //Serial.write(trash); - // delay(1); - // } - - // for (int i = 0; i < NUM_SLOTS; i++) - // { - // // printNodeFile(i); - // } -} - -void savePreformattedNodeFile(int source, int slot, int keepEncoder) -{ - - nodeFile = LittleFS.open("nodeFileSlot" + String(slot) + ".txt", "w+"); - // Serial.println("Slot " + String(slot)); - - // Serial.println(nodeFile); - - if (keepEncoder == 1) - { - // nodeFile.print("{ D12-D7, D7-ADC0, ADC0-UART_RX, D11-GND, D10-ADC2, ADC2-UART_TX, AREF-ADC1, ADC1-GPIO_0, D13-GND, "); - nodeFile.print("{AREF-GND,D11-GND,D10-UART_TX,D12-UART_RX,D13-GPIO_0, "); - // Serial.println(" keeping encoder"); - } - - if (debugFP) - { - Serial.print("source = "); - Serial.println(source); - } - - if (source == 0) - { - while (Serial.available() == 0 || Serial.read() == 'f') - { - } - - while (Serial.available() > 0) - { - // nodeFile.write(Serial.read()); - uint8_t c = Serial.read(); - // Serial.print(c); - if (c != 'f' && c != '}' && c != '{' && c != ' ' && c != '\n' && c != '\r' && c != '\t') - { - nodeFile.write(c); - } - - delayMicroseconds(800); - } - } - if (source == 1) - { - nodeFile.print("f 117-D1, 116-D0,"); - while (Serial1.available() == 0) - { - } - delayMicroseconds(900); - // Serial.println("waiting for Arduino to send file"); - while (Serial1.available() > 0) - { - nodeFile.write(Serial1.read()); - delayMicroseconds(800); - // Serial.println(Serial1.available()); - } - - while (Serial1.available() > 0) - { - Serial1.read(); - delay(1); - } - } - - // nodeFile.write("\n\r"); - - // nodeFile.seek(0); - // nodeFileString.read(nodeFile); - // Serial.println(nodeFileString); - if (keepEncoder == 1) - { - nodeFile.print(" } "); - // Serial.println(" keeping encoder"); - } - - nodeFile.close(); - // Serial.println("Slot " + String(slot) + " saved"); - // printNodeFile(slot); -} - -void printNodeFile(int slot) -{ - - nodeFile = LittleFS.open("nodeFileSlot" + String(slot) + ".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.print(nodeFileString); - - // int newLines = 0; - // Serial.println(nodeFileString.indexOf(",")); - // Serial.println(nodeFileString.charAt(nodeFileString.indexOf(",")+1)); - // Serial.println(nodeFileString.indexOf(",")); - if (debugFP == 0) - { - // nodeFileString.replace("116-80, 117-82, 114-83, 85-100, 81-100,", "rotEnc_0,"); - - nodeFileString.replace("100", "GND"); - nodeFileString.replace("105", "5V"); - nodeFileString.replace("103", "3V3"); - nodeFileString.replace("106", "DAC0"); - nodeFileString.replace("107", "DAC1"); - nodeFileString.replace("108", "I_P"); - nodeFileString.replace("109", "I_N"); - nodeFileString.replace("110", "ADC0"); - nodeFileString.replace("111", "ADC1"); - nodeFileString.replace("112", "ADC2"); - nodeFileString.replace("113", "ADC3"); - nodeFileString.replace("114", "GPIO_0"); - nodeFileString.replace("116", "UART_TX"); - nodeFileString.replace("117", "UART_RX"); - nodeFileString.replace("118", "GPIO_18"); - nodeFileString.replace("119", "GPIO_19"); - nodeFileString.replace("120", "8V_P"); - nodeFileString.replace("121", "8V_N"); - nodeFileString.replace("70", "D0"); - nodeFileString.replace("71", "D1"); - nodeFileString.replace("72", "D2"); - nodeFileString.replace("73", "D3"); - nodeFileString.replace("74", "D4"); - nodeFileString.replace("75", "D5"); - nodeFileString.replace("76", "D6"); - nodeFileString.replace("77", "D7"); - nodeFileString.replace("78", "D8"); - nodeFileString.replace("79", "D9"); - nodeFileString.replace("80", "D10"); - nodeFileString.replace("81", "D11"); - nodeFileString.replace("82", "D12"); - nodeFileString.replace("83", "D13"); - nodeFileString.replace("84", "RESET"); - nodeFileString.replace("85", "AREF"); - nodeFileString.replace("86", "A0"); - nodeFileString.replace("87", "A1"); - nodeFileString.replace("88", "A2"); - nodeFileString.replace("89", "A3"); - nodeFileString.replace("90", "A4"); - nodeFileString.replace("91", "A5"); - nodeFileString.replace("92", "A6"); - nodeFileString.replace("93", "A7"); - } - - if (nodeFileString.charAt(nodeFileString.indexOf(",") + 1) != '\n') - { - nodeFileString.replace(",", ",\n\r"); - nodeFileString.replace("{", "{\n\r"); - } - - // int nodeFileStringLength = nodeFileString.indexOf("}"); - // if (nodeFileStringLength != -1) - // { - // //nodeFileString.remove(nodeFileStringLength + 1, -1); - // } - - // if (nodeFileString.indexOf(",\n\r") == -1) - // { - // nodeFileString.replace(",", ",\n\r"); - // nodeFileString.replace("{", "{\n\r"); - // } - - // nodeFile.close(); - - int nodeFileStringLength = nodeFileString.indexOf("}"); - if (nodeFileStringLength != -1) - { - if (nodeFileString.charAt(nodeFileStringLength + 1) != '\n') - { - nodeFileString.replace("}", "}\n\r"); - } - nodeFileString.remove(nodeFileStringLength + 2, -1); - } - - // nodeFileString.readUntilToken(nodeFileString, "{"); - // nodeFileString.removeLast(9); - - Serial.print(nodeFileString); - // Serial.print('*'); - nodeFileString.clear(); -} - -void parseWokwiFileToNodeFile(void) -{ - - // delay(3000); - LittleFS.begin(); - timeToFP = millis(); - - wokwiFile = LittleFS.open("wokwi.txt", "w+"); - if (!wokwiFile) - { - if (debugFP) - Serial.println("Failed to open wokwi.txt"); - return; - } - else - { - if (debugFP) - { - Serial.println("\n\ropened wokwi.txt\n\r"); - } - else - { - // Serial.println("\n\r"); - } - } - - Serial.println("paste Wokwi diagram.json here\n\r"); - while (Serial.available() == 0) - { - } - - int numCharsRead = 0; - - char firstChar = Serial.read(); - - if (firstChar != '{') // in case you just paste a wokwi file in from the menu, the opening brace will have already been read - { - inputBuffer[numCharsRead] = '{'; - numCharsRead++; - } - else - { - inputBuffer[numCharsRead] = firstChar; - numCharsRead++; - } - /* - Serial.println(firstChar); - Serial.println(firstChar); - Serial.println(firstChar); - Serial.println(firstChar); - Serial.println(firstChar); - Serial.print(firstChar); - */ - delay(1); - while (Serial.available() > 0) - { - char c = Serial.read(); - inputBuffer[numCharsRead] = c; - - numCharsRead++; - - delayMicroseconds(1000); - } - - createSafeStringFromCharArray(wokwiFileString, inputBuffer); - delay(3); - wokwiFile.write(inputBuffer, numCharsRead); - - delay(3); - - wokwiFile.seek(0); - - if (debugFP) - Serial.println("\n\n\rwokwiFile\n\n\r"); - - /* for (int i = 0; i < numCharsRead; i++) - { - Serial.print((char)wokwiFile.read()); - }*/ - if (debugFP) - { - Serial.print(wokwiFileString); - - Serial.println("\n\n\rnumCharsRead = "); - - Serial.print(numCharsRead); - - Serial.println("\n\n\r"); - } - wokwiFile.close(); - - deserializeJson(wokwiJson, inputBuffer); - - if (debugFP) - { - - Serial.println("\n\n\rwokwiJson\n\n\r"); - - Serial.println("\n\n\rconnectionsW\n\n\r"); - } - - numConnsJson = wokwiJson["connections"].size(); - - copyArray(wokwiJson["connections"], connectionsW); - - // deserializeJson(connectionsW, Serial); - if (debugFP) - { - Serial.println(wokwiJson["connections"].size()); - - for (int i = 0; i < MAX_BRIDGES; i++) - { - // Serial.println(wokwiJson["connections"].size()); - if (connectionsW[i][0] == "") - { - break; - } - Serial.print(connectionsW[i][0]); - Serial.print(", \t "); - - Serial.print(connectionsW[i][1]); - Serial.print(", \t "); - - Serial.print(connectionsW[i][2]); - Serial.print(", \t "); - - Serial.print(connectionsW[i][3]); - Serial.print(", \t "); - - Serial.print(connectionsW[i][4]); - Serial.print(", \t "); - - Serial.println(); - } - - Serial.println("\n\n\rRedefining\n\n\r"); - } - - changeWokwiDefinesToJumperless(); - - writeToNodeFile(); - // while(1); - openNodeFile(); -} - -void changeWokwiDefinesToJumperless(void) -{ - - String connString1 = " "; - String connString2 = " "; - String connStringColor = " "; - String bb = "bb1:"; - - int nodeNumber; - - for (int i = 0; i < numConnsJson; i++) - { - if (debugFP) - { - Serial.println(' '); - } - for (int j = 0; j < 2; j++) - { - nodeNumber = -1; - connString1 = connectionsW[i][j]; - if (debugFP) - { - Serial.print(connString1); - Serial.print(" \t\t "); - } - if (connString1.startsWith("bb1:") || connString1.startsWith("bb2:")) - { - // Serial.print("bb1 or bb2 "); - - int periodIndex = connString1.indexOf("."); - connString1 = connString1.substring(4, periodIndex); - - if (connString1.endsWith("b")) - { - nodeNumber = 30; - // Serial.println("bottom"); - connString1.substring(0, connString1.length() - 1); - nodeNumber += connString1.toInt(); - } - else if (connString1.endsWith("t")) - { - nodeNumber = 0; - // Serial.println("top"); - connString1.substring(0, connString1.length() - 1); - nodeNumber += connString1.toInt(); - } - else if (connString1.endsWith("n")) - { - nodeNumber = GND; - } - else if (connString1.endsWith("p")) - { - nodeNumber = SUPPLY_5V; - } - } - else if (connString1.startsWith("nano:")) - { - // Serial.print("nano\t"); - int periodIndex = connString1.indexOf("."); - connString1 = connString1.substring(5, periodIndex); - - nodeNumber = NANO_D0; - - if (isDigit(connString1[connString1.length() - 1])) - { - - nodeNumber += connString1.toInt(); - } - else if (connString1.equals("5V")) - { - nodeNumber = SUPPLY_5V; - } - else if (connString1.equalsIgnoreCase("AREF")) - { - - nodeNumber = NANO_AREF; - } - else if (connString1.equalsIgnoreCase("GND")) - { - nodeNumber = GND; - } - else if (connString1.equalsIgnoreCase("RESET")) - { - - nodeNumber = NANO_RESET; - } - else if (connString1.equalsIgnoreCase("3.3V")) - { - nodeNumber = SUPPLY_3V3; - } - else if (connString1.startsWith("A")) - { - nodeNumber = NANO_A0; - nodeNumber += connString1.toInt(); - } - } - else if (connString1.startsWith("vcc1:")) - { - // Serial.print("vcc1\t"); - nodeNumber = SUPPLY_5V; - } - else if (connString1.startsWith("vcc2:")) - { - // Serial.print("vcc2\t"); - nodeNumber = SUPPLY_3V3; - } - else if (connString1.startsWith("gnd1:")) - { - // Serial.print("gnd1\t"); - nodeNumber = GND; - } - else if (connString1.startsWith("gnd2:")) - { - // Serial.print("gnd2\t"); - nodeNumber = GND; - } - else if (connString1.startsWith("gnd3:")) - { - nodeNumber = GND; - } - else if (connString1.startsWith("pot1:")) - { - nodeNumber = DAC0; - } - else - { - - connectionsW[i][j] = -1; - } - - // nodeNumber += connString1.toInt(); - - connectionsW[i][j] = nodeNumber; - if (debugFP) - { - Serial.print(connectionsW[i][j]); - - Serial.print(" \t "); - } - } - } -} -void clearNodeFile(int slot) -{ - - nodeFile = LittleFS.open("nodeFileSlot" + String(slot) + ".txt", "w+"); - - nodeFile.print("!"); - nodeFile.close(); -} - -void removeBridgeFromNodeFile(int node1, int node2, int slot) -{ - - nodeFile = LittleFS.open("nodeFileSlot" + String(slot) + ".txt", "r+"); - /// Serial.println(nodeFile); - - 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); - char nodeAsChar[20]; - itoa(node1, nodeAsChar, 10); - char paddedChar[21]; - - paddedChar[0] = ' '; - for (int i = 1; i < 20; i++) - { - if (nodeAsChar[i - 1] == '\0') - { - paddedChar[i] = ' '; - paddedChar[i + 1] = '\0'; - break; - } - paddedChar[i] = nodeAsChar[i - 1]; - } - - int numberOfLines = 0; - // Serial.print(paddedChar); - // Serial.println("*"); - - char lines[100][20]; - - int lineIndex = 0; - int charIndex = 0; - - for (int i = 0; i < 100; i++) - { - - if (nodeFileString[charIndex] == '\0') - { - numberOfLines = i; - break; - } - lines[i][0] = ' '; - for (int j = 1; j < 20; j++) - { - if (nodeFileString[charIndex] == ',') - { - lines[i][j] = ' '; - lines[i][j + 1] = ','; - // lines[i][j + 2] = '\n'; - // lines[i][j + 3] = '\r'; - lines[i][j + 2] = '\0'; - - charIndex++; - break; - } - else if (nodeFileString[charIndex] == '-') - { - lines[i][j] = ' '; - lines[i][j + 1] = '-'; - lines[i][j + 2] = ' '; - j += 2; - charIndex++; - // break; - } - else if (nodeFileString[charIndex] == '\n' || nodeFileString[charIndex] == '\r' || nodeFileString[charIndex] == '{' || nodeFileString[charIndex] == '}') - { - lines[i][j] = ' '; - charIndex++; - } - else - { - lines[i][j] = nodeFileString[charIndex]; - charIndex++; - } - } - } - - // Serial.println("\n\r********"); - - for (int i = 0; i < numberOfLines; i++) - { - if (lines[i][0] == '\0') - { - // break; - } - if (strstr(lines[i], paddedChar) != NULL) - { - // Serial.println(lines[i]); - // delay(1); - - for (int j = 0; j < 18; j++) - { - lines[i][j] = ' '; - } - // lines[i][18] = '\n'; - // lines[i][19] = '\r'; - lines[i][0] = '\0'; - } - } - - nodeFileString.clear(); - nodeFileString.concat("{"); - for (int i = 0; i < numberOfLines; i++) - { - if (lines[i][0] == '\0') - { - continue; - } - // Serial.println(i); - // delay(1); - for (int j = 0; j < 20; j++) - { - if (lines[i][j] == '\0') - { - break; - } - if (lines[i][j] == ' ') - { - continue; - } - nodeFileString.concat(lines[i][j]); - // Serial.print(lines[i][j]); - // delay(1); - } - } - nodeFileString.concat("}\n\r"); - - nodeFile.close(); - nodeFile = LittleFS.open("nodeFileSlot" + String(slot) + ".txt", "w+"); - - nodeFile.write(nodeFileString.c_str()); - - nodeFile.close(); -} - -void addBridgeToNodeFile(int node1, int node2, int slot) -{ - nodeFile = LittleFS.open("nodeFileSlot" + String(slot) + ".txt", "r+"); - // Serial.println(nodeFile); - - 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); +const char rotaryConnectionString[] = + "{AREF-GND,D11-GND,D10-UART_TX,D12-UART_RX,D13-GPIO_0, "; + +void createSlots(int slot, int addRotaryConnections) { + /// delay(2000); + if (slot == -1) { + for (int i = 0; i < NUM_SLOTS; i++) { + int index = 0; + // int length = 0; + // nodeFile = LittleFS.open("nodeFileSlot" + String(i) + ".txt", "r+"); + // //nodeFile.seek(0); + // if (addRotaryConnections == 0) + // { + // while(nodeFile.available()) + // { + // if (rotaryConnectionString[index] == nodeFile.read()) + // { + // //nodeFile.write(' '); + // index++; + + // } else + // length++; + // } + // } + // nodeFile.seek(0); + // nodeFile.write("f { "); + // for (int i = 0; i < (index-length); i++) + // { + // nodeFile.seek(index+i); + // uint8_t c = nodeFile.read(); + // nodeFile.seek(i); + // nodeFile.print('t'); + // } + // Serial.println(index); + + // Serial.println(length); + // nodeFile.seek(0); + // while(nodeFile.available()) + // { + // Serial.write(nodeFile.read()); + // } + + // nodeFile.close(); + nodeFile = LittleFS.open("nodeFileSlot" + String(i) + ".txt", "r+"); + + // nodeFileString.clear(); + // while (nodeFile.available()) + // { + // nodeFileString.read(nodeFile); + // //nodeFileString.write(nodeFile.read()); + // } + // nodeFileString.printTo(Serial); + nodeFile.seek(0); + if (nodeFile.size() <= 10) { + nodeFile = LittleFS.open("nodeFileSlot" + String(i) + ".txt", "w+"); + + if (i >= 0) { + // nodeFile.print("{ 83-103, 81-100, 82-110, 117-110, 85-111, 114-111, + // 80-112, 116-112, "); nodeFile.print("{ D5-GND, A3-GND, A5-GPIO_0, + // D4-UART_TX, D6-UART_RX, "); nodeFile.print("{ AREF-D8, D8-ADC0, + // ADC0-GPIO_0, D11-GND, D10-ADC2, ADC2-UART_TX, D12-ADC1, + // ADC1-UART_RX, D13-GND, "); + if (addRotaryConnections > 0) { + nodeFile.print( + "{AREF-GND,D11-GND,D10-UART_TX,D12-UART_RX,D13-GPIO_0,"); + nodeFile.print(i * 4 + 1); nodeFile.print("-"); - nodeFile.print(node2); - nodeFile.print(",\n\r}\n\r"); - - // if (1) - // { - // 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"); - // } - // Serial.print (nodeFile); - nodeFile.close(); - return; + nodeFile.print(i * 4 + 2); + nodeFile.print(",}"); + } else { + nodeFile.print("{ \n\r } \n\r"); + } } + } + // Serial.println(nodeFile.size()); + nodeFile.close(); } - // Serial.println(nodeFileBraceIndex); - nodeFile.seek(nodeFileBraceIndex); + } else { + nodeFile = LittleFS.open("nodeFileSlot" + String(slot) + ".txt", "w"); - nodeFile.print(node1); + // nodeFile.print("{ D12-D7, D7-ADC0, ADC0-UART_RX, D11-GND, D10-ADC2, + // ADC2-UART_TX, AREF-ADC1, ADC1-GPIO_0, D13-GND, "); + if (addRotaryConnections > 0) { + nodeFile.print("{AREF-GND,D11-GND,D10-UART_TX,D12-UART_RX,D13-GPIO_0,} "); + // nodeFile.print(slot * 4 + 1); + // nodeFile.print("-"); + // nodeFile.print(slot * 4 + 2); + // nodeFile.print(", } "); + } + nodeFile.close(); + } +} +void inputNodeFileList(int addRotaryConnections) { + // addRotaryConnections = 1; + // Serial.println("Paste the nodeFile list here\n\n\r"); + + unsigned long humanTime = millis(); + + int shown = 0; + while (Serial.available() == 0) { + if (millis() - humanTime == 400 && shown == 0) { + Serial.println("Paste the nodeFile list here\n\n\r"); + shown = 1; + } + } + nodeFileString.clear(); + // if (addRotaryConnections > 0) + // { + // for (int i = 0; i < 59 ; i++) + // { + // nodeFileString.write(rotaryConnectionString[i]); + // Serial.print(rotaryConnectionString[i]); + // } + // } + int startInsertion = 0; + while (Serial.available() > 0) { + uint8_t c = Serial.read(); + if (c == '{' && addRotaryConnections > 0) { + // startInsertion = 1; + for (int i = 0; i < 53; i++) { + nodeFileString.write(rotaryConnectionString[i]); + // Serial.print(rotaryConnectionString[i]); + } + continue; + } + nodeFileString.write(c); + delayMicroseconds(100); + } + // nodeFileString.read(Serial); + // Serial.println("nodeFileString"); + // Serial.println(nodeFileString); + int lastTokenIndex = 0; + int tokenFound = 0; + uint8_t lastReads[8] = {' ', ' ', ' ', ' '}; + uint8_t slotText[8] = {'S', 'l', 'o', 't', ' '}; + uint8_t searchFor[3] = {'f', ' ', '{'}; + + createSafeString(nodeFileStringSlot, 1200); + nodeFileBuffer = LittleFS.open("nodeFileBuffer.txt", "w+"); + nodeFileString.trim(); + if (nodeFileString.endsWith("}") == 0) { + nodeFileString.concat(" } \n\r"); + } + + nodeFileString.printTo(nodeFileBuffer); + + int index = 0; + + int inFileMeat = 0; + + int numberOfSlotsFound = 0; + int firstSlotNumber = 0; + int firstSlotFound = 0; + + // nodeFileBuffer.seek(nodeFileBuffer.size()); + // nodeFileBuffer.print("fuck \n\r"); + nodeFileBuffer.seek(0); + // Serial.println(" \n\n\n\r"); + // while (nodeFileBuffer.available()) + // { + // Serial.write(nodeFileBuffer.read()); + // } + + for (int i = 0; i < NUM_SLOTS; + i++) // this just searches for how many slots are in the pasted list + { + tokenFound = 0; + nodeFileBuffer.seek(index); + inFileMeat = 0; + + while (nodeFileBuffer.available()) { + uint8_t c = nodeFileBuffer.read(); + lastReads[0] = lastReads[1]; + lastReads[1] = lastReads[2]; + lastReads[2] = lastReads[3]; + lastReads[3] = lastReads[4]; + lastReads[4] = lastReads[5]; + lastReads[5] = c; + + if (lastReads[0] == slotText[0] && lastReads[1] == slotText[1] && + lastReads[2] == slotText[2] && lastReads[3] == slotText[3] && + lastReads[4] == slotText[4] && firstSlotFound == 0) { + + firstSlotFound = 1; + firstSlotNumber = lastReads[5] - '0'; + + // break; + } + + if (lastReads[3] == searchFor[0] && lastReads[4] == searchFor[1] && + lastReads[5] == searchFor[2]) { + inFileMeat = 1; + numberOfSlotsFound++; + } + if (lastReads[2] == '}') { + inFileMeat = 0; + + index++; + break; + } + + if (inFileMeat == 1) { + + // Serial.println(numberOfSlotsFound); + } + index++; + } + } + + index = 0; + int lastSlotNumber = firstSlotNumber + numberOfSlotsFound - 1; + + for (int i = firstSlotNumber; i <= lastSlotNumber; + i++) // this takes the pasted list fron the serial monitor and saves it + // to the nodeFileSlot files + { + + if (i >= firstSlotNumber && i <= lastSlotNumber) { + // Serial.println(i); + nodeFile = LittleFS.open("nodeFileSlot" + String(i) + ".txt", "w"); + } + + // nodeFileStringSlot.clear(); + nodeFileBuffer.seek(index); + + inFileMeat = 0; + + while (nodeFileBuffer.available()) { + uint8_t c = nodeFileBuffer.read(); + lastReads[0] = lastReads[1]; + lastReads[1] = lastReads[2]; + lastReads[2] = c; + + // nodeFile.write(c); + + if (lastReads[0] == searchFor[0] && lastReads[1] == searchFor[1] && + lastReads[2] == searchFor[2]) { + inFileMeat = 1; + } + if (lastReads[1] == '}') { + inFileMeat = 0; + break; + } + + if (inFileMeat == 1 && i >= firstSlotNumber && i <= lastSlotNumber) { + nodeFile.write(c); + // Serial.print(index); + } + index++; + } + if (i >= firstSlotNumber && i <= lastSlotNumber) { + nodeFile.seek(0); + nodeFile.close(); + } + } + // uint8_t trash = Serial.read(); + // Serial.write(trash); + // delay(10); + + // while(Serial.available() > 0) + // { + // trash = Serial.read(); + // //Serial.write(trash); + // delay(1); + // } + + // for (int i = 0; i < NUM_SLOTS; i++) + // { + // // printNodeFile(i); + // } +} + +void savePreformattedNodeFile(int source, int slot, int keepEncoder) { + + nodeFile = LittleFS.open("nodeFileSlot" + String(slot) + ".txt", "w+"); + // Serial.println("Slot " + String(slot)); + + // Serial.println(nodeFile); + + if (keepEncoder == 1) { + // nodeFile.print("{ D12-D7, D7-ADC0, ADC0-UART_RX, D11-GND, D10-ADC2, + // ADC2-UART_TX, AREF-ADC1, ADC1-GPIO_0, D13-GND, "); + nodeFile.print("{AREF-GND,D11-GND,D10-UART_TX,D12-UART_RX,D13-GPIO_0, "); + // Serial.println(" keeping encoder"); + } + + if (debugFP) { + Serial.print("source = "); + Serial.println(source); + } + + if (source == 0) { + while (Serial.available() == 0 || Serial.read() == 'f') { + } + + while (Serial.available() > 0) { + // nodeFile.write(Serial.read()); + uint8_t c = Serial.read(); + // Serial.print(c); + if (c != 'f' && c != '}' && c != '{' && c != ' ' && c != '\n' && + c != '\r' && c != '\t') { + nodeFile.write(c); + } + + delayMicroseconds(800); + } + } + if (source == 1) { + // nodeFile.print("f 117-D1, 116-D0,"); + + // nodeFileString.clear(); + // nodeFileString.read(nodeFile); + + // Serial.println(nodeFileString); + + while (Serial1.available() == 0) { + } + delayMicroseconds(5000); + // Serial.println("waiting for Arduino to send file"); + + nodeFileString.clear(); + + unsigned long timer = millis(); + +int readCount = 0; + +char buffer[1000]; + while (true) { + // while (Serial1.available() == 0) { + if (Serial1.available() > 0) { + buffer[readCount] = Serial1.read(); + //Serial.print(Serial1.read()); + // nodeFile.write(Serial1.read()); + timer = millis(); + readCount++; + } else { + if (millis() - timer > 500) { + break; + } + } + } + Serial.println(buffer); + for (int i = 0; i < readCount; i++) + { + nodeFile.print(buffer[i]); + } + + // while (Serial1.available() > 0) { + // // nodeFile.write(Serial1.read()); + // nodeFileString.read(Serial1); + + // delayMicroseconds(40000); + // // Serial.println(Serial1.available()); + // } + + // nodeFileString.printTo(Serial); + // nodeFileString.printTo(nodeFile); + + // while (Serial1.available() > 0) + // { + // Serial1.read(); + // delayMicroseconds(1000); + // } + } + + // nodeFile.write("\n\r"); + + // nodeFile.seek(0); + // nodeFileString.read(nodeFile); + // Serial.println(nodeFileString); + if (keepEncoder == 1) { + nodeFile.print(" } "); + // Serial.println(" keeping encoder"); + } + + nodeFile.close(); + // Serial.println("Slot " + String(slot) + " saved"); + // printNodeFile(slot); +} + +void printNodeFile(int slot) { + + nodeFile = LittleFS.open("nodeFileSlot" + String(slot) + ".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.print(nodeFileString); + + // int newLines = 0; + // Serial.println(nodeFileString.indexOf(",")); + // Serial.println(nodeFileString.charAt(nodeFileString.indexOf(",")+1)); + // Serial.println(nodeFileString.indexOf(",")); + if (debugFP == 0) { + // nodeFileString.replace("116-80, 117-82, 114-83, 85-100, 81-100,", + // "rotEnc_0,"); + + nodeFileString.replace("100", "GND"); + nodeFileString.replace("105", "5V"); + nodeFileString.replace("103", "3V3"); + nodeFileString.replace("106", "DAC0"); + nodeFileString.replace("107", "DAC1"); + nodeFileString.replace("108", "I_P"); + nodeFileString.replace("109", "I_N"); + nodeFileString.replace("110", "ADC0"); + nodeFileString.replace("111", "ADC1"); + nodeFileString.replace("112", "ADC2"); + nodeFileString.replace("113", "ADC3"); + nodeFileString.replace("114", "GPIO_0"); + nodeFileString.replace("116", "UART_TX"); + nodeFileString.replace("117", "UART_RX"); + nodeFileString.replace("118", "GPIO_18"); + nodeFileString.replace("119", "GPIO_19"); + nodeFileString.replace("120", "8V_P"); + nodeFileString.replace("121", "8V_N"); + nodeFileString.replace("70", "D0"); + nodeFileString.replace("71", "D1"); + nodeFileString.replace("72", "D2"); + nodeFileString.replace("73", "D3"); + nodeFileString.replace("74", "D4"); + nodeFileString.replace("75", "D5"); + nodeFileString.replace("76", "D6"); + nodeFileString.replace("77", "D7"); + nodeFileString.replace("78", "D8"); + nodeFileString.replace("79", "D9"); + nodeFileString.replace("80", "D10"); + nodeFileString.replace("81", "D11"); + nodeFileString.replace("82", "D12"); + nodeFileString.replace("83", "D13"); + nodeFileString.replace("84", "RESET"); + nodeFileString.replace("85", "AREF"); + nodeFileString.replace("86", "A0"); + nodeFileString.replace("87", "A1"); + nodeFileString.replace("88", "A2"); + nodeFileString.replace("89", "A3"); + nodeFileString.replace("90", "A4"); + nodeFileString.replace("91", "A5"); + nodeFileString.replace("92", "A6"); + nodeFileString.replace("93", "A7"); + } + + if (nodeFileString.charAt(nodeFileString.indexOf(",") + 1) != '\n') { + nodeFileString.replace(",", ",\n\r"); + nodeFileString.replace("{", "{\n\r"); + } + + // int nodeFileStringLength = nodeFileString.indexOf("}"); + // if (nodeFileStringLength != -1) + // { + // //nodeFileString.remove(nodeFileStringLength + 1, -1); + // } + + // if (nodeFileString.indexOf(",\n\r") == -1) + // { + // nodeFileString.replace(",", ",\n\r"); + // nodeFileString.replace("{", "{\n\r"); + // } + + // nodeFile.close(); + + int nodeFileStringLength = nodeFileString.indexOf("}"); + if (nodeFileStringLength != -1) { + if (nodeFileString.charAt(nodeFileStringLength + 1) != '\n') { + nodeFileString.replace("}", "}\n\r"); + } + nodeFileString.remove(nodeFileStringLength + 2, -1); + } + + // nodeFileString.readUntilToken(nodeFileString, "{"); + // nodeFileString.removeLast(9); + + Serial.print(nodeFileString); + // Serial.print('*'); + nodeFileString.clear(); +} + +void parseWokwiFileToNodeFile(void) { + + // delay(3000); + LittleFS.begin(); + timeToFP = millis(); + + wokwiFile = LittleFS.open("wokwi.txt", "w+"); + if (!wokwiFile) { + if (debugFP) + Serial.println("Failed to open wokwi.txt"); + return; + } else { + if (debugFP) { + Serial.println("\n\ropened wokwi.txt\n\r"); + } else { + // Serial.println("\n\r"); + } + } + + Serial.println("paste Wokwi diagram.json here\n\r"); + while (Serial.available() == 0) { + } + + int numCharsRead = 0; + + char firstChar = Serial.read(); + + if (firstChar != '{') // in case you just paste a wokwi file in from the menu, + // the opening brace will have already been read + { + inputBuffer[numCharsRead] = '{'; + numCharsRead++; + } else { + inputBuffer[numCharsRead] = firstChar; + numCharsRead++; + } + /* + Serial.println(firstChar); + Serial.println(firstChar); + Serial.println(firstChar); + Serial.println(firstChar); + Serial.println(firstChar); + Serial.print(firstChar); + */ + delay(1); + while (Serial.available() > 0) { + char c = Serial.read(); + inputBuffer[numCharsRead] = c; + + numCharsRead++; + + delayMicroseconds(1000); + } + + createSafeStringFromCharArray(wokwiFileString, inputBuffer); + delay(3); + wokwiFile.write(inputBuffer, numCharsRead); + + delay(3); + + wokwiFile.seek(0); + + if (debugFP) + Serial.println("\n\n\rwokwiFile\n\n\r"); + + /* for (int i = 0; i < numCharsRead; i++) + { + Serial.print((char)wokwiFile.read()); + }*/ + if (debugFP) { + Serial.print(wokwiFileString); + + Serial.println("\n\n\rnumCharsRead = "); + + Serial.print(numCharsRead); + + Serial.println("\n\n\r"); + } + wokwiFile.close(); + + deserializeJson(wokwiJson, inputBuffer); + + if (debugFP) { + + Serial.println("\n\n\rwokwiJson\n\n\r"); + + Serial.println("\n\n\rconnectionsW\n\n\r"); + } + + numConnsJson = wokwiJson["connections"].size(); + + copyArray(wokwiJson["connections"], connectionsW); + + // deserializeJson(connectionsW, Serial); + if (debugFP) { + Serial.println(wokwiJson["connections"].size()); + + for (int i = 0; i < MAX_BRIDGES; i++) { + // Serial.println(wokwiJson["connections"].size()); + if (connectionsW[i][0] == "") { + break; + } + Serial.print(connectionsW[i][0]); + Serial.print(", \t "); + + Serial.print(connectionsW[i][1]); + Serial.print(", \t "); + + Serial.print(connectionsW[i][2]); + Serial.print(", \t "); + + Serial.print(connectionsW[i][3]); + Serial.print(", \t "); + + Serial.print(connectionsW[i][4]); + Serial.print(", \t "); + + Serial.println(); + } + + Serial.println("\n\n\rRedefining\n\n\r"); + } + + changeWokwiDefinesToJumperless(); + + writeToNodeFile(); + // while(1); + openNodeFile(); +} + +void changeWokwiDefinesToJumperless(void) { + + String connString1 = " "; + String connString2 = " "; + String connStringColor = " "; + String bb = "bb1:"; + + int nodeNumber; + + for (int i = 0; i < numConnsJson; i++) { + if (debugFP) { + Serial.println(' '); + } + for (int j = 0; j < 2; j++) { + nodeNumber = -1; + connString1 = connectionsW[i][j]; + if (debugFP) { + Serial.print(connString1); + Serial.print(" \t\t "); + } + if (connString1.startsWith("bb1:") || connString1.startsWith("bb2:")) { + // Serial.print("bb1 or bb2 "); + + int periodIndex = connString1.indexOf("."); + connString1 = connString1.substring(4, periodIndex); + + if (connString1.endsWith("b")) { + nodeNumber = 30; + // Serial.println("bottom"); + connString1.substring(0, connString1.length() - 1); + nodeNumber += connString1.toInt(); + } else if (connString1.endsWith("t")) { + nodeNumber = 0; + // Serial.println("top"); + connString1.substring(0, connString1.length() - 1); + nodeNumber += connString1.toInt(); + } else if (connString1.endsWith("n")) { + nodeNumber = GND; + } else if (connString1.endsWith("p")) { + nodeNumber = SUPPLY_5V; + } + } else if (connString1.startsWith("nano:")) { + // Serial.print("nano\t"); + int periodIndex = connString1.indexOf("."); + connString1 = connString1.substring(5, periodIndex); + + nodeNumber = NANO_D0; + + if (isDigit(connString1[connString1.length() - 1])) { + + nodeNumber += connString1.toInt(); + } else if (connString1.equals("5V")) { + nodeNumber = SUPPLY_5V; + } else if (connString1.equalsIgnoreCase("AREF")) { + + nodeNumber = NANO_AREF; + } else if (connString1.equalsIgnoreCase("GND")) { + nodeNumber = GND; + } else if (connString1.equalsIgnoreCase("RESET")) { + + nodeNumber = NANO_RESET; + } else if (connString1.equalsIgnoreCase("3.3V")) { + nodeNumber = SUPPLY_3V3; + } else if (connString1.startsWith("A")) { + nodeNumber = NANO_A0; + nodeNumber += connString1.toInt(); + } + } else if (connString1.startsWith("vcc1:")) { + // Serial.print("vcc1\t"); + nodeNumber = SUPPLY_5V; + } else if (connString1.startsWith("vcc2:")) { + // Serial.print("vcc2\t"); + nodeNumber = SUPPLY_3V3; + } else if (connString1.startsWith("gnd1:")) { + // Serial.print("gnd1\t"); + nodeNumber = GND; + } else if (connString1.startsWith("gnd2:")) { + // Serial.print("gnd2\t"); + nodeNumber = GND; + } else if (connString1.startsWith("gnd3:")) { + nodeNumber = GND; + } else if (connString1.startsWith("pot1:")) { + nodeNumber = DAC0; + } else { + + connectionsW[i][j] = -1; + } + + // nodeNumber += connString1.toInt(); + + connectionsW[i][j] = nodeNumber; + if (debugFP) { + Serial.print(connectionsW[i][j]); + + Serial.print(" \t "); + } + } + } +} +void clearNodeFile(int slot) { + + nodeFile = LittleFS.open("nodeFileSlot" + String(slot) + ".txt", "w+"); + + nodeFile.print("!"); + nodeFile.close(); +} + +void removeBridgeFromNodeFile(int node1, int node2, int slot) { + + nodeFile = LittleFS.open("nodeFileSlot" + String(slot) + ".txt", "r+"); + /// Serial.println(nodeFile); + + 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); + char nodeAsChar[20]; + itoa(node1, nodeAsChar, 10); + char paddedChar[21]; + + paddedChar[0] = ' '; + for (int i = 1; i < 20; i++) { + if (nodeAsChar[i - 1] == '\0') { + paddedChar[i] = ' '; + paddedChar[i + 1] = '\0'; + break; + } + paddedChar[i] = nodeAsChar[i - 1]; + } + + int numberOfLines = 0; + // Serial.print(paddedChar); + // Serial.println("*"); + + char lines[100][20]; + + int lineIndex = 0; + int charIndex = 0; + + for (int i = 0; i < 100; i++) { + + if (nodeFileString[charIndex] == '\0') { + numberOfLines = i; + break; + } + lines[i][0] = ' '; + for (int j = 1; j < 20; j++) { + if (nodeFileString[charIndex] == ',') { + lines[i][j] = ' '; + lines[i][j + 1] = ','; + // lines[i][j + 2] = '\n'; + // lines[i][j + 3] = '\r'; + lines[i][j + 2] = '\0'; + + charIndex++; + break; + } else if (nodeFileString[charIndex] == '-') { + lines[i][j] = ' '; + lines[i][j + 1] = '-'; + lines[i][j + 2] = ' '; + j += 2; + charIndex++; + // break; + } else if (nodeFileString[charIndex] == '\n' || + nodeFileString[charIndex] == '\r' || + nodeFileString[charIndex] == '{' || + nodeFileString[charIndex] == '}') { + lines[i][j] = ' '; + charIndex++; + } else { + lines[i][j] = nodeFileString[charIndex]; + charIndex++; + } + } + } + + // Serial.println("\n\r********"); + + for (int i = 0; i < numberOfLines; i++) { + if (lines[i][0] == '\0') { + // break; + } + if (strstr(lines[i], paddedChar) != NULL) { + // Serial.println(lines[i]); + // delay(1); + + for (int j = 0; j < 18; j++) { + lines[i][j] = ' '; + } + // lines[i][18] = '\n'; + // lines[i][19] = '\r'; + lines[i][0] = '\0'; + } + } + + nodeFileString.clear(); + nodeFileString.concat("{"); + for (int i = 0; i < numberOfLines; i++) { + if (lines[i][0] == '\0') { + continue; + } + // Serial.println(i); + // delay(1); + for (int j = 0; j < 20; j++) { + if (lines[i][j] == '\0') { + break; + } + if (lines[i][j] == ' ') { + continue; + } + nodeFileString.concat(lines[i][j]); + // Serial.print(lines[i][j]); + // delay(1); + } + } + nodeFileString.concat("}\n\r"); + + nodeFile.close(); + nodeFile = LittleFS.open("nodeFileSlot" + String(slot) + ".txt", "w+"); + + nodeFile.write(nodeFileString.c_str()); + + nodeFile.close(); +} + +void addBridgeToNodeFile(int node1, int node2, int slot) { + nodeFile = LittleFS.open("nodeFileSlot" + String(slot) + ".txt", "r+"); + // Serial.println(nodeFile); + + 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"); + + // if (1) + // { + // 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"); + // } + // Serial.print (nodeFile); + nodeFile.close(); + return; + } + } + // Serial.println(nodeFileBraceIndex); + nodeFile.seek(nodeFileBraceIndex); + + nodeFile.print(node1); + nodeFile.print("-"); + nodeFile.print(node2); + nodeFile.print(",}\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(int slot) { + + nodeFile = LittleFS.open("nodeFile" + String(slot) + ".txt", "w"); + + if (!nodeFile) { + if (debugFP) + Serial.println("Failed to open nodeFile"); + return; + } else { + if (debugFP) + Serial.println( + "\n\rrecreated nodeFile.txt\n\n\rloading bridges from wokwi.txt\n\r"); + } + nodeFile.print("{\n\r"); + for (int i = 0; i < numConnsJson; i++) { + if (connectionsW[i][0] == "-1" && connectionsW[i][1] != "-1") { + // lightUpNode(connectionsW[i][0].toInt()); + continue; + } + if (connectionsW[i][1] == "-1" && connectionsW[i][0] != "-1") { + // lightUpNode(connectionsW[i][1].toInt()); + continue; + } + if (connectionsW[i][0] == connectionsW[i][1]) { + // lightUpNode(connectionsW[i][0].toInt()); + continue; + } + + nodeFile.print(connectionsW[i][0]); nodeFile.print("-"); - nodeFile.print(node2); - nodeFile.print(",}\n\r"); + nodeFile.print(connectionsW[i][1]); + nodeFile.print(",\n\r"); + } + nodeFile.print("\n\r}\n\r"); - if (debugFP) - { - Serial.println("wrote to nodeFile.txt"); + if (debugFP) { + Serial.println("wrote to nodeFile.txt"); - Serial.println("nodeFile.txt contents:\n\r"); - nodeFile.seek(0); + Serial.println("nodeFile.txt contents:"); + nodeFile.seek(0); - while (nodeFile.available()) - { - Serial.write(nodeFile.read()); - } - Serial.println("\n\r"); + while (nodeFile.available()) { + Serial.write(nodeFile.read()); } - nodeFile.close(); + Serial.println("\n\r"); + } + nodeFile.close(); } -void writeToNodeFile(int slot) -{ +void openNodeFile(int slot) { + timeToFP = millis(); - nodeFile = LittleFS.open("nodeFile" + String(slot) + ".txt", "w"); - - if (!nodeFile) - { - if (debugFP) - Serial.println("Failed to open nodeFile"); - return; - } - else - { - if (debugFP) - Serial.println("\n\rrecreated nodeFile.txt\n\n\rloading bridges from wokwi.txt\n\r"); - } - nodeFile.print("{\n\r"); - for (int i = 0; i < numConnsJson; i++) - { - if (connectionsW[i][0] == "-1" && connectionsW[i][1] != "-1") - { - // lightUpNode(connectionsW[i][0].toInt()); - continue; - } - if (connectionsW[i][1] == "-1" && connectionsW[i][0] != "-1") - { - // lightUpNode(connectionsW[i][1].toInt()); - continue; - } - if (connectionsW[i][0] == connectionsW[i][1]) - { - // lightUpNode(connectionsW[i][0].toInt()); - continue; - } - - nodeFile.print(connectionsW[i][0]); - nodeFile.print("-"); - nodeFile.print(connectionsW[i][1]); - nodeFile.print(",\n\r"); - } - nodeFile.print("\n\r}\n\r"); + nodeFile = LittleFS.open("nodeFileSlot" + String(slot) + ".txt", "r"); + if (!nodeFile) { if (debugFP) - { - Serial.println("wrote to nodeFile.txt"); + Serial.println("Failed to open nodeFile"); + return; + } else { + if (debugFP) + Serial.println("\n\ropened nodeFileSlot" + String(slot) + + +".txt\n\n\rloading bridges from file\n\r"); + } - Serial.println("nodeFile.txt contents:"); - nodeFile.seek(0); + nodeFileString.clear(); + nodeFileString.read(nodeFile); + // Serial.println(nodeFileString); - while (nodeFile.available()) - { - Serial.write(nodeFile.read()); - } - Serial.println("\n\r"); - } - nodeFile.close(); + nodeFile.close(); + splitStringToFields(); + // parseStringToBridges(); } -void openNodeFile(int slot) -{ - timeToFP = millis(); +void splitStringToFields() { + int openBraceIndex = 0; + int closeBraceIndex = 0; - nodeFile = LittleFS.open("nodeFileSlot" + String(slot) + ".txt", "r"); + if (debugFP) + Serial.println("\n\rraw input file\n\r"); + if (debugFP) + Serial.println(nodeFileString); + if (debugFP) + Serial.println("\n\rsplitting and cleaning up string\n\r"); + if (debugFP) + Serial.println("_"); - if (!nodeFile) - { - if (debugFP) - Serial.println("Failed to open nodeFile"); - return; - } - else - { - if (debugFP) - Serial.println("\n\ropened nodeFileSlot" + String(slot) + +".txt\n\n\rloading bridges from file\n\r"); - } + openBraceIndex = nodeFileString.indexOf("{"); + closeBraceIndex = nodeFileString.indexOf("}"); + int fIndex = nodeFileString.indexOf("f"); - nodeFileString.clear(); - nodeFileString.read(nodeFile); - // Serial.println(nodeFileString); + int foundOpenBrace = -1; + int foundCloseBrace = -1; + int foundF = -1; - nodeFile.close(); - splitStringToFields(); - // parseStringToBridges(); + if (openBraceIndex != -1) { + foundOpenBrace = 1; + } + if (closeBraceIndex != -1) { + foundCloseBrace = 1; + } + if (fIndex != -1) { + foundF = 1; + } + + // Serial.println(openBraceIndex); + // Serial.println(closeBraceIndex); + // Serial.println(fIndex); + + if (foundF == 1) { + nodeFileString.substring(nodeFileString, fIndex + 1, + nodeFileString.length()); + } + + if (foundOpenBrace == 1 && foundCloseBrace == 1) { + + nodeFileString.substring(specialFunctionsString, openBraceIndex + 1, + closeBraceIndex); + } else { + nodeFileString.substring(specialFunctionsString, 0, + -1); // nodeFileString.length()); + } + specialFunctionsString.trim(); + + if (debugFP) + Serial.println(specialFunctionsString); + + if (debugFP) + Serial.println("^\n\r"); + /* + nodeFileString.remove(0, closeBraceIndex + 1); + nodeFileString.trim(); + + openBraceIndex = nodeFileString.indexOf("{"); + closeBraceIndex = nodeFileString.indexOf("}"); + //nodeFileString.substring(specialFunctionsString, openBraceIndex + 1, + closeBraceIndex); specialFunctionsString.trim(); + if(debugFP)Serial.println("_"); + if(debugFP)Serial.println(specialFunctionsString); + if(debugFP)Serial.println("^\n\r"); + */ + replaceSFNamesWithDefinedInts(); + replaceNanoNamesWithDefinedInts(); + parseStringToBridges(); } -void splitStringToFields() -{ - int openBraceIndex = 0; - int closeBraceIndex = 0; +void replaceSFNamesWithDefinedInts(void) { + specialFunctionsString.toUpperCase(); + if (debugFP) { + Serial.println("replacing special function names with defined ints\n\r"); + Serial.println(specialFunctionsString); + } - if (debugFP) - Serial.println("\n\rraw input file\n\r"); - if (debugFP) - Serial.println(nodeFileString); - if (debugFP) - Serial.println("\n\rsplitting and cleaning up string\n\r"); - if (debugFP) - Serial.println("_"); + specialFunctionsString.replace("GND", "100"); + specialFunctionsString.replace("GROUND", "100"); + specialFunctionsString.replace("SUPPLY_5V", "105"); + specialFunctionsString.replace("SUPPLY_3V3", "103"); - openBraceIndex = nodeFileString.indexOf("{"); - closeBraceIndex = nodeFileString.indexOf("}"); - int fIndex = nodeFileString.indexOf("f"); + specialFunctionsString.replace("DAC0_5V", "106"); + specialFunctionsString.replace("DAC1_8V", "107"); + specialFunctionsString.replace("DAC0", "106"); + specialFunctionsString.replace("DAC1", "107"); - int foundOpenBrace = -1; - int foundCloseBrace = -1; - int foundF = -1; + specialFunctionsString.replace("INA_N", "109"); + specialFunctionsString.replace("INA_P", "108"); + specialFunctionsString.replace("I_N", "109"); + specialFunctionsString.replace("I_P", "108"); + specialFunctionsString.replace("CURRENT_SENSE_MINUS", "109"); + specialFunctionsString.replace("CURRENT_SENSE_PLUS", "108"); + specialFunctionsString.replace("ISENSE_MINUS", "109"); + specialFunctionsString.replace("ISENSE_PLUS", "108"); - if (openBraceIndex != -1) - { - foundOpenBrace = 1; - } - if (closeBraceIndex != -1) - { - foundCloseBrace = 1; - } - if (fIndex != -1) - { - foundF = 1; - } + specialFunctionsString.replace("EMPTY_NET", "127"); - // Serial.println(openBraceIndex); - // Serial.println(closeBraceIndex); - // Serial.println(fIndex); + specialFunctionsString.replace("ADC0_5V", "110"); + specialFunctionsString.replace("ADC1_5V", "111"); + specialFunctionsString.replace("ADC2_5V", "112"); + specialFunctionsString.replace("ADC3_8V", "113"); + specialFunctionsString.replace("ADC0", "110"); + specialFunctionsString.replace("ADC1", "111"); + specialFunctionsString.replace("ADC2", "112"); + specialFunctionsString.replace("ADC3", "113"); - if (foundF == 1) - { - nodeFileString.substring(nodeFileString, fIndex + 1, nodeFileString.length()); - } + specialFunctionsString.replace("+5V", "105"); + specialFunctionsString.replace("5V", "105"); + specialFunctionsString.replace("3.3V", "103"); + specialFunctionsString.replace("3V3", "103"); - if (foundOpenBrace == 1 && foundCloseBrace == 1) - { - - nodeFileString.substring(specialFunctionsString, openBraceIndex + 1, closeBraceIndex); - } - else - { - nodeFileString.substring(specialFunctionsString, 0, -1); // nodeFileString.length()); - } - specialFunctionsString.trim(); - - if (debugFP) - Serial.println(specialFunctionsString); - - if (debugFP) - Serial.println("^\n\r"); - /* - nodeFileString.remove(0, closeBraceIndex + 1); - nodeFileString.trim(); - - openBraceIndex = nodeFileString.indexOf("{"); - closeBraceIndex = nodeFileString.indexOf("}"); - //nodeFileString.substring(specialFunctionsString, openBraceIndex + 1, closeBraceIndex); - specialFunctionsString.trim(); - if(debugFP)Serial.println("_"); - if(debugFP)Serial.println(specialFunctionsString); - if(debugFP)Serial.println("^\n\r"); - */ - replaceSFNamesWithDefinedInts(); - replaceNanoNamesWithDefinedInts(); - parseStringToBridges(); + specialFunctionsString.replace("RP_GPIO_0", "114"); + specialFunctionsString.replace("RP_UART_TX", "116"); + specialFunctionsString.replace("RP_UART_RX", "117"); + specialFunctionsString.replace("GPIO_0", "114"); + specialFunctionsString.replace("UART_TX", "116"); + specialFunctionsString.replace("UART_RX", "117"); } -void replaceSFNamesWithDefinedInts(void) +void replaceNanoNamesWithDefinedInts( + void) // for dome reason Arduino's String wasn't replacing like 1 or 2 of + // the names, so I'm using SafeString now and it works { - specialFunctionsString.toUpperCase(); - if (debugFP) - { - Serial.println("replacing special function names with defined ints\n\r"); - Serial.println(specialFunctionsString); - } + if (debugFP) + Serial.println("replacing special function names with defined ints\n\r"); - specialFunctionsString.replace("GND", "100"); - specialFunctionsString.replace("GROUND", "100"); - specialFunctionsString.replace("SUPPLY_5V", "105"); - specialFunctionsString.replace("SUPPLY_3V3", "103"); + char nanoName[5]; - specialFunctionsString.replace("DAC0_5V", "106"); - specialFunctionsString.replace("DAC1_8V", "107"); - specialFunctionsString.replace("DAC0", "106"); - specialFunctionsString.replace("DAC1", "107"); + itoa(NANO_D10, nanoName, 10); + specialFunctionsString.replace("D10", nanoName); - specialFunctionsString.replace("INA_N", "109"); - specialFunctionsString.replace("INA_P", "108"); - specialFunctionsString.replace("I_N", "109"); - specialFunctionsString.replace("I_P", "108"); - specialFunctionsString.replace("CURRENT_SENSE_MINUS", "109"); - specialFunctionsString.replace("CURRENT_SENSE_PLUS", "108"); - specialFunctionsString.replace("ISENSE_MINUS", "109"); - specialFunctionsString.replace("ISENSE_PLUS", "108"); + itoa(NANO_D11, nanoName, 10); + specialFunctionsString.replace("D11", nanoName); - specialFunctionsString.replace("EMPTY_NET", "127"); + itoa(NANO_D12, nanoName, 10); + specialFunctionsString.replace("D12", nanoName); - specialFunctionsString.replace("ADC0_5V", "110"); - specialFunctionsString.replace("ADC1_5V", "111"); - specialFunctionsString.replace("ADC2_5V", "112"); - specialFunctionsString.replace("ADC3_8V", "113"); - specialFunctionsString.replace("ADC0", "110"); - specialFunctionsString.replace("ADC1", "111"); - specialFunctionsString.replace("ADC2", "112"); - specialFunctionsString.replace("ADC3", "113"); + itoa(NANO_D13, nanoName, 10); + specialFunctionsString.replace("D13", nanoName); - specialFunctionsString.replace("+5V", "105"); - specialFunctionsString.replace("5V", "105"); - specialFunctionsString.replace("3.3V", "103"); - specialFunctionsString.replace("3V3", "103"); + itoa(NANO_D0, nanoName, 10); + specialFunctionsString.replace("D0", nanoName); - specialFunctionsString.replace("RP_GPIO_0", "114"); - specialFunctionsString.replace("RP_UART_TX", "116"); - specialFunctionsString.replace("RP_UART_RX", "117"); - specialFunctionsString.replace("GPIO_0", "114"); - specialFunctionsString.replace("UART_TX", "116"); - specialFunctionsString.replace("UART_RX", "117"); + itoa(NANO_D1, nanoName, 10); + specialFunctionsString.replace("D1", nanoName); + + itoa(NANO_D2, nanoName, 10); + specialFunctionsString.replace("D2", nanoName); + + itoa(NANO_D3, nanoName, 10); + specialFunctionsString.replace("D3", nanoName); + + itoa(NANO_D4, nanoName, 10); + specialFunctionsString.replace("D4", nanoName); + + itoa(NANO_D5, nanoName, 10); + specialFunctionsString.replace("D5", nanoName); + + itoa(NANO_D6, nanoName, 10); + specialFunctionsString.replace("D6", nanoName); + + itoa(NANO_D7, nanoName, 10); + specialFunctionsString.replace("D7", nanoName); + + itoa(NANO_D8, nanoName, 10); + specialFunctionsString.replace("D8", nanoName); + + itoa(NANO_D9, nanoName, 10); + specialFunctionsString.replace("D9", nanoName); + + itoa(NANO_RESET, nanoName, 10); + specialFunctionsString.replace("RESET", nanoName); + + itoa(NANO_AREF, nanoName, 10); + specialFunctionsString.replace("AREF", nanoName); + + itoa(NANO_A0, nanoName, 10); + specialFunctionsString.replace("A0", nanoName); + + itoa(NANO_A1, nanoName, 10); + specialFunctionsString.replace("A1", nanoName); + + itoa(NANO_A2, nanoName, 10); + specialFunctionsString.replace("A2", nanoName); + + itoa(NANO_A3, nanoName, 10); + specialFunctionsString.replace("A3", nanoName); + + itoa(NANO_A4, nanoName, 10); + specialFunctionsString.replace("A4", nanoName); + + itoa(NANO_A5, nanoName, 10); + specialFunctionsString.replace("A5", nanoName); + + itoa(NANO_A6, nanoName, 10); + specialFunctionsString.replace("A6", nanoName); + + itoa(NANO_A7, nanoName, 10); + specialFunctionsString.replace("A7", nanoName); + + // if(debugFP)Serial.println(bridgeString); + if (debugFP) + Serial.println(specialFunctionsString); + if (debugFP) + Serial.println("\n\n\r"); } -void replaceNanoNamesWithDefinedInts(void) // for dome reason Arduino's String wasn't replacing like 1 or 2 of the names, so I'm using SafeString now and it works -{ +void parseStringToBridges(void) { + + // int bridgeStringLength = bridgeString.length() - 1; + + int specialFunctionsStringLength = specialFunctionsString.length() - 1; + + int readLength = 0; + + newBridgeLength = 0; + newBridgeIndex = 0; + + if (debugFP) { + Serial.println("parsing bridges into array\n\r"); + } + int stringIndex = 0; + char delimitersCh[] = "[,- \n\r"; + + createSafeString(buffer, 10); + createSafeStringFromCharArray(delimiters, delimitersCh); + int doneReading = 0; + + for (int i = 0; i <= specialFunctionsStringLength; i++) { + + stringIndex = + specialFunctionsString.stoken(buffer, stringIndex, delimiters); + + // Serial.print("buffer = "); + // Serial.println(buffer); + + // Serial.print("stringIndex = "); + // Serial.println(stringIndex); + + buffer.toInt(path[newBridgeIndex].node1); + + // Serial.print("path[newBridgeIndex].node1 = "); + // Serial.println(path[newBridgeIndex].node1); + + if (debugFP) { + Serial.print("node1 = "); + Serial.println(path[newBridgeIndex].node1); + } + + stringIndex = + specialFunctionsString.stoken(buffer, stringIndex, delimiters); + + buffer.toInt(path[newBridgeIndex].node2); + + if (debugFP) { + Serial.print("node2 = "); + Serial.println(path[newBridgeIndex].node2); + } + + readLength = stringIndex; + + if (readLength == -1) { + doneReading = 1; + break; + } + newBridgeLength++; + newBridgeIndex++; + + if (debugFP) { + Serial.print("readLength = "); + Serial.println(readLength); + Serial.print("specialFunctionsString.length() = "); + Serial.println(specialFunctionsString.length()); + } + if (debugFP) - Serial.println("replacing special function names with defined ints\n\r"); - - char nanoName[5]; - - itoa(NANO_D10, nanoName, 10); - specialFunctionsString.replace("D10", nanoName); - - itoa(NANO_D11, nanoName, 10); - specialFunctionsString.replace("D11", nanoName); - - itoa(NANO_D12, nanoName, 10); - specialFunctionsString.replace("D12", nanoName); - - itoa(NANO_D13, nanoName, 10); - specialFunctionsString.replace("D13", nanoName); - - itoa(NANO_D0, nanoName, 10); - specialFunctionsString.replace("D0", nanoName); - - itoa(NANO_D1, nanoName, 10); - specialFunctionsString.replace("D1", nanoName); - - itoa(NANO_D2, nanoName, 10); - specialFunctionsString.replace("D2", nanoName); - - itoa(NANO_D3, nanoName, 10); - specialFunctionsString.replace("D3", nanoName); - - itoa(NANO_D4, nanoName, 10); - specialFunctionsString.replace("D4", nanoName); - - itoa(NANO_D5, nanoName, 10); - specialFunctionsString.replace("D5", nanoName); - - itoa(NANO_D6, nanoName, 10); - specialFunctionsString.replace("D6", nanoName); - - itoa(NANO_D7, nanoName, 10); - specialFunctionsString.replace("D7", nanoName); - - itoa(NANO_D8, nanoName, 10); - specialFunctionsString.replace("D8", nanoName); - - itoa(NANO_D9, nanoName, 10); - specialFunctionsString.replace("D9", nanoName); - - itoa(NANO_RESET, nanoName, 10); - specialFunctionsString.replace("RESET", nanoName); - - itoa(NANO_AREF, nanoName, 10); - specialFunctionsString.replace("AREF", nanoName); - - itoa(NANO_A0, nanoName, 10); - specialFunctionsString.replace("A0", nanoName); - - itoa(NANO_A1, nanoName, 10); - specialFunctionsString.replace("A1", nanoName); - - itoa(NANO_A2, nanoName, 10); - specialFunctionsString.replace("A2", nanoName); - - itoa(NANO_A3, nanoName, 10); - specialFunctionsString.replace("A3", nanoName); - - itoa(NANO_A4, nanoName, 10); - specialFunctionsString.replace("A4", nanoName); - - itoa(NANO_A5, nanoName, 10); - specialFunctionsString.replace("A5", nanoName); - - itoa(NANO_A6, nanoName, 10); - specialFunctionsString.replace("A6", nanoName); - - itoa(NANO_A7, nanoName, 10); - specialFunctionsString.replace("A7", nanoName); - - // if(debugFP)Serial.println(bridgeString); + Serial.print(newBridgeIndex); if (debugFP) - Serial.println(specialFunctionsString); + Serial.print("-"); if (debugFP) - Serial.println("\n\n\r"); + Serial.println(newBridge[newBridgeIndex][1]); + } + + newBridgeIndex = 0; + if (debugFP) + for (int i = 0; i < newBridgeLength; i++) { + Serial.print("["); + Serial.print(path[newBridgeIndex].node1); + Serial.print("-"); + Serial.print(path[newBridgeIndex].node2); + Serial.print("],"); + newBridgeIndex++; + } + if (debugFP) + Serial.print("\n\rbridge pairs = "); + if (debugFP) + Serial.println(newBridgeLength); + + nodeFileString.clear(); + + // if(debugFP)Serial.println(nodeFileString); + timeToFP = millis() - timeToFP; + if (debugFPtime) + Serial.print("\n\rtook "); + + if (debugFPtime) + Serial.print(timeToFP); + if (debugFPtime) + Serial.println("ms to open and parse file\n\r"); } -void parseStringToBridges(void) -{ - - // int bridgeStringLength = bridgeString.length() - 1; - - int specialFunctionsStringLength = specialFunctionsString.length() - 1; - - int readLength = 0; - - newBridgeLength = 0; - newBridgeIndex = 0; - - if (debugFP) - { - Serial.println("parsing bridges into array\n\r"); - } - int stringIndex = 0; - char delimitersCh[] = "[,- \n\r"; - - createSafeString(buffer, 10); - createSafeStringFromCharArray(delimiters, delimitersCh); - int doneReading = 0; - - for (int i = 0; i <= specialFunctionsStringLength; i++) - { - - stringIndex = specialFunctionsString.stoken(buffer, stringIndex, delimiters); - - // Serial.print("buffer = "); - // Serial.println(buffer); - - // Serial.print("stringIndex = "); - // Serial.println(stringIndex); - - buffer.toInt(path[newBridgeIndex].node1); - - // Serial.print("path[newBridgeIndex].node1 = "); - // Serial.println(path[newBridgeIndex].node1); - - if (debugFP) - { - Serial.print("node1 = "); - Serial.println(path[newBridgeIndex].node1); - } - - stringIndex = specialFunctionsString.stoken(buffer, stringIndex, delimiters); - - buffer.toInt(path[newBridgeIndex].node2); - - if (debugFP) - { - Serial.print("node2 = "); - Serial.println(path[newBridgeIndex].node2); - } - - readLength = stringIndex; - - if (readLength == -1) - { - doneReading = 1; - break; - } - newBridgeLength++; - newBridgeIndex++; - - if (debugFP) - { - Serial.print("readLength = "); - Serial.println(readLength); - Serial.print("specialFunctionsString.length() = "); - Serial.println(specialFunctionsString.length()); - } - - if (debugFP) - Serial.print(newBridgeIndex); - if (debugFP) - Serial.print("-"); - if (debugFP) - Serial.println(newBridge[newBridgeIndex][1]); - } - - newBridgeIndex = 0; - if (debugFP) - for (int i = 0; i < newBridgeLength; i++) - { - Serial.print("["); - Serial.print(path[newBridgeIndex].node1); - Serial.print("-"); - Serial.print(path[newBridgeIndex].node2); - Serial.print("],"); - newBridgeIndex++; - } - if (debugFP) - Serial.print("\n\rbridge pairs = "); - if (debugFP) - Serial.println(newBridgeLength); - - nodeFileString.clear(); - - // if(debugFP)Serial.println(nodeFileString); - timeToFP = millis() - timeToFP; - if (debugFPtime) - Serial.print("\n\rtook "); - - if (debugFPtime) - Serial.print(timeToFP); - if (debugFPtime) - Serial.println("ms to open and parse file\n\r"); +int lenHelper(int x) { + if (x >= 1000000000) + return 10; + if (x >= 100000000) + return 9; + if (x >= 10000000) + return 8; + if (x >= 1000000) + return 7; + if (x >= 100000) + return 6; + if (x >= 10000) + return 5; + if (x >= 1000) + return 4; + if (x >= 100) + return 3; + if (x >= 10) + return 2; + return 1; } -int lenHelper(int x) -{ - if (x >= 1000000000) - return 10; - if (x >= 100000000) - return 9; - if (x >= 10000000) - return 8; - if (x >= 1000000) - return 7; - if (x >= 100000) - return 6; - if (x >= 10000) - return 5; - if (x >= 1000) - return 4; - if (x >= 100) - return 3; - if (x >= 10) - return 2; - return 1; -} +int printLen(int x) { return x < 0 ? lenHelper(-x) + 1 : lenHelper(x); } -int printLen(int x) -{ - return x < 0 ? lenHelper(-x) + 1 : lenHelper(x); -} +void debugFlagInit(void) { -void debugFlagInit(void) -{ - - if (EEPROM.read(FIRSTSTARTUPADDRESS) == 255) - { - EEPROM.write(FIRSTSTARTUPADDRESS, 0); - EEPROM.write(DEBUG_FILEPARSINGADDRESS, 0); - EEPROM.write(TIME_FILEPARSINGADDRESS, 0); - EEPROM.write(DEBUG_NETMANAGERADDRESS, 0); - EEPROM.write(TIME_NETMANAGERADDRESS, 0); - EEPROM.write(DEBUG_NETTOCHIPCONNECTIONSADDRESS, 0); - EEPROM.write(DEBUG_NETTOCHIPCONNECTIONSALTADDRESS, 0); - EEPROM.write(DEBUG_LEDSADDRESS, 0); - EEPROM.write(LEDBRIGHTNESSADDRESS, DEFAULTBRIGHTNESS); - EEPROM.write(RAILBRIGHTNESSADDRESS, DEFAULTRAILBRIGHTNESS); - EEPROM.write(SPECIALBRIGHTNESSADDRESS, DEFAULTSPECIALNETBRIGHTNESS); - EEPROM.write(PROBESWAPADDRESS, 0); - EEPROM.write(ROTARYENCODER_MODE_ADDRESS, 0); - - EEPROM.commit(); - delay(5); - } - -#ifdef EEPROMSTUFF - debugFP = EEPROM.read(DEBUG_FILEPARSINGADDRESS); - debugFPtime = EEPROM.read(TIME_FILEPARSINGADDRESS); - - debugNM = EEPROM.read(DEBUG_NETMANAGERADDRESS); - debugNMtime = EEPROM.read(TIME_NETMANAGERADDRESS); - - debugNTCC = EEPROM.read(DEBUG_NETTOCHIPCONNECTIONSADDRESS); - debugNTCC2 = EEPROM.read(DEBUG_NETTOCHIPCONNECTIONSALTADDRESS); - - LEDbrightnessRail = EEPROM.read(RAILBRIGHTNESSADDRESS); - LEDbrightness = EEPROM.read(LEDBRIGHTNESSADDRESS); - LEDbrightnessSpecial = EEPROM.read(SPECIALBRIGHTNESSADDRESS); - - debugLEDs = EEPROM.read(DEBUG_LEDSADDRESS); - - rotaryEncoderMode = EEPROM.read(ROTARYENCODER_MODE_ADDRESS); - - probeSwap = EEPROM.read(PROBESWAPADDRESS); - loadFileOnStart = EEPROM.read(LOADFILEONSTART_ADDRESS); - -#else - - debugFP = 1; - debugFPtime = 1; - - debugNM = 1; - debugNMtime = 1; - - debugNTCC = 1; - debugNTCC2 = 1; - - // debugLEDs = 1; -#endif - if (loadFileOnStart != 0 && loadFileOnStart != 1) - EEPROM.write(LOADFILEONSTART_ADDRESS, 0); - - if (debugFP != 0 && debugFP != 1) - EEPROM.write(DEBUG_FILEPARSINGADDRESS, 0); - - if (debugFPtime != 0 && debugFPtime != 1) - EEPROM.write(TIME_FILEPARSINGADDRESS, 0); - - if (debugNM != 0 && debugNM != 1) - EEPROM.write(DEBUG_NETMANAGERADDRESS, 0); - - if (debugNMtime != 0 && debugNMtime != 1) - EEPROM.write(TIME_NETMANAGERADDRESS, 0); - - if (debugNTCC != 0 && debugNTCC != 1) - EEPROM.write(DEBUG_NETTOCHIPCONNECTIONSADDRESS, 0); - - if (debugNTCC2 != 0 && debugNTCC2 != 1) - EEPROM.write(DEBUG_NETTOCHIPCONNECTIONSALTADDRESS, 0); - - if (debugLEDs != 0 && debugLEDs != 1) - EEPROM.write(DEBUG_LEDSADDRESS, 0); - - if (LEDbrightnessRail < 0 || LEDbrightnessRail > 200) - { - EEPROM.write(RAILBRIGHTNESSADDRESS, DEFAULTRAILBRIGHTNESS); - - LEDbrightnessRail = DEFAULTRAILBRIGHTNESS; - } - if (LEDbrightness < 0 || LEDbrightness > 200) - { - EEPROM.write(LEDBRIGHTNESSADDRESS, DEFAULTBRIGHTNESS); - LEDbrightness = DEFAULTBRIGHTNESS; - } - - if (LEDbrightnessSpecial < 0 || LEDbrightnessSpecial > 200) - { - EEPROM.write(SPECIALBRIGHTNESSADDRESS, DEFAULTSPECIALNETBRIGHTNESS); - LEDbrightnessSpecial = DEFAULTSPECIALNETBRIGHTNESS; - } - if (rotaryEncoderMode != 0 && rotaryEncoderMode != 1) - { - EEPROM.write(ROTARYENCODER_MODE_ADDRESS, 0); - rotaryEncoderMode = 0; - } + if (EEPROM.read(FIRSTSTARTUPADDRESS) == 255) { + EEPROM.write(FIRSTSTARTUPADDRESS, 0); + EEPROM.write(DEBUG_FILEPARSINGADDRESS, 0); + EEPROM.write(TIME_FILEPARSINGADDRESS, 0); + EEPROM.write(DEBUG_NETMANAGERADDRESS, 0); + EEPROM.write(TIME_NETMANAGERADDRESS, 0); + EEPROM.write(DEBUG_NETTOCHIPCONNECTIONSADDRESS, 0); + EEPROM.write(DEBUG_NETTOCHIPCONNECTIONSALTADDRESS, 0); + EEPROM.write(DEBUG_LEDSADDRESS, 0); + EEPROM.write(LEDBRIGHTNESSADDRESS, DEFAULTBRIGHTNESS); + EEPROM.write(RAILBRIGHTNESSADDRESS, DEFAULTRAILBRIGHTNESS); + EEPROM.write(SPECIALBRIGHTNESSADDRESS, DEFAULTSPECIALNETBRIGHTNESS); + EEPROM.write(PROBESWAPADDRESS, 0); + EEPROM.write(ROTARYENCODER_MODE_ADDRESS, 0); EEPROM.commit(); delay(5); + } + +#ifdef EEPROMSTUFF + debugFP = EEPROM.read(DEBUG_FILEPARSINGADDRESS); + debugFPtime = EEPROM.read(TIME_FILEPARSINGADDRESS); + + debugNM = EEPROM.read(DEBUG_NETMANAGERADDRESS); + debugNMtime = EEPROM.read(TIME_NETMANAGERADDRESS); + + debugNTCC = EEPROM.read(DEBUG_NETTOCHIPCONNECTIONSADDRESS); + debugNTCC2 = EEPROM.read(DEBUG_NETTOCHIPCONNECTIONSALTADDRESS); + + LEDbrightnessRail = EEPROM.read(RAILBRIGHTNESSADDRESS); + LEDbrightness = EEPROM.read(LEDBRIGHTNESSADDRESS); + LEDbrightnessSpecial = EEPROM.read(SPECIALBRIGHTNESSADDRESS); + + debugLEDs = EEPROM.read(DEBUG_LEDSADDRESS); + + rotaryEncoderMode = EEPROM.read(ROTARYENCODER_MODE_ADDRESS); + + probeSwap = EEPROM.read(PROBESWAPADDRESS); + loadFileOnStart = EEPROM.read(LOADFILEONSTART_ADDRESS); + +#else + + debugFP = 1; + debugFPtime = 1; + + debugNM = 1; + debugNMtime = 1; + + debugNTCC = 1; + debugNTCC2 = 1; + + // debugLEDs = 1; +#endif + if (loadFileOnStart != 0 && loadFileOnStart != 1) + EEPROM.write(LOADFILEONSTART_ADDRESS, 0); + + if (debugFP != 0 && debugFP != 1) + EEPROM.write(DEBUG_FILEPARSINGADDRESS, 0); + + if (debugFPtime != 0 && debugFPtime != 1) + EEPROM.write(TIME_FILEPARSINGADDRESS, 0); + + if (debugNM != 0 && debugNM != 1) + EEPROM.write(DEBUG_NETMANAGERADDRESS, 0); + + if (debugNMtime != 0 && debugNMtime != 1) + EEPROM.write(TIME_NETMANAGERADDRESS, 0); + + if (debugNTCC != 0 && debugNTCC != 1) + EEPROM.write(DEBUG_NETTOCHIPCONNECTIONSADDRESS, 0); + + if (debugNTCC2 != 0 && debugNTCC2 != 1) + EEPROM.write(DEBUG_NETTOCHIPCONNECTIONSALTADDRESS, 0); + + if (debugLEDs != 0 && debugLEDs != 1) + EEPROM.write(DEBUG_LEDSADDRESS, 0); + + if (LEDbrightnessRail < 0 || LEDbrightnessRail > 200) { + EEPROM.write(RAILBRIGHTNESSADDRESS, DEFAULTRAILBRIGHTNESS); + + LEDbrightnessRail = DEFAULTRAILBRIGHTNESS; + } + if (LEDbrightness < 0 || LEDbrightness > 200) { + EEPROM.write(LEDBRIGHTNESSADDRESS, DEFAULTBRIGHTNESS); + LEDbrightness = DEFAULTBRIGHTNESS; + } + + if (LEDbrightnessSpecial < 0 || LEDbrightnessSpecial > 200) { + EEPROM.write(SPECIALBRIGHTNESSADDRESS, DEFAULTSPECIALNETBRIGHTNESS); + LEDbrightnessSpecial = DEFAULTSPECIALNETBRIGHTNESS; + } + if (rotaryEncoderMode != 0 && rotaryEncoderMode != 1) { + EEPROM.write(ROTARYENCODER_MODE_ADDRESS, 0); + rotaryEncoderMode = 0; + } + + EEPROM.commit(); + delay(5); } -void debugFlagSet(int flag) -{ - int flagStatus; - switch (flag) - { - case 1: - { - flagStatus = EEPROM.read(DEBUG_FILEPARSINGADDRESS); - if (flagStatus == 0) - { - EEPROM.write(DEBUG_FILEPARSINGADDRESS, 1); +void debugFlagSet(int flag) { + int flagStatus; + switch (flag) { + case 1: { + flagStatus = EEPROM.read(DEBUG_FILEPARSINGADDRESS); + if (flagStatus == 0) { + EEPROM.write(DEBUG_FILEPARSINGADDRESS, 1); - debugFP = true; - } - else - { - EEPROM.write(DEBUG_FILEPARSINGADDRESS, 0); + debugFP = true; + } else { + EEPROM.write(DEBUG_FILEPARSINGADDRESS, 0); - debugFP = false; - } - - break; + debugFP = false; } - case 2: + break; + } + + case 2: { + flagStatus = EEPROM.read(DEBUG_NETMANAGERADDRESS); + + if (flagStatus == 0) { + EEPROM.write(DEBUG_NETMANAGERADDRESS, 1); + + debugNM = true; + } else { + EEPROM.write(DEBUG_NETMANAGERADDRESS, 0); + + debugNM = false; + } + break; + } + + case 3: { + flagStatus = EEPROM.read(DEBUG_NETTOCHIPCONNECTIONSADDRESS); + + if (flagStatus == 0) { + EEPROM.write(DEBUG_NETTOCHIPCONNECTIONSADDRESS, 1); + + debugNTCC = true; + } else { + EEPROM.write(DEBUG_NETTOCHIPCONNECTIONSADDRESS, 0); + + debugNTCC = false; + } + + break; + } + case 4: { + flagStatus = EEPROM.read(DEBUG_NETTOCHIPCONNECTIONSALTADDRESS); + + if (flagStatus == 0) { + EEPROM.write(DEBUG_NETTOCHIPCONNECTIONSALTADDRESS, 1); + + debugNTCC2 = true; + } else { + EEPROM.write(DEBUG_NETTOCHIPCONNECTIONSALTADDRESS, 0); + + debugNTCC2 = false; + } + break; + } + + case 5: { + flagStatus = EEPROM.read(DEBUG_LEDSADDRESS); + + if (flagStatus == 0) { + EEPROM.write(DEBUG_LEDSADDRESS, 1); + + debugLEDs = true; + } else { + EEPROM.write(DEBUG_LEDSADDRESS, 0); + + debugLEDs = false; + } + break; + } + + case 6: { + flagStatus = EEPROM.read(PROBESWAPADDRESS); + + if (flagStatus == 0) { + EEPROM.write(PROBESWAPADDRESS, 1); + + probeSwap = true; + } else { + EEPROM.write(PROBESWAPADDRESS, 0); + + probeSwap = false; + } + break; + } + + case 0: { + EEPROM.write(DEBUG_FILEPARSINGADDRESS, 0); + EEPROM.write(TIME_FILEPARSINGADDRESS, 0); + EEPROM.write(DEBUG_NETMANAGERADDRESS, 0); + EEPROM.write(TIME_NETMANAGERADDRESS, 0); + EEPROM.write(DEBUG_NETTOCHIPCONNECTIONSADDRESS, 0); + EEPROM.write(DEBUG_NETTOCHIPCONNECTIONSALTADDRESS, 0); + EEPROM.write(DEBUG_LEDSADDRESS, 0); + + debugFP = false; + debugFPtime = false; + debugNM = false; + debugNMtime = false; + debugNTCC = false; + debugNTCC2 = false; + debugLEDs = false; + + break; + } + + case 9: { + EEPROM.write(DEBUG_FILEPARSINGADDRESS, 1); + EEPROM.write(TIME_FILEPARSINGADDRESS, 1); + EEPROM.write(DEBUG_NETMANAGERADDRESS, 1); + EEPROM.write(TIME_NETMANAGERADDRESS, 1); + EEPROM.write(DEBUG_NETTOCHIPCONNECTIONSADDRESS, 1); + EEPROM.write(DEBUG_NETTOCHIPCONNECTIONSALTADDRESS, 1); + EEPROM.write(DEBUG_LEDSADDRESS, 1); + debugFP = true; + debugFPtime = true; + debugNM = true; + debugNMtime = true; + debugNTCC = true; + debugNTCC2 = true; + debugLEDs = true; + break; + } + case 10: { { - flagStatus = EEPROM.read(DEBUG_NETMANAGERADDRESS); + EEPROM.write(ROTARYENCODER_MODE_ADDRESS, 0); - if (flagStatus == 0) - { - EEPROM.write(DEBUG_NETMANAGERADDRESS, 1); - - debugNM = true; - } - else - { - EEPROM.write(DEBUG_NETMANAGERADDRESS, 0); - - debugNM = false; - } - break; + rotaryEncoderMode = 0; } - - case 3: + break; + } + case 11: { { - flagStatus = EEPROM.read(DEBUG_NETTOCHIPCONNECTIONSADDRESS); + EEPROM.write(ROTARYENCODER_MODE_ADDRESS, 1); - if (flagStatus == 0) - { - EEPROM.write(DEBUG_NETTOCHIPCONNECTIONSADDRESS, 1); - - debugNTCC = true; - } - else - { - EEPROM.write(DEBUG_NETTOCHIPCONNECTIONSADDRESS, 0); - - debugNTCC = false; - } - - break; + rotaryEncoderMode = 1; } - case 4: - { - flagStatus = EEPROM.read(DEBUG_NETTOCHIPCONNECTIONSALTADDRESS); + break; + } + case 7: { + if (loadFileOnStart == 0) { + EEPROM.write(LOADFILEONSTART_ADDRESS, 1); - if (flagStatus == 0) - { - EEPROM.write(DEBUG_NETTOCHIPCONNECTIONSALTADDRESS, 1); + loadFileOnStart = 1; + } else { + EEPROM.write(LOADFILEONSTART_ADDRESS, 0); - debugNTCC2 = true; - } - else - { - EEPROM.write(DEBUG_NETTOCHIPCONNECTIONSALTADDRESS, 0); - - debugNTCC2 = false; - } - break; + loadFileOnStart = 0; } + break; + } + } + delay(4); + EEPROM.commit(); + delay(8); + return; +} - case 5: - { - flagStatus = EEPROM.read(DEBUG_LEDSADDRESS); - - if (flagStatus == 0) - { - EEPROM.write(DEBUG_LEDSADDRESS, 1); - - debugLEDs = true; - } - else - { - EEPROM.write(DEBUG_LEDSADDRESS, 0); - - debugLEDs = false; - } - break; - } - - case 6: - { - flagStatus = EEPROM.read(PROBESWAPADDRESS); - - if (flagStatus == 0) - { - EEPROM.write(PROBESWAPADDRESS, 1); - - probeSwap = true; - } - else - { - EEPROM.write(PROBESWAPADDRESS, 0); - - probeSwap = false; - } - break; - } - - case 0: - { - EEPROM.write(DEBUG_FILEPARSINGADDRESS, 0); - EEPROM.write(TIME_FILEPARSINGADDRESS, 0); - EEPROM.write(DEBUG_NETMANAGERADDRESS, 0); - EEPROM.write(TIME_NETMANAGERADDRESS, 0); - EEPROM.write(DEBUG_NETTOCHIPCONNECTIONSADDRESS, 0); - EEPROM.write(DEBUG_NETTOCHIPCONNECTIONSALTADDRESS, 0); - EEPROM.write(DEBUG_LEDSADDRESS, 0); - - debugFP = false; - debugFPtime = false; - debugNM = false; - debugNMtime = false; - debugNTCC = false; - debugNTCC2 = false; - debugLEDs = false; - - break; - } - - case 9: - { - EEPROM.write(DEBUG_FILEPARSINGADDRESS, 1); - EEPROM.write(TIME_FILEPARSINGADDRESS, 1); - EEPROM.write(DEBUG_NETMANAGERADDRESS, 1); - EEPROM.write(TIME_NETMANAGERADDRESS, 1); - EEPROM.write(DEBUG_NETTOCHIPCONNECTIONSADDRESS, 1); - EEPROM.write(DEBUG_NETTOCHIPCONNECTIONSALTADDRESS, 1); - EEPROM.write(DEBUG_LEDSADDRESS, 1); - debugFP = true; - debugFPtime = true; - debugNM = true; - debugNMtime = true; - debugNTCC = true; - debugNTCC2 = true; - debugLEDs = true; - break; - } - case 10: - { - { - EEPROM.write(ROTARYENCODER_MODE_ADDRESS, 0); - - rotaryEncoderMode = 0; - } - break; - } - case 11: - { - { - EEPROM.write(ROTARYENCODER_MODE_ADDRESS, 1); - - rotaryEncoderMode = 1; - } - break; - } - case 7: - { - if (loadFileOnStart == 0) - { - EEPROM.write(LOADFILEONSTART_ADDRESS, 1); - - loadFileOnStart = 1; - } - else - { - EEPROM.write(LOADFILEONSTART_ADDRESS, 0); - - loadFileOnStart = 0; - } - break; - } - } - delay(4); - EEPROM.commit(); - delay(8); +void runCommandAfterReset(char command) { + if (EEPROM.read(CLEARBEFORECOMMANDADDRESS) == 1) { return; + } else { + + EEPROM.write(CLEARBEFORECOMMANDADDRESS, 1); + EEPROM.write(LASTCOMMANDADDRESS, command); + EEPROM.commit(); + + digitalWrite(RESETPIN, HIGH); + delay(1); + digitalWrite(RESETPIN, LOW); + + AIRCR_Register = 0x5FA0004; // hard reset + } } -void runCommandAfterReset(char command) -{ - if (EEPROM.read(CLEARBEFORECOMMANDADDRESS) == 1) - { - return; - } - else - { +char lastCommandRead(void) { - EEPROM.write(CLEARBEFORECOMMANDADDRESS, 1); - EEPROM.write(LASTCOMMANDADDRESS, command); - EEPROM.commit(); + Serial.print("last command: "); - digitalWrite(RESETPIN, HIGH); - delay(1); - digitalWrite(RESETPIN, LOW); + Serial.println((char)EEPROM.read(LASTCOMMANDADDRESS)); - AIRCR_Register = 0x5FA0004; // hard reset - } + return EEPROM.read(LASTCOMMANDADDRESS); } +void lastCommandWrite(char lastCommand) { -char lastCommandRead(void) -{ - - Serial.print("last command: "); - - Serial.println((char)EEPROM.read(LASTCOMMANDADDRESS)); - - return EEPROM.read(LASTCOMMANDADDRESS); -} -void lastCommandWrite(char lastCommand) -{ - - EEPROM.write(LASTCOMMANDADDRESS, lastCommand); + EEPROM.write(LASTCOMMANDADDRESS, lastCommand); } diff --git a/JumperlessNano/src/Peripherals.cpp b/JumperlessNano/src/Peripherals.cpp index ffefc01..2b3eb69 100644 --- a/JumperlessNano/src/Peripherals.cpp +++ b/JumperlessNano/src/Peripherals.cpp @@ -1,24 +1,25 @@ // SPDX-License-Identifier: MIT - #include "Peripherals.h" #include "Adafruit_INA219.h" -#include "NetManager.h" -#include "MatrixStateRP2040.h" #include "LEDs.h" +#include "MatrixStateRP2040.h" +#include "NetManager.h" -#include #include "hardware/adc.h" -#include -#include "pico/stdlib.h" #include "hardware/gpio.h" #include "pico/cyw43_arch.h" +#include "pico/stdlib.h" +#include +#include -#include "mcp4725.hpp" -#include "MCP_DAC.h" #include "AdcUsb.h" +#include "MCP_DAC.h" +#include "mcp4725.hpp" + +#include "Probing.h" #include @@ -71,14 +72,20 @@ uint32_t lastTime = 0; uint16_t sine0[360]; uint16_t sine1[360]; +void initADC(void) { + // pinMode(ADC0_PIN, INPUT); + // pinMode(ADC1_PIN, INPUT); + // pinMode(ADC2_PIN, INPUT); + // pinMode(ADC3_PIN, INPUT); -void initDAC(void) -{ + analogReadResolution(12); +} + +void initDAC(void) { Wire.begin(); delay(5); - if (dac1_8V.begin(MCP4725A1_Addr_A01, i2c0, 400, 4, 5) == true) - { + if (dac1_8V.begin(MCP4725A1_Addr_A01, i2c0, 400, 4, 5) == true) { revisionNumber = 2; amplitude[1] = 3500; @@ -96,12 +103,11 @@ void initDAC(void) dac0_5V.setVoltage(0.00); // setDac0_5VinputCode(0,MCP4725_EEPROM_Mode,MCP4725_PowerDown_Off); delay(1); - dac1_8V.setInputCode(offset[1] + calib[1], MCP4725_EEPROM_Mode, MCP4725_PowerDown_Off); + dac1_8V.setInputCode(offset[1] + calib[1], MCP4725_EEPROM_Mode, + MCP4725_PowerDown_Off); delay(1); dac1_8V.setInputCode(offset[1] + calib[1]); - } - else - { + } else { revisionNumber = 3; // dac_rev3.begin(); @@ -127,8 +133,7 @@ void initDAC(void) } } -void initINA219(void) -{ +void initINA219(void) { // delay(3000); // Serial.println(__FILE__); @@ -139,8 +144,7 @@ void initINA219(void) // Wire.setClock(1000000); Wire.begin(); - if (!INA0.begin() || !INA1.begin()) - { + if (!INA0.begin() || !INA1.begin()) { Serial.println("Failed to find INA219 chip"); } @@ -151,46 +155,33 @@ void initINA219(void) Serial.println(INA1.setBusVoltageRange(16)); } - - - - - - -void dacSine(int resolution) -{ +void dacSine(int resolution) { uint16_t i; - switch (resolution) - { + switch (resolution) { case 0 ... 5: - for (i = 0; i < 32; i++) - { + for (i = 0; i < 32; i++) { setDac1_8VinputCode(DACLookup_FullSine_5Bit[i]); } break; case 6: - for (i = 0; i < 64; i++) - { + for (i = 0; i < 64; i++) { setDac1_8VinputCode(DACLookup_FullSine_6Bit[i]); } break; case 7: - for (i = 0; i < 128; i++) - { + for (i = 0; i < 128; i++) { setDac1_8VinputCode(DACLookup_FullSine_7Bit[i]); } break; case 8: - for (i = 0; i < 256; i++) - { + for (i = 0; i < 256; i++) { setDac1_8VinputCode(DACLookup_FullSine_8Bit[i]); } break; case 9 ... 12: - for (i = 0; i < 512; i++) - { + for (i = 0; i < 512; i++) { setDac1_8VinputCode(DACLookup_FullSine_9Bit[i]); } break; @@ -200,14 +191,10 @@ void dacSine(int resolution) uint16_t lastInputCode0 = 0; uint16_t lastInputCode1 = offset[1] + calib[1]; -void setDac0_5Vvoltage(float voltage) -{ - if (revisionNumber == 2) - { +void setDac0_5Vvoltage(float voltage) { + if (revisionNumber == 2) { dac0_5V.setVoltage(voltage); - } - else - { + } else { int voltageCode = voltage * 4095 / 5; // dac_rev3.analogWrite((uint16_t)voltageCode, 0); @@ -217,14 +204,10 @@ void setDac0_5Vvoltage(float voltage) } } -void setDac0_5VinputCode(uint16_t inputCode) -{ - if (revisionNumber == 2) - { +void setDac0_5VinputCode(uint16_t inputCode) { + if (revisionNumber == 2) { dac0_5V.setInputCode(inputCode); - } - else - { + } else { dac_rev3.analogWrite(inputCode, 0); dac_rev3.fastWriteA(inputCode); lastInputCode0 = inputCode; @@ -232,14 +215,10 @@ void setDac0_5VinputCode(uint16_t inputCode) } } -void setDac1_8Vvoltage(float voltage) -{ - if (revisionNumber == 2) - { +void setDac1_8Vvoltage(float voltage) { + if (revisionNumber == 2) { dac1_8V.setVoltage(voltage); - } - else - { + } else { int voltageCode = voltage * 4095 / 16; voltageCode = voltageCode + 2048; @@ -251,14 +230,10 @@ void setDac1_8Vvoltage(float voltage) } } -void setDac1_8VinputCode(uint16_t inputCode) -{ - if (revisionNumber == 2) - { +void setDac1_8VinputCode(uint16_t inputCode) { + if (revisionNumber == 2) { dac1_8V.setInputCode(inputCode); - } - else - { + } else { // Serial.println(inputCode); // dac_rev3.analogWrite(inputCode, 1); @@ -268,8 +243,7 @@ void setDac1_8VinputCode(uint16_t inputCode) } } -void chooseShownReadings(void) -{ +void chooseShownReadings(void) { showADCreadings[0] = 0; showADCreadings[1] = 0; showADCreadings[2] = 0; @@ -281,40 +255,33 @@ void chooseShownReadings(void) inaConnected = 0; - for (int i = 0; i <= newBridgeIndex; i++) - { + for (int i = 0; i <= newBridgeIndex; i++) { - if (path[i].node1 == ADC0 || path[i].node2 == ADC0) - { + if (path[i].node1 == ADC0 || path[i].node2 == ADC0) { showADCreadings[0] = path[i].net; } - if (path[i].node1 == ADC1 || path[i].node2 == ADC1) - { + if (path[i].node1 == ADC1 || path[i].node2 == ADC1) { showADCreadings[1] = path[i].net; } - if (path[i].node1 == ADC2 || path[i].node2 == ADC2) - { + if (path[i].node1 == ADC2 || path[i].node2 == ADC2) { showADCreadings[2] = path[i].net; } - if (path[i].node1 == ADC3 || path[i].node2 == ADC3) - { + if (path[i].node1 == ADC3 || path[i].node2 == ADC3) { showADCreadings[3] = path[i].net; } - if (path[i].node1 == ISENSE_PLUS || path[i].node1 == ISENSE_PLUS || path[i].node2 == ISENSE_MINUS || path[i].node2 == ISENSE_MINUS) - { - //Serial.println(showReadings); + if (path[i].node1 == ISENSE_PLUS || path[i].node1 == ISENSE_PLUS || + path[i].node2 == ISENSE_MINUS || path[i].node2 == ISENSE_MINUS) { + // Serial.println(showReadings); inaConnected = 1; - switch (showReadings) - { + switch (showReadings) { case 0: - break; - + break; case 1: showINA0[0] = 1; @@ -338,30 +305,93 @@ void chooseShownReadings(void) // Serial.println(showINA0[1]); // Serial.println(showINA0[2]); // Serial.println(" "); - } - } - if (inaConnected == 0) - { - showINA0[0] = 0; - showINA0[1] = 0; - showINA0[2] = 0; - //showReadings = 3; } - - + } + if (inaConnected == 0) { + showINA0[0] = 0; + showINA0[1] = 0; + showINA0[2] = 0; + // showReadings = 3; + } } -void showMeasurements(int samples) -{ +void showLEDmeasurements(void) { + int samples = 16; + + int adc0ReadingUnscaled; + float adc0Reading; + + int adc1ReadingUnscaled; + float adc1Reading; + + int adc2ReadingUnscaled; + float adc2Reading; + + int adc3ReadingUnscaled; + float adc3Reading; + int bs = 0; + + if (showADCreadings[0] != 0) { + + adc0ReadingUnscaled = readAdc(0, samples); + + adc0Reading = (adc0ReadingUnscaled) * (5.0 / 4095); + int mappedAdc0Reading = map(adc0ReadingUnscaled, 0, 4095, 3, 180); + + lightUpNet(showADCreadings[0], -1, 1, mappedAdc0Reading, + mappedAdc0Reading / 2); + + showLEDsCore2 = 2; + } + + if (showADCreadings[1] != 0) { + + adc1ReadingUnscaled = readAdc(1, samples); + adc1Reading = (adc1ReadingUnscaled) * (5.0 / 4095); + int mappedAdc1Reading = map(adc1ReadingUnscaled, 0, 4095, 3, 180); + + lightUpNet(showADCreadings[1], -1, 1, mappedAdc1Reading, + mappedAdc1Reading / 2); + showLEDsCore2 = 2; + } + + if (showADCreadings[2] != 0) { + + adc2ReadingUnscaled = readAdc(2, samples); + adc2Reading = (adc2ReadingUnscaled) * (5.0 / 4095); + + int mappedAdc2Reading = map(adc2ReadingUnscaled, 0, 4095, 3, 180); + lightUpNet(showADCreadings[2], -1, 1, mappedAdc2Reading, + mappedAdc2Reading / 2); + showLEDsCore2 = 2; + } + + if (showADCreadings[3] != 0) { + + adc3ReadingUnscaled = readAdc(3, samples); + adc3Reading = (adc3ReadingUnscaled) * (16.0 / 4010); + adc3Reading -= 8.1; // offset + int mappedAdc3Reading = map(adc3ReadingUnscaled, 0, 4095, -80, 80); + int hueShift = 0; + + if (mappedAdc3Reading < 0) { + hueShift = map(mappedAdc3Reading, -80, 0, 0, 200); + mappedAdc3Reading = abs(mappedAdc3Reading); + } + + lightUpNet(showADCreadings[3], -1, 1, mappedAdc3Reading, hueShift); + showLEDsCore2 = 2; + } +} + +void showMeasurements(int samples) { while (Serial.available() == 0 && Serial1.available() == 0) - - { - // CSI - // Serial.write("\x1B\x5B 2K"); - // Serial.write("2K"); - Serial.print("\r \r"); + { + + Serial.print("\r " + " \r"); int adc0ReadingUnscaled; float adc0Reading; @@ -375,31 +405,25 @@ void showMeasurements(int samples) float adc3Reading; int bs = 0; - // Serial.print(showINA0[0]); - // Serial.print(showINA0[1]); - // Serial.print(showINA0[2]); - // Serial.print("\t"); - - - - if (showADCreadings[0] != 0) - { + if (showADCreadings[0] != 0) { + // if (readFloatingOrState(ADC0_PIN, -1) == floating)//this doesn't + // work because it's buffered + // { + // bs += Serial.print("Floating "); + // } adc0ReadingUnscaled = readAdc(0, samples); + // Serial.print("D0: "); + // Serial.println(adc0ReadingUnscaled); + // Serial.print("V\n\r"); adc0Reading = (adc0ReadingUnscaled) * (5.0 / 4095); // adc0Reading -= 0.1; // offset bs += Serial.print("D0: "); bs += Serial.print(adc0Reading); bs += Serial.print("V\t"); - - int mappedAdc0Reading = map(adc0ReadingUnscaled, 0, 4095, 5, 80); - lightUpNet(showADCreadings[0], -1, 1, mappedAdc0Reading, 0); - showLEDsCore2 = 1; - } - if (showADCreadings[1] != 0) - { + if (showADCreadings[1] != 0) { adc1ReadingUnscaled = readAdc(1, samples); adc1Reading = (adc1ReadingUnscaled) * (5.0 / 4095); @@ -407,17 +431,9 @@ void showMeasurements(int samples) bs += Serial.print("D1: "); bs += Serial.print(adc1Reading); bs += Serial.print("V\t"); - int mappedAdc1Reading = map(adc1ReadingUnscaled, 0, 4095, 5, 80); - - - lightUpNet(showADCreadings[1], -1, 1, mappedAdc1Reading, 0); -showLEDsCore2 = 1; - - } - if (showADCreadings[2] != 0) - { + if (showADCreadings[2] != 0) { adc2ReadingUnscaled = readAdc(2, samples); adc2Reading = (adc2ReadingUnscaled) * (5.0 / 4095); @@ -426,52 +442,40 @@ showLEDsCore2 = 1; bs += Serial.print("D2: "); bs += Serial.print(adc2Reading); bs += Serial.print("V\t"); - int mappedAdc2Reading = map(adc2ReadingUnscaled, 0, 4095, 5, 80); - lightUpNet(showADCreadings[2], -1, 1, mappedAdc2Reading, 0); - showLEDsCore2 = 1; } - if (showADCreadings[3] != 0) - { + if (showADCreadings[3] != 0) { adc3ReadingUnscaled = readAdc(3, samples); adc3Reading = (adc3ReadingUnscaled) * (16.0 / 4010); - adc3Reading -= 8.7; // offset + adc3Reading -= 8.1; // offset bs += Serial.print("D3: "); bs += Serial.print(adc3Reading); bs += Serial.print("V\t"); int mappedAdc3Reading = map(adc3ReadingUnscaled, 0, 4095, -80, 80); int hueShift = 0; - if (mappedAdc3Reading < 0) - { + if (mappedAdc3Reading < 0) { hueShift = map(mappedAdc3Reading, -80, 0, 0, 200); mappedAdc3Reading = abs(mappedAdc3Reading); } - - lightUpNet(showADCreadings[3], -1, 1, mappedAdc3Reading, hueShift); - showLEDsCore2 = 1; } - if (showINA0[0] == 1 || showINA0[1] == 1 || showINA0[2] == 1) - { + if (showINA0[0] == 1 || showINA0[1] == 1 || showINA0[2] == 1) { bs += Serial.print(" INA219: "); } - if (showINA0[0] == 1) - { + if (showINA0[0] == 1) { bs += Serial.print("I: "); bs += Serial.print(INA0.getCurrent_mA()); bs += Serial.print("mA\t"); } - if (showINA0[1] == 1) - { + if (showINA0[1] == 1) { bs += Serial.print(" V: "); bs += Serial.print(INA0.getBusVoltage()); bs += Serial.print("V\t"); } - if (showINA0[2] == 1) - { + if (showINA0[2] == 1) { bs += Serial.print("P: "); bs += Serial.print(INA0.getPower_mW()); bs += Serial.print("mW\t"); @@ -479,50 +483,19 @@ showLEDsCore2 = 1; bs += Serial.print(" \r"); - // for (int i = 0; i < bs; i++) - // { - // Serial.print("\b"); - // } - - // Serial.print("ADC1: "); - // Serial.print(adc1ReadingUnscaled); - // Serial.print("V\n\r"); - // Serial.print("ADC2: "); - // Serial.print(adc2ReadingUnscaled); - // Serial.print("V\n\r"); - // Serial.print("ADC3: "); - // Serial.print(adc3ReadingUnscaled); - // Serial.print("V\n\n\r"); - - if (Serial.available() == 0 && Serial1.available() == 0) - { - delay(350); - } - // else { - // Serial.print("Serial.available ="); - // Serial.print(Serial.available()); - // Serial.print("\nSerial1.available ="); - // Serial.print(Serial1.available()); - // Serial.print("\n\r"); - // delay(1000); - // // break; - // } - - - } -// else{ -// Serial.print("\r nothing to sample \r"); -// } + if (Serial.available() == 0 && Serial1.available() == 0) { + showLEDmeasurements(); + delay(150); + } + } } -int readAdc(int channel, int samples) -{ +int readAdc(int channel, int samples) { int adcReadingAverage = 0; - for (int i = 0; i < samples; i++) - { - adcReadingAverage += adcReadings[channel]; - delay(1); + for (int i = 0; i < samples; i++) { + adcReadingAverage += analogRead(channel + ADC0_PIN); + delayMicroseconds(100); } int adcReading = adcReadingAverage / samples; @@ -532,8 +505,7 @@ int readAdc(int channel, int samples) return adcReading; } -int waveGen(void) -{ +int waveGen(void) { int loopCounter = 0; int c = 0; listSpecialNets(); @@ -557,10 +529,14 @@ int waveGen(void) Serial.println(dac_rev3.maxValue()); Serial.print("Revision = "); Serial.println(revisionNumber); - Serial.println("\n\r\t\t\t\t waveGen\t\n\n\r\toptions\t\t\twaves\t\t\tadjust frequency\n\r"); - Serial.println("\t5/0 = dac 0 0-5V (togg)\tq = square\t\t+ = frequency++\n\r"); + Serial.println( + "\n\r\t\t\t\t waveGen\t\n\n\r\toptions\t\t\twaves\t\t\tadjust " + "frequency\n\r"); + Serial.println( + "\t5/0 = dac 0 0-5V (togg)\tq = square\t\t+ = frequency++\n\r"); Serial.println("\t8/1 = dac 1 +-8V (togg)\ts = sine\t\t- = frequency--\n\r"); - Serial.println("\ta = set amplitude (p-p)\tw = sawtooth\t\t* = frequency*2\n\r"); + Serial.println( + "\ta = set amplitude (p-p)\tw = sawtooth\t\t* = frequency*2\n\r"); Serial.println("\to = set offset\t\tt = triangle\t\t/ = frequency/2\n\r"); Serial.println("\tv = voltage\t\tr = random\t\t \n\r"); Serial.println("\th = show this menu\tx = exit\t\t \n\r"); @@ -574,31 +550,27 @@ int waveGen(void) int firstCrossFreq0 = 0; int firstCrossFreq1 = 0; - while (1) - { + while (1) { yield(); uint32_t now = micros(); count++; - // float adc3Voltage = (adc3Reading - 2528) / 220.0; //painstakingly measured - // float adc0Voltage = ((adc0Reading) / 400.0) - 0.69; //- 0.93; //painstakingly measured + // float adc3Voltage = (adc3Reading - 2528) / 220.0; //painstakingly + // measured float adc0Voltage = ((adc0Reading) / 400.0) - 0.69; //- 0.93; + // //painstakingly measured int adc0Reading = 0; int brightness0 = 0; int hueShift0 = 0; // firstCrossFreq0 = 1; - if (dacOn[0] == 1 && freq[0] < 33) - { + if (dacOn[0] == 1 && freq[0] < 33) { // adc0Reading = INA1.getBusVoltage_mV(); // adc0Reading = dac0_5V.getInputCode(); - if (c == 'q') - { - } - else - { + if (c == 'q') { + } else { adc0Reading = readAdc(26, 1); adc0Reading = abs(adc0Reading); @@ -609,11 +581,8 @@ int waveGen(void) showLEDsCore2 = 1; firstCrossFreq0 = 1; } - } - else - { - if (firstCrossFreq0 == 1) - { + } else { + if (firstCrossFreq0 == 1) { lightUpNet(4); showLEDsCore2 = 1; firstCrossFreq0 = 0; @@ -624,8 +593,7 @@ int waveGen(void) int brightness1 = 0; int hueShift1 = 0; - if (dacOn[1] == 1 && freq[1] < 17) - { + if (dacOn[1] == 1 && freq[1] < 17) { adc1Reading = readAdc(29, 1); hueShift1 = map(adc1Reading, -2048, 2048, -50, 45); adc1Reading = adc1Reading - 2048; @@ -637,19 +605,15 @@ int waveGen(void) lightUpNet(5, -1, 1, brightness1, hueShift1); showLEDsCore2 = 1; firstCrossFreq1 = 1; - } - else - { - if (firstCrossFreq1 == 1) - { + } else { + if (firstCrossFreq1 == 1) { lightUpNet(5); showLEDsCore2 = 1; firstCrossFreq1 = 0; } } - if (now - lastTime > 100000) - { + if (now - lastTime > 100000) { loopCounter++; // // int adc0Reading = analogRead(26); @@ -677,38 +641,26 @@ int waveGen(void) // Serial.println(count); // show # updates per 0.1 second count = 0; - if (Serial.available() == 0) - { + if (Serial.available() == 0) { // break; - } - else - { + } else { c = Serial.read(); - switch (c) - { + switch (c) { case '+': - if (freq[activeDac] >= 1.0) - { + if (freq[activeDac] >= 1.0) { freq[activeDac]++; - } - else - { + } else { freq[activeDac] += 0.1; } break; case '-': - if (freq[activeDac] > 1.0) - { + if (freq[activeDac] > 1.0) { freq[activeDac]--; - } - else if (freq[activeDac] > 0.1) - { + } else if (freq[activeDac] > 0.1) { freq[activeDac] -= 0.1; - } - else - { + } else { freq[activeDac] = 0.0; } @@ -720,8 +672,7 @@ int waveGen(void) freq[activeDac] /= 2; break; case '8': - if (activeDac == 0) - { + if (activeDac == 0) { setDac0_5Vvoltage(0.0); dacOn[0] = 0; } @@ -731,15 +682,13 @@ int waveGen(void) activeDac = 1; - if (dacOn[1] == 0) - { + if (dacOn[1] == 0) { setDac1_8VinputCode(offset[1] + calib[1]); } break; case '5': - if (activeDac == 1) - { + if (activeDac == 1) { setDac1_8VinputCode(offset[1] + calib[1]); dacOn[1] = 0; } @@ -748,8 +697,7 @@ int waveGen(void) dacOn[0] = !dacOn[0]; activeDac = 0; - if (dacOn[activeDac] == 0) - { + if (dacOn[activeDac] == 0) { setDac0_5Vvoltage(0.0); } break; @@ -757,10 +705,8 @@ int waveGen(void) // freq[activeDac] = 0; break; - case 's': - { - if (mode[2] == 'v') - { + case 's': { + if (mode[2] == 'v') { refillTable(amplitude[activeDac], offset[activeDac] + calib[1], 1); mode[2] = 's'; } @@ -792,27 +738,21 @@ int waveGen(void) mode[activeDac] = c; break; case '{': - case 'f': - { - if (mode[0] != 'v') - { + case 'f': { + if (mode[0] != 'v') { setDac0_5Vvoltage(0.0); } - if (mode[1] != 'v') - { + if (mode[1] != 'v') { setDac1_8VinputCode(offset[1]); } return 0; } - case 'x': - { - if (mode[0] != 'v') - { + case 'x': { + if (mode[0] != 'v') { setDac0_5Vvoltage(0.0); } - if (mode[1] != 'v') - { + if (mode[1] != 'v') { setDac1_8VinputCode(offset[1]); } @@ -824,8 +764,7 @@ int waveGen(void) } period[activeDac] = 1e6 / freq[activeDac]; halvePeriod[activeDac] = period[activeDac] / 2; - if (activeDac == 0) - { + if (activeDac == 0) { Serial.print("dac 0: "); Serial.print("ampl: "); Serial.print((float)(amplitude[activeDac]) / 819); @@ -840,9 +779,7 @@ int waveGen(void) Serial.print(freq[activeDac]); // Serial.print("\t\n\r"); - } - else if (activeDac == 1) - { + } else if (activeDac == 1) { Serial.print("dac 1: "); Serial.print("ampl: "); Serial.print((float)(amplitude[activeDac]) / 276); @@ -872,34 +809,25 @@ int waveGen(void) uint32_t t = now % period[activeDac]; // if (dacOn[activeDac] == 1 ) //{ - switch (mode[activeDac]) - { + switch (mode[activeDac]) { case 'q': - if (t < halvePeriod[activeDac]) - { - if (activeDac == 0 && dacOn[activeDac] == 1) - { + if (t < halvePeriod[activeDac]) { + if (activeDac == 0 && dacOn[activeDac] == 1) { setDac0_5VinputCode(amplitude[activeDac]); lightUpNet(4, -1, 1, DEFAULTSPECIALNETBRIGHTNESS, 12); showLEDsCore2 = 1; - } - else if (activeDac == 1 && dacOn[activeDac] == 1) - { + } else if (activeDac == 1 && dacOn[activeDac] == 1) { setDac1_8VinputCode(amplitude[activeDac]); showLEDsCore2 = 1; } - } - else - { - if (activeDac == 0 && dacOn[activeDac] == 1) - { + } else { + if (activeDac == 0 && dacOn[activeDac] == 1) { setDac0_5VinputCode(0); lightUpNet(4, -1, 1, 2, 12); } - else if (activeDac == 1 && dacOn[activeDac] == 1) - { + else if (activeDac == 1 && dacOn[activeDac] == 1) { setDac1_8VinputCode(offset[activeDac]); } } @@ -911,27 +839,28 @@ int waveGen(void) setDac1_8VinputCode(t * amplitude[activeDac] / period[activeDac]); break; case 't': - if (activeDac == 0 && dacOn[activeDac] == 1) - { + if (activeDac == 0 && dacOn[activeDac] == 1) { if (t < halvePeriod[activeDac]) - setDac0_5VinputCode(((t * amplitude[activeDac]) / halvePeriod[activeDac])); + setDac0_5VinputCode( + ((t * amplitude[activeDac]) / halvePeriod[activeDac])); else - setDac0_5VinputCode((((period[activeDac] - t) * (amplitude[activeDac]) / halvePeriod[activeDac]))); - } - else if (activeDac == 1 && dacOn[activeDac] == 1) - { + setDac0_5VinputCode( + (((period[activeDac] - t) * (amplitude[activeDac]) / + halvePeriod[activeDac]))); + } else if (activeDac == 1 && dacOn[activeDac] == 1) { if (t < halvePeriod[activeDac]) - setDac1_8VinputCode(t * amplitude[activeDac] / halvePeriod[activeDac]); + setDac1_8VinputCode(t * amplitude[activeDac] / + halvePeriod[activeDac]); else - setDac1_8VinputCode((period[activeDac] - t) * amplitude[activeDac] / halvePeriod[activeDac]); + setDac1_8VinputCode((period[activeDac] - t) * amplitude[activeDac] / + halvePeriod[activeDac]); } break; case 'r': if (activeDac == 0 && dacOn[activeDac] == 1) setDac0_5VinputCode(random(amplitude[activeDac])); - else if (activeDac == 1 && dacOn[activeDac] == 1) - { + else if (activeDac == 1 && dacOn[activeDac] == 1) { setDac1_8VinputCode(random(amplitude[activeDac])); } break; @@ -942,10 +871,15 @@ int waveGen(void) setDac1_8VinputCode(offset[activeDac]); break; case 'h': // high - Serial.println("\n\r\t\t\t\t waveGen\t\n\n\r\toptions\t\t\twaves\t\t\tadjust frequency\n\r"); - Serial.println("\t5/0 = dac 0 0-5V (togg)\tq = square\t\t+ = frequency++\n\r"); - Serial.println("\t8/1 = dac 1 +-8V (togg)\ts = sine\t\t- = frequency--\n\r"); - Serial.println("\ta = set amplitude (p-p)\tw = sawtooth\t\t* = frequency*2\n\r"); + Serial.println( + "\n\r\t\t\t\t waveGen\t\n\n\r\toptions\t\t\twaves\t\t\tadjust " + "frequency\n\r"); + Serial.println( + "\t5/0 = dac 0 0-5V (togg)\tq = square\t\t+ = frequency++\n\r"); + Serial.println( + "\t8/1 = dac 1 +-8V (togg)\ts = sine\t\t- = frequency--\n\r"); + Serial.println( + "\ta = set amplitude (p-p)\tw = sawtooth\t\t* = frequency*2\n\r"); Serial.println("\to = set offset\t\tt = triangle\t\t/ = frequency/2\n\r"); Serial.println("\tv = voltage\t\tr = random\t\t \n\r"); Serial.println("\th = show this menu\tx = exit\t\t \n\r"); @@ -954,15 +888,13 @@ int waveGen(void) case 'm': // mid // setDac1_8VinputCode(2047); break; - case 'a': - { + case 'a': { float newAmplitudeF = 0; int newAmplitude = 0; int input = 0; char aC = 0; int a = 0; - if (activeDac == 0) - { + if (activeDac == 0) { Serial.print("\n\renter amplitude (0-5): "); while (Serial.available() == 0) @@ -974,8 +906,7 @@ int waveGen(void) Serial.print(aC); - if (a >= 48 && a <= 53) - { + if (a >= 48 && a <= 53) { input = a - 48; newAmplitude = input * 819; @@ -984,16 +915,14 @@ int waveGen(void) ; a = Serial.read(); - if (a == '.') - { + if (a == '.') { while (Serial.available() == 0) ; a = Serial.read(); } - if (a >= 48 && a <= 57) - { + if (a >= 48 && a <= 57) { Serial.print((char)a); input = a - 48; newAmplitude += input * 81.9; @@ -1002,13 +931,11 @@ int waveGen(void) Serial.print("\tamplitude: "); Serial.print((float)(amplitude[activeDac]) / 819); Serial.println("V"); - if ((offset[activeDac] - (amplitude[activeDac] / 2)) < 10 || ((amplitude[activeDac] / 2) - offset[activeDac]) < 10) - { + if ((offset[activeDac] - (amplitude[activeDac] / 2)) < 10 || + ((amplitude[activeDac] / 2) - offset[activeDac]) < 10) { offset[activeDac] = (amplitude[activeDac] / 2) - 1; } - { - offset[activeDac] = (amplitude[activeDac] / 2) - 2; - } + { offset[activeDac] = (amplitude[activeDac] / 2) - 2; } refillTable(amplitude[activeDac], offset[activeDac], 0); mode[activeDac] = mode[2]; @@ -1016,9 +943,7 @@ int waveGen(void) break; } } - } - else if (activeDac == 1) - { + } else if (activeDac == 1) { Serial.print("\n\renter peak amplitude (0-7.5): "); while (Serial.available() == 0) @@ -1030,8 +955,7 @@ int waveGen(void) Serial.print(aC); - if (a >= 48 && a <= 55) - { + if (a >= 48 && a <= 55) { input = a - 48; newAmplitude = input * 276; @@ -1040,16 +964,14 @@ int waveGen(void) ; a = Serial.read(); - if (a == '.') - { + if (a == '.') { while (Serial.available() == 0) ; a = Serial.read(); } - if (a >= 48 && a <= 57) - { + if (a >= 48 && a <= 57) { Serial.print((char)a); input = a - 48; newAmplitude += input * 27.6; @@ -1071,15 +993,13 @@ int waveGen(void) } } } - case 'o': - { + case 'o': { int newOffset = 0; int input = 0; char aC = 0; int o = 0; - if (activeDac == 0) - { + if (activeDac == 0) { Serial.print("\n\renter offset (0-5): "); while (Serial.available() == 0) @@ -1092,8 +1012,7 @@ int waveGen(void) Serial.print(aC); - if (o >= 48 && o <= 53) - { + if (o >= 48 && o <= 53) { input = o - 48; newOffset = input * 819; @@ -1102,16 +1021,14 @@ int waveGen(void) ; o = Serial.read(); - if (o == '.') - { + if (o == '.') { while (Serial.available() == 0) ; o = Serial.read(); } - if (o >= 48 && o <= 57) - { + if (o >= 48 && o <= 57) { Serial.print((char)o); input = o - 48; newOffset += input * 81.9; @@ -1127,17 +1044,14 @@ int waveGen(void) break; } } - } - else if (activeDac == 1) - { + } else if (activeDac == 1) { int negative = 0; Serial.print("\n\rEnter offset (-7 - 7): "); while (Serial.available() == 0) ; aC = Serial.read(); - if (aC == '-') - { + if (aC == '-') { Serial.print('-'); negative = 1; while (Serial.available() == 0) @@ -1149,32 +1063,26 @@ int waveGen(void) Serial.print(aC); - if (o >= 48 && o <= 55) - { + if (o >= 48 && o <= 55) { input = o - 48; newOffset = input * 276; - if (input == '7') - { + if (input == '7') { Serial.print(".00"); - } - else - { + } else { Serial.print("."); while (Serial.available() == 0) ; o = Serial.read(); - if (o == '.') - { + if (o == '.') { while (Serial.available() == 0) ; o = Serial.read(); } - if (o >= 48 && o <= 57) - { + if (o >= 48 && o <= 57) { Serial.print((char)o); input = o - 48; newOffset += input * 27.6; @@ -1200,23 +1108,18 @@ int waveGen(void) } } } - case 'v': - { - if (activeDac == 0 && mode[2] != 'v') - { + case 'v': { + if (activeDac == 0 && mode[2] != 'v') { // freq[activeDac] = 0; setDac0_5Vvoltage(amplitude[activeDac] / 819); mode[2] = 'v'; - } - else if (activeDac == 1 && mode[2] != 'v') - { + } else if (activeDac == 1 && mode[2] != 'v') { // freq[activeDac] = 0; // refillTable(0, offset[activeDac] + calib[1], 1); - setDac1_8Vvoltage(((amplitude[activeDac] + calib[1]) / 276) - ((offset[activeDac] / 276) - 7)); + setDac1_8Vvoltage(((amplitude[activeDac] + calib[1]) / 276) - + ((offset[activeDac] / 276) - 7)); mode[2] = 'v'; - } - else if (mode[2] == 'v') - { + } else if (mode[2] == 'v') { // mode[2] = 's'; } @@ -1229,8 +1132,7 @@ int waveGen(void) // float f = ((PI * 2) * t)/period; // setDac1_8VinputCode(2047 + 2047 * sin(f)); // - if (mode[activeDac] != 'v') - { + if (mode[activeDac] != 'v') { int idx = (360 * t) / period[activeDac]; if (activeDac == 0 && dacOn[activeDac] == 1) setDac0_5VinputCode(sine0[idx]); // lookuptable @@ -1242,34 +1144,26 @@ int waveGen(void) } } -void refillTable(int amplitude, int offset, int dac) -{ +void refillTable(int amplitude, int offset, int dac) { // int offsetCorr = 0; - if (dac == 0) - { + if (dac == 0) { // offset = amplitude / 2; } - for (int i = 0; i < 360; i++) - { - if (dac == 0) - { + for (int i = 0; i < 360; i++) { + if (dac == 0) { sine0[i] = offset + round(amplitude / 2 * sin(i * PI / 180)); - } - else if (dac == 1) - { - sine1[i] = offset + round((amplitude - (offset - 2047)) / 2 * sin(i * PI / 180)); - } - else if (dac == 2) - { + } else if (dac == 1) { + sine1[i] = + offset + round((amplitude - (offset - 2047)) / 2 * sin(i * PI / 180)); + } else if (dac == 2) { sine0[i] = offset + round(amplitude / 2 * sin(i * PI / 180)); sine1[i] = offset + round(amplitude / 2 * sin(i * PI / 180)); } } } -void GetAdc29Status(int i) -{ - gpio_function gpio29Function = gpio_get_function(29); +void GetAdc29Status(int i) { + gpio_function_t gpio29Function = gpio_get_function(29); Serial.print("GPIO29 func: "); Serial.println(gpio29Function); @@ -1296,5 +1190,7 @@ void GetAdc29Status(int i) bool out = gpio_is_dir_out(29); Serial.print("GPIO29 out: "); Serial.println(out); - Serial.printf("(%i) GPIO29 func: %i, pd: %i, h: %i, slew: %i, drive: %i, irqmask: %i, out: %i\n", i, gpio29Function, pd, h, slew, drive, irqmask, out); + Serial.printf("(%i) GPIO29 func: %i, pd: %i, h: %i, slew: %i, drive: %i, " + "irqmask: %i, out: %i\n", + i, gpio29Function, pd, h, slew, drive, irqmask, out); } diff --git a/JumperlessNano/src/Peripherals.h b/JumperlessNano/src/Peripherals.h index 910c4f6..19a8c91 100644 --- a/JumperlessNano/src/Peripherals.h +++ b/JumperlessNano/src/Peripherals.h @@ -38,11 +38,12 @@ void setDac1_8VinputCode(uint16_t value); void refillTable (int amplitude = 2047, int offset = 2047, int adc = 2); int waveGen(void); void GetAdc29Status(int i); -int readAdc(int channel, int samples = 10); +int readAdc(int channel, int samples = 32); void chooseShownReadings(void); -void showMeasurements(int samples = 50); - +void showLEDmeasurements(void); +void showMeasurements(int samples = 32); +void initADC(void); const uint16_t DACLookup_FullSine_9Bit[512] = { diff --git a/JumperlessNano/src/Probing.cpp b/JumperlessNano/src/Probing.cpp index b71d026..6a20c4b 100644 --- a/JumperlessNano/src/Probing.cpp +++ b/JumperlessNano/src/Probing.cpp @@ -592,8 +592,8 @@ probeActive = 1; //showNets(); showLEDsCore2 = 1; rawOtherColors[1] = 0x550004; - showLEDsCore2 = 1; - + showLEDsCore2 = 1; + //delay(25); sendAllPathsCore2 = 1; // delay(25); // pinMode(probePin, INPUT); diff --git a/JumperlessNano/src/main.cpp b/JumperlessNano/src/main.cpp index ed48b84..fd9cffa 100644 --- a/JumperlessNano/src/main.cpp +++ b/JumperlessNano/src/main.cpp @@ -28,23 +28,23 @@ KevinC@ppucc.io #include "ArduinoStuff.h" #include "JumperlessDefinesRP2040.h" -#include "NetManager.h" #include "MatrixStateRP2040.h" +#include "NetManager.h" -#include "NetsToChipConnections.h" #include "LEDs.h" +#include "NetsToChipConnections.h" // #include "CH446Q.h" -#include "Peripherals.h" -#include -#include #include "MachineCommands.h" +#include "Peripherals.h" +#include +#include // #include #include #include "CH446Q.h" -#include "RotaryEncoder.h" #include "FileParsing.h" +#include "RotaryEncoder.h" #include "LittleFS.h" @@ -73,7 +73,8 @@ void lastNetConfirm(int forceLastNet = 0); unsigned long lastNetConfirmTimer = 0; // int machineMode = 0; -volatile int sendAllPathsCore2 = 0; // this signals the core 2 to send all the paths to the CH446Q +volatile int sendAllPathsCore2 = + 0; // this signals the core 2 to send all the paths to the CH446Q int loadFileOnStart = 1; int rotEncInit = 0; @@ -81,8 +82,9 @@ int rotEncInit = 0; int core2setupFinished = 0; -void setup() -{ +int baudRate = 115200; + +void setup() { pinMode(0, OUTPUT); pinMode(2, INPUT); pinMode(3, INPUT); @@ -121,10 +123,10 @@ void setup() setDac0_5Vvoltage(0.0); setDac1_8Vvoltage(1.9); - // if (rotaryEncoderMode == 1) - // { - createSlots(-1, rotaryEncoderMode); - //} + // if (rotaryEncoderMode == 1) + // { + createSlots(-1, rotaryEncoderMode); + //} // clearAllNTCC(); @@ -133,14 +135,15 @@ void setup() // rotEncInit = 1; initRotaryEncoder(); //} + initADC(); // delay(20); // setupAdcUsbStuff(); // I took this out because it was causing a crash on delay(10); + setBaudRate(baudRate); } -void setup1() -{ +void setup1() { delay(4); initCH446Q(); @@ -151,7 +154,7 @@ void setup1() startupColors(); delay(4); lightUpRail(); -core2setupFinished = 1; + core2setupFinished = 1; delay(4); showLEDsCore2 = 1; @@ -163,19 +166,19 @@ char input; int serSource = 0; int readInNodesArduino = 0; -int baudRate = 115200; + int restoredNodeFile = 0; -const char firmwareVersion[] = "1.3.15"; //// remember to update this +const char firmwareVersion[] = "1.3.18"; //// remember to update this int firstLoop = 1; volatile int probeActive = 1; int showExtraMenu = 0; +int printingMeasurements = 0; -void loop() -{ +void loop() { unsigned long timer = 0; @@ -200,34 +203,40 @@ menu: Serial.print("\to = load node files by slot\n\r"); Serial.print("\tf = load node file to current slot\n\r"); Serial.print("\tr = rotary encoder mode -"); - rotaryEncoderMode == 1 ? Serial.print(" ON (z/x to cycle)\n\r") : Serial.print(" off\n\r"); + rotaryEncoderMode == 1 ? Serial.print(" ON (z/x to cycle)\n\r") + : Serial.print(" off\n\r"); Serial.print("\t\b\bz/x = cycle slots - current slot "); Serial.print(netSlot); Serial.print("\n\r"); Serial.print("\te = show extra menu options\n\r"); - if (showExtraMenu == 1) - { - Serial.print("\tb = show bridge array\n\r"); - Serial.print("\tp = probe connections\n\r"); - Serial.print("\tw = waveGen\n\r"); - Serial.print("\tv = toggle show current/voltage\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"); - + if (showExtraMenu == 1) { + Serial.print("\tb = show bridge array\n\r"); + Serial.print("\tp = probe connections\n\r"); + Serial.print("\tw = waveGen\n\r"); + Serial.print("\tv = toggle show current/voltage\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("\tc = clear nodes with probe\n\r"); + // Serial.print("\tc = clear nodes with probe\n\r"); Serial.print("\n\n\r"); - if (firstLoop == 1 && rotaryEncoderMode == 1) - { + if (firstLoop == 1 && rotaryEncoderMode == 1) { Serial.print("Use the rotary encoder to change slots\n\r"); Serial.print("Press the button to select\n\r"); Serial.print("\n\n\r"); firstLoop = 0; probeActive = 0; + goto loadfile; + } else if (firstLoop == 1) { + // delay(20); + // Serial.println("Press the button to load the current slot\n\r"); + // delay(20); + firstLoop = 0; + probeActive = 0; + goto loadfile; } // if (firstLoop == 1 && rotaryEncoderMode == 0 && loadFileOnStart == 1) @@ -246,33 +255,26 @@ dontshowmenu: connectFromArduino = '\0'; - while (Serial.available() == 0 && connectFromArduino == '\0' && slotChanged == 0) - { + while (Serial.available() == 0 && connectFromArduino == '\0' && + slotChanged == 0) { - if (showReadings >= 1) - { + if (showReadings >= 1) { showMeasurements(); // Serial.print("\n\n\r"); // showLEDsCore2 = 1; } - if (BOOTSEL) - { + if (BOOTSEL) { lastNetConfirm(1); } - if ((millis() % 200) < 5) - { - if (checkProbeButton() == 1) - { + if ((millis() % 200) < 5) { + if (checkProbeButton() == 1) { int longShort = longShortPress(1000); - if (longShort == 1) - { + if (longShort == 1) { input = 'c'; probingTimer = millis(); goto skipinput; - } - else if (longShort == 0) - { + } else if (longShort == 0) { input = 'p'; probingTimer = millis(); goto skipinput; @@ -283,115 +285,95 @@ dontshowmenu: } } - if (slotChanged == 1) - { + if (slotChanged == 1) { // showLEDsCore2 = 1; goto loadfile; } - if (connectFromArduino != '\0') - { - } - else - { + if (connectFromArduino != '\0') { + } else { input = Serial.read(); - //Serial.print("\n\r"); - if (input == '}' || input == ' ' || input == '\n' || input == '\r') - { + // Serial.print("\n\r"); + if (input == '}' || input == ' ' || input == '\n' || input == '\r') { goto dontshowmenu; } - //Serial.write(input); + // Serial.write(input); } // Serial.print(input); skipinput: - switch (input) - { - case '?': - { + switch (input) { + case '?': { Serial.print("Jumperless firmware version: "); Serial.println(firmwareVersion); break; } - case '$': - { - //return current slot number + case '$': { + // return current slot number Serial.println(netSlot); break; } - case '_'://hold arduino in reset + case '_': // hold arduino in reset { pinMode(16, OUTPUT); pinMode(17, INPUT); clearAllConnectionsOnChip(CHIP_I, 0); - sendXYraw(CHIP_I,11,0,1); - sendXYraw(CHIP_I,15,0,1); + sendXYraw(CHIP_I, 11, 0, 1); + sendXYraw(CHIP_I, 15, 0, 1); - sendXYraw(CHIP_I,11,1,1);//double up connections - sendXYraw(CHIP_I,15,1,1); + sendXYraw(CHIP_I, 11, 1, 1); // double up connections + sendXYraw(CHIP_I, 15, 1, 1); -goto dontshowmenu; + goto dontshowmenu; } - case '-': - { + case '-': { clearAllConnectionsOnChip(CHIP_I, 1); - sendXYraw(CHIP_I,11,0,0); - sendXYraw(CHIP_I,15,0,0); + sendXYraw(CHIP_I, 11, 0, 0); + sendXYraw(CHIP_I, 15, 0, 0); - sendXYraw(CHIP_I,11,1,0);//double up connections - sendXYraw(CHIP_I,15,1,0); + sendXYraw(CHIP_I, 11, 1, 0); // double up connections + sendXYraw(CHIP_I, 15, 1, 0); sendAllPathsCore2 = 1; break; } - case 'e': - { - if (showExtraMenu == 0) - { + case 'e': { + if (showExtraMenu == 0) { showExtraMenu = 1; - } - else - { + } else { showExtraMenu = 0; } break; } - case 's': - { + case 's': { int fileNo = -1; - if (Serial.available() > 0) - { + if (Serial.available() > 0) { fileNo = Serial.read(); // break; } Serial.print("\n\n\r"); - if (fileNo == -1) - { + if (fileNo == -1) { Serial.print("\tSlot Files"); - } - else - { + } else { Serial.print("\tSlot File "); Serial.print(fileNo - '0'); } Serial.print("\n\n\r"); - Serial.print("\n\ryou can paste this text reload this circuit (enter 'o' first)"); + Serial.print( + "\n\ryou can paste this text reload this circuit (enter 'o' first)"); Serial.print("\n\r(or even just a single slot)\n\n\n\r"); - if (fileNo == -1) - { - for (int i = 0; i < NUM_SLOTS; i++) - { + if (fileNo == -1) { + for (int i = 0; i < NUM_SLOTS; i++) { Serial.print("\n\rSlot "); Serial.print(i); - if (i == netSlot) - { + if (i == netSlot) { Serial.print(" <--- current slot"); } @@ -403,9 +385,7 @@ goto dontshowmenu; printNodeFile(i); Serial.print("\n\n\n\r"); } - } - else - { + } else { Serial.print("\n\rnodeFileSlot"); Serial.print(fileNo - '0'); @@ -421,20 +401,17 @@ goto dontshowmenu; } case 'v': - if (showReadings >= 3 || (inaConnected == 0 && showReadings >= 1)) - { + if (showReadings >= 3 || (inaConnected == 0 && showReadings >= 1)) { showReadings = 0; break; - } - else - { + } 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("\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"); @@ -449,8 +426,7 @@ goto dontshowmenu; goto dontshowmenu; // break; } - case 'p': - { + case 'p': { probeActive = 1; delayMicroseconds(1500); @@ -459,8 +435,7 @@ goto dontshowmenu; probeActive = 0; break; } - case 'c': - { + case 'c': { // removeBridgeFromNodeFile(19, 1); probeActive = 1; delayMicroseconds(1500); @@ -500,55 +475,52 @@ goto dontshowmenu; case 'w': - if (waveGen() == 1) - { + if (waveGen() == 1) { break; } - case 'o': - { + case 'o': { probeActive = 1; inputNodeFileList(rotaryEncoderMode); showSavedColors(netSlot); - //input = ' '; + // input = ' '; showLEDsCore2 = 1; + sendAllPathsCore2 = 1; probeActive = 0; + chooseShownReadings(); goto dontshowmenu; break; } - case 'x': - { - - if (netSlot == NUM_SLOTS-1) - { + case 'x': { + + if (netSlot == NUM_SLOTS - 1) { netSlot = 0; } else { - netSlot ++; + netSlot++; } Serial.print("\r \r"); Serial.print("Slot "); Serial.print(netSlot); slotPreview = netSlot; + chooseShownReadings(); goto loadfile; - } - case 'z': - { - - if (netSlot == 0) - { + } + case 'z': { + + if (netSlot == 0) { netSlot = NUM_SLOTS - 1; - } else{ + } else { netSlot--; } Serial.print("\r \r"); Serial.print("Slot "); Serial.print(netSlot); slotPreview = netSlot; + chooseShownReadings(); goto loadfile; - } - case 'y': - { + } + case 'y': { loadfile: probeActive = 1; clearAllNTCC(); @@ -556,15 +528,17 @@ goto dontshowmenu; getNodesToConnect(); bridgesToPaths(); clearLEDs(); - //leds.clear(); - //assignNetColors(); + // leds.clear(); + // assignNetColors(); digitalWrite(RESETPIN, HIGH); delayMicroseconds(100); // Serial.print("bridgesToPaths\n\r"); digitalWrite(RESETPIN, LOW); // showNets(); // saveRawColors(netSlot); + probeActive = 0; showSavedColors(netSlot); + chooseShownReadings(); sendAllPathsCore2 = 1; slotChanged = 0; input = ' '; @@ -573,7 +547,7 @@ goto dontshowmenu; // { // goto dontshowmenu; // } - probeActive = 0; + break; } case 'f': @@ -587,12 +561,9 @@ goto dontshowmenu; // clearNodeFile(netSlot); - if (connectFromArduino != '\0') - { + if (connectFromArduino != '\0') { serSource = 1; - } - else - { + } else { serSource = 0; } savePreformattedNodeFile(serSource, netSlot, rotaryEncoderMode); @@ -611,11 +582,11 @@ goto dontshowmenu; digitalWrite(RESETPIN, LOW); // showNets(); // saveRawColors(netSlot); + chooseShownReadings(); sendAllPathsCore2 = 1; showLEDsCore2 = 1; - if (debugNMtime) - { + if (debugNMtime) { Serial.print("\n\n\r"); Serial.print("took "); Serial.print(millis() - timer); @@ -624,8 +595,7 @@ goto dontshowmenu; input = ' '; probeActive = 0; - if (connectFromArduino != '\0') - { + if (connectFromArduino != '\0') { connectFromArduino = '\0'; // Serial.print("connectFromArduino\n\r"); // delay(2000); @@ -679,8 +649,7 @@ goto dontshowmenu; break; case 'l': - if (LEDbrightnessMenu() == '!') - { + if (LEDbrightnessMenu() == '!') { clearLEDs(); delayMicroseconds(9200); sendAllPathsCore2 = 1; @@ -689,8 +658,7 @@ goto dontshowmenu; case 'r': - if (rotaryEncoderMode == 1) - { + if (rotaryEncoderMode == 1) { // unInitRotaryEncoder(); rotaryEncoderMode = 0; @@ -704,9 +672,7 @@ goto dontshowmenu; showLEDsCore2 = 1; debugFlagSet(10); // encoderModeOff goto menu; - } - else - { + } else { rotaryEncoderMode = 1; if (rotEncInit == 0) // only do this once { @@ -750,8 +716,7 @@ goto dontshowmenu; setBaudRate(baudRate); break; - case 'd': - { + case 'd': { debugFlagInit(); debugFlags: @@ -771,16 +736,13 @@ goto dontshowmenu; Serial.print("\n\r5. LEDs = "); Serial.print(debugLEDs); Serial.print("\n\n\r6. swap probe pin = "); - if (probeSwap == 0) - { + if (probeSwap == 0) { Serial.print("19"); - } - else - { + } else { Serial.print("18"); } Serial.print("\n\n\r7. load slots on start = "); - Serial.print(loadFileOnStart? "on" : "off"); + Serial.print(loadFileOnStart ? "on" : "off"); Serial.print("\n\n\n\r"); @@ -791,40 +753,33 @@ goto dontshowmenu; Serial.write(toggleDebug); toggleDebug -= '0'; - if (toggleDebug >= 0 && toggleDebug <= 9) - { + if (toggleDebug >= 0 && toggleDebug <= 9) { debugFlagSet(toggleDebug); delay(10); goto debugFlags; - } - else - { + } else { break; } } case ':': - if (Serial.read() == ':') - { + if (Serial.read() == ':') { // Serial.print("\n\r"); // Serial.print("entering machine mode\n\r"); machineMode(); showLEDsCore2 = 1; goto dontshowmenu; break; - } - else - { + } else { break; } default: - while (Serial.available() > 0) - { + while (Serial.available() > 0) { int f = Serial.read(); delayMicroseconds(30); } @@ -837,8 +792,7 @@ goto dontshowmenu; // #include // Include the necessary header file -void lastNetConfirm(int forceLastNet) -{ +void lastNetConfirm(int forceLastNet) { // while (tud_connected() == 0 && millis() < 500) // ; @@ -850,8 +804,7 @@ void lastNetConfirm(int forceLastNet) // return; // } - if (forceLastNet == 1) - { + if (forceLastNet == 1) { int bootselPressed = 0; openNodeFile(); @@ -866,13 +819,11 @@ void lastNetConfirm(int forceLastNet) Serial.print("\n\r short press BOOTSEL to restore last netlist\n\r"); Serial.print(" long press to cancel\n\r"); delay(250); - if (BOOTSEL) - { + if (BOOTSEL) { bootselPressed = 1; } - while (forceLastNet == 1) - { + while (forceLastNet == 1) { if (BOOTSEL) bootselPressed = 1; @@ -895,12 +846,10 @@ void lastNetConfirm(int forceLastNet) bootselPressed = 1; // delay(250); - if (bootselPressed == 1) - { + if (bootselPressed == 1) { unsigned long longPressTimer = millis(); int fade = 8; - while (BOOTSEL) - { + while (BOOTSEL) { sendAllPathsCore2 = 1; showLEDsCore2 = 2; @@ -909,8 +858,7 @@ void lastNetConfirm(int forceLastNet) // leds.clear(); showLEDsCore2 = 2; - if (fade <= 0) - { + if (fade <= 0) { clearAllNTCC(); clearLEDs(); startupColors(); @@ -947,19 +895,18 @@ void machineMode(void) // read in commands in machine readable format lastTimeCommandRecieved = millis(); - if (millis() - lastTimeCommandRecieved > 100) - { + if (millis() - lastTimeCommandRecieved > 100) { machineModeRespond(sequenceNumber, true); return; } - enum machineModeInstruction receivedInstruction = parseMachineInstructions(&sequenceNumber); + enum machineModeInstruction receivedInstruction = + parseMachineInstructions(&sequenceNumber); // Serial.print("receivedInstruction: "); // Serial.print(receivedInstruction); // Serial.print("\n\r"); - switch (receivedInstruction) - { + switch (receivedInstruction) { case netlist: lastTimeNetlistLoaded = millis(); clearAllNTCC(); @@ -980,13 +927,10 @@ void machineMode(void) // read in commands in machine readable format break; case getnetlist: - if (millis() - lastTimeNetlistLoaded > 300) - { + if (millis() - lastTimeNetlistLoaded > 300) { listNetsMachine(); - } - else - { + } else { machineModeRespond(0, true); // Serial.print ("too soon bro\n\r"); return; @@ -1072,8 +1016,7 @@ void machineMode(void) // read in commands in machine readable format machineModeRespond(sequenceNumber, true); } -void loadFile(int slot) -{ +void loadFile(int slot) { clearAllNTCC(); openNodeFile(netSlot); getNodesToConnect(); @@ -1099,30 +1042,24 @@ volatile uint8_t pauseCore2 = 0; void loop1() // core 2 handles the LEDs and the CH446Q8 { - // while (1) rainbowBounce(50); //I uncomment this to test the LEDs on a fresh board + // while (1) rainbowBounce(50); //I uncomment this to test the LEDs on a fresh + // board - while(pauseCore2 == 1) - { - + while (pauseCore2 == 1) { } - - if (showLEDsCore2 >= 1) - { + if (showLEDsCore2 >= 1) { int rails = showLEDsCore2; - if (rails == 1 || rails == 2) - { + if (rails == 1 || rails == 2) { lightUpRail(-1, -1, 1, 28, supplySwitchPosition); } - if (rails != 2) - { + if (rails != 2) { showNets(); } - if (rails > 3) - { + if (rails > 3) { Serial.print("\n\r"); Serial.print(rails); } @@ -1133,8 +1070,7 @@ void loop1() // core 2 handles the LEDs and the CH446Q8 showLEDsCore2 = 0; } - if (sendAllPathsCore2 == 1) - { + if (sendAllPathsCore2 == 1) { delayMicroseconds(6200); sendAllPaths(); delayMicroseconds(2200); @@ -1147,11 +1083,12 @@ void loop1() // core 2 handles the LEDs and the CH446Q8 // logicAnalyzer.processCommand(); // } - if (arduinoReset == 0 && USBSer1.peek() == 0x30) // 0x30 is the first thing AVRDUDE sends + if (arduinoReset == 0 && + USBSer1.peek() == 0x30) // 0x30 is the first thing AVRDUDE sends { - //Serial.print("resetting arduino\n\r"); + // Serial.print("resetting arduino\n\r"); - //resetArduino(); + // resetArduino(); arduinoReset = 1; lastTimeReset = millis(); } @@ -1164,77 +1101,68 @@ void loop1() // core 2 handles the LEDs and the CH446Q8 // setDac0_5Vvoltage(0.0); // } - while (arduinoReset == 1) - { + while (arduinoReset == 1) { - if (USBSer1.available()) - { + if (USBSer1.available()) { char ch = USBSer1.read(); - //Serial.write(ch); + // Serial.write(ch); Serial1.write(ch); } - if (Serial1.available()) - { + if (Serial1.available()) { char ch = Serial1.read(); - //Serial.write(ch); + // Serial.write(ch); USBSer1.write(ch); } - if (millis() - lastTimeReset > 4000) // if the arduino hasn't been reset in a second, reset the flag + if (millis() - lastTimeReset > + 4000) // if the arduino hasn't been reset in a second, reset the flag { arduinoReset = 0; } } - if (readInNodesArduino == 0) - { + if (readInNodesArduino == 0) { - if (USBSer1.available()) - { + while (USBSer1.available()) { char ch = USBSer1.read(); Serial1.write(ch); // Serial.print(ch); } - if (Serial1.available()) - { + if (Serial1.available()) { char ch = Serial1.read(); USBSer1.write(ch); - // Serial.print(ch); + // Serial.print(ch); - if (ch == 'f' && connectFromArduino == '\0') - { + if (ch == 'f' && connectFromArduino == '\0') { input = 'f'; connectFromArduino = 'f'; - // Serial.print("!!!!"); - } - else - { - // connectFromArduino = '\0'; + Serial.print("!!!!"); + while (connectFromArduino == 'f') { + //delay(10); + } + } else { + //connectFromArduino = '\0'; } } } - if (rotaryEncoderMode == 1) - { + if (rotaryEncoderMode == 1) { rotaryEncoderStuff(); - } - else - { + } else { showingPreview = 0; - if (logoFlash == 2) - { + if (logoFlash == 2) { logoFlashTimer = millis(); logoFlash = 1; } - if (logoFlash == 1 && logoFlashTimer != 0 && millis() - logoFlashTimer > (20)) - { + if (logoFlash == 1 && logoFlashTimer != 0 && + millis() - logoFlashTimer > (20)) { logoFlash = 0; logoFlashTimer = 0; lightUpRail(); @@ -1247,6 +1175,9 @@ void loop1() // core 2 handles the LEDs and the CH446Q8 leds.show(); } } + if (showReadings == 0 && probeActive == 0) { + showLEDmeasurements(); + } // logicAnalyzer.processCommand(); } diff --git a/Jumperless_Wokwi_Bridge_App/JumperlessWokwiBridge/JumperlessWokwiBridge.py b/Jumperless_Wokwi_Bridge_App/JumperlessWokwiBridge/JumperlessWokwiBridge.py deleted file mode 100644 index 3aa07ee..0000000 --- a/Jumperless_Wokwi_Bridge_App/JumperlessWokwiBridge/JumperlessWokwiBridge.py +++ /dev/null @@ -1,1940 +0,0 @@ -# SPDX-License-Identifier: MIT - -from bs4 import BeautifulSoup - -import pathlib - -import requests -import json -import serial -import time - -import sys -import codecs -import os -import pyduinocli - -import psutil -import shutil -from urllib.request import urlretrieve - -import ssl -ssl._create_default_https_context = ssl._create_unverified_context - -os.system("") -#import platform - -#from watchedserial import WatchedReaderThread - -import serial.tools.list_ports - - -debug = False - - - -justreconnected = 0 - -global serialconnected -serialconnected = 0 - -portSelected = 0 - -stringified = ' ' -lastDiagram = [' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '] -diagram = [' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '] - - -menuEntered = 0 - -portName = ' ' - - - -arduinoPort = 0 - -noWokwiStuff = False - -disableArduinoFlashing = 1 - -def resource_path(relative_path): - """ Get absolute path to resource, works for dev and for PyInstaller """ - base_path = getattr(sys, '_MEIPASS', os.path.dirname(os.path.abspath(__file__))) - return os.path.join(base_path, relative_path) -#Path.mkdir(Path.cwd() / "JumperlessFiles/", exist_ok=True) - - -slotAssignmentsFile = ("JumperlessFiles/slotAssignments.txt") -savedProjectsFile = ("JumperlessFiles/savedProjects.txt") - -pathlib.Path(slotAssignmentsFile).parent.mkdir(parents=True, exist_ok=True) -pathlib.Path(savedProjectsFile).parent.mkdir(parents=True, exist_ok=True) -# Path.home() / "JumperlessFiles" / "savedProjects.txt" - -#arduino = pyduinocli.Arduino("arduino-cli") - -#### If you're running this in thonny, make sure you download arduino-cli and put it in the same folder as this script -#### then uncomment this below and comment the one above -# arduino = pyduinocli.Arduino("./arduino-cli") -noArduinocli = True -# try: -# arduino = pyduinocli.Arduino(resource_path("arduino-cli")) -# except: -# try: -# arduino = pyduinocli.Arduino("arduino-cli") -# except: -# try: -# arduino = pyduinocli.Arduino("./arduino-cli") -# except: -# print ("Couldn't find arduino-cli") -# noArduinocli = True -# pass - - -# print ('\n\n\n\rarduino') -# print(arduino) - -serialconnected = 0 - - -if (noArduinocli == True): - - disableArduinoFlashing = 1 - - -def openSerial(): - global portName - global ser - global serTickle - global arduinoPort - global disableArduinoFlashing - global serialconnected - - portSelected = 0 - foundports = [] - - print("\n") - - while portSelected == False: - autodetected = -1 - ports = serial.tools.list_ports.comports() - - i = 0 - for port, desc, hwid in ports: - i = i + 1 - - hwidString = hwid - splitAt = "VID:PID=" - splitInd = hwidString.find(splitAt) - - hwidString = hwidString[splitInd+8:splitInd+17] - #print (hwidString) - - - vid = hwidString[0:4] - pid = hwidString[5:9] - #print ("vid = " + vid) - #print ("pid = " + pid) - print("{}: {} [{}]".format(i, port, desc)) - if desc == "Jumperless" or pid == "ACAB" or pid == "1312": - autodetected = i - foundports.append(ports[autodetected-1][0]) - - selection = -1 - sortedports = sorted(foundports,key = lambda x:x[-1]) - #print (foundports) - #print(sortedports) - print ("\n") - - jumperlessIndex = chooseJumperlessPort(sortedports) - arduinoIndex = (jumperlessIndex + 1) % 2 - - #print (jumperlessIndex) - #print (arduinoIndex) - - if autodetected != -1: - #if False: - try: - selection = autodetected - - #portName = ports[int(selection) - 1].device - - portName = sortedports[jumperlessIndex] - - arduinoPort = sortedports[arduinoIndex] - - portSelected = True - serialconnected = 1 - - print("\nAutodetected Jumperless at", end=" ") - print(portName) - - print ("Autodetected USB-Serial at ", end="") - print (arduinoPort) - except: - pass - - - - else: - selection = input( - "\n\nSelect the port connected to your Jumperless ('r' to rescan)\n\n(Choose the lower numbered port, the other is routable USB-Serial)\n\n") - - - if selection.isdigit() == True and int(selection) <= i: - portName = ports[int(selection) - 1].device - print("\n\n") - i = 0 - - for port, desc, hwid in ports: - i = i + 1 - print("{}: {} [{}]".format(i, port, desc)) - - - ArduinoSelection = -1 - sortedports = sorted(foundports,key = lambda x:x[-1]) - #print (foundports) - #print(sortedports) - print ("\n\n") - ArduinoSelection = input( - "\n\nChoose the Arduino port ('x' to skip)\n\n(Choose the higher numbered port)\n\n") - - if (ArduinoSelection == 'x' or ArduinoSelection == 'X'): - disableArduinoFlashing = 1 - - if ArduinoSelection.isdigit() == True and int(ArduinoSelection) <= i: - - arduinoPort = ports[int(ArduinoSelection) - 1].device - aPortSelected = True - print(ports[int(ArduinoSelection) - 1].device) - - - portSelected = True - print(ports[int(selection) - 1].device) - - - - serialconnected = 1 - - - - - - -#portName = '/dev/cu.usbmodem11301' - - ser = serial.Serial(portName, 115200, timeout=None) - #ser.open() - - -jumperlessFirmwareNumber = [0,0,0,0,0,0] - -def chooseJumperlessPort(sortedports): - global jumperlessFirmwareString - global jumperlessFirmwareNumber - - jumperlessFirmwareString = ' ' - tryPort = 0 - - while (tryPort < len(sortedports)): - - tempSer1 = serial.Serial(sortedports[tryPort], 115200, timeout=None) - #print (tryPort) - tempSer1.write(b'?') - - time.sleep(0.1) - inputBuffer2 = b' ' - - if (tempSer1.in_waiting > 0): - #justChecked = 0 - #reading = 1 - inputBuffer2 = b' ' - - waiting = tempSer1.in_waiting - - while (serialconnected >= 0): - inByte = tempSer1.read() - - inputBuffer2 += inByte - - if (tempSer1.in_waiting == 0): - time.sleep(0.05) - - if (tempSer1.in_waiting == 0): - break - else: - continue - tempSer1.close() - - inputBuffer2 = str(inputBuffer2) - inputBuffer2 = inputBuffer2.strip('b\'\\n \\r ') - - jumperlessFirmwareString = inputBuffer2.split('\\r\\n')[0] - - #print (inputBuffer2) - #print (jumperlessFirmwareString) - - if (jumperlessFirmwareString.startswith("Jumperless firmware version:") == True): - - #print(jumperlessFirmwareString[29:39]) - - - jumperlessFirmwareNumber = jumperlessFirmwareString[29:39].split('.') - - #print (jumperlessFirmwareNumber) - - #print ("found a match!") - # - return tryPort - - else: - - tryPort = tryPort+1 - else: - tryPort = tryPort+1 - #print ("fuck") - return 0 - - - - - - -justChecked = 0 -reading = 0 - - -latestFirmwareAddress = "https://github.com/Architeuthis-Flux/Jumperless/releases/latest/download/firmware.uf2" - -url_link = 0 - -currentString = 'fuck' - -def checkIfFWisOld (): - global currentString - global jumperlessFirmwareString - - response = requests.get("https://github.com/Architeuthis-Flux/Jumperless/releases/latest") - version = response.url.split("/").pop() - #print(version) - - latestVersion = version.split('.') - latestString = latestVersion[0] + '.' + latestVersion[1] + '.' + latestVersion[2] - - splitIndex = jumperlessFirmwareString.rfind(':') - - #print(jumperlessFirmwareString) - currentString = jumperlessFirmwareString[splitIndex+2:] - - - - - - latestList = latestString.split('.') - currentList = currentString.split('.') - # print(currentList) - # print(latestList) - - - #latestInt = (int(latestList[0])* 100) + (int(latestList[2])* 10) + (int(latestList[2])) - #currentInt = (int(currentList[0])* 100) + (int(currentList[2])* 10) + (int(currentList[2])) - # try: - latestInt = int("".join(latestList)) - try: - currentInt = int("".join(currentList)) - except: - currentInt = 0 - #return True - # print (latestInt) - # print (currentInt) - - - if (latestInt > currentInt): - - - print("\n\n\rThe latest firmware is: " + latestString) - print( "You're running version: " + currentString) - return True - else: - return False - - - -def updateJumperlessFirmware(force): - global ser - global menuEntered - global currentString - global serialconnected - - #newFirmware = r - - if (force == False): - if (checkIfFWisOld() == False): - #print ("\n\n\r'update' to force firmware update - yours is up to date (" + currentString + ")") - return - - print("\n\rWould you like to update your Jumperless with the latest firmware? Y/n\n\r") - if (force == True or input ("\n\r").lower() == "y"): - - print ("\n\rDownloading latest firmware...") - - serialconnected = 0 - menuEntered = 1 - - urlretrieve(latestFirmwareAddress, "firmware.uf2") - - ser.close() - time.sleep(0.50) - - print("Putting Jumperless in BOOTSEL...") - - serTickle = serial.Serial(portName, 1200, timeout=None) - - - serTickle.close() - time.sleep(0.55) - -# serTickle.open() -# time.sleep(0.95) -# serTickle.close() - - print ("Waiting for mounted drive...") - - foundVolume = "none" - - while (foundVolume == "none"): - time.sleep(0.5) - partitions = psutil.disk_partitions() - - for p in partitions: - #print(p.mountpoint) - if (p.mountpoint.endswith("RPI-RP2") == True): - foundVolume = p.mountpoint - print("Found Jumperless at " + foundVolume + "...") - break - - - #if (win32api.GetVolumeInformation(p.mountpoint)[0] == "RPI-RP2"): - # foundVolume = p.mountpoint - # print("Found Jumperless at " + foundVolume + "...") - # break - - fullPathRP = os.path.join(foundVolume, "firmware.uf2") - #print(fullPathRP) - time.sleep(0.2) - print ("Copying firmware.uf2 to Jumperless...\n\r") - try: - shutil.copy("firmware.uf2", fullPathRP) - - - except: - pass - - time.sleep(0.75) - print("Jumperless updated to latest firmware!") - - - #ser.open() - time.sleep(0.75) - - #openSerial() - ser = serial.Serial(portName, 115200, timeout=None) - ser.flush() - menuEntered = 0 - serialConnected = 1 - - - -defaultWokwiSketchText = 'void setup() {' - - -# 555 project - -# https://wokwi.com/projects/369024970682423297 - - -# the website URL -#url_link = "https://wokwi.com/projects/369024970682423297" -menuEntered = 0 - - -def bridgeMenu(): - global menuEntered - global ser - global disableArduinoFlashing - global noWokwiStuff - global url_link - global currentString - global numAssignedSlots - #global serTickle - - - while(menuEntered == 1): - - print("\t\t\tBridge App Menu\n\n") - - print("\t\ta = Assign Wokwi Links to Slots", end='') - if (numAssignedSlots > 0): - print(" - " + str(numAssignedSlots) + " assigned") - else: - print() - print("\t\td = Delete Saved Projects") - print("\t\tr = Restart Bridge App") - print("\t\ts = Restart Serial") - #print("\t\tl = Load Project") - # print("\t\tf = Disable Auto-flashing Arduino - ", end='') - # if (disableArduinoFlashing == 0): - # print("Enabled") - # else: - # print("Disabled") - - print("\t\tu = Update Jumperless Firmware - " + currentString) - - print("\t\tj = Go Back To Jumperless\n") - - menuSelection = input("\n\n") - - - - # if(menuSelection == 'f'): - # if (disableArduinoFlashing == 0): - # disableArduinoFlashing = 1 - # else: - # disableArduinoFlashing = 0 - - # #disableArduinoFlashing = 1 - # break - - if (menuSelection == 's'): - ser.close() - - - openSerial() - #time.sleep(1) - menuEntered = 0 - time.sleep(.25) - ser.write(b'm') - break - - if (menuSelection == 'l'): - openProject() - #time.sleep(1) - menuEntered = 0 - time.sleep(.25) - ser.write(b'm') - - break - - if (menuSelection == 'r'): - ser.close() - openSerial() - #openProject() - assignWokwiSlots() - #time.sleep(1) - menuEntered = 0 - time.sleep(.5) - ser.write(b'm') - - break - - if(menuSelection == 'j'): - menuEntered = 0 - time.sleep(.25) - ser.write(b'm') - break - - if(menuSelection == 'u'): - updateJumperlessFirmware(True) - menuEntered = 0 - time.sleep(.25) - ser.write(b'm') - break - - if(menuSelection == 'a'): - assignWokwiSlots() - menuEntered = 0 - time.sleep(.25) - ser.write(b'm') - break - - - while (menuSelection == 'd'): - - print('\n\nEnter the index of the project you\'d like to delete:\n\nr = Return To Menu\ta = Delete All\n\n') - - try: - f = open(savedProjectsFile, "r") - except: - f = open(savedProjectsFile, "x") - f = open(savedProjectsFile, "r") - - index = 0 - - lines = f.readlines() - - for line in lines: - if (line != '\n'): - index += 1 - print(index, end="\t") - - print(line) - - linkInput = input('\n\n') - - if (linkInput == 'a'): - f.close() - f = open(savedProjectsFile, "w") - f.close() - - - - if (linkInput.isdigit() == True) and (int(linkInput) <= index): - otherIndex = 0 - realIndex = 0 - for idx in lines: - - if (idx != '\n'): - - otherIndex += 1 - - if (otherIndex == int(linkInput)): - print(idx) - del lines[realIndex] - #del lines[idx+1] - idx = idx.rsplit('\t\t') - idxLink = idx[1].rstrip('\n') - print("\n\nDeleting project ", end='') - print(idx[0]) - break - - realIndex += 1 - - f.close() - f = open(savedProjectsFile, "w") - - for line in lines: - - f.write(line) - f.close() - f = open(savedProjectsFile, "r") - print (f.read()) - f.close() - #menuEntered = 0 - else: - break - - -slotLines = [ "slot 0\n", "slot 1\n", "slot 2\n", "slot 3\n", "slot 4\n", "slot 5\n", "slot 6\n", "slot 7\n"] -defaultSlotLines = [ "slot 0\n", "slot 1\n", "slot 2\n", "slot 3\n", "slot 4\n", "slot 5\n", "slot 6\n", "slot 7\n"] -slotURLs = [ '!', '!', '!', '!', '!', '!', '!', '!', '!'] - -numAssignedSlots = 0 - -def countAssignedSlots(): - global slotLines - global slotURLs - global numAssignedSlots - numAssignedSlots = 0 - try: - slot = open(slotAssignmentsFile, "r") - except: - return - slot.seek(0) - slotLines = slot.readlines() - splitLine = ' ' - - idx = 0 - for line in slotLines: - if (line != '\n'): - splitLine = line.split('\t') - if (len(splitLine) > 1): - slotURLs[idx] = splitLine[1] - numAssignedSlots += 1 - idx += 1 - - #print(slotURLs) - slot.close() - return numAssignedSlots - -def printSavedProjects(): - try: - f = open(savedProjectsFile, "r") - except: - f = open(savedProjectsFile, "x") - f = open(savedProjectsFile, "r") - - index = 0 - - lines = f.readlines() - - for line in lines: - if (line != '\n'): - index += 1 - print(index, end="\t") - - print(line, end='') - - f.close() - - -def printOpenProjectOptions(): - - print("\n\n") - - print(" 'menu' to open the Bridge App menu") - print(" 'skip' to disable Wokwi updates and just use as a terminal") - print(" 'update' to force firmware update - yours is up to date (" + currentString + ")") - print(" 'slots' to assign Wokwi projects to slots (this menu) ", end='') - - countAssignedSlots() - if (numAssignedSlots > 0): - print("- " + str(numAssignedSlots) + " assigned") - # else: - # print("\n") - - print("\n ^-- (you can enter these commands at any time)\n") - - print(" ENTER to accept and go to Jumperless\n") - -def printSlotOptions(): - - print( " 'x' to clear all slots") - print( " 'c' to clear a single slot") - print( "\nEnter the slot number you'd like to assign a project to:\n") -savedProjectIndex = 0 - -somethingChoosen = False - - -def assignWokwiSlots(): - global url_link - global slotLines - global slotURLs - global numAssignedSlots - printOpenProjectOptions() - printSlotOptions() - #countAssignedSlots() - - try: - slot = open(slotAssignmentsFile, "r") - - except: - - slot = open(slotAssignmentsFile, "x") - slot.close() - slot = open(slotAssignmentsFile, "w") - - - slot.writelines(defaultSlotLines) - - #print(slot.read()) - slot.close() - slot = open(slotAssignmentsFile, "r") - - slot.seek(0) - firstLine = slot.readline() - - firstLine = firstLine.strip() - firstLineIndex = 0 - - while ((firstLine.startswith('slot 0') == False or firstLine.startswith('#') == True or firstLine.startswith('//') == True) ): - - # print("firstLine = ", end='') - # print(firstLine) - firstLine = slot.readline() - firstLine = firstLine.strip() - firstLineIndex = firstLineIndex + 1 - - if (firstLineIndex > 20): - slot = open(slotAssignmentsFile, "w") - - - slot.writelines(defaultSlotLines) - firstLineIndex = 0 - #slot.close() - slot = open(slotAssignmentsFile, "r") - break - - index = 0 - # print("\n\n") - # print(firstLineIndex) - # print("\n\n") - # slot.seek(firstLineIndex) - - # slot = open(slotAssignmentsFile, "r") - slot.seek(0) - # while (index < firstLineIndex): - # slot.readline() - # index += 1 - - lines = slot.readlines() - #0print("\n\n") - # print(firstLineIndex) - # print(lines[0]) - index = 0 - - numAssignedSlots = countAssignedSlots() - #print(numAssignedSlots) - - for line in lines: - - if (line != '\n'): - - index += 1 - print(line, end='') - slot.close() - - slotInput = '' - linkInput = '' - slotInput = input('\n\n') - #print(slotInput) - - - - # if (slotInput == 'r'): - # openProject() - - - if (slotInput == 'x'): - print("\n\nClearing all slots\n\n") - slot = open(slotAssignmentsFile, "w") - index = 0 - slot.writelines(defaultSlotLines) - slot = open(slotAssignmentsFile, "r") - #print(slot.readlines()) - numAssignedSlots = 0 - slot.close() - somethingChoosen = False - assignWokwiSlots() - - elif (slotInput.startswith('c')): - #slot = open(slotAssignmentsFile, "w") - #slotInput = slotInput.lstrip('c') - slotInput = input("\n\nEnter the slot number you'd like to clear:\n") - - if (slotInput.isdigit() == True ): - if (int(slotInput) < len(lines)): - slotInputInt = int(slotInput) - if (slotInputInt < len(lines)): - slot = open(slotAssignmentsFile, "w") - lines[slotInputInt] = "slot " + str(slotInputInt) + "\n" - - slot.writelines(lines) - numAssignedSlots -= 1 - slot.close() - assignWokwiSlots() - else: - print("\nInvalid slot") - - assignWokwiSlots() - else: - print("\nInvalid slot") - - assignWokwiSlots() - else: - - print("\nInvalid slot") - - assignWokwiSlots() - - - elif (slotInput == ''): - #print("skipping") - #print(slotInput) - countAssignedSlots() - - if (numAssignedSlots > 0): - return - else: - #assignWokwiSlots() - slotInput = '0' - elif (slotInput.isdigit() == False ): - slotInput = '' - print("\nInvalid slot") - assignWokwiSlots() - - elif (int(slotInput) >= len(lines)): - slotInput = '' - print("\nInvalid slot") - assignWokwiSlots() - else: - print("\nChoose from saved or paste a link to a Wokwi project for Slot ", end='') - print( slotInput ) - print("\n\n") - printSavedProjects() - - if (slotInput.isdigit() == True): - if (int(slotInput) <= len(lines)): - linkInput = searchSavedProjects(input()) - checkurl = ' ' - url_link = linkInput - try: - checkurl = requests.get(url_link) - if (checkurl.status_code == requests.codes.ok): - - - notes = searchSavedProjects(linkInput, True) - - print("\n" + notes + " selected for slot " + slotInput) - - slot = open(slotAssignmentsFile, "w") - lines[int(slotInput)] = "slot " + slotInput + "\t" + url_link + "\t " + notes + "\n" - #for line in lines: - slot.writelines(lines) - #print(line) - slot.close() - assignWokwiSlots() - else: - print("\n\nBad Link") - except Exception as e: - print(e) - print("\n\nBad Link!") - assignWokwiSlots() - - - countAssignedSlots() - - - -def searchSavedProjects(inputToSearchFor, returnName = False): - try: - f = open(savedProjectsFile, "r") - except: - f = open(savedProjectsFile, "x") - f = open(savedProjectsFile, "r") - - index = 0 - matchFound = 0 - returnLink = ' ' - - lines = f.readlines() - - linkInput = inputToSearchFor - - if (linkInput.startswith("http") == True): #pasted a link - noWokwiStuff = False - entryType = "link" - if (returnName == False): - return linkInput - #return linkInput - - elif (linkInput.isdigit() == True ): #entered a number - #print(linkInput) - # print(int(linkInput)) - linkInt = int(linkInput) - otherIndex = 0 - entryType = "index" - - for idx in lines: - if (idx != '\n'): - otherIndex += 1 - if (otherIndex == linkInt): - idx = idx.rsplit('\t\t') - idxLink = idx[1].rstrip('\n') - linkInput = idxLink.rstrip('\n') - if (returnName == False): - return idxLink.rstrip('\n') - break - else: #entered a name - #print("entered a name") - for name in lines: - if name != '\n': - name = name.rsplit('\t\t') - nameText = name[0] - #print (nameText) - if (nameText == linkInput): - entryType = "name" - linkInput = name[1].rstrip('\n') - if (returnName == False): - - return linkInput - break - index += 1 - matchFound = 0 - line = 0 - index = 0 - - for line in lines: - if (line != '\n'): - line = line.rsplit('\t\t') - name = line[0] - line = line[1] - - line = line.rstrip('\n') - index += 1 - - if line == linkInput: - #print ( "Match Found at index ", end = '') - matchFound = index - if (returnName == False): - return line - else: - return name - #return line - # break - # url_selected = 1 - - - - if matchFound == 0: - try: - checkurl = requests.get(linkInput) - #print(checkurl.status_code) - if (checkurl.status_code == requests.codes.ok): - url_selected = 1 - noWokwiStuff = False - - name = input("\n\nEnter a name for this new project\n\n") - f.close() - f = open(savedProjectsFile, "a") - f.write(name) - f.write('\t\t') - f.write(linkInput) - f.write("\n") - f.close() - if (returnName == False): - return linkInput - else: - return name - - else: - assignWokwiSlots() - except: - assignWokwiSlots() - - - - - - - -def openProject(): - global url_link - global disableArduinoFlashing - global noWokwiStuff - global menuEntered - global currentString - global numAssignedSlots - url_entered = 0 - url_selected = 0 - entryType = -1 # 0 for index, 1 for name, 2 for link - try: - numAssignedSlots = countAssignedSlots() - except: - numAssignedSlots = 0 - - disableArduinoFlashing = 1 - - - - - linkInput = input('\n\n') - - if (linkInput == 'slots' or linkInput == 'slot' or linkInput == 's'): - assignWokwiSlots() - openProject() - elif (linkInput == 'force' or linkInput == 'update' or linkInput == 'force update'): - jumperlessFirmwareString = ' ' - updateJumperlessFirmware(True) - - elif(linkInput == 'skip' ): - noWokwiStuff = True - url_link = ' ' - print("\nWokwi updates disabled\n\n") - ser.write('m'.encode()) - url_selected = 1 - #break - return - - - elif(linkInput == 'menu' or linkInput == 'm'): - menuEntered = 1 - - #while(menuEntered == 1): - bridgeMenu() - - openProject() - - else: - linkInput = searchSavedProjects(linkInput) - - - checkurl = ' ' - url_link = linkInput - -# print("\n\n linkInput = ", end='') -# print(linkInput) -# print("\n\n url_link = ", end='') -# print(url_link) - - #checkurl = requests.get(url_link) - #print(checkurl.status_code) - if (noWokwiStuff == False): - try: - checkurl = requests.get(url_link) - #print(checkurl.status_code) - if (checkurl.status_code == requests.codes.ok): - url_selected = 1 - noWokwiStuff = False - # break - else: - print("\n\nBad Link - Status Code: ", end='') - print(checkurl.status_code) - url_link = 0 - linkInput = 0 - openProject() - - except: - print("\n\nBad Link!!!") - url_link = 0 - openProject() - - matchFound = 0 - line = 0 - index = 0 - - - #saveConfig() - - - - - - - - -openSerial() -updateJumperlessFirmware(False) -assignWokwiSlots() -#openProject() - -if (noWokwiStuff == False): - print("\n\nSave your Wokwi project to update the Jumperless\n\n") - - - - - - - -portNotFound = 1 - -def check_presence(correct_port, interval=.15): - global ser - global justreconnected - global serialconnected - global justChecked - global reading - - portFound = 0 - while True: - - - if (reading == 0): - - portFound = 0 - - for port in serial.tools.list_ports.comports(): - - if portName in port.device: - - portFound = 1 - - #print (portFound) - - if portFound == 1: - try: - #print (portName) - #ser = serial.Serial(portName, 115200) - #print (portName) - #ser.open(portName) - justChecked = 1 - serialconnected = 1 - time.sleep(0.1) - justChecked = 0 - - - except: - - continue - - else: - justreconnected = 1 - justChecked = 0 - serialconnected = 0 - - ser.close() - - time.sleep(interval) - - -import threading -port_controller = threading.Thread( - target=check_presence, args=(portName, .15,), daemon=True) -# port_controller.daemon(True) -port_controller.start() - -#ser.in_waiting - - - -def serialTermIn(): - global serialconnected - global ser - global justChecked - global reading - global menuEntered - global portNotFound - - while True: - readLength = 0 - - - while menuEntered == 0: - try: - if (ser.in_waiting > 0): - #justChecked = 0 - #reading = 1 - inputBuffer = b' ' - - waiting = ser.in_waiting - - while (serialconnected >= 0): - inByte = ser.read() - - inputBuffer += inByte - - if (ser.in_waiting == 0): - time.sleep(0.05) - - if (ser.in_waiting == 0): - break - else: - continue - - inputBuffer = str(inputBuffer) - - inputBuffer.encode() - decoded_string = codecs.escape_decode( - bytes(inputBuffer, "utf-8"))[0].decode("utf-8") - - decoded_string = decoded_string.lstrip("b' ") - decoded_string = decoded_string.rstrip("'") - decoded_string = decoded_string.rstrip("\"") - - print(decoded_string, end='') - #print ("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!") - readlength = 0 - #justChecked = 0 - reading = 0 - portNotFound = 0 - - except: - try: - ser.close() - except: - pass - print("Disconnected") - portNotFound = 1 - while (portNotFound == 1): - portFound = 0 - - time.sleep(0.2) - for port in serial.tools.list_ports.comports(): - - if portName in port.device: - - portFound = 1 - portNotFound = 0 - #print ("found ") - #print (port.device) - - if portFound == 1: - try: - ser = serial.Serial(portName, 115200, timeout=None) - justChecked = 1 - serialconnected = 1 - time.sleep(0.2) - justChecked = 0 - portNotFound = 0 - #justreconnected = 1 - except: - portFound = 0 - portNotFound = 1 - time.sleep(0.25) - - else: - #justreconnected = 1 - justChecked = 0 - serialconnected = 0 - - #ser.close() - portNotFound = 1 - time.sleep(.1) - - -port_controller = threading.Thread(target=serialTermIn, daemon=True) -# port_controller.daemon(True) -port_controller.start() - -forceWokwiUpdate = 0 - -def serialTermOut(): - global serialconnected - global ser - global justChecked - global justreconnected - global menuEntered - global forceWokwiUpdate - global noWokwiStuff - - - - while True: - justreconnected = 0 - resetEntered = 0 - - while (menuEntered == 0): - - outputBuffer = input() - - if (outputBuffer == 'menu') or (outputBuffer == 'Menu'): - print("Menu Entered") - menuEntered = 1 - continue - if (outputBuffer == 'slots') or (outputBuffer == 'Slots'): - assignWokwiSlots() - #outputBuffer = ' ' - continue - if (outputBuffer == 'wokwi'): - forceWokwiUpdate = 1 - print("Wokwi update forced") - continue - - if(outputBuffer == 'skip'): - if (noWokwiStuff == False): - noWokwiStuff = True - print("\nWokwi updates disabled\n\n") - else: - print("\nWokwi updates enabled\n\n") - noWokwiStuff = True - outputBuffer = ' ' - continue - - - #if outputBuffer == b'r': - #resetEntered = 1 - - if (serialconnected == 1): - #justChecked = 0 - while (justChecked == 0): - time.sleep(0.01) - else: - - #print (outputBuffer) - if (outputBuffer != ' '): - try: - #print (outputBuffer.encode('ascii')) - ser.write(outputBuffer.encode('ascii')) - except: - portNotFound = 1 - - while (portNotFound == 1): - portFound = 0 - - for port in serial.tools.list_ports.comports(): - - if portName in port.device: - - portFound = 1 - print (port.device) - - if portFound >= 1: - # - justChecked = 1 - serialconnected = 1 - time.sleep(0.05) - justChecked = 0 - portNotFound = 0 - - else: - justreconnected = 0 - justChecked = 0 - serialconnected = 0 - - ser.close() - portNotFound = 1 - time.sleep(.1) - try: - print(outputBuffer.encode('ascii')) - ser.write(outputBuffer.encode('ascii')) - except: - serialconnected=0 - - if (resetEntered == 1): - time.sleep(.5) - print("reset") - justreconnected = 1 - - # time.sleep(.5) - -def removeLibraryLines(line): - - if "#" in line: - return False - if (len(line) == 0): - return False - else: - return True - - - -def findsketchindex(decoded): - - doneSearching = 0 - index = 0 - - while (doneSearching == 0): - if (decoded['props']['pageProps']['p']['files'][index]['name'] == "sketch.ino"): - doneSearching = 1 - #print ("sketch found at index " , end='') - #print(index) - return index - else: - if (index > 20): - doneSearching = 1 - return 0 - - else: - index = index + 1 - - - - -def finddiagramindex(decoded): - - doneSearching = 0 - index = 0 - - while (doneSearching == 0): - if (decoded['props']['pageProps']['p']['files'][index]['name'] == "diagram.json"): - doneSearching = 1 - #print ("diagram found at index " , end='') - #print(index) - return index - else: - if (index > 20): - doneSearching = 1 - return 2 - - else: - index = index + 1 - - - -def findlibrariesindex(decoded): - doneSearching = 0 - index = 0 - - while (doneSearching == 0): - if (decoded['props']['pageProps']['p']['files'][index]['name'] == "libraries.txt"): - doneSearching = 1 - #print ("libraries found at index " , end='') - #print(index) - return index - else: - if (index > 20): - doneSearching = 1 - return 3 - - else: - index = index + 1 - #print (decoded) - - - - -port_controller = threading.Thread(target=serialTermOut, daemon=True) - -port_controller.start() - -time.sleep(.75) - - -sketch = [' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '] -lastsketch = [' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '] -lastlibraries = ' ' -blankDiagrams = [' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '] - -#print (arduino.board.attach(arduinoPort,None,"WokwiSketch")) -#print (arduinoPort) - -try: - ser.write('m'.encode()) -except: - pass - -currentSlotUpdate = 1 -cycled = 0 -while True: - - if (menuEntered == 1): - bridgeMenu() - - # while portIsUsable(portName) == True: - # print('fuck') - # ser.close() - # time.sleep(.5) - #ser = serial.Serial(portName, 460800, timeout=0.050) - - while (justreconnected == 1): - - #print("just reconnected") - lastDiagram = blankDiagrams - - forceWokwiUpdate = 1 - time.sleep(.1) - ser.close() - time.sleep(.1)####### - #if (portNotFound != 1): - #ser = serial.Serial(portName, 115200, timeout=None) - if (serialconnected == 1): - print('Reconnected') - portNotFound = 0 - portFound = 1 - justreconnected = 0 - forceWokwiUpdate = 1 - break - else: - justreconnected = 0 - - #print("noWokwiStuff") - #print(noWokwiStuff) - - if (serialconnected == 1 and noWokwiStuff == False): - #print ("connected!!!") - - # if (forceWokwiUpdate == 1 and cycled == 0): - # #currentSlotUpdate = 0 - # cycled = 0 - - if (numAssignedSlots > 0): - # print(currentSlotUpdate) - # print(slotURLs) - currentSlotUpdate += 1 - - - if (currentSlotUpdate > 7): - - currentSlotUpdate = 0 - #cycled += 1 - - - # if (forceWokwiUpdate == 1 and cycled == 2): - - # forceWokwiUpdate = 0 - # cycled = 0 - - while(slotURLs[currentSlotUpdate] == '!'): - - #print(currentSlotUpdate) - currentSlotUpdate += 1 - if (currentSlotUpdate > 7): - currentSlotUpdate = 0 - forceWokwiUpdate = 0 - - try: - - result = requests.get(slotURLs[currentSlotUpdate]).text - except Exception as e: - #print(e) - continue - - - else: - currentSlotUpdate = 0 - assignWokwiSlots() - #result = requests.get(url_link).text - - #print(currentSlotUpdate) - - - - doc = BeautifulSoup(result, "html.parser") - - - s = doc.find('script', type='application/json').get_text() - - stringex = str(s) - - #print (stringex) - - d = json.loads(stringex) - - decoded = json.loads(stringex) - - #print (decoded['props']['pageProps']['p']['files'][0]['name']) - - - librariesExist = 0 - - - - # c = decoded['props']['pageProps']['p']['files'][findsketchindex(decoded)]['content'] - - try: - l = d['props']['pageProps']['p']['files'][findlibrariesindex(decoded)]['content'] - libraries = str(l) - librariesExist = 1 - except: - pass - - d = decoded['props']['pageProps']['p']['files'][finddiagramindex(decoded)]['content'] - #print (d) - - - f = json.loads(d) - - #cf = json.loads(c) - - diagram[currentSlotUpdate] = str(d) - #sketch[currentSlotUpdate] = str(c) - #print(c) - - if debug == True: - print("\n\ndiagram.json\n") - print(diagram[currentSlotUpdate]) - - # print("\n\nsketch.ino\n") - # print(sketch[currentSlotUpdate]) - - print("\n\nlibraries.txt\n") - print(libraries) - - # print("\n\ndiagram.json\n") - # print(diagram[currentSlotUpdate]) - justFlashed = 0 - - # if (sketch[0] != lastsketch[0] and disableArduinoFlashing == 0 and noWokwiStuff == False): - - # #all of this sucks and should probably never be used (on Rev 3 at least) - # lastsketch = sketch - # justFlashed = 1 - - - # try: - # newpath = './WokwiSketch' - # compilePath = './WokwiSketch/compile' - - # if not os.path.exists(newpath): - # os.makedirs(newpath) - # os.makedirs(compilePath) - - - # #print("\n\rFlashing Arduino") - # sk = open("./WokwiSketch/WokwiSketch.ino", "w") - # sk.write(sketch[0]) - # sk.close() - # time.sleep(0.1) - - # ser.write("f 116-70,117-71,".encode()) - # time.sleep(0.3) - - # try: - # menuEntered = 1 - # cor = ['arduino:avr'] - # #arduino.core.download(cor) - # #arduino.commands.core.install.(cor) - # #arduino.core.update_index() - # arduino.core.install(cor, no_overwrite= None) - # time.sleep(0.5) - - # menuEntered = 0 - - - # #installedCores = arduino.core.list() - # #print(installedCores) - # except Exception as c: - # print(c) - - # if librariesExist == 1 and lastlibraries != libraries: - # lastlibraries = libraries - # libList = list(libraries.split("\n")) - # filteredLibs = list(filter(lambda x: removeLibraryLines(x), libList)) - # if len(filteredLibs) > 0: - # print("Installing Arduino Libraries ", end="") - # liberror = arduino.lib.install(filteredLibs) - # print(filteredLibs) - - - - # #ser.write('r\n'.encode()) - # time.sleep(0.1) - - # #arduino.compile( "./WokwiSketch" ,port=arduinoPort,fqbn="arduino:avr:nano", upload=True) - # # try: - # #arduino.config("-v") - # ser.write("_".encode()) - # print ("Compiling...") - # compiledCode = arduino.compile( "./WokwiSketch" ,port=arduinoPort,fqbn="arduino:avr:nano", build_path="./WokwiSketch/compile" ) - # ser.write("-".encode()) - # time.sleep(0.1) - # print ("Flashing Arduino...") - # ser.write("f {116-70,117-71, }".encode()) - # time.sleep(0.1) - - # arduino.upload( "./WokwiSketch" ,port=arduinoPort,fqbn="arduino:avr:nano", input_dir="./WokwiSketch/compile", discovery_timeout="3s", verify=False ) - # print ("Arduino flashed successfully!") - # time.sleep(0.1) - # # except:# Exception as ardEx: - # #print (arduino.errors) - # # print (ardEx) - - - - # except Exception as e: - - # #errors = ({'__stdout': '{\n "compiler_out": "",\n "compiler_err": "",\n "builder_result": null,\n "upload_result": null,\n "success": false,\n "error": "Error during build: Platform \'arduino:avr\' not found: platform not installed\\nTry running `arduino-cli core install arduino:avr`"\n}', '__stderr': '', 'result': {'compiler_out': '', 'compiler_err': '', 'builder_result': None, 'upload_result': None, 'success': False, 'error': "Error during build: Platform 'arduino:avr' not found: platform not installed\nTry running `arduino-cli core install arduino:avr`"}},) - # try: - # jd = json.loads(e.args[0]['__stdout'] ) - # print(jd['error']) - # except: - # print(e) - # #errorMessages = e.args[0]['__stdout'] - # #print (errorMessages) - # #print ("Couldn't Flash Arduino") - - # #continue - # try: - # ser.write('m'.encode()) - # except: - # pass - # #if(noWokwiStuff == True and justreconnected == 1): - # #time.sleep(0.1) - # #print('Just Reconnected\n\n') - # #justreconnected = 0 - - - - if ((lastDiagram != diagram or justFlashed == 1 and noWokwiStuff == False) or (forceWokwiUpdate == 1)): - justFlashed = 0 - #print(forceWokwiUpdate) - forceWokwiUpdate = 0 - justreconnected = 0 - length = len(f["connections"]) - - p = "{ " - - for i in range(length): - - conn1 = str(f["connections"][i][0]) - - if conn1.startswith('pot1:SIG'): - conn1 = "106" - elif conn1.startswith('pot2:SIG'): - conn1 = "107" - - if conn1.startswith('logic1:'): - if conn1.endswith('0'): - conn1 = "110" - elif conn1.endswith('1'): - conn1 = "111" - elif conn1.endswith('2'): - conn1 = "112" - elif conn1.endswith('3'): - conn1 = "113" - elif conn1.endswith('4'): - conn1 = "108" - elif conn1.endswith('5'): - conn1 = "109" - elif conn1.endswith('6'): - conn1 = "116" - elif conn1.endswith('7'): - conn1 = "117" - elif conn1.endswith('D'): - conn1 = "114" - - if conn1.startswith("bb1:") == True: - periodIndex = conn1.find('.') - conn1 = conn1[4:periodIndex] - - if conn1.endswith('t') == True: - conn1 = conn1[0:(len(conn1) - 1)] - elif conn1.endswith('b') == True: - conn1 = conn1[0:(len(conn1) - 1)] - conn1 = int(conn1) - conn1 = conn1 + 30 - conn1 = str(conn1) - elif conn1.endswith('n') == True: - conn1 = "100" - elif conn1.startswith("GND") == True: - conn1 = "100" - elif conn1.endswith('p') == True: - if conn1.startswith('t') == True: - conn1 = "105" - elif conn1.startswith('b') == True: - conn1 = "103" - - if conn1.startswith("nano:") == True: - periodIndex = conn1.find('.') - conn1 = conn1[5:len(conn1)] - - if conn1.startswith("GND") == True: - conn1 = "100" - elif conn1 == "AREF": - conn1 = "85" - elif conn1 == "RESET": - conn1 = "84" - elif conn1 == "5V": - conn1 = "105" - elif conn1 == "3.3V": - conn1 = "103" - elif conn1 == "5V": - conn1 = "105" - - elif conn1.startswith("A") == True: - conn1 = conn1[1:(len(conn1))] - conn1 = int(conn1) - conn1 = conn1 + 86 - conn1 = str(conn1) - elif conn1.isdigit() == True: - conn1 = int(conn1) - conn1 = conn1 + 70 - conn1 = str(conn1) - - conn2 = str(f["connections"][i][1]) - - if conn2.startswith('pot1:SIG'): - conn2 = "106" - elif conn2.startswith('pot2:SIG'): - conn2 = "107" - - if conn2.startswith('logic1:'): - if conn2.endswith('0'): - conn2 = "110" - elif conn2.endswith('1'): - conn2 = "111" - elif conn2.endswith('2'): - conn2 = "112" - elif conn2.endswith('3'): - conn2 = "113" - elif conn2.endswith('4'): - conn2 = "108" - elif conn2.endswith('5'): - conn2 = "109" - elif conn2.endswith('6'): - conn2 = "116" - elif conn2.endswith('7'): - conn2 = "117" - elif conn2.endswith('D'): - conn2 = "114" - - if conn2.startswith("bb1:") == True: - periodIndex = conn2.find('.') - conn2 = conn2[4:periodIndex] - - if conn2.endswith('t') == True: - conn2 = conn2[0:(len(conn2) - 1)] - elif conn2.endswith('b') == True: - conn2 = conn2[0:(len(conn2) - 1)] - conn2 = int(conn2) - conn2 = conn2 + 30 - conn2 = str(conn2) - elif conn2.endswith('n') == True: - conn2 = "100" - elif conn2.startswith("GND") == True: - conn2 = "100" - elif conn2.endswith('p') == True: - if conn2.startswith('t') == True: - conn2 = "105" - elif conn2.startswith('b') == True: - conn2 = "103" - - if conn2.startswith("nano:") == True: - periodIndex = conn2.find('.') - conn2 = conn2[5:len(conn2)] - - if conn2.startswith("GND") == True: - conn2 = "100" - elif conn2 == "AREF": - conn2 = "85" - elif conn2 == "RESET": - conn2 = "84" - elif conn2 == "5V": - conn2 = "105" - elif conn2 == "3.3V": - conn2 = "103" - elif conn2 == "5V": - conn2 = "105" - - elif conn2.startswith("A") == True and conn2 != "AREF": - - conn2 = conn2[1:(len(conn2))] - conn2 = int(conn2) - conn2 = conn2 + 86 - conn2 = str(conn2) - elif conn2.isdigit() == True: - conn2 = int(conn2) - conn2 = conn2 + 70 - conn2 = str(conn2) - - if conn1.isdigit() == True and conn2.isdigit() == True: - - p = (p + conn1 + '-') - p = (p + conn2 + ',') - - p = ( p + "} ") - - lastDiagram[currentSlotUpdate] = diagram[currentSlotUpdate] - #lastDiagram = diagram - - try: - #print(f) - #print(p) - time.sleep(0.1) - if (numAssignedSlots > 0 and slotURLs[currentSlotUpdate] != '!'): - ser.write('o'.encode()) - time.sleep(0.010) - ser.write("Slot ".encode()) - #print("Slot " + str(currentSlot) + " " + ) - ser.write(str(currentSlotUpdate).encode()) - ser.write("\n\n\rf ".encode()) - ser.write(p.encode()) - time.sleep(0.4) - # else: - # ser.write('f'.encode()) - # time.sleep(0.001) - # ser.write(p.encode()) - #time.sleep(0.001) - #print(p) - - - except Exception as e: - #print('try again') - forceWokwiUpdate = 1 - # if (forceWokwiUpdate >= 2): - # print(e) - # forceWokwiUpdate = 0 - # #print('try again') - # continue - time.sleep(.5) - continue - # waitForReconnect() - - # ser.write('f'.encode()) - - # time.sleep(0.05) - - # ser.write(p.encode()) - - #print (p) - - - - - - - else: - if (noWokwiStuff == False): - time.sleep(.75) - diff --git a/Jumperless_Wokwi_Bridge_App/JumperlessWokwiBridge/Packager.py b/Jumperless_Wokwi_Bridge_App/JumperlessWokwiBridge/Packager.py deleted file mode 100644 index 18e3609..0000000 --- a/Jumperless_Wokwi_Bridge_App/JumperlessWokwiBridge/Packager.py +++ /dev/null @@ -1,141 +0,0 @@ -import PyInstaller.__main__ - -import pathlib -import os - -import shutil - - -# PyInstaller.__main__.run([ -# 'JumperlessWokwiBridge.py', -# '--onefile', -# '--windowed', -# '--onedir', -# '--icon=icon.icns', -# #'--add-binary=arduino-cli:.', -# '--console', -# '--target-arch=arm64', -# '--path=/Users/kevinsanto/Documents/GitHub/Jumperless/Jumperless_Wokwi_Bridge_App/JumperlessWokwiBridge/.venv/lib/python3.12/site-packages', -# '--noconfirm', -# #'--clean', - - -# ]) - -os.system(f"python -m PyInstaller --icon=\"/Users/kevinsanto/Documents/GitHub/Jumperless/Jumperless_Wokwi_Bridge_App/jumperlesswokwibridge/icon.icns\" \ --y \ ---console \ ---windowed \ ---target-arch arm64 \ ---path \"/Users/kevinsanto/Documents/GitHub/Jumperless/Jumperless_Wokwi_Bridge_App/JumperlessWokwiBridge/.venv/lib/python3.12/site-packages\" \ -JumperlessWokwiBridge.py \ ---name Jumperless ") - -generated_app_path = pathlib.Path("dist/Jumperless.app/Contents/MacOS/Jumperless") -generated_app_path_renamed = generated_app_path.with_name("Jumperless_cli") -target_app_path = pathlib.Path("dist/Jumperless.app/Contents/MacOS/") -icon_path = pathlib.Path("icon.icns") -nonexec_launcher_path = pathlib.Path("Jumperless_cli_launcher.sh") -launcher_path = pathlib.Path("Jumperless") -app_path = pathlib.Path("Jumperless.app") -apple_silicon_folder = pathlib.Path("apple silicon/Jumperless.app") -intel_folder = pathlib.Path("intel mac/Jumperless.app") - -# rename the app to JumperlessWokwiBridge_cli -print("chmodding launcher") -os.system(f"chmod 755 {nonexec_launcher_path}") -print("Changed permissions for " + str(nonexec_launcher_path)+ '\n') - -print("Renaming launcher to Jumperless") -os.system(f'cp {nonexec_launcher_path} {launcher_path}') -print("Renamed " + str(nonexec_launcher_path) + " to " + str(launcher_path)+ '\n') - - -print("Renaming app main app to Jumperless_cli") -os.rename(generated_app_path, generated_app_path_renamed) -print("Renamed " + str(generated_app_path) + "(main app) to " + str(generated_app_path_renamed)+ '\n') - - -os.system(f"cp {launcher_path} {target_app_path}") -print("Copied " + str(launcher_path) + "(launcher) to " + str(target_app_path)+ '\n') - - -# os.system(f"cp {generated_app_path} {target_app_path}") -# print("Copied " + str(generated_app_path) + " to " + str(target_app_path)) - -App = "/Applications/" -print("Copying app to applications folder") -shutil.copytree("Jumperless.app", App + "Jumperless.app", dirs_exist_ok=True ) -print("Copied " + str(app_path) + " to " + str(App)+ '\n') - -print("Copying app to apple silicon folder") -shutil.copytree("Jumperless.app", apple_silicon_folder, dirs_exist_ok=True ) - -print("doing this all again for intel mac") - - -os.system(f"python -m PyInstaller --icon=\"/Users/kevinsanto/Documents/GitHub/Jumperless/Jumperless_Wokwi_Bridge_App/jumperlesswokwibridge/icon.icns\" \ --y \ ---console \ ---windowed \ ---target-arch universal2 \ ---path \"/Users/kevinsanto/Documents/GitHub/Jumperless/Jumperless_Wokwi_Bridge_App/JumperlessWokwiBridge/.venv/lib/python3.12/site-packages\" \ -JumperlessWokwiBridge.py \ ---name Jumperless ") - - - - -print("chmodding launcher") -os.system(f"chmod 755 {nonexec_launcher_path}") -print("Changed permissions for " + str(nonexec_launcher_path)+ '\n') - -print("Renaming launcher to Jumperless") -os.system(f'cp {nonexec_launcher_path} {launcher_path}') -print("Renamed " + str(nonexec_launcher_path) + " to " + str(launcher_path)+ '\n') - - -print("Renaming app main app to Jumperless_cli") -os.rename(generated_app_path, generated_app_path_renamed) -print("Renamed " + str(generated_app_path) + "(main app) to " + str(generated_app_path_renamed)+ '\n') - - -os.system(f"cp {launcher_path} {target_app_path}") -print("Copied " + str(launcher_path) + "(launcher) to " + str(target_app_path)+ '\n') - - -# os.system(f"cp {generated_app_path} {target_app_path}") -# print("Copied " + str(generated_app_path) + " to " + str(target_app_path)) - -App = "/Applications/" -print("Copying app to applications folder") -shutil.copytree("Jumperless.app", App + "Jumperless.app", dirs_exist_ok=True ) -print("Copied " + str(app_path) + " to " + str(App)+ '\n') - -print("Copying app to intel mac folder") -shutil.copytree("Jumperless.app", intel_folder, dirs_exist_ok=True ) - - - - - - - - - -# os.system(f"cp {"JumperlessWokwiBridge.app"} {App}") - -# os.system(f"cp {icon_path} {generated_app_path}") - -print("Done") - - -# python -m PyInstaller \ -# --icon="/Users/kevinsanto/Documents/GitHub/Jumperless/Jumperless_Wokwi_Bridge_App/jumperlesswokwibridge/icon.icns" \ -# -y \ -# --console \ -# --windowed \ -# --target-arch x86_64 \ -# --path "/Users/kevinsanto/Documents/GitHub/Jumperless/Jumperless_Wokwi_Bridge_App/JumperlessWokwiBridge/.venv/lib/python3.12/site-packages" \ -# --add-binary "arduino-cli:." \ -# JumperlessWokwiBridge.py \ No newline at end of file