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:
#include <type_traits>
#include <string.h>
#include <time.h>
#include <stdint.h>
#include "time_compat.h"
#define DEFAULT_CLOUD_EVENT_TTL 60
enum ParticleKeyErrorFlag: uint32_t
{
NO_ERROR = 0,
PUBLIC_SERVER_KEY_BLANK = 1,
PUBLIC_SERVER_KEY_CORRUPTED = 2,
SERVER_ADDRESS_BLANK = 4,
SERVER_ADDRESS_CORRUPTED = 8,
PUBLIC_DEVICE_KEY_BLANK = 16,
PUBLIC_DEVICE_KEY_CORRUPTED = 32,
PRIVATE_DEVICE_KEY_BLANK = 64,
PRIVATE_DEVICE_KEY_CORRUPTED = 128
};
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.
system
Closed
March 15, 2023, 1:58am
4
This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.