Browse Source

Revert "Wrap embeddis commands and move feedback to caller"

This reverts commit 7ad0e3a02b.
refactor-terminal
Xose Pérez 5 years ago
parent
commit
b9e13446fc
13 changed files with 104 additions and 124 deletions
  1. +1
    -1
      code/espurna/config/prototypes.h
  2. +10
    -8
      code/espurna/eeprom.ino
  3. +3
    -3
      code/espurna/homeassistant.ino
  4. +2
    -2
      code/espurna/i2c.ino
  5. +5
    -5
      code/espurna/light.ino
  6. +1
    -1
      code/espurna/mqtt.ino
  7. +1
    -1
      code/espurna/nofuss.ino
  8. +4
    -7
      code/espurna/ota.ino
  9. +3
    -3
      code/espurna/relay.ino
  10. +6
    -6
      code/espurna/rfbridge.ino
  11. +42
    -56
      code/espurna/sensor.ino
  12. +20
    -25
      code/espurna/terminal.ino
  13. +6
    -6
      code/espurna/wifi.ino

+ 1
- 1
code/espurna/config/prototypes.h View File

@ -147,7 +147,7 @@ bool settingsRestoreJson(JsonObject& data);
// Terminal // Terminal
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
#if TERMINAL_SUPPORT #if TERMINAL_SUPPORT
void terminalRegisterCommand(const String& name, bool (*call)(Embedis*));
void terminalRegisterCommand(const String& name, void (*call)(Embedis*));
void terminalInject(void *data, size_t len); void terminalInject(void *data, size_t len);
Stream & terminalSerial(); Stream & terminalSerial();
#endif #endif


+ 10
- 8
code/espurna/eeprom.ino View File

@ -65,34 +65,36 @@ void _eepromInitCommands() {
DEBUG_MSG_P(PSTR("[MAIN] Commits done: %lu\n"), _eeprom_commit_count); DEBUG_MSG_P(PSTR("[MAIN] Commits done: %lu\n"), _eeprom_commit_count);
DEBUG_MSG_P(PSTR("[MAIN] Last result: %s\n"), _eeprom_last_commit_result ? "OK" : "ERROR"); DEBUG_MSG_P(PSTR("[MAIN] Last result: %s\n"), _eeprom_last_commit_result ? "OK" : "ERROR");
} }
return true;
DEBUG_MSG_P(PSTR("+OK\n"));
}); });
terminalRegisterCommand(F("EEPROM.COMMIT"), [](Embedis* e) { terminalRegisterCommand(F("EEPROM.COMMIT"), [](Embedis* e) {
const bool res = _eepromCommit(); const bool res = _eepromCommit();
if (res) return true;
DEBUG_MSG_P(PSTR("-ERROR\n"));
return false;
if (res) {
DEBUG_MSG_P(PSTR("+OK\n"));
} else {
DEBUG_MSG_P(PSTR("-ERROR\n"));
}
}); });
terminalRegisterCommand(F("EEPROM.DUMP"), [](Embedis* e) { terminalRegisterCommand(F("EEPROM.DUMP"), [](Embedis* e) {
EEPROMr.dump(terminalSerial()); EEPROMr.dump(terminalSerial());
return true;
DEBUG_MSG_P(PSTR("\n+OK\n"));
}); });
terminalRegisterCommand(F("FLASH.DUMP"), [](Embedis* e) { terminalRegisterCommand(F("FLASH.DUMP"), [](Embedis* e) {
if (e->argc < 2) { if (e->argc < 2) {
DEBUG_MSG_P(PSTR("-ERROR: Wrong arguments\n")); DEBUG_MSG_P(PSTR("-ERROR: Wrong arguments\n"));
return false;
return;
} }
uint32_t sector = String(e->argv[1]).toInt(); uint32_t sector = String(e->argv[1]).toInt();
uint32_t max = ESP.getFlashChipSize() / SPI_FLASH_SEC_SIZE; uint32_t max = ESP.getFlashChipSize() / SPI_FLASH_SEC_SIZE;
if (sector >= max) { if (sector >= max) {
DEBUG_MSG_P(PSTR("-ERROR: Sector out of range\n")); DEBUG_MSG_P(PSTR("-ERROR: Sector out of range\n"));
return false;
return;
} }
EEPROMr.dump(terminalSerial(), sector); EEPROMr.dump(terminalSerial(), sector);
return true;
DEBUG_MSG_P(PSTR("\n+OK\n"));
}); });
} }


