From 3fb34c1cc4aaa5ea8e5856032e21b564a6033301 Mon Sep 17 00:00:00 2001 From: Niek van der Maas Date: Sun, 30 Jun 2019 00:24:48 +0200 Subject: [PATCH] Add ability to print all GPIO values at once (#1798) * Added ability to print all GPIO values at once * Print input/output pin state, optimize code --- code/espurna/terminal.ino | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/code/espurna/terminal.ino b/code/espurna/terminal.ino index 9081a4d8..5dd5ffb3 100644 --- a/code/espurna/terminal.ino +++ b/code/espurna/terminal.ino @@ -107,20 +107,29 @@ void _terminalInitCommand() { }); terminalRegisterCommand(F("GPIO"), [](Embedis* e) { + int pin = -1; + if (e->argc < 2) { - terminalError(F("Wrong arguments")); - return; + DEBUG_MSG("Printing all GPIO pins:\n"); + } else { + pin = String(e->argv[1]).toInt(); + if (!gpioValid(pin)) { + terminalError(F("Invalid GPIO pin")); + return; + } + + if (e->argc > 2) { + bool state = String(e->argv[2]).toInt() == 1; + digitalWrite(pin, state); + } } - int pin = String(e->argv[1]).toInt(); - //if (!gpioValid(pin)) { - // terminalError(F("Invalid GPIO")); - // return; - //} - if (e->argc > 2) { - bool state = String(e->argv[2]).toInt() == 1; - digitalWrite(pin, state); + + for (int i = 0; i <= 15; i++) { + if (gpioValid(i) && (pin == -1 || pin == i)) { + DEBUG_MSG_P(PSTR("GPIO %s pin %d is %s\n"), GPEP(i) ? "output" : "input", i, digitalRead(i) == HIGH ? "HIGH" : "LOW"); + } } - DEBUG_MSG_P(PSTR("GPIO %d is %s\n"), pin, digitalRead(pin) == HIGH ? "HIGH" : "LOW"); + terminalOK(); });