JoaoLopesF / RemoteDebug

Library for Arduino to debug projects over WiFi, with web app or telnet, with print commands like Serial Monitor
MIT License
613 stars 127 forks source link

Ability to use flash strings in debug messages #64

Open kostuch opened 4 years ago

kostuch commented 4 years ago

Is your feature request related to a problem? Please describe.

All messages processed by debug are stored in RAM memory. So in effect, observing/debugging application causes huge difference in RAM utilisation.

Describe the solution you'd like

Something like: debugI(F("some message stored in flash"));

Besides: excellent library.

jeroenst commented 4 years ago

I doubt if the messages are stored in RAM, maybe for just a little time until it is processed, but is that really an issue?

kostuch commented 4 years ago

As far as I know, all commands like debugI("Debug message") or Serial.print("something to print") by default put string data to the RAM. When I compile my app with many debug inserts, I can see that RAM utilization grows rapidly. If there is a huge amount of RAM available, then there is no issue, but sometime we hit the limit and additional consumption by debug is a problem.

jeroenst commented 5 months ago

You can use this:

if (Debug.isActive(Debug.INFO)) Debug.printf(cF("example"));

With cf and this macro's:

#define _gFmtBufSize 100+1

// ERB - Force format strings and string constants into FLASH Memory
#define sF(x) String( F(x) )
         // Used as an F() when being used as the first Element
         // of a Multi-Element Expression
char _gFmtBuf[_gFmtBufSize];
         // Buffer, Used with cF() to store constants in program space (FLASH)
#define cF(x) strncpy_P(_gFmtBuf, (PGM_P)PSTR(x), sizeof(_gFmtBuf)) 
// Used with printf() for the char format string