+ 3
- 3
code/espurna/homeassistant.ino View File

@ -269,7 +269,7 @@ void _haInitCommands() {
terminalRegisterCommand(F("HA.CONFIG"), [](Embedis* e) { terminalRegisterCommand(F("HA.CONFIG"), [](Embedis* e) {
DEBUG_MSG(_haGetConfig().c_str()); DEBUG_MSG(_haGetConfig().c_str());
return true;
DEBUG_MSG_P(PSTR("+OK\n"));
}); });
terminalRegisterCommand(F("HA.SEND"), [](Embedis* e) { terminalRegisterCommand(F("HA.SEND"), [](Embedis* e) {
@ -278,7 +278,7 @@ void _haInitCommands() {
#if WEB_SUPPORT #if WEB_SUPPORT
wsSend(_haWebSocketOnSend); wsSend(_haWebSocketOnSend);
#endif #endif
return true;
DEBUG_MSG_P(PSTR("+OK\n"));
}); });
terminalRegisterCommand(F("HA.CLEAR"), [](Embedis* e) { terminalRegisterCommand(F("HA.CLEAR"), [](Embedis* e) {
@ -287,7 +287,7 @@ void _haInitCommands() {
#if WEB_SUPPORT #if WEB_SUPPORT
wsSend(_haWebSocketOnSend); wsSend(_haWebSocketOnSend);
#endif #endif
return true;
DEBUG_MSG_P(PSTR("+OK\n"));
}); });
} }


+ 2
- 2
code/espurna/i2c.ino View File

@ -355,12 +355,12 @@ void i2cCommands() {
terminalRegisterCommand(F("I2C.SCAN"), [](Embedis* e) { terminalRegisterCommand(F("I2C.SCAN"), [](Embedis* e) {
i2cScan(); i2cScan();
return true;
DEBUG_MSG_P(PSTR("+OK\n"));
}); });
terminalRegisterCommand(F("I2C.CLEAR"), [](Embedis* e) { terminalRegisterCommand(F("I2C.CLEAR"), [](Embedis* e) {
i2cClearBus(); i2cClearBus();
return true;
DEBUG_MSG_P(PSTR("+OK\n"));
}); });
} }


+ 5
- 5
code/espurna/light.ino View File

@ -989,7 +989,7 @@ void _lightInitCommands() {
lightUpdate(true, true); lightUpdate(true, true);
} }
DEBUG_MSG_P(PSTR("Brightness: %d\n"), lightBrightness()); DEBUG_MSG_P(PSTR("Brightness: %d\n"), lightBrightness());
return true;
DEBUG_MSG_P(PSTR("+OK\n"));
}); });
terminalRegisterCommand(F("CHANNEL"), [](Embedis* e) { terminalRegisterCommand(F("CHANNEL"), [](Embedis* e) {
@ -1003,7 +1003,7 @@ void _lightInitCommands() {
lightUpdate(true, true); lightUpdate(true, true);
} }
DEBUG_MSG_P(PSTR("Channel #%d: %d\n"), id, lightChannel(id)); DEBUG_MSG_P(PSTR("Channel #%d: %d\n"), id, lightChannel(id));
return true;
DEBUG_MSG_P(PSTR("+OK\n"));
}); });
terminalRegisterCommand(F("COLOR"), [](Embedis* e) { terminalRegisterCommand(F("COLOR"), [](Embedis* e) {
@ -1013,7 +1013,7 @@ void _lightInitCommands() {
lightUpdate(true, true); lightUpdate(true, true);
} }
DEBUG_MSG_P(PSTR("Color: %s\n"), lightColor().c_str()); DEBUG_MSG_P(PSTR("Color: %s\n"), lightColor().c_str());
return true;
DEBUG_MSG_P(PSTR("+OK\n"));
}); });
terminalRegisterCommand(F("KELVIN"), [](Embedis* e) { terminalRegisterCommand(F("KELVIN"), [](Embedis* e) {
@ -1023,7 +1023,7 @@ void _lightInitCommands() {
lightUpdate(true, true); lightUpdate(true, true);
} }
DEBUG_MSG_P(PSTR("Color: %s\n"), lightColor().c_str()); DEBUG_MSG_P(PSTR("Color: %s\n"), lightColor().c_str());
return true;
DEBUG_MSG_P(PSTR("+OK\n"));
}); });
terminalRegisterCommand(F("MIRED"), [](Embedis* e) { terminalRegisterCommand(F("MIRED"), [](Embedis* e) {
@ -1033,7 +1033,7 @@ void _lightInitCommands() {
lightUpdate(true, true); lightUpdate(true, true);
} }
DEBUG_MSG_P(PSTR("Color: %s\n"), lightColor().c_str()); DEBUG_MSG_P(PSTR("Color: %s\n"), lightColor().c_str());
return true;
DEBUG_MSG_P(PSTR("+OK\n"));
}); });
} }


