-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
function to print current debugLevel as string #7
Comments
I came up with an alternate (better method) putting the strings into PROGMEM to save RAM... // Enum Strings stored in PROGMEM
//----------------------------------------------------------------------------
// const char stringName [NUMBER_OF_ELEMENTS] [MAX_SIZE] PROGMEM = {
// http://www.gammon.com.au/forum/?id=12615
const char debugModeString [6] [ENUM_STRING_BUFFER_SIZE] PROGMEM =
{
{"DBG_NONE"},
{"DBG_ERROR"},
{"DBG_WARNING"},
{"DBG_INFO"},
{"DBG_DEBUG"},
{"DBG_VERBOSE"},
}; // END -- debugModeString[][] To print the strings from PROGMEM, I have this helper function: char progMemStringBuffer [ENUM_STRING_BUFFER_SIZE]; // global char buffer for getProgMemString()
// Return a string from PROGMEM directly, use with Serial.print() or sprintf()
char* getProgMemString(const char * progMemString)
{
// Retrieve PROGMEM enum string for use in Debug.print message
sprintf_P (progMemStringBuffer, PSTR ("%S"), progMemString); // use %S (not %s) for PROGMEM string flag
return progMemStringBuffer;
} // END -- getProgMemString() and call in my program like this: Serial.print(getProgMemString(debugModeString[debugLevel+1])); // +1 due to debugLevel enum value settings in Arduino_DebugUtils.h |
Hi @MattStarfield 👋 Since you've got it all figured out already, how about a PR? Please consider that PROGMEM is something AVR-specific, consequently your PR should also support other Arduino cores (which is actually quite trivial). |
At times, it can be helpful to print the current debug level to the serial monitor as a string. I've implemented this in my own code, but it could be helpful to include in the library to be accessible to all...
The text was updated successfully, but these errors were encountered: