diff --git a/DCC.cpp b/DCC.cpp index 71a09c7..f8ca7b1 100644 --- a/DCC.cpp +++ b/DCC.cpp @@ -62,11 +62,7 @@ byte DCC::globalSpeedsteps=128; void DCC::begin(const FSH * motorShieldName) { shieldName=(FSH *)motorShieldName; -#if defined(ARDUINO_ARCH_SAMD) - StringFormatter::send(SerialUSB,F("\n"), F(VERSION), F(ARDUINO_TYPE), shieldName, F(GITHUB_SHA)); -#else - StringFormatter::send(Serial,F("\n"), F(VERSION), F(ARDUINO_TYPE), shieldName, F(GITHUB_SHA)); -#endif + StringFormatter::send(&USB_SERIAL,F("\n"), F(VERSION), F(ARDUINO_TYPE), shieldName, F(GITHUB_SHA)); #ifndef DISABLE_EEPROM // Load stuff from EEprom (void)EEPROM; // tell compiler not to warn this is unused diff --git a/DCCEXParser.cpp b/DCCEXParser.cpp index d264281..d1630c2 100644 --- a/DCCEXParser.cpp +++ b/DCCEXParser.cpp @@ -183,7 +183,7 @@ void DCCEXParser::parse(const FSH * cmd) { int size=strlen_P((char *)cmd)+1; char buffer[size]; strcpy_P(buffer,(char *)cmd); - parse(&Serial,(byte *)buffer,NULL); + parse(&USB_SERIAL,(byte *)buffer,NULL); } // See documentation on DCC class for info on this section diff --git a/SerialManager.cpp b/SerialManager.cpp index 93dc1bb..4b6bcf5 100644 --- a/SerialManager.cpp +++ b/SerialManager.cpp @@ -22,6 +22,7 @@ #include "SerialManager.h" #include "DCCEXParser.h" +#include "StringFormatter.h" SerialManager * SerialManager::first=NULL; @@ -34,14 +35,10 @@ SerialManager::SerialManager(Stream * myserial) { } void SerialManager::init() { -#if defined(ARDUINO_ARCH_SAMD) - SerialUSB.begin(115200); - new SerialManager(&SerialUSB); -#else - Serial.begin(115200); - while (!Serial && millis() < 5000); // wait max 5s for Serial to start - new SerialManager(&Serial); -#endif + USB_SERIAL.begin(115200); + while (!USB_SERIAL && millis() < 5000); // wait max 5s for Serial to start + new SerialManager(&USB_SERIAL); + #ifdef SERIAL3_COMMANDS Serial3.begin(115200); new SerialManager(&Serial3); diff --git a/StringFormatter.cpp b/StringFormatter.cpp index ff5a96a..ccb6ef3 100644 --- a/StringFormatter.cpp +++ b/StringFormatter.cpp @@ -18,15 +18,6 @@ */ #include "StringFormatter.h" #include - -#if defined(ARDUINO_ARCH_SAMD) - // Some processors use a gcc compiler that renames va_list!!! - #include - Print * StringFormatter::diagSerial= &SerialUSB; -#else - Print * StringFormatter::diagSerial=&Serial; -#endif - #include "LCDDisplay.h" bool Diag::ACK=false; @@ -38,22 +29,21 @@ bool Diag::LCN=false; void StringFormatter::diag( const FSH* input...) { - if (!diagSerial) return; - diagSerial->print(F("<* ")); + USB_SERIAL.print(F("<* ")); va_list args; va_start(args, input); - send2(diagSerial,input,args); - diagSerial->print(F(" *>\n")); + send2(&USB_SERIAL,input,args); + USB_SERIAL.print(F(" *>\n")); } void StringFormatter::lcd(byte row, const FSH* input...) { va_list args; // Issue the LCD as a diag first - send(diagSerial,F("<* LCD%d:"),row); + send(&USB_SERIAL,F("<* LCD%d:"),row); va_start(args, input); - send2(diagSerial,input,args); - send(diagSerial,F(" *>\n")); + send2(&USB_SERIAL,input,args); + send(&USB_SERIAL,F(" *>\n")); if (!LCDDisplay::lcdDisplay) return; LCDDisplay::lcdDisplay->setRow(row); @@ -164,7 +154,7 @@ void StringFormatter::printEscapes(Print * stream, const FSH * input) { } void StringFormatter::printEscape( char c) { - printEscape(diagSerial,c); + printEscape(&USB_SERIAL,c); } void StringFormatter::printEscape(Print * stream, char c) { diff --git a/StringFormatter.h b/StringFormatter.h index 1e225b5..4787715 100644 --- a/StringFormatter.h +++ b/StringFormatter.h @@ -21,12 +21,6 @@ #include #include "FSH.h" #include "RingStream.h" - -#if defined(ARDUINO_ARCH_SAMD) - // Some processors use a gcc compiler that renames va_list!!! - #include -#endif - #include "LCDDisplay.h" class Diag { public: @@ -50,7 +44,6 @@ class StringFormatter static void printEscape(Print * serial, char c); // DIAG support - static Print * diagSerial; static void diag( const FSH* input...); static void lcd(byte row, const FSH* input...); static void printEscapes(char * input); diff --git a/WifiInterface.cpp b/WifiInterface.cpp index b7b059e..5f3b8e6 100644 --- a/WifiInterface.cpp +++ b/WifiInterface.cpp @@ -381,7 +381,7 @@ bool WifiInterface::checkForOK( const unsigned int timeout, const FSH * waitfor, int ch = wifiStream->read(); if (echo) { if (escapeEcho) StringFormatter::printEscape( ch); /// THIS IS A DIAG IN DISGUISE - else StringFormatter::diagSerial->print((char)ch); + else USB_SERIAL.print((char)ch); } if (ch != GETFLASH(locator)) locator = (char *)waitfor; if (ch == GETFLASH(locator)) { diff --git a/defines.h b/defines.h index a51f41f..d2aba22 100644 --- a/defines.h +++ b/defines.h @@ -41,6 +41,7 @@ // figure out if we have enough memory for advanced features // so define HAS_ENOUGH_MEMORY until proved otherwise. #define HAS_ENOUGH_MEMORY +#define USB_SERIAL Serial #if defined(ARDUINO_AVR_UNO) #define ARDUINO_TYPE "UNO" @@ -71,6 +72,8 @@ #define ARDUINO_TYPE "ESP32" #elif defined(ARDUINO_ARCH_SAMD) #define ARDUINO_TYPE "SAMD21" +#undef USB_SERIAL +#define USB_SERIAL SerialUSB // SAMD support for I2C is awaiting development #ifndef DISABLE_EEPROM #define DISABLE_EEPROM