Different Code for Target Platforms

I'm adding P2 to an existing codebase and I need to use BLE.selectAntenna() for P2 WiFi.

Is the best way to do so by checking PLATFORM_ID like so:



Yes, in this specific case.

In general you should check for features such as cellular, Wi-Fi, power manager, etc. instead of checking for the device platform, but the antenna selector doesn't have a feature define. You could use #if Wiring_BLE which is a little different, but probably close enough.

1 Like

Is it safe to use BLE.selectAntenna switch the P2/Photon2 WiFi antenna at any time, for instance every 30 seconds (not that I would need to do that, but is it safe?).

I would only set it if the value changes. It writes the value to the flash file system as it's persistent, but the call always writes even if the value is unchanged.

Every 30 seconds is probably fine for writing to the file system, but if it's unchanged you might as well save the processing and flash wear and just get the antenna selection before setting it, and only set it if it changed.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.