From bff7555102f52ef5debb423c27ce16b0ba0603ce Mon Sep 17 00:00:00 2001 From: Harald Barth Date: Fri, 25 Sep 2020 22:49:53 +0200 Subject: [PATCH] NUM_SERIAL tells us how many serial lines to check --- CommandStation-EX.ino | 6 +++++- defines.h | 10 ++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/CommandStation-EX.ino b/CommandStation-EX.ino index 6613d9e..e9b33eb 100644 --- a/CommandStation-EX.ino +++ b/CommandStation-EX.ino @@ -175,17 +175,21 @@ void setup() Serial1.begin(WIFI_SERIAL_LINK_SPEED); wifiUp = WifiInterface::setup(Serial1, wifiESSID, wifiPassword, dccex, port); +#if NUM_SERIAL > 1 if (!wifiUp) { Serial2.begin(WIFI_SERIAL_LINK_SPEED); wifiUp = WifiInterface::setup(Serial2, wifiESSID, wifiPassword, dccex, port); } +#if NUM_SERIAL > 2 if (!wifiUp) { Serial3.begin(WIFI_SERIAL_LINK_SPEED); wifiUp = WifiInterface::setup(Serial3, wifiESSID, wifiPassword, dccex, port); } -#endif +#endif // >2 +#endif // >1 +#endif // WIFI_ON // Responsibility 3: Start the DCC engine. // Note: this provides DCC with two motor drivers, main and prog, which handle the motor shield(s) diff --git a/defines.h b/defines.h index 8279b8b..700687b 100644 --- a/defines.h +++ b/defines.h @@ -33,3 +33,13 @@ // #define WIFI_SERIAL_LINK_SPEED 115200 +//////////////////////////////////////////////////////////////////////////////// +// +// Figure out number of serial ports depending on hardware +// +#if (defined(ARDUINO_AVR_MEGA) || defined(ARDUINO_AVR_MEGA2560)) +#define NUM_SERIAL 3 +#endif +#ifndef NUM_SERIAL +#define NUM_SERIAL 1 +#endif