New Wokwi Bridge app

This commit is contained in:
Kevin Santo Cappuccio 2024-05-31 08:10:37 -07:00
parent 52a830841a
commit 94572acf75
1152 changed files with 47964 additions and 431 deletions

View File

@ -0,0 +1 @@
{"hostname":"Kevins-MBP","username":"kevinsanto"}

View File

@ -219,8 +219,56 @@ void sendAllPaths(void) // should we sort them by chip? for now, no
}
}
uint8_t restoreConnections[12][16][2]; // [chip][index][pairs 0=x, 1=y]
int clearAllConnectionsOnChip(int chip, int clearOrRestore)
{
int numCleared = 0;
uint8_t netCleared = 0;
if (clearOrRestore == 0)
{
for (int x = 0; x < 16; x++)
{
if (ch[chip].xStatus[x] != -1)
{
netCleared = ch[chip].xStatus[x];
for (int y = 0; y < 8; y++)
{
if (ch[chip].yStatus[y] == netCleared)
{
restoreConnections[chip][numCleared][0] = x;
restoreConnections[chip][numCleared][1] = y;
numCleared++;
Serial.print("chip ");
Serial.print(chip);
Serial.print(" x:");
Serial.print(x);
Serial.print(" y:");
Serial.print(y);
Serial.print(" net:");
Serial.print(netCleared);
Serial.print("\n\r");
sendXYraw(chip, x, y, 0);
}
}
}
}
} else {
for (int i = 0; i < numCleared; i++)
{
sendXYraw(chip, restoreConnections[chip][i][0], restoreConnections[chip][i][1], 1);
}
}
return numCleared;
}
void sendPath(int i, int setOrClear)
{

View File

@ -14,6 +14,7 @@ extern int lightUpNetCore2;
void initCH446Q(void);
void sendXYraw(int chip, int x, int y, int setorclear);
int clearAllConnectionsOnChip(int chip, int clearOrRestore);//returns number of connections cleared
void sendAllPaths(void); // should we sort them by chip? for now, no
void resetArduino (void);

View File

@ -35,7 +35,7 @@ File nodeFileBuffer;
unsigned long timeToFP = 0;
const char rotaryConnectionString[] = "{ AREF-GND, D11-GND, D10-UART_TX, D12-UART_RX, D13-GPIO_0, ";
const char rotaryConnectionString[] = "{AREF-GND,D11-GND,D10-UART_TX,D12-UART_RX,D13-GPIO_0, ";
void createSlots(int slot, int addRotaryConnections)
{
@ -55,8 +55,8 @@ void createSlots(int slot, int addRotaryConnections)
// {
// //nodeFile.write(' ');
// index++;
// } else
// } else
// length++;
// }
// }
@ -78,11 +78,7 @@ void createSlots(int slot, int addRotaryConnections)
// Serial.write(nodeFile.read());
// }
// nodeFile.close();
nodeFile = LittleFS.open("nodeFileSlot" + String(i) + ".txt", "w");
if (i >= 0)
@ -92,11 +88,11 @@ void createSlots(int slot, int addRotaryConnections)
// 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("{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(", }");
nodeFile.print(",}");
}
else
{
@ -113,7 +109,7 @@ void createSlots(int slot, int addRotaryConnections)
// 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("{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);
@ -122,22 +118,51 @@ void createSlots(int slot, int addRotaryConnections)
nodeFile.close();
}
}
void inputNodeFileList(void)
void inputNodeFileList(int addRotaryConnections)
{
Serial.println("Paste the nodeFile list here");
// 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)
{
nodeFileString.write(Serial.read());
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);
// Serial.println(nodeFileString);
int lastTokenIndex = 0;
int tokenFound = 0;
uint8_t lastReads[8] = {' ', ' ', ' ', ' '};
@ -165,10 +190,11 @@ void inputNodeFileList(void)
// nodeFileBuffer.seek(nodeFileBuffer.size());
// nodeFileBuffer.print("fuck \n\r");
nodeFileBuffer.seek(0);
// while (nodeFileBuffer.available())
// {
// Serial.write(nodeFileBuffer.read());
// }
// 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
{
@ -215,15 +241,8 @@ void inputNodeFileList(void)
}
index++;
}
// Serial.println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
// nodeFile.close();
}
Serial.print("\n\rFirst slot found: ");
Serial.println(firstSlotNumber, HEX);
Serial.println("Number of slots found: " + String(numberOfSlotsFound));
index = 0;
int lastSlotNumber = firstSlotNumber + numberOfSlotsFound - 1;
@ -232,7 +251,7 @@ void inputNodeFileList(void)
if (i >= firstSlotNumber && i <= lastSlotNumber)
{
Serial.println(i);
// Serial.println(i);
nodeFile = LittleFS.open("nodeFileSlot" + String(i) + ".txt", "w");
}
@ -270,31 +289,38 @@ void inputNodeFileList(void)
if (i >= firstSlotNumber && i <= lastSlotNumber)
{
nodeFile.seek(0);
printNodeFile(i);
// Serial.println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
nodeFile.close();
}
}
// uint8_t trash = Serial.read();
// Serial.write(trash);
// delay(10);
for (int i = 0; i < NUM_SLOTS; i++)
{
// printNodeFile(i);
}
// 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("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, ");
nodeFile.print("{AREF-GND,D11-GND,D10-UART_TX,D12-UART_RX,D13-GPIO_0, ");
// Serial.println(" keeping encoder");
}

View File

@ -19,7 +19,7 @@ extern bool debugMM;
//extern File nodeFile;
void createSlots(int slot = -1, int addRotaryConnections = 0);
void inputNodeFileList(void);
void inputNodeFileList(int addRotaryConnections = 0);
//this just opens the file, takes out all the bullshit, and then populates the newBridge array
void parseWokwiFileToNodeFile();
void changeWokwiDefinesToJumperless ();

View File

@ -564,6 +564,7 @@ void showSavedColors(int slot)
// }
// Serial.print("\rNo saved colors for slot ");
// Serial.print(slot);
///pauseCore2 = 1;
clearAllNTCC();
openNodeFile(slot);
getNodesToConnect();
@ -572,8 +573,9 @@ void showSavedColors(int slot)
// leds.clear();
assignNetColors();
//pauseCore2 = 0;
showNets();
lightUpRail();
//lightUpRail();
// delayMicroseconds(100);
// saveRawColors(slot);
}

View File

@ -43,6 +43,8 @@
extern volatile uint8_t LEDbrightness;
extern volatile uint8_t LEDbrightnessSpecial;
extern volatile uint8_t pauseCore2;
extern Adafruit_NeoPixel leds;
extern bool debugLEDs;

View File

@ -27,7 +27,7 @@ int lastButtonState = 0;
volatile int rotaryEncoderMode = 0;
int slotPreview = 0;
volatile int slotPreview = 0;
void initRotaryEncoder(void)
@ -80,7 +80,7 @@ const char rotaryEncoderHelp[]= "\n\r" //Github copilot, please don't help me w
"Wokwi sketches will be loaded into whichever slot is active\n\n\r"
"This is a WIP, so let me know if something's broken or you want\n\r"
"something added. \n\n\r"
"something added. \n\n\r "
;
@ -89,7 +89,7 @@ void printRotaryEncoderHelp(void)
Serial.print(rotaryEncoderHelp);
return;
}
unsigned long previewLength = 2500;
unsigned long previewLength = 3500;
unsigned long previewTimer = 0;
unsigned long buttonHoldTimer = 0;
@ -110,11 +110,13 @@ int justPressed = 1;
int probeWasActive = 0;
int printSlotChanges = 0;
void rotaryEncoderStuff(void)
{
probeWasActive = probeActive;
if (probeActive == 1)
if (probeActive == 1 || millis() < 500)
{
// return;
// }
@ -186,13 +188,16 @@ void rotaryEncoderStuff(void)
slotChanged = 1;
netSlot = slotPreview;
buttonHoldTimer = millis();
if(printSlotChanges == 1)
{
Serial.print("\r \r");
Serial.print("\rCurrent Slot: ");
Serial.print(netSlot);
Serial.print("\t\t");
Serial.print("Selected Slot: ");
Serial.print(slotPreview);
Serial.print("\t");
}
// Serial.print("\t\t");
// Serial.print("Selected Slot: ");
// Serial.print(slotPreview);
}
else
@ -206,13 +211,20 @@ void rotaryEncoderStuff(void)
if (millis() - previewTimer > previewLength && showingPreview == 1 && netSlot != slotPreview)
{
slotPreview = netSlot;
showSavedColors(netSlot);
//showSavedColors(slotPreview);
lightUpRail();
leds.show();
showingPreview = 0;
rawOtherColors[1] = 0x550008,
rawOtherColors[1] = 0x550008;
if (printSlotChanges == 1)
{
Serial.print("\r \r");
Serial.print("\rCurrent Slot: ");
Serial.print(netSlot);
Serial.print("\t");
}
previewTimer = millis();
}
@ -296,14 +308,19 @@ void rotaryEncoderStuff(void)
leds.show();
previewTimer = millis();
if (printSlotChanges == 1)
{
Serial.print("\r \r");
Serial.print("\rCurrent Slot: ");
Serial.print(netSlot);
Serial.print("\t\t");
Serial.print("Selected Slot: ");
Serial.print(slotPreview);
Serial.print("\t");
if (slotPreview != netSlot)
{
Serial.print("\tSelected Slot: ");
Serial.print(slotPreview);
}
}
// leds.setPixelColor((lastPosition)+98, 0);
// leds.setPixelColor((position)+98, 0x460035);

View File

@ -7,6 +7,7 @@ extern volatile int rotaryEncoderMode;
extern int netSlot;
extern volatile int slotChanged;
extern volatile int slotPreview;
extern int rotState;
extern int encoderIsPressed;
extern int showingPreview;

View File

@ -120,9 +120,9 @@ void setup()
createSlots(-1, rotaryEncoderMode);
clearAllNTCC();
// if (rotaryEncoderMode == 1)
// if (rotaryEncoderMode == 1)
// {
//rotEncInit = 1;
// rotEncInit = 1;
initRotaryEncoder();
//}
@ -146,8 +146,6 @@ void setup1()
delay(4);
showLEDsCore2 = 1;
}
@ -164,7 +162,9 @@ int restoredNodeFile = 0;
const char firmwareVersion[] = "1.3.13"; //// remember to update this
int firstLoop = 1;
volatile int probeActive = 0;
volatile int probeActive = 1;
int showExtraMenu = 0;
void loop()
{
@ -182,20 +182,34 @@ menu:
// // }
// Serial.print("Updated!\n\r");
Serial.print("\n\n\r\t\t\tMenu\n\n\r");
Serial.print("\n\n\r\t\tMenu\n\r");
// Serial.print("Slot ");
// Serial.print(netSlot);
Serial.print("\n\r");
Serial.print("\tm = show this menu\n\r");
Serial.print("\tn = show netlist\n\r");
Serial.print("\ts = show node files by slot\n\r");
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");
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("\ts = show node file\n\r");
Serial.print("\tf = load formatted node file\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("\tr = rotary encoder mode -");
rotaryEncoderMode == 1 ? Serial.print(" ON (z/x to cycle)\n\r") : Serial.print(" off\n\r");
Serial.print("\tp = probe connections\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)
@ -204,6 +218,7 @@ menu:
Serial.print("Press the button to select\n\r");
Serial.print("\n\n\r");
firstLoop = 0;
probeActive = 0;
goto loadfile;
}
@ -266,7 +281,12 @@ dontshowmenu:
else
{
input = Serial.read();
Serial.print("\n\r");
//Serial.print("\n\r");
if (input == '}' || input == ' ' || input == '\n' || input == '\r')
{
goto dontshowmenu;
}
//Serial.write(input);
}
// Serial.print(input);
@ -279,6 +299,52 @@ skipinput:
Serial.println(firmwareVersion);
break;
}
case '$':
{
//return current slot number
Serial.println(netSlot);
break;
}
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,1,1);//double up connections
sendXYraw(CHIP_I,15,1,1);
goto dontshowmenu;
}
case '-':
{
clearAllConnectionsOnChip(CHIP_I, 1);
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);
sendAllPathsCore2 = 1;
break;
}
case 'e':
{
if (showExtraMenu == 0)
{
showExtraMenu = 1;
}
else
{
showExtraMenu = 0;
}
break;
}
case 's':
{
@ -290,12 +356,18 @@ skipinput:
// break;
}
Serial.print("\n\n\r");
Serial.print("\tSlot File ");
Serial.print(fileNo - '0');
if (fileNo == -1)
{
Serial.print("\tSlot Files");
}
else
{
Serial.print("\tSlot File ");
Serial.print(fileNo - '0');
}
Serial.print("\n\n\r");
Serial.print("\tNode File\n\r");
Serial.print("\n\ryou can paste this into the menu to reload this circuit");
Serial.print("\n\r(make sure you grab an extra blank line at the end)\n\r");
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++)
@ -313,7 +385,7 @@ skipinput:
Serial.print("\n\rf ");
printNodeFile(i);
Serial.print("\n\r");
Serial.print("\n\n\n\r");
}
}
else
@ -418,36 +490,51 @@ skipinput:
}
case 'o':
{
inputNodeFileList();
probeActive = 1;
inputNodeFileList(rotaryEncoderMode);
showSavedColors(netSlot);
//input = ' ';
showLEDsCore2 = 1;
probeActive = 0;
goto dontshowmenu;
break;
}
case 'x':
//{
netSlot++;
if (netSlot >= NUM_SLOTS)
{
if (netSlot == NUM_SLOTS)
{
netSlot = 0;
} else {
netSlot ++;
}
Serial.print("\r \r");
Serial.print("Slot: ");
Serial.print("Slot ");
Serial.print(netSlot);
slotPreview = netSlot;
goto loadfile;
}
case 'z':
//{
netSlot--;
if (netSlot < 0)
{
if (netSlot == 0)
{
netSlot = NUM_SLOTS - 1;
} else{
netSlot--;
}
Serial.print("\r \r");
Serial.print("Slot: ");
Serial.print("Slot ");
Serial.print(netSlot);
slotPreview = netSlot;
goto loadfile;
}
case 'y':
{
loadfile:
probeActive = 1;
clearAllNTCC();
openNodeFile(netSlot);
getNodesToConnect();
@ -459,17 +546,22 @@ skipinput:
// Serial.print("bridgesToPaths\n\r");
digitalWrite(RESETPIN, LOW);
// showNets();
//saveRawColors(netSlot);
// saveRawColors(netSlot);
showSavedColors(netSlot);
sendAllPathsCore2 = 1;
slotChanged = 0;
input = ' ';
// break;
goto dontshowmenu;
// if (rotaryEncoderMode == 1)
// {
// goto dontshowmenu;
// }
probeActive = 0;
break;
}
case 'f':
probeActive = 1;
readInNodesArduino = 1;
clearAllNTCC();
@ -486,11 +578,6 @@ skipinput:
{
serSource = 0;
}
// if (rotaryEncoderMode == 1)
// {
// createSlots(netSlot);
// }
savePreformattedNodeFile(serSource, netSlot, rotaryEncoderMode);
// Serial.print("savePFNF\n\r");
@ -506,8 +593,9 @@ skipinput:
// Serial.print("bridgesToPaths\n\r");
digitalWrite(RESETPIN, LOW);
// showNets();
saveRawColors(netSlot);
// saveRawColors(netSlot);
sendAllPathsCore2 = 1;
showLEDsCore2 = 1;
if (debugNMtime)
{
@ -517,6 +605,8 @@ skipinput:
Serial.print("ms");
}
input = ' ';
probeActive = 0;
if (connectFromArduino != '\0')
{
connectFromArduino = '\0';
@ -524,8 +614,10 @@ skipinput:
// delay(2000);
input = ' ';
readInNodesArduino = 0;
goto dontshowmenu;
}
connectFromArduino = '\0';
readInNodesArduino = 0;
break;
@ -585,8 +677,13 @@ skipinput:
// unInitRotaryEncoder();
rotaryEncoderMode = 0;
//createSlots(-1, rotaryEncoderMode);
// showSavedColors(netSlot);
// createSlots(-1, rotaryEncoderMode);
// showSavedColors(netSlot);
// assignNetColors();
// showNets();
lightUpRail();
showLEDsCore2 = 1;
debugFlagSet(10); // encoderModeOff
goto menu;
@ -978,11 +1075,19 @@ unsigned long logoFlashTimer = 0;
int arduinoReset = 0;
unsigned long lastTimeReset = 0;
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(pauseCore2 == 1)
{
}
if (showLEDsCore2 >= 1)
{
int rails = showLEDsCore2;
@ -1025,8 +1130,9 @@ void loop1() // core 2 handles the LEDs and the CH446Q8
if (arduinoReset == 0 && USBSer1.peek() == 0x30) // 0x30 is the first thing AVRDUDE sends
{
//Serial.print("resetting arduino\n\r");
resetArduino();
//resetArduino();
arduinoReset = 1;
lastTimeReset = millis();
}
@ -1046,12 +1152,14 @@ void loop1() // core 2 handles the LEDs and the CH446Q8
{
char ch = USBSer1.read();
//Serial.write(ch);
Serial1.write(ch);
}
if (Serial1.available())
{
char ch = Serial1.read();
//Serial.write(ch);
USBSer1.write(ch);
}

View File

@ -0,0 +1,15 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Python Debugger: Current File",
"type": "debugpy",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal"
}
]
}

View File

@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDisplayName</key>
<string>Jumperless</string>
<key>CFBundleExecutable</key>
<string>Jumperless</string>
<key>CFBundleIconFile</key>
<string>icon.icns</string>
<key>CFBundleIdentifier</key>
<string>Jumperless</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>Jumperless</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>0.0.0</string>
<key>NSHighResolutionCapable</key>
<true/>
</dict>
</plist>

View File

@ -0,0 +1,12 @@
#!/bin/bash
# This is the launcher for OSX, this way the app will be opened
# when you double click it from the apps folder
open -n -F /Applications/Jumperless.app/Contents/MacOS/Jumperless_cli
#this should be called jumperlesswokwibridge in the contents folder of the app
#and the real app should be renamed to jumperlesswokwibridge_cli
#it's a hack to allow you to both have a .app file and actually run it in a persistent Terminal

Some files were not shown because too many files have changed in this diff Show More