letscontrolit/ESPEasy

Question about defining feature in custom.h

chromoxdor opened this issue · 5 comments

Hi @TD-er,

in my fork of ESPEasy I use some extra code to retrieve weather data from openweathermap.org and now also from open-meteo.com.
https://github.com/chromoxdor/ESPEasy/blob/openweather-event/src/src/Helpers/Networking.cpp#L1665

I would like to easily turn these features on and off by defining them in custom.h.
For example:

#define FEATURE_OMETEO_EVENT 1

How would I do this as it doesn't work this way and I don't seem to understand the structure of this?

// Just define FEATURE_FOO, no value assigned to it
#define FEATURE_FOO

// Define FEATURE_BAR with a value not being 0 (thus true when evaluating)
#define FEATURE_BAR  1

// Check for FEATURE_FOO
#ifdef FEATURE_FOO
  ...
#endif

// Check for FEATURE_BAR 
#if FEATURE_BAR 
  ...
#endif

So when you assign a value to it like either 0 or 1, you can use #if
When you don't assign any value to it, you should use #ifdef or #ifndef for checking if it isn't defined.

I am using the "BAR" approach but in VSCode it is still greyed out... maybe it is a problem with VSC and I should try to compile it anyway.

Yep you should try to see if it compiles.
Also check your 'default' PlatformIO env as that's used by Intellisense to parse your code.

maybe it is a problem with VSC and I should try to compile it anyway.

It was included even though it was greyed out. There seems to be a problem with VSC somewhere. 🙄

Edit: Trying this earlier would have saved me a lot of time... 🤷‍♂️

Edit: Trying this earlier would have saved me a lot of time... 🤷‍♂️

Sounds familiar