Now the connections can be received from UART

This commit is contained in:
Kevin Santo Cappuccio 2023-12-15 09:07:18 -08:00
parent fc1287b61d
commit 3a1525b410
3 changed files with 92 additions and 38 deletions

View File

@ -101,7 +101,7 @@ void isrFromPio(void)
digitalWriteFast(CS_J, LOW); digitalWriteFast(CS_J, LOW);
digitalWriteFast(CS_K, LOW); digitalWriteFast(CS_K, LOW);
digitalWriteFast(CS_L, LOW); digitalWriteFast(CS_L, LOW);
delayMicroseconds(2); delayMicroseconds(1);
irq_flags = pio0_hw->irq; irq_flags = pio0_hw->irq;
pio_interrupt_clear(pio, PIO0_IRQ_0); pio_interrupt_clear(pio, PIO0_IRQ_0);
hw_clear_bits(&pio0_hw->irq, irq_flags); hw_clear_bits(&pio0_hw->irq, irq_flags);
@ -179,7 +179,7 @@ void resetArduino(void)
path[lastPath].y[1] = 0; path[lastPath].y[1] = 0;
sendPath(lastPath, 1); sendPath(lastPath, 1);
delay(3); delay(5);
sendPath(lastPath, 0); sendPath(lastPath, 0);
} }
void sendAllPaths(void) // should we sort them by chip? for now, no void sendAllPaths(void) // should we sort them by chip? for now, no
@ -264,11 +264,11 @@ void sendPath(int i, int setOrClear)
// delayMicroseconds(50); // delayMicroseconds(50);
delayMicroseconds(30); delayMicroseconds(20);
pio_sm_put(pio, sm, chAddress); pio_sm_put(pio, sm, chAddress);
delayMicroseconds(60); delayMicroseconds(40);
//} //}
} }
} }

View File

@ -38,15 +38,28 @@ void savePreformattedNodeFile(void)
nodeFile = LittleFS.open("nodeFile.txt", "w+"); nodeFile = LittleFS.open("nodeFile.txt", "w+");
while (Serial.available() == 0)
while (Serial.available() == 0 && Serial1.available() == 0)
{ {
} }
if (Serial.available() > 0)
{
while (Serial.available() > 0) while (Serial.available() > 0)
{ {
nodeFile.write(Serial.read()); nodeFile.write(Serial.read());
delay(1); delay(1);
} }
} else if (Serial1.available() > 0)
{
while (Serial1.available() > 0)
{
nodeFile.write(Serial1.read());
delay(1);
//Serial.print("1");
}
}
nodeFile.close(); nodeFile.close();
} }

View File

