Fix error with Pin selection and ESP201

add seting to select input or input pull up
add more debug log
This commit is contained in:
Luc 2016-10-30 23:44:28 +01:00
parent 546b74d444
commit e33e83771d

View File

@ -294,7 +294,8 @@ void COMMAND::execute_command(int cmd,String cmd_params)
//[ESP201]P<pin> V<value> //[ESP201]P<pin> V<value>
case 201: { case 201: {
//check if have pin //check if have pin
parameter = get_param(cmd_params,"P", true); parameter = get_param(cmd_params,"P", false);
LOG("Pin:")
LOG(parameter) LOG(parameter)
LOG("\n") LOG("\n")
if (parameter == "") { if (parameter == "") {
@ -304,17 +305,26 @@ void COMMAND::execute_command(int cmd,String cmd_params)
//check pin is valid and not serial used pins //check pin is valid and not serial used pins
if ((pin >= 0) && (pin <= 16) && !((pin == 1) || (pin == 3))) { if ((pin >= 0) && (pin <= 16) && !((pin == 1) || (pin == 3))) {
//check if is set or get //check if is set or get
parameter = get_param(cmd_params,"V", true); parameter = get_param(cmd_params,"V", false);
//it is a get //it is a get
if (parameter == "") { if (parameter == "") {
//GPIO16 is different than parameter = get_param(cmd_params,"PULLUP=", false);
if (pin <16) { if (parameter == "YES"){
pinMode(pin, INPUT_PULLUP); //GPIO16 is different than others
} else { if (pin <16) {
pinMode(pin, INPUT_PULLDOWN_16); LOG("Set as input pull up\n")
} pinMode(pin, INPUT_PULLUP);
delay(10); } else {
int value = digitalRead(pin); 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)); Serial.println(String(value));
} else { } else {
//it is a set //it is a set
@ -323,6 +333,9 @@ void COMMAND::execute_command(int cmd,String cmd_params)
if ((value == 0) || (value == 1)) { if ((value == 0) || (value == 1)) {
pinMode(pin, OUTPUT); pinMode(pin, OUTPUT);
delay(10); delay(10);
LOG("Set:")
LOG(String((value == 0)?LOW:HIGH))
LOG("\n")
digitalWrite(pin, (value == 0)?LOW:HIGH); digitalWrite(pin, (value == 0)?LOW:HIGH);
} else { } else {
Serial.println(INCORRECT_CMD_MSG); Serial.println(INCORRECT_CMD_MSG);