mirror of
https://github.com/DCC-EX/CommandStation-EX.git
synced 2024-11-22 23:56:13 +01:00
Serial/SerialUSB cleanup
This commit is contained in:
parent
9768083bfe
commit
3681f0e445
6
DCC.cpp
6
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("<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
|
||||
StringFormatter::send(&USB_SERIAL,F("<iDCC-EX V-%S / %S / %S G-%S>\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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -18,15 +18,6 @@
|
|||
*/
|
||||
#include "StringFormatter.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"
|
||||
|
||||
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) {
|
||||
|
|
|
@ -21,12 +21,6 @@
|
|||
#include <Arduino.h>
|
||||
#include "FSH.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"
|
||||
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);
|
||||
|
|
|
@ -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)) {
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue
Block a user