@ -109,10 +109,13 @@ void setup1()
showLEDsCore2 = 1; showLEDsCore2 = 1;
} }
char connectFromArduino = '\0';
char input;
void loop() void loop()
{ {
char input;
unsigned long timer = 0; unsigned long timer = 0;
menu: menu:
@ -131,7 +134,8 @@ menu:
Serial.print("\n\n\r"); Serial.print("\n\n\r");
dontshowmenu: dontshowmenu:
while (Serial.available() == 0)
while (Serial.available() == 0 && connectFromArduino == '\0')
{ {
if (showReadings >= 1) if (showReadings >= 1)
{ {
@ -139,10 +143,20 @@ dontshowmenu:
} }
} }
input = Serial.read(); if (connectFromArduino != '\0')
{
input = 'f';
}
else
{
input = Serial.read();
Serial.print("\n\r");
}
// Serial.print(input); // Serial.print(input);
Serial.print("\n\r");
switch (input) switch (input)
{ {
@ -158,7 +172,7 @@ dontshowmenu:
{ {
showReadings++; showReadings++;
chooseShownReadings(); chooseShownReadings();
// Serial.write("\033"); // 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("\x1B\x5B");
// Serial.write("1F");//scroll up one line // Serial.write("1F");//scroll up one line
// Serial.write("\x1B\x5B"); // Serial.write("\x1B\x5B");
@ -213,11 +227,9 @@ dontshowmenu:
case 'f': case 'f':
clearAllNTCC(); clearAllNTCC();
// sendAllPathsCore2 = 1;
//sendAllPathsCore2 = 1;
timer = millis(); timer = millis();
#ifdef FSSTUFF #ifdef FSSTUFF
clearNodeFile(); clearNodeFile();
@ -231,8 +243,7 @@ dontshowmenu:
clearLEDs(); clearLEDs();
assignNetColors(); assignNetColors();
digitalWrite(RESETPIN, LOW);
digitalWrite(RESETPIN, LOW);
// showNets(); // showNets();
#ifdef PIOSTUFF #ifdef PIOSTUFF
@ -248,6 +259,12 @@ dontshowmenu:
Serial.print("ms"); Serial.print("ms");
} }
if (connectFromArduino != '\0')
{
connectFromArduino = '\0';
goto dontshowmenu;
}
break; break;
case '\n': case '\n':
@ -433,10 +450,10 @@ void loop1() // core 2 handles the LEDs and the CH446Q8
Serial.print("\n\r"); Serial.print("\n\r");
Serial.print(rails); Serial.print(rails);
} }
delayMicroseconds(3200); delayMicroseconds(2200);
leds.show(); leds.show();
delayMicroseconds(8200); delayMicroseconds(5200);
showLEDsCore2 = 0; showLEDsCore2 = 0;
} }
@ -446,31 +463,17 @@ void loop1() // core 2 handles the LEDs and the CH446Q8
sendAllPaths(); sendAllPaths();
delayMicroseconds(2200); delayMicroseconds(2200);
showNets(); showNets();
delayMicroseconds(9200); delayMicroseconds(7200);
sendAllPathsCore2 = 0; sendAllPathsCore2 = 0;
} }
if (logoFlash == 2)
{
logoFlashTimer = millis();
logoFlash = 1;
}
if (logoFlash == 1 && logoFlashTimer != 0 && millis() - logoFlashTimer > 600)
{
logoFlash = 0;
logoFlashTimer = 0;
// lightUpRail();
leds.setPixelColor(110, 0x550008);
leds.show();
}
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
{ {
resetArduino(); resetArduino();
arduinoReset = 1; arduinoReset = 1;
lastTimeReset = millis(); lastTimeReset = millis();
// Serial.print("resetting Arduino\n\r");
} }
if (USBSer1.available()) if (USBSer1.available())
@ -478,17 +481,55 @@ void loop1() // core 2 handles the LEDs and the CH446Q8
char ch = USBSer1.read(); char ch = USBSer1.read();
Serial1.write(ch); Serial1.write(ch);
} }
if (Serial1.available())
if (arduinoReset == 1 && Serial1.available() > 0)
{ {
char ch = Serial1.read(); char ch = Serial1.read();
USBSer1.write(ch); USBSer1.write(ch);
} }
if (Serial1.available() && connectFromArduino == '\0')
{
char ch = Serial1.read();
if (millis() - lastTimeReset > 1000) //if the arduino hasn't been reset in a second, reset the flag if (ch == 'f' && connectFromArduino == '\0')
{
input = 'f';
connectFromArduino = ch;
// Serial.print("!!!!");
}
// Serial.write(ch);
USBSer1.write(ch);
}
if (millis() - lastTimeReset > 3000) // if the arduino hasn't been reset in a second, reset the flag
{ {
arduinoReset = 0; arduinoReset = 0;
} }
else
{
while (USBSer1.available())
{
char ch = USBSer1.read();
Serial1.write(ch);
}
}
if (logoFlash == 2)
{
logoFlashTimer = millis();
logoFlash = 1;
}
if (logoFlash == 1 && logoFlashTimer != 0 && millis() - logoFlashTimer > 250)
{
logoFlash = 0;
logoFlashTimer = 0;
// lightUpRail();
leds.setPixelColor(110, 0x550008);
leds.show();
}
} }