+ 1
- 1
code/espurna/mqtt.ino View File

@ -353,7 +353,7 @@ void _mqttInitCommands() {
terminalRegisterCommand(F("MQTT.RESET"), [](Embedis* e) { terminalRegisterCommand(F("MQTT.RESET"), [](Embedis* e) {
_mqttConfigure(); _mqttConfigure();
mqttDisconnect(); mqttDisconnect();
return true;
DEBUG_MSG_P(PSTR("+OK\n"));
}); });
} }


+ 1
- 1
code/espurna/nofuss.ino View File

@ -75,8 +75,8 @@ void _nofussConfigure() {
void _nofussInitCommands() { void _nofussInitCommands() {
terminalRegisterCommand(F("NOFUSS"), [](Embedis* e) { terminalRegisterCommand(F("NOFUSS"), [](Embedis* e) {
DEBUG_MSG_P(PSTR("+OK\n"));
nofussRun(); nofussRun();
return true;
}); });
} }


+ 4
- 7
code/espurna/ota.ino View File

@ -189,16 +189,13 @@ void _otaFrom(String url) {
void _otaInitCommands() { void _otaInitCommands() {
terminalRegisterCommand(F("OTA"), [](Embedis* e) { terminalRegisterCommand(F("OTA"), [](Embedis* e) {
if (e->argc < 2) { if (e->argc < 2) {
DEBUG_MSG_P(PSTR("-ERROR: Wrong arguments\n")); DEBUG_MSG_P(PSTR("-ERROR: Wrong arguments\n"));
return false
} else {
DEBUG_MSG_P(PSTR("+OK\n"));
String url = String(e->argv[1]);
_otaFrom(url);
} }
String url = String(e->argv[1]);
_otaFrom(url);
return true;
}); });
} }


+ 3
- 3
code/espurna/relay.ino View File

@ -986,12 +986,12 @@ void _relayInitCommands() {
terminalRegisterCommand(F("RELAY"), [](Embedis* e) { terminalRegisterCommand(F("RELAY"), [](Embedis* e) {
if (e->argc < 2) { if (e->argc < 2) {
DEBUG_MSG_P(PSTR("-ERROR: Wrong arguments\n")); DEBUG_MSG_P(PSTR("-ERROR: Wrong arguments\n"));
return false;
return;
} }
int id = String(e->argv[1]).toInt(); int id = String(e->argv[1]).toInt();
if (id >= relayCount()) { if (id >= relayCount()) {
DEBUG_MSG_P(PSTR("-ERROR: Wrong relayID (%d)\n"), id); DEBUG_MSG_P(PSTR("-ERROR: Wrong relayID (%d)\n"), id);
return false;
return;
} }
if (e->argc > 2) { if (e->argc > 2) {
@ -1008,7 +1008,7 @@ void _relayInitCommands() {
DEBUG_MSG_P(PSTR("Pulse time: %d\n"), _relays[id].pulse_ms); DEBUG_MSG_P(PSTR("Pulse time: %d\n"), _relays[id].pulse_ms);
} }
return true;
DEBUG_MSG_P(PSTR("+OK\n"));
}); });
} }


+ 6
- 6
code/espurna/rfbridge.ino View File

@ -609,20 +609,20 @@ void _rfbInitCommands() {
if (e->argc < 3) { if (e->argc < 3) {
DEBUG_MSG_P(PSTR("-ERROR: Wrong arguments\n")); DEBUG_MSG_P(PSTR("-ERROR: Wrong arguments\n"));
return false;
return;
} }
int id = String(e->argv[1]).toInt(); int id = String(e->argv[1]).toInt();
if (id >= relayCount()) { if (id >= relayCount()) {
DEBUG_MSG_P(PSTR("-ERROR: Wrong relayID (%d)\n"), id); DEBUG_MSG_P(PSTR("-ERROR: Wrong relayID (%d)\n"), id);
return false;
return;
} }
int status = String(e->argv[2]).toInt(); int status = String(e->argv[2]).toInt();
rfbLearn(id, status == 1); rfbLearn(id, status == 1);
return true;
DEBUG_MSG_P(PSTR("+OK\n"));
}); });
@ -630,20 +630,20 @@ void _rfbInitCommands() {
if (e->argc < 3) { if (e->argc < 3) {
DEBUG_MSG_P(PSTR("-ERROR: Wrong arguments\n")); DEBUG_MSG_P(PSTR("-ERROR: Wrong arguments\n"));
return false;
return;
} }
int id = String(e->argv[1]).toInt(); int id = String(e->argv[1]).toInt();
if (id >= relayCount()) { if (id >= relayCount()) {
DEBUG_MSG_P(PSTR("-ERROR: Wrong relayID (%d)\n"), id); DEBUG_MSG_P(PSTR("-ERROR: Wrong relayID (%d)\n"), id);
return false;
return;
} }
int status = String(e->argv[2]).toInt(); int status = String(e->argv[2]).toInt();
rfbForget(id, status == 1); rfbForget(id, status == 1);
return true;
DEBUG_MSG_P(PSTR("+OK\n"));
}); });


