mirror of
https://github.com/xoseperez/espurna.git
synced 2026-03-05 07:54:18 +01:00
Terminal command to set and get a GPIO value
This commit is contained in:
@@ -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"));
|
||||
|
||||
Reference in New Issue
Block a user