I want to create a product that can either be equipped with an Electron or a Photon (because of the footprint compatibility, this can physically be done).
But how can this be handled in code? We need to manage the includes and preprocessor statements, but there is no #if defined(ELECTRON) available (to my knowledge, only the PLATFORM_ID). If it is a Photon I need to have SoftAp available and if it is the Electron, I need to manage the APN programmatically.
So basically what I want to do in “pseudo” code is:
#if ( PLATFORM_ID = 10 )
#if ( PLATFORM_ID = 6 )
STARTUP( softap_set_application_page_handler( myPages, nullptr ) );
But unfortunately “=” is not valid in preprocessor expressions, so the above code will not compile. #if defined( ELECTRON ) would compile nice, but unfortunately I think it is available
This is C, so the comparison operator is
== the single equals sign (
=) is the assignment operator.
So you`d write
#if (PLATFORM_ID == 10)
This will build
I’d guess you might have got an error message, that told - but it might well be cryptic for most people
@ScruffR, yes indeed, my bad, I am sorry very much I messed out the double == (shame on me)!!!
This code does build OK:
#if ( PLATFORM_ID == 10 )
#if ( PLATFORM_ID == 6 )
I just learned from @mdma that there’s a
platforms.h file that has definitions for all the Particle platforms. You can now write easier to read code like this instead of using magic numbers:
#if ( PLATFORM_ID == PLATFORM_ELECTRON_PRODUCTION )
#if ( PLATFORM_ID == PLATFORM_PHOTON_PRODUCTION )
I noticed this in the file platforms.h exists #define PLATFORM_ETHERNET_PROTO 9.
Does that mean that already you started or plan to develop ethernet version?
@Pixelmatix thank you for the information. Indeed with the platforms.h the code is much more easier to read!