1
0
mirror of https://github.com/DCC-EX/CommandStation-EX.git synced 2024-11-27 01:56:14 +01:00

Serial/SerialUSB cleanup

This commit is contained in:
Asbelos 2022-07-08 15:52:46 +01:00
parent 9768083bfe
commit 3681f0e445
7 changed files with 18 additions and 39 deletions

View File

@ -62,11 +62,7 @@ byte DCC::globalSpeedsteps=128;
void DCC::begin(const FSH * motorShieldName) { void DCC::begin(const FSH * motorShieldName) {
shieldName=(FSH *)motorShieldName; shieldName=(FSH *)motorShieldName;
#if defined(ARDUINO_ARCH_SAMD) StringFormatter::send(&USB_SERIAL,F("<iDCC-EX V-%S / %S / %S G-%S>\n"), F(VERSION), F(ARDUINO_TYPE), shieldName, F(GITHUB_SHA));
StringFormatter::send(SerialUSB,F("<iDCC-EX V-%S / %S / %S G-%S>\n"), F(VERSION), F(ARDUINO_TYPE), shieldName, F(GITHUB_SHA));
#else
StringFormatter::send(Serial,F("<iDCC-EX V-%S / %S / %S G-%S>\n"), F(VERSION), F(ARDUINO_TYPE), shieldName, F(GITHUB_SHA));
#endif
#ifndef DISABLE_EEPROM #ifndef DISABLE_EEPROM
// Load stuff from EEprom // Load stuff from EEprom
(void)EEPROM; // tell compiler not to warn this is unused (void)EEPROM; // tell compiler not to warn this is unused

View File

@ -183,7 +183,7 @@ void DCCEXParser::parse(const FSH * cmd) {
int size=strlen_P((char *)cmd)+1; int size=strlen_P((char *)cmd)+1;
char buffer[size]; char buffer[size];
strcpy_P(buffer,(char *)cmd); 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 // See documentation on DCC class for info on this section

View File

@ -22,6 +22,7 @@
#include "SerialManager.h" #include "SerialManager.h"
#include "DCCEXParser.h" #include "DCCEXParser.h"
#include "StringFormatter.h"
SerialManager * SerialManager::first=NULL; SerialManager * SerialManager::first=NULL;
@ -34,14 +35,10 @@ SerialManager::SerialManager(Stream * myserial) {
} }
void SerialManager::init() { void SerialManager::init() {
#if defined(ARDUINO_ARCH_SAMD) USB_SERIAL.begin(115200);
SerialUSB.begin(115200); while (!USB_SERIAL && millis() < 5000); // wait max 5s for Serial to start
new SerialManager(&SerialUSB); new SerialManager(&USB_SERIAL);
#else
Serial.begin(115200);
while (!Serial && millis() < 5000); // wait max 5s for Serial to start
new SerialManager(&Serial);
#endif
#ifdef SERIAL3_COMMANDS #ifdef SERIAL3_COMMANDS
Serial3.begin(115200); Serial3.begin(115200);
new SerialManager(&Serial3); new SerialManager(&Serial3);

View File

@ -18,15 +18,6 @@
*/ */
#include "StringFormatter.h" #include "StringFormatter.h"
#include <stdarg.h> #include <stdarg.h>
#if defined(ARDUINO_ARCH_SAMD)
// Some processors use a gcc compiler that renames va_list!!!
#include <cstdarg>
Print * StringFormatter::diagSerial= &SerialUSB;
#else
Print * StringFormatter::diagSerial=&Serial;
#endif
#include "LCDDisplay.h" #include "LCDDisplay.h"
bool Diag::ACK=false; bool Diag::ACK=false;
@ -38,22 +29,21 @@ bool Diag::LCN=false;
void StringFormatter::diag( const FSH* input...) { void StringFormatter::diag( const FSH* input...) {
if (!diagSerial) return; USB_SERIAL.print(F("<* "));
diagSerial->print(F("<* "));
va_list args; va_list args;
va_start(args, input); va_start(args, input);
send2(diagSerial,input,args); send2(&USB_SERIAL,input,args);
diagSerial->print(F(" *>\n")); USB_SERIAL.print(F(" *>\n"));
} }
void StringFormatter::lcd(byte row, const FSH* input...) { void StringFormatter::lcd(byte row, const FSH* input...) {
va_list args; va_list args;
// Issue the LCD as a diag first // Issue the LCD as a diag first
send(diagSerial,F("<* LCD%d:"),row); send(&USB_SERIAL,F("<* LCD%d:"),row);
va_start(args, input); va_start(args, input);
send2(diagSerial,input,args); send2(&USB_SERIAL,input,args);
send(diagSerial,F(" *>\n")); send(&USB_SERIAL,F(" *>\n"));
if (!LCDDisplay::lcdDisplay) return; if (!LCDDisplay::lcdDisplay) return;
LCDDisplay::lcdDisplay->setRow(row); LCDDisplay::lcdDisplay->setRow(row);
@ -164,7 +154,7 @@ void StringFormatter::printEscapes(Print * stream, const FSH * input) {
} }
void StringFormatter::printEscape( char c) { void StringFormatter::printEscape( char c) {
printEscape(diagSerial,c); printEscape(&USB_SERIAL,c);
} }
void StringFormatter::printEscape(Print * stream, char c) { void StringFormatter::printEscape(Print * stream, char c) {

View File

@ -21,12 +21,6 @@
#include <Arduino.h> #include <Arduino.h>
#include "FSH.h" #include "FSH.h"
#include "RingStream.h" #include "RingStream.h"
#if defined(ARDUINO_ARCH_SAMD)
// Some processors use a gcc compiler that renames va_list!!!
#include <cstdarg>
#endif
#include "LCDDisplay.h" #include "LCDDisplay.h"
class Diag { class Diag {
public: public:
@ -50,7 +44,6 @@ class StringFormatter
static void printEscape(Print * serial, char c); static void printEscape(Print * serial, char c);
// DIAG support // DIAG support
static Print * diagSerial;
static void diag( const FSH* input...); static void diag( const FSH* input...);
static void lcd(byte row, const FSH* input...); static void lcd(byte row, const FSH* input...);
static void printEscapes(char * input); static void printEscapes(char * input);

View File

@ -381,7 +381,7 @@ bool WifiInterface::checkForOK( const unsigned int timeout, const FSH * waitfor,
int ch = wifiStream->read(); int ch = wifiStream->read();
if (echo) { if (echo) {
if (escapeEcho) StringFormatter::printEscape( ch); /// THIS IS A DIAG IN DISGUISE 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)) locator = (char *)waitfor;
if (ch == GETFLASH(locator)) { if (ch == GETFLASH(locator)) {

View File

@ -41,6 +41,7 @@
// figure out if we have enough memory for advanced features // figure out if we have enough memory for advanced features
// so define HAS_ENOUGH_MEMORY until proved otherwise. // so define HAS_ENOUGH_MEMORY until proved otherwise.
#define HAS_ENOUGH_MEMORY #define HAS_ENOUGH_MEMORY
#define USB_SERIAL Serial
#if defined(ARDUINO_AVR_UNO) #if defined(ARDUINO_AVR_UNO)
#define ARDUINO_TYPE "UNO" #define ARDUINO_TYPE "UNO"
@ -71,6 +72,8 @@
#define ARDUINO_TYPE "ESP32" #define ARDUINO_TYPE "ESP32"
#elif defined(ARDUINO_ARCH_SAMD) #elif defined(ARDUINO_ARCH_SAMD)
#define ARDUINO_TYPE "SAMD21" #define ARDUINO_TYPE "SAMD21"
#undef USB_SERIAL
#define USB_SERIAL SerialUSB
// SAMD support for I2C is awaiting development // SAMD support for I2C is awaiting development
#ifndef DISABLE_EEPROM #ifndef DISABLE_EEPROM
#define DISABLE_EEPROM #define DISABLE_EEPROM