ParticleKeyErrorFlag

Hi-
I’m using SEEED’s library GitHub - Seeed-Studio/Seeed_PM2_5_sensor_HM3301, and am encountering an odd compile error with an enum variable declared in Seeed_HM330X.h

error: cannot convert ‘ParticleKeyErrorFlag’ to ‘HM330XErrorCode’ in return
** 65 | return NO_ERROR;**

Is ParticleKeyErrorFlag a predeclared variable inside Particle firmware?

Workaround is to rename NO_ERROR in the project ino-file and in all the library references, but only if there’s no other option.

Specifics: Argon, deviceOS@4.0.0, VSCode 1.71.0

Thanks.

Yes, it is built-in, defined here:

This is annoying to fix. Because it’s an enum instead of enum class the name is globally scoped. Both are defined to 0 but because ParticleKeyErrorFlag is unsigned and HM330XErrorCode is signed even though both have a value of 0 it’s a compile error.

What I’d probably do is change the library to make its definitions enum class:

enum class HM330XErrorCode {
    NO_ERROR = 0,
    ERROR_PARAM = -1,
    ERROR_COMM = -2,
    ERROR_OTHERS = -128,
};

This has two unfortunate side-effects, however:

  • You then need to replace every NO_ERROR with HM330XErrorCode::NO_ERROR, and the same for the other 3 error constants.
  • There are two places in the basic_demo file where the result code is tested as a boolean, which you need to change to something like:
if (sensor.init() != HM330XErrorCode::NO_ERROR) {

Of course you can fix it a completely different way, but that’s how I got it to compile.

Thanks @rickkas7 for digging into this one, and confirming that changes are needed to the SEEED library. Maybe down the road the SEEED folks will make a modification to permit compatibility. Thanks again.