diff --git a/platformio.ini b/platformio.ini index ba95bc4..37e55b3 100644 --- a/platformio.ini +++ b/platformio.ini @@ -14,6 +14,7 @@ build_flags = -D CONFIG_ARDUHAL_LOG_COLORS -D CORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_DEBUG ; -D DASH_USE_LEGACY_CHART_STORAGE=1 + ; -D DASH_USE_STL_STRING=1 lib_deps = bblanchon/ArduinoJson@^7.1.0 mathieucarbou/ESPAsyncWebServer@^3.3.14 diff --git a/src/Card.cpp b/src/Card.cpp index 07b6cd2..47049ab 100644 --- a/src/Card.cpp +++ b/src/Card.cpp @@ -99,11 +99,11 @@ void Card::update(float value){ _value_f = value; } -void Card::update(const String &value, const char* symbol){ +void Card::update(const DASH_STR &value, const char* symbol){ update(value.c_str(), symbol); } -void Card::update(const String &value){ +void Card::update(const DASH_STR &value){ update(value.c_str()); } @@ -130,7 +130,7 @@ void Card::update(const char* value){ _value_s = value; } -void Card::update(String&& value, const char* symbol){ +void Card::update(DASH_STR&& value, const char* symbol){ if(_value_type == Card::STRING){ if(_value_s != value) _changed = true; @@ -143,7 +143,7 @@ void Card::update(String&& value, const char* symbol){ _value_s = std::move(value); } -void Card::update(String&& value){ +void Card::update(DASH_STR&& value){ if(_value_type == Card::STRING){ if(_value_s != value) _changed = true; diff --git a/src/Card.h b/src/Card.h index 530bb69..6745e4e 100644 --- a/src/Card.h +++ b/src/Card.h @@ -8,6 +8,13 @@ #include "ESPDash.h" #include "ArduinoJson.h" +#ifdef DASH_USE_STL_STRING + #include + #define DASH_STR std::string +#else + #define DASH_STR String +#endif + struct CardNames { int value; const char* type; @@ -41,7 +48,7 @@ class Card { float _value_f; int _value_i; }; - String _value_s; + DASH_STR _value_s; union alignas(4) { float _value_min_f; int _value_min; @@ -71,10 +78,10 @@ class Card { void update(float value, const char* symbol); void update(const char* value); void update(const char* value, const char* symbol); - void update(const String &value); - void update(const String &value, const char* symbol); - void update(String &&value); - void update(String &&value, const char* symbol); + void update(const DASH_STR &value); + void update(const DASH_STR &value, const char* symbol); + void update(DASH_STR &&value); + void update(DASH_STR &&value, const char* symbol); ~Card(); friend class ESPDash; diff --git a/src/ESPDash.cpp b/src/ESPDash.cpp index 7ea478a..e013b0d 100644 --- a/src/ESPDash.cpp +++ b/src/ESPDash.cpp @@ -382,7 +382,7 @@ void ESPDash::generateComponentJSON(JsonObject& doc, Card* card, bool change_onl doc["v"] = String(card->_value_f, 2); break; case Card::STRING: - if(change_only || !card->_value_s.isEmpty()) { + if(change_only || card->_value_s.size()) { doc["v"] = card->_value_s; } break; diff --git a/src/ESPDash.h b/src/ESPDash.h index 80e116d..c5147dc 100644 --- a/src/ESPDash.h +++ b/src/ESPDash.h @@ -96,6 +96,13 @@ Github URL: https://github.com/ayushsharma82/ESP-DASH #define DASH_MAX_WS_CLIENTS DEFAULT_MAX_WS_CLIENTS #endif +#ifdef DASH_USE_STL_STRING + #include + #define DASH_STR std::string +#else + #define DASH_STR String +#endif + // Forward Declaration class Card; class Chart;