Description
Working on ESPEasy, a plugin based IoT solution for ESP8266 and ESP32, we have been struggling with keeping sketch size as small as possible.
Using this library to connect the SCD40/SCD41 environmental sensors does add quite some .bin size to our project, and parts of that will never be used: the debug log. There are quite a few, and rather long, flash-strings used that I'd like to exclude from our builds.
To be able to reduce sketch size, ca. 2.5 kB, I'm introducing a compiler define LIBRARIES_NO_LOG=1
on our side to exclude these unused logs from used libraries, like this:
//Enable/disable including debug log (to allow saving some space)
#ifndef SCD4x_ENABLE_DEBUGLOG
#if defined(LIBRARIES_NO_LOG) && LIBRARIES_NO_LOG
#define SCD4x_ENABLE_DEBUGLOG 0 // OFF/disabled/excluded on demand
#else
#define SCD4x_ENABLE_DEBUGLOG 1 // ON/enabled/included by default
#endif
#endif
And in the library code I use (for example):
#if SCD4x_ENABLE_DEBUGLOG
if (_printDebug == true)
{
_debugPort->println(F("SCD4x::setSensorAltitude: periodic measurements are running. Aborting"));
}
#endif // if SCD4x_ENABLE_DEBUGLOG
return (false);
}
This will by default leave all debug code in and logging usable, only to be inhibited when LIBRARIES_NO_LOG
is set to 1
. (Using 0/1 as that's easier readable than false/true.)
I'll create a PR to add this to the library, and kindly request to merge and release that, so we can use this original work, instead of a copy/adjusted version in our repository.