From e33e83771d96c98a41431286b35a29d31aef20f7 Mon Sep 17 00:00:00 2001 From: Luc Date: Sun, 30 Oct 2016 23:44:28 +0100 Subject: [PATCH] Fix error with Pin selection and ESP201 add seting to select input or input pull up add more debug log --- esp3d/command.cpp | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/esp3d/command.cpp b/esp3d/command.cpp index e878d820..a0b6a6b5 100644 --- a/esp3d/command.cpp +++ b/esp3d/command.cpp @@ -294,7 +294,8 @@ void COMMAND::execute_command(int cmd,String cmd_params) //[ESP201]P V case 201: { //check if have pin - parameter = get_param(cmd_params,"P", true); + parameter = get_param(cmd_params,"P", false); + LOG("Pin:") LOG(parameter) LOG("\n") if (parameter == "") { @@ -304,17 +305,26 @@ void COMMAND::execute_command(int cmd,String cmd_params) //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); + parameter = get_param(cmd_params,"V", false); //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); + parameter = get_param(cmd_params,"PULLUP=", false); + if (parameter == "YES"){ + //GPIO16 is different than others + if (pin <16) { + LOG("Set as input pull up\n") + pinMode(pin, INPUT_PULLUP); + } else { + LOG("Set as input pull down 16\n") + pinMode(pin, INPUT_PULLDOWN_16); + } + }else { + LOG("Set as input\n") + pinMode(pin, INPUT); + } + delay(100); + int value = digitalRead(pin); + LOG("Read:"); Serial.println(String(value)); } else { //it is a set @@ -323,6 +333,9 @@ void COMMAND::execute_command(int cmd,String cmd_params) if ((value == 0) || (value == 1)) { pinMode(pin, OUTPUT); delay(10); + LOG("Set:") + LOG(String((value == 0)?LOW:HIGH)) + LOG("\n") digitalWrite(pin, (value == 0)?LOW:HIGH); } else { Serial.println(INCORRECT_CMD_MSG);