Browse Source

Help command

fastled
Xose Pérez 7 years ago
parent
commit
b83c483bcd
2 changed files with 160 additions and 115 deletions
  1. +24
    -0
      code/espurna/libs/EmbedisWrap.h
  2. +136
    -115
      code/espurna/settings.ino

+ 24
- 0
code/espurna/libs/EmbedisWrap.h View File

@ -0,0 +1,24 @@
// -----------------------------------------------------------------------------
// Wrap class around Embedis (settings & terminal)
// -----------------------------------------------------------------------------
#pragma once
#include "Embedis.h"
class EmbedisWrap : public Embedis {
public:
EmbedisWrap(Stream& stream, size_t buflen = 128, size_t argvlen = 8): Embedis(stream, buflen, argvlen) {}
unsigned char getCommandsCount() {
return commands.size();
}
String getCommandName(unsigned char i) {
if (i < commands.size()) return commands[i].name;
return String();
}
};

+ 136
- 115
code/espurna/settings.ino View File

@ -6,9 +6,9 @@ Copyright (C) 2016-2017 by Xose Pérez <xose dot perez at gmail dot com>
*/
#include "Embedis.h"
#include <EEPROM.h>
#include "spi_flash.h"
#include "libs/EmbedisWrap.h"
#include <StreamString.h>
#if TELNET_SUPPORT
@ -18,12 +18,12 @@ Copyright (C) 2016-2017 by Xose Pérez <xose dot perez at gmail dot com>
#else
StreamInjector _serial = StreamInjector(Serial);
#endif
Embedis embedis(_serial);
EmbedisWrap embedis(_serial);
#else
#ifdef DEBUG_PORT
Embedis embedis(DEBUG_PORT);
EmbedisWrap embedis(DEBUG_PORT);
#else
Embedis embedis(_serial);
EmbedisWrap embedis(_serial);
#endif
#endif
@ -97,6 +97,18 @@ void settingsFactoryReset() {
EEPROM.commit();
}
void settingsHelp() {
unsigned char len = embedis.getCommandsCount();
DEBUG_MSG_P(PSTR("\nAvailable commands:\n\n"));
for (unsigned char i=0; i<len; i++) {
DEBUG_MSG_P(PSTR("* %s\n"), embedis.getCommandName(i).c_str());
if (embedis.getCommandName(i).equals("WRITE")) {
DEBUG_MSG_P(PSTR("\n"));
}
}
DEBUG_MSG_P(PSTR("\n"));
}
void settingsSetup() {
EEPROM.begin(SPI_FLASH_SEC_SIZE);
@ -126,33 +138,82 @@ void settingsSetup() {
// -------------------------------------------------------------------------
Embedis::command( F("RESET.WIFI"), [](Embedis* e) {
wifiConfigure();
wifiDisconnect();
DEBUG_MSG_P(PSTR("+OK\n"));
});
#if LIGHT_PROVIDER != LIGHT_PROVIDER_NONE
Embedis::command( F("BRIGHTNESS"), [](Embedis* e) {
if (e->argc > 1) {
lightBrightness(String(e->argv[1]).toInt());
lightUpdate(true, true);
}
DEBUG_MSG_P(PSTR("Brightness: %d\n"), lightBrightness());
DEBUG_MSG_P(PSTR("+OK\n"));
});
#endif
#if MQTT_SUPPORT
Embedis::command( F("RESET.MQTT"), [](Embedis* e) {
mqttConfigure();
mqttDisconnect();
#if LIGHT_PROVIDER != LIGHT_PROVIDER_NONE
Embedis::command( F("CHANNEL"), [](Embedis* e) {
if (e->argc < 2) {
DEBUG_MSG_P(PSTR("-ERROR: Wrong arguments\n"));
}
int id = String(e->argv[1]).toInt();
if (e->argc > 2) {
int value = String(e->argv[2]).toInt();
lightChannel(id, value);
lightUpdate(true, true);
}
DEBUG_MSG_P(PSTR("Channel #%d: %d\n"), id, lightChannel(id));
DEBUG_MSG_P(PSTR("+OK\n"));
});
#endif
Embedis::command( F("INFO"), [](Embedis* e) {
welcome();
#if LIGHT_PROVIDER != LIGHT_PROVIDER_NONE
Embedis::command( F("COLOR"), [](Embedis* e) {
if (e->argc > 1) {
String color = String(e->argv[1]);
lightColor(color.c_str());
lightUpdate(true, true);
}
DEBUG_MSG_P(PSTR("Color: %s\n"), lightColor().c_str());
DEBUG_MSG_P(PSTR("+OK\n"));
});
#endif
#if DEBUG_SUPPORT
Embedis::command( F("CRASH"), [](Embedis* e) {
debugDumpCrashInfo();
DEBUG_MSG_P(PSTR("+OK\n"));
});
#endif
Embedis::command( F("DUMP"), [](Embedis* e) {
unsigned int size = settingsKeyCount();
for (unsigned int i=0; i<size; i++) {
String key = settingsKeyName(i);
String value = getSetting(key);
DEBUG_MSG_P(PSTR("+%s => %s\n"), key.c_str(), value.c_str());
}
DEBUG_MSG_P(PSTR("+OK\n"));
});
Embedis::command( F("UPTIME"), [](Embedis* e) {
DEBUG_MSG_P(PSTR("Uptime: %d seconds\n"), getUptime());
DEBUG_MSG_P(PSTR("+OK\n"));
Embedis::command( F("DUMP.RAW"), [](Embedis* e) {
bool ascii = false;
if (e->argc == 2) ascii = String(e->argv[1]).toInt() == 1;
for (unsigned int i = 0; i < SPI_FLASH_SEC_SIZE; i++) {
if (i % 16 == 0) DEBUG_MSG_P(PSTR("\n[%04X] "), i);
byte c = EEPROM.read(i);
if (ascii && 32 <= c && c <= 126) {
DEBUG_MSG_P(PSTR(" %c "), c);
} else {
DEBUG_MSG_P(PSTR("%02X "), c);
}
}
DEBUG_MSG_P(PSTR("\n+OK\n"));
});
Embedis::command( F("RESET"), [](Embedis* e) {
Embedis::command( F("EEPROM"), [](Embedis* e) {
unsigned long freeEEPROM = SPI_FLASH_SEC_SIZE - settingsSize();
DEBUG_MSG_P(PSTR("Number of keys: %d\n"), settingsKeyCount());
DEBUG_MSG_P(PSTR("Free EEPROM: %d bytes (%d%%)\n"), freeEEPROM, 100 * freeEEPROM / SPI_FLASH_SEC_SIZE);
DEBUG_MSG_P(PSTR("+OK\n"));
deferredReset(100, CUSTOM_RESET_TERMINAL);
});
Embedis::command( F("ERASE.CONFIG"), [](Embedis* e) {
@ -162,13 +223,6 @@ void settingsSetup() {
*((int*) 0) = 0; // see https://github.com/esp8266/Arduino/issues/1494
});
#if NOFUSS_SUPPORT
Embedis::command( F("NOFUSS"), [](Embedis* e) {
DEBUG_MSG_P(PSTR("+OK\n"));
nofussRun();
});
#endif
Embedis::command( F("FACTORY.RESET"), [](Embedis* e) {
settingsFactoryReset();
DEBUG_MSG_P(PSTR("+OK\n"));
@ -179,6 +233,48 @@ void settingsSetup() {
DEBUG_MSG_P(PSTR("+OK\n"));
});
Embedis::command( F("HELP"), [](Embedis* e) {
settingsHelp();
DEBUG_MSG_P(PSTR("+OK\n"));
});
Embedis::command( F("INFO"), [](Embedis* e) {
welcome();
wifiStatus();
DEBUG_MSG_P(PSTR("+OK\n"));
});
#if LIGHT_PROVIDER != LIGHT_PROVIDER_NONE
Embedis::command( F("KELVIN"), [](Embedis* e) {
if (e->argc > 1) {
String color = String("K") + String(e->argv[1]);
lightColor(color.c_str());
lightUpdate(true, true);
}
DEBUG_MSG_P(PSTR("Color: %s\n"), lightColor().c_str());
DEBUG_MSG_P(PSTR("+OK\n"));
});
#endif
#if LIGHT_PROVIDER != LIGHT_PROVIDER_NONE
Embedis::command( F("MIRED"), [](Embedis* e) {
if (e->argc > 1) {
String color = String("M") + String(e->argv[1]);
lightColor(color.c_str());
lightUpdate(true, true);
}
DEBUG_MSG_P(PSTR("Color: %s\n"), lightColor().c_str());
DEBUG_MSG_P(PSTR("+OK\n"));
});
#endif
#if NOFUSS_SUPPORT
Embedis::command( F("NOFUSS"), [](Embedis* e) {
DEBUG_MSG_P(PSTR("+OK\n"));
nofussRun();
});
#endif
Embedis::command( F("RELAY"), [](Embedis* e) {
if (e->argc < 2) {
DEBUG_MSG_P(PSTR("-ERROR: Wrong arguments\n"));
@ -196,105 +292,30 @@ void settingsSetup() {
DEBUG_MSG_P(PSTR("+OK\n"));
});
#if LIGHT_PROVIDER != LIGHT_PROVIDER_NONE
if (lightHasColor()) {
Embedis::command( F("COLOR"), [](Embedis* e) {
if (e->argc > 1) {
String color = String(e->argv[1]);
lightColor(color.c_str());
lightUpdate(true, true);
}
DEBUG_MSG_P(PSTR("Color: %s\n"), lightColor().c_str());
DEBUG_MSG_P(PSTR("+OK\n"));
});
Embedis::command( F("BRIGHTNESS"), [](Embedis* e) {
if (e->argc > 1) {
lightBrightness(String(e->argv[1]).toInt());
lightUpdate(true, true);
}
DEBUG_MSG_P(PSTR("Brightness: %d\n"), lightBrightness());
DEBUG_MSG_P(PSTR("+OK\n"));
});
Embedis::command( F("MIRED"), [](Embedis* e) {
if (e->argc > 1) {
String color = String("M") + String(e->argv[1]);
lightColor(color.c_str());
lightUpdate(true, true);
}
DEBUG_MSG_P(PSTR("Color: %s\n"), lightColor().c_str());
DEBUG_MSG_P(PSTR("+OK\n"));
});
Embedis::command( F("KELVIN"), [](Embedis* e) {
if (e->argc > 1) {
String color = String("K") + String(e->argv[1]);
lightColor(color.c_str());
lightUpdate(true, true);
}
DEBUG_MSG_P(PSTR("Color: %s\n"), lightColor().c_str());
DEBUG_MSG_P(PSTR("+OK\n"));
});
}
Embedis::command( F("RESET"), [](Embedis* e) {
DEBUG_MSG_P(PSTR("+OK\n"));
deferredReset(100, CUSTOM_RESET_TERMINAL);
});
Embedis::command( F("CHANNEL"), [](Embedis* e) {
if (e->argc < 2) {
DEBUG_MSG_P(PSTR("-ERROR: Wrong arguments\n"));
}
int id = String(e->argv[1]).toInt();
if (e->argc > 2) {
int value = String(e->argv[2]).toInt();
lightChannel(id, value);
lightUpdate(true, true);
}
DEBUG_MSG_P(PSTR("Channel #%d: %d\n"), id, lightChannel(id));
#if MQTT_SUPPORT
Embedis::command( F("RESET.MQTT"), [](Embedis* e) {
mqttConfigure();
mqttDisconnect();
DEBUG_MSG_P(PSTR("+OK\n"));
});
#endif
Embedis::command( F("EEPROM"), [](Embedis* e) {
unsigned long freeEEPROM = SPI_FLASH_SEC_SIZE - settingsSize();
DEBUG_MSG_P(PSTR("Number of keys: %d\n"), settingsKeyCount());
DEBUG_MSG_P(PSTR("Free EEPROM: %d bytes (%d%%)\n"), freeEEPROM, 100 * freeEEPROM / SPI_FLASH_SEC_SIZE);
Embedis::command( F("RESET.WIFI"), [](Embedis* e) {
wifiConfigure();
wifiDisconnect();
DEBUG_MSG_P(PSTR("+OK\n"));
});
Embedis::command( F("DUMP"), [](Embedis* e) {
unsigned int size = settingsKeyCount();
for (unsigned int i=0; i<size; i++) {
String key = settingsKeyName(i);
String value = getSetting(key);
DEBUG_MSG_P(PSTR("+%s => %s\n"), key.c_str(), value.c_str());
}
Embedis::command( F("UPTIME"), [](Embedis* e) {
DEBUG_MSG_P(PSTR("Uptime: %d seconds\n"), getUptime());
DEBUG_MSG_P(PSTR("+OK\n"));
});
#if DEBUG_SUPPORT
Embedis::command( F("CRASH"), [](Embedis* e) {
debugDumpCrashInfo();
DEBUG_MSG_P(PSTR("+OK\n"));
});
#endif
Embedis::command( F("DUMP.RAW"), [](Embedis* e) {
bool ascii = false;
if (e->argc == 2) ascii = String(e->argv[1]).toInt() == 1;
for (unsigned int i = 0; i < SPI_FLASH_SEC_SIZE; i++) {
if (i % 16 == 0) DEBUG_MSG_P(PSTR("\n[%04X] "), i);
byte c = EEPROM.read(i);
if (ascii && 32 <= c && c <= 126) {
DEBUG_MSG_P(PSTR(" %c "), c);
} else {
DEBUG_MSG_P(PSTR("%02X "), c);
}
}
DEBUG_MSG_P(PSTR("\n+OK\n"));
});
DEBUG_MSG_P(PSTR("[SETTINGS] EEPROM size: %d bytes\n"), SPI_FLASH_SEC_SIZE);
DEBUG_MSG_P(PSTR("[SETTINGS] Settings size: %d bytes\n"), settingsSize());


Loading…
Cancel
Save