diff --git a/extras/tests/Helpers/Arduino.h b/extras/tests/Helpers/Arduino.h index 5f6f3fe3..ef3640d9 100644 --- a/extras/tests/Helpers/Arduino.h +++ b/extras/tests/Helpers/Arduino.h @@ -7,5 +7,7 @@ #include "api/Print.h" #include "api/Stream.h" #include "api/String.h" +#include "avr/pgmspace.h" +#define ARDUINO #define ARDUINO_H_INCLUDED 1 diff --git a/extras/tests/Helpers/progmem_emulation.hpp b/extras/tests/Helpers/avr/pgmspace.h similarity index 98% rename from extras/tests/Helpers/progmem_emulation.hpp rename to extras/tests/Helpers/avr/pgmspace.h index ecb9f509..378065da 100644 --- a/extras/tests/Helpers/progmem_emulation.hpp +++ b/extras/tests/Helpers/avr/pgmspace.h @@ -2,6 +2,8 @@ // Copyright © 2014-2023, Benoit BLANCHON // MIT License +#pragma once + #include // uint8_t #define PROGMEM diff --git a/extras/tests/JsonDocument/MemberProxy.cpp b/extras/tests/JsonDocument/MemberProxy.cpp index 261cb271..002983fe 100644 --- a/extras/tests/JsonDocument/MemberProxy.cpp +++ b/extras/tests/JsonDocument/MemberProxy.cpp @@ -2,8 +2,6 @@ // Copyright © 2014-2023, Benoit BLANCHON // MIT License -#include "progmem_emulation.hpp" - #define ARDUINOJSON_ENABLE_ARDUINO_STRING 1 #define ARDUINOJSON_ENABLE_PROGMEM 1 #include diff --git a/extras/tests/JsonDocument/add.cpp b/extras/tests/JsonDocument/add.cpp index 9a3870c8..98c082e3 100644 --- a/extras/tests/JsonDocument/add.cpp +++ b/extras/tests/JsonDocument/add.cpp @@ -2,8 +2,6 @@ // Copyright © 2014-2023, Benoit BLANCHON // MIT License -#include "progmem_emulation.hpp" - #define ARDUINOJSON_ENABLE_ARDUINO_STRING 1 #define ARDUINOJSON_ENABLE_PROGMEM 1 #include diff --git a/extras/tests/Misc/StringAdapters.cpp b/extras/tests/Misc/StringAdapters.cpp index cc6d681b..1c77e08b 100644 --- a/extras/tests/Misc/StringAdapters.cpp +++ b/extras/tests/Misc/StringAdapters.cpp @@ -2,17 +2,16 @@ // Copyright © 2014-2023, Benoit BLANCHON // MIT License -#define ARDUINOJSON_ENABLE_PROGMEM 1 - -#include "custom_string.hpp" -#include "progmem_emulation.hpp" -#include "weird_strcmp.hpp" +#include #include #include #include +#include "custom_string.hpp" +#include "weird_strcmp.hpp" + using namespace ArduinoJson::detail; TEST_CASE("ZeroTerminatedRamString") { diff --git a/extras/tests/Misc/StringWriter.cpp b/extras/tests/Misc/StringWriter.cpp index 32b8b936..afc8cca8 100644 --- a/extras/tests/Misc/StringWriter.cpp +++ b/extras/tests/Misc/StringWriter.cpp @@ -2,10 +2,13 @@ // Copyright © 2014-2023, Benoit BLANCHON // MIT License -#define ARDUINOJSON_ENABLE_ARDUINO_STRING 1 +#include + #define ARDUINOJSON_STRING_BUFFER_SIZE 5 #include + #include + #include "custom_string.hpp" using namespace ArduinoJson::detail; diff --git a/extras/tests/MixedConfiguration/enable_progmem_1.cpp b/extras/tests/MixedConfiguration/enable_progmem_1.cpp index 303dcb9e..cbec2028 100644 --- a/extras/tests/MixedConfiguration/enable_progmem_1.cpp +++ b/extras/tests/MixedConfiguration/enable_progmem_1.cpp @@ -2,8 +2,6 @@ // Copyright © 2014-2023, Benoit BLANCHON // MIT License -#include "progmem_emulation.hpp" - #define ARDUINOJSON_ENABLE_PROGMEM 1 #include diff --git a/extras/tests/MixedConfiguration/issue1707.cpp b/extras/tests/MixedConfiguration/issue1707.cpp index 71fbd01f..94838634 100644 --- a/extras/tests/MixedConfiguration/issue1707.cpp +++ b/extras/tests/MixedConfiguration/issue1707.cpp @@ -5,8 +5,6 @@ #define ARDUINO #define memcpy_P(dest, src, n) memcpy((dest), (src), (n)) -#include "progmem_emulation.hpp" - #include #include diff --git a/src/ArduinoJson.hpp b/src/ArduinoJson.hpp index 7678180c..0604527d 100644 --- a/src/ArduinoJson.hpp +++ b/src/ArduinoJson.hpp @@ -13,7 +13,8 @@ // Include Arduino.h before stdlib.h to avoid conflict with atexit() // https://github.com/bblanchon/ArduinoJson/pull/1693#issuecomment-1001060240 #if ARDUINOJSON_ENABLE_ARDUINO_STRING || ARDUINOJSON_ENABLE_ARDUINO_STREAM || \ - ARDUINOJSON_ENABLE_ARDUINO_PRINT || ARDUINOJSON_ENABLE_PROGMEM + ARDUINOJSON_ENABLE_ARDUINO_PRINT || \ + (ARDUINOJSON_ENABLE_PROGMEM && defined(ARDUINO)) # include #endif diff --git a/src/ArduinoJson/Deserialization/Readers/FlashReader.hpp b/src/ArduinoJson/Deserialization/Readers/FlashReader.hpp index df2314ef..97714afb 100644 --- a/src/ArduinoJson/Deserialization/Readers/FlashReader.hpp +++ b/src/ArduinoJson/Deserialization/Readers/FlashReader.hpp @@ -4,7 +4,7 @@ #pragma once -#include +#include ARDUINOJSON_BEGIN_PRIVATE_NAMESPACE diff --git a/src/ArduinoJson/Polyfills/pgmspace.hpp b/src/ArduinoJson/Polyfills/pgmspace.hpp index 03adc6f1..9e66f96a 100644 --- a/src/ArduinoJson/Polyfills/pgmspace.hpp +++ b/src/ArduinoJson/Polyfills/pgmspace.hpp @@ -4,7 +4,13 @@ #pragma once -#include +#ifdef ARDUINO +# include +#else +// Allow using PROGMEM outside of Arduino (issue #1903) +class __FlashStringHelper; +# include +#endif #include #include diff --git a/src/ArduinoJson/Strings/Adapters/FlashString.hpp b/src/ArduinoJson/Strings/Adapters/FlashString.hpp index eaffe7e3..4989315a 100644 --- a/src/ArduinoJson/Strings/Adapters/FlashString.hpp +++ b/src/ArduinoJson/Strings/Adapters/FlashString.hpp @@ -4,8 +4,6 @@ #pragma once -#include - #include #include