diff --git a/docs/Commands.txt b/docs/Commands.txt index ae414448..b726176b 100644 --- a/docs/Commands.txt +++ b/docs/Commands.txt @@ -44,6 +44,14 @@ if authentication is on, need admin password * Get hostname [ESP112]
+ + +*Get/Set pin value +[ESP201]P V +if no V get P value +if V 0/1 set INPUT_PULLUP value, but for GPIO16 INPUT_PULLDOWN_16 +GPIO1 and GPIO3 cannot be used as they are used for serial + * Get/Set ESP mode cmd can be RESET, SAFEMODE, CONFIG, RESTART [ESP444] diff --git a/esp3d/command.cpp b/esp3d/command.cpp index 9aad662b..91c67f4c 100644 --- a/esp3d/command.cpp +++ b/esp3d/command.cpp @@ -273,6 +273,54 @@ void COMMAND::execute_command(int cmd,String cmd_params) Serial.print("\r\n"); } break; + +#ifdef DIRECT_PIN_FEATURE + //Get/Set pin value + //[ESP201]P V + case 201: { + //check if have pin + parameter = get_param(cmd_params,"P", true); + LOG(parameter) + LOG("\n") + if (parameter == "") + { + Serial.println(INCORRECT_CMD_MSG); + } + else{ + int pin = parameter.toInt(); + //check pin is valid and not serial used pins + if ((pin >= 0) && (pin <= 16) && !((pin == 1) || (pin == 3))) + { + //check if is set or get + parameter = get_param(cmd_params,"V", true); + //it is a get + if (parameter == "") + { //GPIO16 is different than + if (pin <16) pinMode(pin, INPUT_PULLUP); + else pinMode(pin, INPUT_PULLDOWN_16); + delay(10); + int value = digitalRead(pin); + Serial.println(String(value)); + } + else{ + //it is a set + int value = parameter.toInt(); + //verify it is a 0 or a 1 + if ((value == 0) || (value == 1)) + { + pinMode(pin, OUTPUT); + delay(10); + digitalWrite(pin, (value == 0)?LOW:HIGH); + } + else Serial.println(INCORRECT_CMD_MSG); + } + } + else Serial.println(INCORRECT_CMD_MSG); + } + } + break; +#endif + //Get/Set ESP mode //cmd is RESET, SAFEMODE, CONFIG, RESTART //[ESP444]pwd= diff --git a/esp3d/config.h b/esp3d/config.h index 46d35fe7..13d3cf5b 100644 --- a/esp3d/config.h +++ b/esp3d/config.h @@ -65,6 +65,9 @@ #define RESET_CONFIG_PIN 2 #endif +//DIRECT_PIN_FEATURE: allow to access pin using ESP201 command +#define DIRECT_PIN_FEATURE + //INFO_MSG_FEATURE: catch the Info msg and filter it to specific table #define INFO_MSG_FEATURE