+ 42
- 56
code/espurna/sensor.ino View File

@ -271,7 +271,6 @@ void _sensorAPISetup() {
#if TERMINAL_SUPPORT #if TERMINAL_SUPPORT
void _sensorInitCommands() { void _sensorInitCommands() {
terminalRegisterCommand(F("MAGNITUDES"), [](Embedis* e) { terminalRegisterCommand(F("MAGNITUDES"), [](Embedis* e) {
for (unsigned char i=0; i<_magnitudes.size(); i++) { for (unsigned char i=0; i<_magnitudes.size(); i++) {
sensor_magnitude_t magnitude = _magnitudes[i]; sensor_magnitude_t magnitude = _magnitudes[i];
@ -283,40 +282,34 @@ void _sensorInitCommands() {
magnitude.global magnitude.global
); );
} }
return true;
DEBUG_MSG_P(PSTR("+OK\n"));
}); });
#if PZEM004T_SUPPORT #if PZEM004T_SUPPORT
terminalRegisterCommand(F("PZ.ADDRESS"), [](Embedis* e) {
if (e->argc == 1) {
DEBUG_MSG_P(PSTR("[SENSOR] PZEM004T\n"));
unsigned char dev_count = pzem004t_sensor->getAddressesCount();
for(unsigned char dev = 0; dev < dev_count; dev++) {
DEBUG_MSG_P(PSTR("Device %d/%s\n"), dev, pzem004t_sensor->getAddress(dev).c_str());
}
return true;
} else if(e->argc == 2) {
IPAddress addr;
if (addr.fromString(String(e->argv[1]))) {
if (pzem004t_sensor->setDeviceAddress(&addr)) {
return true;
}
terminalRegisterCommand(F("PZ.ADDRESS"), [](Embedis* e) {
if (e->argc == 1) {
DEBUG_MSG_P(PSTR("[SENSOR] PZEM004T\n"));
unsigned char dev_count = pzem004t_sensor->getAddressesCount();
for(unsigned char dev = 0; dev < dev_count; dev++) {
DEBUG_MSG_P(PSTR("Device %d/%s\n"), dev, pzem004t_sensor->getAddress(dev).c_str());
}
DEBUG_MSG_P(PSTR("+OK\n"));
} else if(e->argc == 2) {
IPAddress addr;
if (addr.fromString(String(e->argv[1]))) {
if(pzem004t_sensor->setDeviceAddress(&addr)) {
DEBUG_MSG_P(PSTR("+OK\n"));
} }
DEBUG_MSG_P(PSTR("-ERROR: Invalid address argument\n"));
} else { } else {
DEBUG_MSG_P(PSTR("-ERROR: Wrong arguments\n"));
}
return false;
});
terminalRegisterCommand(F("PZ.RESET"), [](Embedis* e) {
if (e->argc > 2) {
DEBUG_MSG_P(PSTR("-ERROR: Wrong arguments\n"));
return false;
DEBUG_MSG_P(PSTR("-ERROR: Invalid address argument\n"));
} }
} else {
DEBUG_MSG_P(PSTR("-ERROR: Wrong arguments\n"));
}
});
terminalRegisterCommand(F("PZ.RESET"), [](Embedis* e) {
if(e->argc > 2) {
DEBUG_MSG_P(PSTR("-ERROR: Wrong arguments\n"));
} else {
unsigned char init = e->argc == 2 ? String(e->argv[1]).toInt() : 0; unsigned char init = e->argc == 2 ? String(e->argv[1]).toInt() : 0;
unsigned char limit = e->argc == 2 ? init +1 : pzem004t_sensor->getAddressesCount(); unsigned char limit = e->argc == 2 ? init +1 : pzem004t_sensor->getAddressesCount();
DEBUG_MSG_P(PSTR("[SENSOR] PZEM004T\n")); DEBUG_MSG_P(PSTR("[SENSOR] PZEM004T\n"));
@ -325,39 +318,32 @@ void _sensorInitCommands() {
setSetting("pzEneTotal", dev, offset); setSetting("pzEneTotal", dev, offset);
DEBUG_MSG_P(PSTR("Device %d/%s - Offset: %s\n"), dev, pzem004t_sensor->getAddress(dev).c_str(), String(offset).c_str()); DEBUG_MSG_P(PSTR("Device %d/%s - Offset: %s\n"), dev, pzem004t_sensor->getAddress(dev).c_str(), String(offset).c_str());
} }
return true;
});
terminalRegisterCommand(F("PZ.VALUE"), [](Embedis* e) {
if(e->argc > 2) {
DEBUG_MSG_P(PSTR("-ERROR: Wrong arguments\n"));
return false;
}
DEBUG_MSG_P(PSTR("+OK\n"));
}
});
terminalRegisterCommand(F("PZ.VALUE"), [](Embedis* e) {
if(e->argc > 2) {
DEBUG_MSG_P(PSTR("-ERROR: Wrong arguments\n"));
} else {
unsigned char init = e->argc == 2 ? String(e->argv[1]).toInt() : 0; unsigned char init = e->argc == 2 ? String(e->argv[1]).toInt() : 0;
unsigned char limit = e->argc == 2 ? init +1 : pzem004t_sensor->getAddressesCount(); unsigned char limit = e->argc == 2 ? init +1 : pzem004t_sensor->getAddressesCount();
DEBUG_MSG_P(PSTR("[SENSOR] PZEM004T\n")); DEBUG_MSG_P(PSTR("[SENSOR] PZEM004T\n"));
for(unsigned char dev = init; dev < limit; dev++) { for(unsigned char dev = init; dev < limit; dev++) {
DEBUG_MSG_P(
PSTR("Device %d/%s - Current: %s Voltage: %s Power: %s Energy: %s\n"), //
dev,
pzem004t_sensor->getAddress(dev).c_str(),
String(pzem004t_sensor->value(dev * PZ_MAGNITUDE_CURRENT_INDEX)).c_str(),
String(pzem004t_sensor->value(dev * PZ_MAGNITUDE_VOLTAGE_INDEX)).c_str(),
String(pzem004t_sensor->value(dev * PZ_MAGNITUDE_POWER_ACTIVE_INDEX)).c_str(),
String(pzem004t_sensor->value(dev * PZ_MAGNITUDE_ENERGY_INDEX)).c_str()
);
DEBUG_MSG_P(PSTR("Device %d/%s - Current: %s Voltage: %s Power: %s Energy: %s\n"), //
dev,
pzem004t_sensor->getAddress(dev).c_str(),
String(pzem004t_sensor->value(dev * PZ_MAGNITUDE_CURRENT_INDEX)).c_str(),
String(pzem004t_sensor->value(dev * PZ_MAGNITUDE_VOLTAGE_INDEX)).c_str(),
String(pzem004t_sensor->value(dev * PZ_MAGNITUDE_POWER_ACTIVE_INDEX)).c_str(),
String(pzem004t_sensor->value(dev * PZ_MAGNITUDE_ENERGY_INDEX)).c_str());
} }
return true;
});
#endif // PZEM004T_SUPPORT
DEBUG_MSG_P(PSTR("+OK\n"));
}
});
#endif
} }
#endif // TERMINAL_SUPPORT
#endif
void _sensorTick() { void _sensorTick() {
for (unsigned char i=0; i<_sensors.size(); i++) { for (unsigned char i=0; i<_sensors.size(); i++) {


+ 20
- 25
code/espurna/terminal.ino View File

@ -83,13 +83,13 @@ void _terminalInitCommand() {
terminalRegisterCommand(F("CRASH"), [](Embedis* e) { terminalRegisterCommand(F("CRASH"), [](Embedis* e) {
crashDump(); crashDump();
crashClear(); crashClear();
return true;
DEBUG_MSG_P(PSTR("+OK\n"));
}); });
#endif #endif
terminalRegisterCommand(F("COMMANDS"), [](Embedis* e) { terminalRegisterCommand(F("COMMANDS"), [](Embedis* e) {
_terminalHelpCommand(); _terminalHelpCommand();
return true;
DEBUG_MSG_P(PSTR("+OK\n"));
}); });
terminalRegisterCommand(F("ERASE.CONFIG"), [](Embedis* e) { terminalRegisterCommand(F("ERASE.CONFIG"), [](Embedis* e) {
@ -102,13 +102,13 @@ void _terminalInitCommand() {
terminalRegisterCommand(F("FACTORY.RESET"), [](Embedis* e) { terminalRegisterCommand(F("FACTORY.RESET"), [](Embedis* e) {
resetSettings(); resetSettings();
return true;
DEBUG_MSG_P(PSTR("+OK\n"));
}); });
terminalRegisterCommand(F("GPIO"), [](Embedis* e) { terminalRegisterCommand(F("GPIO"), [](Embedis* e) {
if (e->argc < 2) { if (e->argc < 2) {
DEBUG_MSG_P(PSTR("-ERROR: Wrong arguments\n")); DEBUG_MSG_P(PSTR("-ERROR: Wrong arguments\n"));
return false;
return;
} }
int pin = String(e->argv[1]).toInt(); int pin = String(e->argv[1]).toInt();
//if (!gpioValid(pin)) { //if (!gpioValid(pin)) {
@ -120,39 +120,38 @@ void _terminalInitCommand() {
digitalWrite(pin, state); digitalWrite(pin, state);
} }
DEBUG_MSG_P(PSTR("GPIO %d is %s\n"), pin, digitalRead(pin) == HIGH ? "HIGH" : "LOW"); DEBUG_MSG_P(PSTR("GPIO %d is %s\n"), pin, digitalRead(pin) == HIGH ? "HIGH" : "LOW");
return true;
DEBUG_MSG_P(PSTR("+OK\n"));
}); });
terminalRegisterCommand(F("HEAP"), [](Embedis* e) { terminalRegisterCommand(F("HEAP"), [](Embedis* e) {
infoMemory("Heap", getInitialFreeHeap(), getFreeHeap()); infoMemory("Heap", getInitialFreeHeap(), getFreeHeap());
return true;
DEBUG_MSG_P(PSTR("+OK\n"));
}); });
terminalRegisterCommand(F("STACK"), [](Embedis* e) { terminalRegisterCommand(F("STACK"), [](Embedis* e) {
infoMemory("Stack", 4096, getFreeStack()); infoMemory("Stack", 4096, getFreeStack());
return true;
DEBUG_MSG_P(PSTR("+OK\n"));
}); });
terminalRegisterCommand(F("HELP"), [](Embedis* e) { terminalRegisterCommand(F("HELP"), [](Embedis* e) {
_terminalHelpCommand(); _terminalHelpCommand();
return true;
DEBUG_MSG_P(PSTR("+OK\n"));
}); });
terminalRegisterCommand(F("INFO"), [](Embedis* e) { terminalRegisterCommand(F("INFO"), [](Embedis* e) {
info(); info();
return true;
DEBUG_MSG_P(PSTR("+OK\n"));
}); });
terminalRegisterCommand(F("KEYS"), [](Embedis* e) { terminalRegisterCommand(F("KEYS"), [](Embedis* e) {
_terminalKeysCommand(); _terminalKeysCommand();
return true;
DEBUG_MSG_P(PSTR("+OK\n"));
}); });
terminalRegisterCommand(F("GET"), [](Embedis* e) { terminalRegisterCommand(F("GET"), [](Embedis* e) {
if (e->argc < 2) { if (e->argc < 2) {
DEBUG_MSG_P(PSTR("-ERROR: Wrong arguments\n")); DEBUG_MSG_P(PSTR("-ERROR: Wrong arguments\n"));
return false;
return;
} }
for (unsigned char i = 1; i < e->argc; i++) { for (unsigned char i = 1; i < e->argc; i++) {
@ -166,29 +165,28 @@ void _terminalInitCommand() {
DEBUG_MSG_P(PSTR("> %s => \"%s\"\n"), key.c_str(), value.c_str()); DEBUG_MSG_P(PSTR("> %s => \"%s\"\n"), key.c_str(), value.c_str());
} }
return true;
DEBUG_MSG_P(PSTR("+OK\n"));
}); });
terminalRegisterCommand(F("RELOAD"), [](Embedis* e) { terminalRegisterCommand(F("RELOAD"), [](Embedis* e) {
espurnaReload(); espurnaReload();
return true;
DEBUG_MSG_P(PSTR("+OK\n"));
}); });
terminalRegisterCommand(F("RESET"), [](Embedis* e) { terminalRegisterCommand(F("RESET"), [](Embedis* e) {
DEBUG_MSG_P(PSTR("+OK\n"));
deferredReset(100, CUSTOM_RESET_TERMINAL); deferredReset(100, CUSTOM_RESET_TERMINAL);
return true;
}); });
terminalRegisterCommand(F("RESET.SAFE"), [](Embedis* e) { terminalRegisterCommand(F("RESET.SAFE"), [](Embedis* e) {
EEPROMr.write(EEPROM_CRASH_COUNTER, SYSTEM_CHECK_MAX); EEPROMr.write(EEPROM_CRASH_COUNTER, SYSTEM_CHECK_MAX);
DEBUG_MSG_P(PSTR("+OK\n"));
deferredReset(100, CUSTOM_RESET_TERMINAL); deferredReset(100, CUSTOM_RESET_TERMINAL);
return true;
}); });
terminalRegisterCommand(F("UPTIME"), [](Embedis* e) { terminalRegisterCommand(F("UPTIME"), [](Embedis* e) {
DEBUG_MSG_P(PSTR("Uptime: %d seconds\n"), getUptime()); DEBUG_MSG_P(PSTR("Uptime: %d seconds\n"), getUptime());
return true;
DEBUG_MSG_P(PSTR("+OK\n"));
}); });
terminalRegisterCommand(F("CONFIG"), [](Embedis* e) { terminalRegisterCommand(F("CONFIG"), [](Embedis* e) {
@ -198,13 +196,13 @@ void _terminalInitCommand() {
String output; String output;
root.printTo(output); root.printTo(output);
DEBUG_MSG(output.c_str()); DEBUG_MSG(output.c_str());
return true;
DEBUG_MSG_P(PSTR("\n+OK\n"));
}); });
#if not SETTINGS_AUTOSAVE #if not SETTINGS_AUTOSAVE
terminalRegisterCommand(F("SAVE"), [](Embedis* e) { terminalRegisterCommand(F("SAVE"), [](Embedis* e) {
eepromCommit(); eepromCommit();
return true;
DEBUG_MSG_P(PSTR("\n+OK\n"));
}); });
#endif #endif
@ -247,11 +245,8 @@ Stream & terminalSerial() {
return (Stream &) _serial; return (Stream &) _serial;
} }
void terminalRegisterCommand(const String& name, bool (*callback)(Embedis*)) {
Embedis::command(name, [callback](Embedis* e) {
bool ret = callback(e);
if (ret) DEBUG_MSG_P(PSTR("+OK\n"));
);
void terminalRegisterCommand(const String& name, void (*call)(Embedis*)) {
Embedis::command(name, call);
}; };
void terminalSetup() { void terminalSetup() {


+ 6
- 6
code/espurna/wifi.ino View File

@ -387,37 +387,37 @@ void _wifiInitCommands() {
terminalRegisterCommand(F("WIFI"), [](Embedis* e) { terminalRegisterCommand(F("WIFI"), [](Embedis* e) {
wifiDebug(); wifiDebug();
return true;
DEBUG_MSG_P(PSTR("+OK\n"));
}); });
terminalRegisterCommand(F("WIFI.RESET"), [](Embedis* e) { terminalRegisterCommand(F("WIFI.RESET"), [](Embedis* e) {
_wifiConfigure(); _wifiConfigure();
wifiDisconnect(); wifiDisconnect();
return true;
DEBUG_MSG_P(PSTR("+OK\n"));
}); });
terminalRegisterCommand(F("WIFI.AP"), [](Embedis* e) { terminalRegisterCommand(F("WIFI.AP"), [](Embedis* e) {
wifiStartAP(); wifiStartAP();
return true;
DEBUG_MSG_P(PSTR("+OK\n"));
}); });
#if defined(JUSTWIFI_ENABLE_WPS) #if defined(JUSTWIFI_ENABLE_WPS)
terminalRegisterCommand(F("WIFI.WPS"), [](Embedis* e) { terminalRegisterCommand(F("WIFI.WPS"), [](Embedis* e) {
wifiStartWPS(); wifiStartWPS();
return true;
DEBUG_MSG_P(PSTR("+OK\n"));
}); });
#endif // defined(JUSTWIFI_ENABLE_WPS) #endif // defined(JUSTWIFI_ENABLE_WPS)
#if defined(JUSTWIFI_ENABLE_SMARTCONFIG) #if defined(JUSTWIFI_ENABLE_SMARTCONFIG)
terminalRegisterCommand(F("WIFI.SMARTCONFIG"), [](Embedis* e) { terminalRegisterCommand(F("WIFI.SMARTCONFIG"), [](Embedis* e) {
wifiStartSmartConfig(); wifiStartSmartConfig();
return true;
DEBUG_MSG_P(PSTR("+OK\n"));
}); });
#endif // defined(JUSTWIFI_ENABLE_SMARTCONFIG) #endif // defined(JUSTWIFI_ENABLE_SMARTCONFIG)
terminalRegisterCommand(F("WIFI.SCAN"), [](Embedis* e) { terminalRegisterCommand(F("WIFI.SCAN"), [](Embedis* e) {
_wifiScan(); _wifiScan();
return true;
DEBUG_MSG_P(PSTR("+OK\n"));
}); });
} }


Loading…
Cancel
Save