From 91a62693ed0cdd8df515ed55d2876e90455b30c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Xose=20P=C3=A9rez?= Date: Tue, 11 Dec 2018 12:34:30 +0100 Subject: [PATCH] Added learn and forget terminal commands to RFBridge and RF modules (#1253) --- code/espurna/rf.ino | 56 ++++++++++++++++++++++++++++++++++++++- code/espurna/rfbridge.ino | 54 +++++++++++++++++++++++++++++++++++++ 2 files changed, 109 insertions(+), 1 deletion(-) diff --git a/code/espurna/rf.ino b/code/espurna/rf.ino index 68756b6d..ef137882 100644 --- a/code/espurna/rf.ino +++ b/code/espurna/rf.ino @@ -87,6 +87,56 @@ bool _rfMatch(unsigned long code, unsigned char& relayID, unsigned char& value) } +#if TERMINAL_SUPPORT + +void _rfInitCommands() { + + settingsRegisterCommand(F("LEARN"), [](Embedis* e) { + + if (e->argc < 3) { + DEBUG_MSG_P(PSTR("-ERROR: Wrong arguments\n")); + return; + } + + int id = String(e->argv[1]).toInt(); + if (id >= relayCount()) { + DEBUG_MSG_P(PSTR("-ERROR: Wrong relayID (%d)\n"), id); + return; + } + + int status = String(e->argv[2]).toInt(); + + _rfLearn(id, status == 1); + + DEBUG_MSG_P(PSTR("+OK\n")); + + }); + + settingsRegisterCommand(F("FORGET"), [](Embedis* e) { + + if (e->argc < 3) { + DEBUG_MSG_P(PSTR("-ERROR: Wrong arguments\n")); + return; + } + + int id = String(e->argv[1]).toInt(); + if (id >= relayCount()) { + DEBUG_MSG_P(PSTR("-ERROR: Wrong relayID (%d)\n"), id); + return; + } + + int status = String(e->argv[2]).toInt(); + + _rfForget(id, status == 1); + + DEBUG_MSG_P(PSTR("+OK\n")); + + }); + +} + +#endif // TERMINAL_SUPPORT + // ----------------------------------------------------------------------------- // WEB // ----------------------------------------------------------------------------- @@ -184,7 +234,11 @@ void rfSetup() { wsOnActionRegister(_rfWebSocketOnAction); #endif - // Register loop + #if TERMINAL_SUPPORT + _rfInitCommands(); + #endif + + // Register loop espurnaRegisterLoop(rfLoop); } diff --git a/code/espurna/rfbridge.ino b/code/espurna/rfbridge.ino index 582ae38e..0f986a13 100644 --- a/code/espurna/rfbridge.ino +++ b/code/espurna/rfbridge.ino @@ -523,6 +523,56 @@ void _rfbMqttCallback(unsigned int type, const char * topic, const char * payloa } #endif +#if TERMINAL_SUPPORT + +void _rfbInitCommands() { + + settingsRegisterCommand(F("LEARN"), [](Embedis* e) { + + if (e->argc < 3) { + DEBUG_MSG_P(PSTR("-ERROR: Wrong arguments\n")); + return; + } + + int id = String(e->argv[1]).toInt(); + if (id >= relayCount()) { + DEBUG_MSG_P(PSTR("-ERROR: Wrong relayID (%d)\n"), id); + return; + } + + int status = String(e->argv[2]).toInt(); + + rfbLearn(id, status == 1); + + DEBUG_MSG_P(PSTR("+OK\n")); + + }); + + settingsRegisterCommand(F("FORGET"), [](Embedis* e) { + + if (e->argc < 3) { + DEBUG_MSG_P(PSTR("-ERROR: Wrong arguments\n")); + return; + } + + int id = String(e->argv[1]).toInt(); + if (id >= relayCount()) { + DEBUG_MSG_P(PSTR("-ERROR: Wrong relayID (%d)\n"), id); + return; + } + + int status = String(e->argv[2]).toInt(); + + rfbForget(id, status == 1); + + DEBUG_MSG_P(PSTR("+OK\n")); + + }); + +} + +#endif // TERMINAL_SUPPORT + // ----------------------------------------------------------------------------- // PUBLIC // ----------------------------------------------------------------------------- @@ -620,6 +670,10 @@ void rfbSetup() { wsOnActionRegister(_rfbWebSocketOnAction); #endif + #if TERMINAL_SUPPORT + _rfbInitCommands(); + #endif + #if RFB_DIRECT _rfModem = new RCSwitch(); _rfModem->enableReceive(RFB_RX_PIN);