From eb00a4db11f82dd5f8c2400dc21480507393dfd8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Xose=20P=C3=A9rez?= Date: Tue, 9 Jan 2018 19:13:17 +0100 Subject: [PATCH] Terminal command to set and get a GPIO value --- code/espurna/settings.ino | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/code/espurna/settings.ino b/code/espurna/settings.ino index 81d9719f..6536952c 100644 --- a/code/espurna/settings.ino +++ b/code/espurna/settings.ino @@ -250,6 +250,24 @@ void settingsSetup() { DEBUG_MSG_P(PSTR("+OK\n")); }); + Embedis::command( F("GPIO"), [](Embedis* e) { + if (e->argc < 2) { + DEBUG_MSG_P(PSTR("-ERROR: Wrong arguments\n")); + return; + } + int pin = String(e->argv[1]).toInt(); + //if (!gpioValid(pin)) { + // DEBUG_MSG_P(PSTR("-ERROR: Invalid GPIO\n")); + // return; + //} + if (e->argc > 2) { + bool state = String(e->argv[2]).toInt() == 1; + digitalWrite(pin, state); + } + DEBUG_MSG_P(PSTR("GPIO %d is %s\n"), pin, digitalRead(pin) == HIGH ? "HIGH" : "LOW"); + DEBUG_MSG_P(PSTR("+OK\n")); + }); + Embedis::command( F("HEAP"), [](Embedis* e) { DEBUG_MSG_P(PSTR("Free HEAP: %d bytes\n"), getFreeHeap()); DEBUG_MSG_P(PSTR("+OK\n"));