diff --git a/CVReader.ino b/CVReader.ino index 31c813c..9c378ec 100644 --- a/CVReader.ino +++ b/CVReader.ino @@ -85,7 +85,8 @@ void setup() { // The main sketch has responsibilities during setup() // Responsibility 1: Start the usb connection for diagnostics and possible JMRI input - Serial.begin(115200); + // DIAGSERAL is normally Serial but uses SerialUSB on a SAMD processor + DIAGSERIAL.begin(115200); // Responsibility 2: Start the DCC engine. DCC::begin(); @@ -122,7 +123,7 @@ void loop() { DCC::loop(); // Responsibility 2: handle any incoming commands on USB connection - serialParser.loop(Serial); + serialParser.loop(DIAGSERIAL); // Responsibility 3: Optionally handle any incoming WiFi traffic #ifdef WIFI diff --git a/Hardware.cpp b/Hardware.cpp index 5b3aa51..91e475d 100644 --- a/Hardware.cpp +++ b/Hardware.cpp @@ -17,7 +17,8 @@ * along with CommandStation. If not, see . */ #include -#include // use IDE menu Tools..Manage Libraries to locate and install TimerOne +//#include // use IDE menu Tools..Manage Libraries to locate and install TimerOne +#include // use IDE menu Tools..Manage Libraries to locate and install TimerOne #include "avdweb_AnalogReadFast.h" #include "Hardware.h" #include "Config.h" @@ -82,11 +83,10 @@ unsigned int Hardware::getCurrentMilliamps(bool isMainTrack, int raw) { } void Hardware::setCallback(int duration, void (*isr)()) { - Timer1.initialize(duration); - // We don't want the timer to set pins because these often clash with motor shields etc. - Timer1.disablePwm(TIMER1_A_PIN); - Timer1.disablePwm(TIMER1_B_PIN); - Timer1.attachInterrupt(isr); + TimerA.initialize(); + TimerA.setPeriod(duration); + TimerA.attachInterrupt(isr); + TimerA.start(); } // shortcut to cpu dependent high speed write diff --git a/StringFormatter.cpp b/StringFormatter.cpp index 6fa1a9e..f7e7f25 100644 --- a/StringFormatter.cpp +++ b/StringFormatter.cpp @@ -18,12 +18,11 @@ */ #include "StringFormatter.h" #include - - + void StringFormatter::print( const __FlashStringHelper* input...) { va_list args; va_start(args, input); - send2(Serial,input,args); + send2(DIAGSERIAL,input,args); } void StringFormatter::send(Print & stream, const __FlashStringHelper* input...) { diff --git a/StringFormatter.h b/StringFormatter.h index 888eca9..7b25329 100644 --- a/StringFormatter.h +++ b/StringFormatter.h @@ -19,6 +19,15 @@ #ifndef StringFormatter_h #define StringFormatter_h #include + +#if defined(ARDUINO_ARCH_SAMD) + // Some processors use a gcc compiler that renames va_list!!! + #include + #define DIAGSERIAL SerialUSB +#elif defined(ARDUINO_ARCH_AVR) + #define DIAGSERIAL Serial +#endif + class StringFormatter { public: