PowerBroker2 / SafeString

This SafeString library is designed for beginners to be a safe, robust and debuggable replacement for string processing in Arduino. Note, this is NOT my work, I am simply hosting it for easy access. The original code belongs to Forward Computing and Control Pty. Ltd.
https://www.forward.com.au/pfod/ArduinoProgramming/SafeString/index.html
38 stars 12 forks source link

Make compatible with PlatformIO #61

Closed twhiston closed 5 months ago

twhiston commented 2 years ago

I found I couldn't build projects using this library with PlatformIO because you use Printable without prefixing the Arduino namespace to it. Simply adding this fixes it, and everything still builds successfully with the Arduino IDE.

PowerBroker2 commented 2 years ago

@drmpf Let me know if you want me to merge

drmpf commented 2 years ago

With this change the SafeString_Tests->SafeStringPrint test sketch fails to compile on UNO and ESP32 (at least) under 1.8.19 Can you supply a #define that will restrict the change to Platform IO?

twhiston commented 2 years ago

Thanks for testing this, I don't have either of those boards, unfortunately. I'm using an M0 Pro and this test compiles with that. Not sure if it's relevant but I did find that regardless of using the original code or with the prefixed arduino:: all tests after the first result in an error.

It doesn't seem like PlatformIO adds anything at all to the code which allows the preprocessor to tell if it's being used, which is slightly annoying. I'll see if I can get my hands on a board where it fails to compile to find a solution

drmpf commented 2 years ago

@PowerBroker2 You can close this for now thanks (Can you drop me your email via forward.com.au at fcc ?)

twhiston commented 2 years ago

Spoke too soon, I found a way to guard for this

drmpf commented 2 years ago

Actually it is probably a board problem not a PlatformIO problem see the file SafeStringNameSpace.h and SafeStringNameSpaceStart.h These add the arduino name space for specific boards. Try adding a define test to those files for the board you are using

twhiston commented 2 years ago

The m0 pro is defined as ARDUINO_SAMD_ZERO, which means according to that file it's deliberately skipping using the namespace. I tried moving this to include the namespacing for this chipset and found that although it still seems to compile properly in the Arduino IDE I'm back to the initial problem with platformIO expected class-name before ',' token so I think it might actually need a PlatformIO specific fix.

drmpf commented 1 year ago

V4.1.27 of SafeString now has two PlatformIO version included. Read the readme in the PlatformIO sub-dir for the details of how to use them

drmpf commented 5 months ago

Partial fix in V4.1.27