1
0
mirror of https://github.com/DCC-EX/CommandStation-EX.git synced 2024-12-23 12:51:24 +01:00

Make all Wifi code disappear if Wifi is not enabled.

This commit is contained in:
Harald Barth 2020-09-25 22:14:20 +02:00
parent bc8b01fbd6
commit 32f1d7d890
5 changed files with 56 additions and 15 deletions

View File

@ -12,16 +12,13 @@
// REFER TO SEPARATE EXAMPLE.
////////////////////////////////////////////////////////////////////////////////////
// This defines the speed at which the Arduino will communicate with the ESP8266 module.
// Currently only Arduino Mega and 115200 is supported.
#define WIFI_SERIAL_LINK_SPEED 115200
#include "config.h"
#include "defines.h"
#include "DCC.h"
#include "DIAG.h"
#include "DCCEXParser.h"
#include "version.h"
#if ENABLE_WIFI && (defined(ARDUINO_AVR_MEGA) || defined(ARDUINO_AVR_MEGA2560))
#ifdef WIFI_ON
#include "WifiInterface.h"
#endif
#if ENABLE_FREE_MEM_WARNING
@ -169,7 +166,7 @@ void setup()
DIAG(F("\n===== DCC::getLocoId has returned, but the callback wont be executed until we are in loop() ======\n"));
#endif
#if ENABLE_WIFI && (defined(ARDUINO_AVR_MEGA) || defined(ARDUINO_AVR_MEGA2560))
#ifdef WIFI_ON
bool wifiUp = false;
const __FlashStringHelper *wifiESSID = F(WIFI_SSID);
const __FlashStringHelper *wifiPassword = F(WIFI_PASSWORD);
@ -215,7 +212,7 @@ void loop()
serialParser.loop(Serial);
// Responsibility 3: Optionally handle any incoming WiFi traffic
#if ENABLE_WIFI && (defined(ARDUINO_AVR_MEGA) || defined(ARDUINO_AVR_MEGA2560))
#ifdef WIFI_ON
WifiInterface::loop();
#endif

View File

@ -1,7 +1,8 @@
/*
* © 2020, Chris Harlow. All rights reserved.
* © 2020, Harald Barth.
*
* This file is part of Asbelos DCC API
* This file is part of CommandStation-EX
*
* This is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -16,11 +17,13 @@
* You should have received a copy of the GNU General Public License
* along with CommandStation. If not, see <https://www.gnu.org/licenses/>.
*/
#include "config.h"
#include "defines.h"
#include "StringFormatter.h"
#include "DCCEXParser.h"
#include "DCC.h"
#include "DCCWaveform.h"
#if ENABLE_WIFI && (defined(ARDUINO_AVR_MEGA) || defined(ARDUINO_AVR_MEGA2560))
#ifdef WIFI_ON
#include "WifiInterface.h"
#endif
#include "Turnouts.h"
@ -391,7 +394,7 @@ void DCCEXParser::parse(Print *stream, byte *com, bool blocking)
DIAG(F("Setting loco %d F%d %S"), p[0], p[1], p[2] ? F("ON") : F("OFF"));
DCC::setFn(p[0], p[1], p[2] == 1);
return;
#if ENABLE_WIFI && (defined(ARDUINO_AVR_MEGA) || defined(ARDUINO_AVR_MEGA2560))
#ifdef WIFI_ON
case '+': // Complex Wifi interface command (not usual parse)
WifiInterface::ATCommand(com);
return;

View File

@ -1,7 +1,8 @@
/*
© 2020, Chris Harlow. All rights reserved.
© 2020, Harald Barth.
This file is part of Asbelos DCC API
This file is part of CommandStation-EX
This is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@ -17,8 +18,9 @@
along with CommandStation. If not, see <https://www.gnu.org/licenses/>.
*/
#include "WifiInterface.h" /* config.h and defines.h included here */
#ifdef WIFI_ON /* from config.h and defines.h */
#include <avr/pgmspace.h>
#include "WifiInterface.h"
#include "DIAG.h"
#include "StringFormatter.h"
#include "WiThrottle.h"
@ -400,3 +402,4 @@ void WifiInterface::loop() {
loopTimeoutStart = millis();
loopstate = 10; // non-blocking loop waits for > before sending
}
#endif // WIFI_ON

View File

@ -1,7 +1,8 @@
/*
* © 2020, Chris Harlow. All rights reserved.
* © 2020, Harald Barth.
*
* This file is part of Asbelos DCC API
* This file is part of CommandStation-EX
*
* This is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -16,9 +17,11 @@
* You should have received a copy of the GNU General Public License
* along with CommandStation. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef WifiInterface_h
#define WifiInterface_h
#include "config.h"
#include "defines.h"
#ifdef WIFI_ON
#include "DCCEXParser.h"
#include "MemStream.h"
@ -55,5 +58,5 @@ private:
static byte buffer[MAX_WIFI_BUFFER + 1];
static MemStream streamer;
};
#endif // WIFI_ON
#endif

35
defines.h Normal file
View File

@ -0,0 +1,35 @@
/*
© 2020, Harald Barth.
This file is part of CommandStation-EX
This is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
It is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with CommandStation. If not, see <https://www.gnu.org/licenses/>.
*/
////////////////////////////////////////////////////////////////////////////////
//
// WIFI_ON: All prereqs for running with WIFI are met
//
#if ENABLE_WIFI && (defined(ARDUINO_AVR_MEGA) || defined(ARDUINO_AVR_MEGA2560))
#define WIFI_ON
#endif
////////////////////////////////////////////////////////////////////////////////
//
// This defines the speed at which the Arduino will communicate with the ESP8266 module.
// Currently only devices which can communicate at 115200 are supported.
//
#define WIFI_SERIAL_LINK_SPEED 115200