Skip to content

Commit 717754e

Browse files
committed
Fixes #349
allow to disable serial (tested on esp8266 not yet esp32)
1 parent 1bdcc4f commit 717754e

File tree

4 files changed

+54
-2
lines changed

4 files changed

+54
-2
lines changed

docs/Commands.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,5 +165,8 @@ Get will give type and settings only not the protected T1/T2
165165
* Get fw target
166166
[ESP801]<header answer>
167167

168+
* Get state / Set Enable / Disable Serial Communication
169+
[ESP900]<ENABLE/DISABLE>
170+
168171

169172

esp3d/command.cpp

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1909,6 +1909,37 @@ bool COMMAND::execute_command (int cmd, String cmd_params, tpipe output, level_a
19091909
case 810:
19101910
web_interface->blockserial = false;
19111911
break;
1912+
case 900:
1913+
parameter = get_param (cmd_params, "", true);
1914+
#ifdef AUTHENTICATION_FEATURE
1915+
if (auth_type == LEVEL_GUEST) {
1916+
ESPCOM::println (INCORRECT_CMD_MSG, output, espresponse);
1917+
response = false;
1918+
}
1919+
#endif
1920+
if (parameter.length() == 0) {
1921+
if (CONFIG::is_com_enabled) {
1922+
ESPCOM::print (F ("ENABLED"), output, espresponse);
1923+
} else {
1924+
ESPCOM::print (F ("DISABLED"), output, espresponse);
1925+
}
1926+
} else {
1927+
if (parameter == "ENABLE") {
1928+
CONFIG::DisableSerial();
1929+
if (!CONFIG::InitBaudrate()){
1930+
ESPCOM::print (F ("Cannot enable serial communication"), output, espresponse);
1931+
} else {
1932+
ESPCOM::print (F ("Enable serial communication"), output, espresponse);
1933+
}
1934+
} else if (parameter == "DISABLE") {
1935+
ESPCOM::print (F ("Disable serial communication"), output, espresponse);
1936+
CONFIG::DisableSerial();
1937+
} else {
1938+
ESPCOM::println (INCORRECT_CMD_MSG, output, espresponse);
1939+
response = false;
1940+
}
1941+
}
1942+
break;
19121943

19131944
default:
19141945
ESPCOM::println (INCORRECT_CMD_MSG, output, espresponse);

esp3d/config.cpp

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ extern DHTesp dht;
4949

5050
uint8_t CONFIG::FirmwareTarget = UNKNOWN_FW;
5151
byte CONFIG::output_flag = DEFAULT_OUTPUT_FLAG;
52-
52+
bool CONFIG::is_com_enabled = false;
5353
#ifdef DHT_FEATURE
5454
byte CONFIG::DHT_type = DEFAULT_DHT_TYPE;
5555
int CONFIG::DHT_interval = DEFAULT_DHT_INTERVAL;
@@ -162,6 +162,21 @@ void CONFIG::InitDirectSD()
162162

163163
}
164164

165+
bool CONFIG::DisableSerial()
166+
{
167+
#ifdef USE_SERIAL_0
168+
Serial.end();
169+
#endif
170+
#ifdef USE_SERIAL_1
171+
Serial1.end();
172+
#endif
173+
#ifdef USE_SERIAL_2
174+
Serial2.end();
175+
#endif
176+
CONFIG::is_com_enabled = false;
177+
return true;
178+
}
179+
165180
bool CONFIG::InitBaudrate(long value)
166181
{
167182
long baud_rate = 0;
@@ -214,6 +229,7 @@ bool CONFIG::InitBaudrate(long value)
214229

215230
wifi_config.baud_rate = baud_rate;
216231
delay (100);
232+
CONFIG::is_com_enabled = true;
217233
return true;
218234
}
219235

esp3d/config.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
*/
2020

2121
//version and sources location
22-
#define FW_VERSION "2.1.0.b32"
22+
#define FW_VERSION "2.1.0.b33"
2323
#define REPOSITORY "https://github.com/luc-github/ESP3D"
2424

2525
//Customize ESP3D ////////////////////////////////////////////////////////////////////////
@@ -530,6 +530,7 @@ class CONFIG
530530
static int DHT_interval;
531531
static void InitDHT(bool refresh = false);
532532
#endif
533+
static bool is_com_enabled;
533534
static bool is_locked(byte flag);
534535
static bool is_direct_sd;
535536
static bool read_string (int pos, char byte_buffer[], int size_max);
@@ -548,6 +549,7 @@ class CONFIG
548549
static void InitDirectSD();
549550
static void InitPins();
550551
static bool InitBaudrate(long value = 0);
552+
static bool DisableSerial();
551553
static bool InitExternalPorts();
552554
static uint8_t GetFirmwareTarget();
553555
static const char* GetFirmwareTargetName();

0 commit comments

Comments
 (0)