Browse Source

Added learn and forget terminal commands to RFBridge and RF modules (#1253)

alexa
Xose Pérez 6 years ago
parent
commit
91a62693ed
2 changed files with 109 additions and 1 deletions
  1. +55
    -1
      code/espurna/rf.ino
  2. +54
    -0
      code/espurna/rfbridge.ino

+ 55
- 1
code/espurna/rf.ino View File

@ -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 // WEB
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
@ -184,7 +234,11 @@ void rfSetup() {
wsOnActionRegister(_rfWebSocketOnAction); wsOnActionRegister(_rfWebSocketOnAction);
#endif #endif
// Register loop
#if TERMINAL_SUPPORT
_rfInitCommands();
#endif
// Register loop
espurnaRegisterLoop(rfLoop); espurnaRegisterLoop(rfLoop);
} }


+ 54
- 0
code/espurna/rfbridge.ino View File

@ -523,6 +523,56 @@ void _rfbMqttCallback(unsigned int type, const char * topic, const char * payloa
} }
#endif #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 // PUBLIC
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
@ -620,6 +670,10 @@ void rfbSetup() {
wsOnActionRegister(_rfbWebSocketOnAction); wsOnActionRegister(_rfbWebSocketOnAction);
#endif #endif
#if TERMINAL_SUPPORT
_rfbInitCommands();
#endif
#if RFB_DIRECT #if RFB_DIRECT
_rfModem = new RCSwitch(); _rfModem = new RCSwitch();
_rfModem->enableReceive(RFB_RX_PIN); _rfModem->enableReceive(RFB_RX_PIN);


Loading…
Cancel
Save