From 1416f83f8cbc00255c57336ba4f900718f154c9d Mon Sep 17 00:00:00 2001 From: Harald Barth Date: Sat, 15 Jan 2022 17:24:18 +0100 Subject: [PATCH] Serial check, mostly for Teensy, does not impact startup if Serial is available --- SerialManager.cpp | 36 +++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/SerialManager.cpp b/SerialManager.cpp index 6fbdf61..8717227 100644 --- a/SerialManager.cpp +++ b/SerialManager.cpp @@ -1,5 +1,6 @@ /* * © 2021 Chris Harlow + * © 2022 Harald Barth * All rights reserved. * * This file is part of DCC++EX @@ -19,32 +20,33 @@ */ #include "SerialManager.h" - #include "DCCEXParser.h" - SerialManager * SerialManager::first=NULL; +#include "DCCEXParser.h" +SerialManager * SerialManager::first=NULL; - SerialManager::SerialManager(Stream * myserial) { - serial=myserial; - next=first; - first=this; - bufferLength=0; - inCommandPayload=false; - } +SerialManager::SerialManager(Stream * myserial) { + serial=myserial; + next=first; + first=this; + bufferLength=0; + inCommandPayload=false; +} void SerialManager::init() { + while (!Serial && millis() < 5000); // wait max 5s for Serial to start + Serial.begin(115200); + new SerialManager(&Serial); #ifdef SERIAL3_COMMANDS - Serial3.begin(115200); - new SerialManager(&Serial3); + Serial3.begin(115200); + new SerialManager(&Serial3); #endif #ifdef SERIAL2_COMMANDS - Serial2.begin(115200); - new SerialManager(&Serial2); + Serial2.begin(115200); + new SerialManager(&Serial2); #endif #ifdef SERIAL1_COMMANDS - Serial1.begin(115200); - new SerialManager(&Serial1); + Serial1.begin(115200); + new SerialManager(&Serial1); #endif - Serial.begin(115200); - new SerialManager(&Serial); } void SerialManager::broadcast(RingStream * ring) {