mirror of
https://git.mirrors.martin98.com/https://github.com/luc-github/ESP3D.git
synced 2025-08-13 08:58:59 +08:00
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:
parent
546b74d444
commit
e33e83771d
@ -294,7 +294,8 @@ void COMMAND::execute_command(int cmd,String cmd_params)
|
||||
//[ESP201]P<pin> V<value>
|
||||
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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user