Browse Source

sns: more flash strings

pull/2525/head
Maxim Prokhorov 2 years ago
parent
commit
6a0d6b0c49
7 changed files with 47 additions and 41 deletions
  1. +13
    -13
      code/espurna/light.cpp
  2. +12
    -13
      code/espurna/prometheus.cpp
  3. +8
    -8
      code/espurna/relay.cpp
  4. +2
    -2
      code/espurna/rfbridge.cpp
  5. +10
    -3
      code/espurna/sensor.cpp
  6. +1
    -1
      code/espurna/terminal.cpp
  7. +1
    -1
      code/espurna/wifi.cpp

+ 13
- 13
code/espurna/light.cpp View File

@ -2359,30 +2359,30 @@ void _lightWebSocketOnConnected(JsonObject& root) {
void _lightWebSocketOnAction(uint32_t client_id, const char* action, JsonObject& data) {
if (_light_has_color) {
if (strcmp(action, "color") == 0) {
if (data.containsKey("rgb")) {
_lightFromRgbPayload(data["rgb"].as<const char*>());
if (STRING_VIEW("color") == action) {
if (data.containsKey(F("rgb"))) {
_lightFromRgbPayload(data[F("rgb")].as<const char*>());
lightUpdate();
} else if (data.containsKey("hsv")) {
_lightFromHsvPayload(data["hsv"].as<const char*>());
_lightFromHsvPayload(data[F("hsv")].as<const char*>());
lightUpdate();
}
}
}
if (strcmp(action, "mireds") == 0) {
if (data.containsKey("mireds")) {
_fromMireds(data["mireds"].as<long>());
if (STRING_VIEW("mireds") == action) {
if (data.containsKey(F("mireds"))) {
_fromMireds(data[F("mireds")].as<long>());
lightUpdate();
}
} else if (strcmp(action, "channel") == 0) {
if (data.containsKey("id") && data.containsKey("value")) {
lightChannel(data["id"].as<size_t>(), data["value"].as<long>());
} else if (STRING_VIEW("channel") == action) {
if (data.containsKey(F("id")) && data.containsKey(F("value"))) {
lightChannel(data[F("id")].as<size_t>(), data[F("value")].as<long>());
lightUpdate();
}
} else if (strcmp(action, "brightness") == 0) {
if (data.containsKey("value")) {
lightBrightness(data["value"].as<long>());
} else if (STRING_VIEW("brightness") == action) {
if (data.containsKey(F("value"))) {
lightBrightness(data[F("value")].as<long>());
lightUpdate();
}
}


+ 12
- 13
code/espurna/prometheus.cpp View File

@ -25,11 +25,11 @@ namespace build {
namespace {
constexpr bool relaySupport() {
return RELAY_SUPPORT == 1;
return 1 == RELAY_SUPPORT;
}
constexpr bool sensorSupport() {
return SENSOR_SUPPORT == 1;
return 1 == SENSOR_SUPPORT;
}
static_assert(relaySupport() || sensorSupport(), "");
@ -45,25 +45,24 @@ void handler(AsyncWebServerRequest* request) {
// Note: Response 'stream' backing buffer is customizable. Default is 1460 bytes (see ESPAsyncWebServer.h)
// In case printf overflows, memory of CurrentSize+N{overflow} will be allocated to replace
// the existing buffer. Previous buffer will be copied into the new and destroyed after that.
AsyncResponseStream *response = request->beginResponseStream("text/plain");
auto *response = request->beginResponseStream("text/plain");
#if RELAY_SUPPORT
for (unsigned char index = 0; index < relayCount(); ++index) {
response->printf("relay%u %d\n", index, static_cast<int>(relayStatus(index)));
if (build::relaySupport()) {
for (size_t index = 0; index < relayCount(); ++index) {
response->printf_P(PSTR("relay%u %d\n"), index, relayStatus(index) ? 1 : 0);
}
#endif
}
#if SENSOR_SUPPORT
for (unsigned char index = 0; index < magnitudeCount(); ++index) {
if (build::sensorSupport()) {
for (size_t index = 0; index < magnitudeCount(); ++index) {
auto value = magnitudeValue(index);
if (value) {
value.topic.remove('/');
response->printf("%s %s\n",
value.topic.c_str(),
value.repr.c_str());
response->printf_P(PSTR("%s %s\n"),
value.topic.c_str(), value.repr.c_str());
}
}
#endif
}
response->write('\n');


+ 8
- 8
code/espurna/relay.cpp View File

@ -2163,8 +2163,8 @@ void _relayConfigure() {
namespace {
bool _relayWebSocketOnKeyCheck(const char * key, JsonVariant&) {
return (strncmp(key, "relay", 5) == 0);
bool _relayWebSocketOnKeyCheck(const char* key, JsonVariant&) {
return strncmp_P(key, PSTR("relay"), 5) == 0;
}
void _relayWebSocketUpdate(JsonObject& root) {
@ -2187,8 +2187,8 @@ void _relayWebSocketSendRelays(JsonObject& root) {
::web::ws::EnumerableConfig config{root, STRING_VIEW("relayConfig")};
auto& container = config.root();
container["size"] = _relays.size();
container["start"] = 0;
container[F("size")] = _relays.size();
container[F("start")] = 0;
config(STRING_VIEW("relays"), _relays.size(),
espurna::relay::settings::query::IndexedSettings);
@ -2216,14 +2216,14 @@ void _relayWebSocketOnConnected(JsonObject& root) {
}
void _relayWebSocketOnAction(uint32_t, const char* action, JsonObject& data) {
if (strcmp(action, "relay") == 0) {
if (!data.is<size_t>("id") || !data.is<String>("status")) {
if (strncmp_P(action, PSTR("relay"), 5) == 0) {
if (!data.is<size_t>(F("id")) || !data.is<String>(F("status"))) {
return;
}
_relayHandlePayload(
data["id"].as<size_t>(),
data["status"].as<String>().c_str());
data[F("id")].as<size_t>(),
data[F("status")].as<String>().c_str());
}
}


+ 2
- 2
code/espurna/rfbridge.cpp View File

@ -432,7 +432,7 @@ void _rfbWebSocketOnConnected(JsonObject& root) {
void _rfbWebSocketOnAction(uint32_t client_id, const char* action, JsonObject& data) {
#if RELAY_SUPPORT
if (strncmp(action, "rfb", 3) != 0) {
if (STRING_VIEW("rfb") == action) {
return;
}
@ -458,7 +458,7 @@ void _rfbWebSocketOnAction(uint32_t client_id, const char* action, JsonObject& d
}
bool _rfbWebSocketOnKeyCheck(const char * key, JsonVariant& value) {
return (strncmp(key, "rfb", 3) == 0);
return strncmp_P(key, PSTR("rfb"), 3) == 0;
}
#endif // WEB_SUPPORT


+ 10
- 3
code/espurna/sensor.cpp View File

@ -2176,7 +2176,7 @@ void _sensorWebSocketSendData(JsonObject& root) {
}
void _sensorWebSocketOnAction(uint32_t client_id, const char* action, JsonObject& data) {
if (strcmp(action, "emon-expected") == 0) {
if (STRING_VIEW("emon-expected") == action) {
auto id = data["id"].as<size_t>();
if (id < _magnitudes.size()) {
auto expected = data["expected"].as<float>();
@ -2190,10 +2190,17 @@ void _sensorWebSocketOnAction(uint32_t client_id, const char* action, JsonObject
root[key] = _sensorApiEmonExpectedValue(magnitude, expected);
});
}
} else if (strcmp(action, "emon-reset-ratios") == 0) {
return;
}
if (STRING_VIEW("emon-reset-ratios") == action) {
_sensorApiEmonResetRatios();
} else if (strcmp(action, "analog-calibrate") == 0) {
return;
}
if (STRING_VIEW("analog-calibrate") == action) {
_sensorApiAnalogCalibrate();
return;
}
}


+ 1
- 1
code/espurna/terminal.cpp View File

@ -702,7 +702,7 @@ void terminalWebApiSetup() {
apiRegister(getSetting("termWebApiPath", TERMINAL_WEB_API_PATH),
[](ApiRequest& api) {
api.handle([](AsyncWebServerRequest* request) {
AsyncResponseStream *response = request->beginResponseStream("text/plain");
AsyncResponseStream *response = request->beginResponseStream(F("text/plain"));
for (auto* name : _terminal.names()) {
response->print(name);
response->print("\r\n");


+ 1
- 1
code/espurna/wifi.cpp View File

@ -2519,7 +2519,7 @@ void onScan(uint32_t client_id) {
}
void onAction(uint32_t client_id, const char* action, JsonObject&) {
if (strcmp(action, "scan") == 0) {
if (STRING_VIEW("scan") == action) {
onScan(client_id);
}
}


Loading…
Cancel
Save