Skip to content

Commit 6939db9

Browse files
committed
Merge branch 'devel' of https://github.com/DCC-EX/CommandStation-EX into devel
2 parents 12e81d9 + a9dffff commit 6939db9

File tree

3 files changed

+18
-8
lines changed

3 files changed

+18
-8
lines changed

CommandStation-EX.ino

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -111,17 +111,14 @@ void setup()
111111
// Responsibility 2: Start all the communications before the DCC engine
112112
// Start the WiFi interface on a MEGA, Uno cannot currently handle WiFi
113113
// Start Ethernet if it exists
114-
#ifndef ARDUINO_ARCH_ESP32
115114
#if WIFI_ON
116115
PASSWDCHECK(WIFI_PASSWORD); // compile time check
116+
#ifndef ARDUINO_ARCH_ESP32
117117
WifiInterface::setup(WIFI_SERIAL_LINK_SPEED, F(WIFI_SSID), F(WIFI_PASSWORD), F(WIFI_HOSTNAME), IP_PORT, WIFI_CHANNEL, WIFI_FORCE_AP);
118-
#endif // WIFI_ON
119118
#else
120-
#if WIFI_ON
121-
PASSWDCHECK(WIFI_PASSWORD); // compile time check
122119
WifiESP::setup(WIFI_SSID, WIFI_PASSWORD, WIFI_HOSTNAME, IP_PORT, WIFI_CHANNEL, WIFI_FORCE_AP);
123-
#endif // WIFI_ON
124120
#endif // ARDUINO_ARCH_ESP32
121+
#endif // WIFI_ON
125122

126123
#if ETHERNET_ON
127124
EthernetInterface::setup();

DCCEXParser.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -737,7 +737,7 @@ void DCCEXParser::parseOne(Print *stream, byte *com, RingStream * ringStream)
737737
DCCDecoder::onoff(on);
738738
return;
739739
}
740-
#if ENABLE_WIFI
740+
#if WIFI_ON
741741
if (p[0] == "WIFI"_hk) { // <C WIFI SSID PASSWORD>
742742
if (params != 5) // the 5 params 0 to 4 are (kinda): WIFI_hk 0x7777 &SSID 0x7777 &PASSWORD
743743
break;
@@ -763,7 +763,16 @@ void DCCEXParser::parseOne(Print *stream, byte *com, RingStream * ringStream)
763763
break;
764764

765765
case '#': // NUMBER OF LOCOSLOTS <#>
766-
StringFormatter::send(stream, F("<# %d>\n"), MAX_LOCOS);
766+
{
767+
int free = DCCTimer::getMinimumFreeMemory();
768+
int freeSlotGuess = free/sizeof(LocoSlot);
769+
freeSlotGuess = freeSlotGuess - 2; // be conservative
770+
if (freeSlotGuess > MAX_LOCOS)
771+
freeSlotGuess = MAX_LOCOS;
772+
if (freeSlotGuess < 0)
773+
freeSlotGuess = 0;
774+
StringFormatter::send(stream, F("<# %d>\n"), freeSlotGuess);
775+
}
767776
return;
768777

769778
case '-': // Forget Loco <- [cab]>

WifiESP32.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,11 @@ bool WifiESP::setup(const char *SSid,
170170
uint8_t tries = 40;
171171
if (wifiUp)
172172
teardown();
173-
173+
if (strcmp("OFF", SSid) == 0) {
174+
WiFi.disconnect(true);
175+
WiFi.mode(WIFI_OFF);
176+
return false; // debatable if that is true (success) or false (no network)
177+
}
174178
//#ifdef SERIAL_BT_COMMANDS
175179
//return false;
176180
//#endif

0 commit comments

Comments
 (0)