Problems including Particle Firmware API calls in non-INO files

Greetings,

Starting my second project with Particle (this time with a Photon), and am determined to get past a problem that I kludged in the first one. For reference, I’m using the Atom-based Particle Dev IDE.

For some reason, I cannot seem to be able to make calls to the Particle Firmware API anywhere outside of the main / INO file. Current example is any Wire (I2C) call. I’ve seen this done in other third-party libraries (e.g. those from SparkFun), and am including stdio.h, stdint.h, and application.h in my C source file. However, I’m now getting the following compilation errors:

  • system_version.h (53:19): expected ":", ",", ";", "}", or "_attribute_" before "=" token
  • spring_wiring_constants.h (31:23): type_traits: no such file or directory

Clues here? I’m hoping that this is a simple, stupid mistake, as I would really like to be able to make things a whole lot more modular going forward, as opposed to using the “big ball o’ code” INO design methodology.

Thanks much,
Ivan

Use #include "application.h" in the .h files of those libraries you wish to use Particle API calls :smile:

Thanks, but I’m already doing so. Leaving out application.h gives me complaints about Wire not being declared.

Only after I include those three headers mentioned (or really only application.h) do I get the more cryptic error messages about system_version | _wiring_constants.

Yep, read right through that without registering it, sorry about that. I’ve yet to connect any I2C modules to my Photon. We should call in the big guns on this one. @ScruffR or @Moors7 any idea what’s going on here?

1 Like

If you show your code it might be easier to see your problem.
As you said, it’s possible and others do it all the time, so it’s most likely your code.

BTW: I’m not that big a gun :wink: More like a water pistol - there are others way cleverer, but I’m round a lot, so people just can’t help having to read my stuff :sunglasses:

3 Likes

@IvanY, like @ScruffR said, it’s difficult to help without seeing some code. I have several libraries making Wire calls so I’m not sure what’s up with your code. Also, how are you compiling (IDE, CLI, DEV or local toolchain)?

@peekay123 he’s using Dev :smile:

1 Like

Okay, I’ve reproduced this with a greatly-simplified set of files (not that the previous ones were a whole lot more complex):

Test.ino:

#include "I2CInterface.h"
void setup() {
  Wire.begin();
}
void loop() {
  basicFunction();
}

I2CInterface.h:

#ifndef _I2C_Interface_h_
#define _I2C_Interface_h_
void basicFunction();
#endif

I2CInterface.c:

#include "application.h"
#include "I2CInterface.h"

//-I2C address
#define I2C_ADDRESS 0x48

void basicFunction() {
  Wire.requestFrom(I2C_ADDRESS, 2);
}

Compilation with Particle Dev, same two system_*.h compilation errors as before.

I’ve just built above code without issue with Dev, but I have used I2CInterface.cpp instead of just .c

I thought that issue was resolved already, but as it seems not.


@suda - I thought this was done back when glowfi.sh contributed the HTTPS library, wasn’t it?

2 Likes

Umm if I remember correctly this was an issue with Build not Dev. This seems to be just an issue of mixing C and C++ code without wrapping: https://isocpp.org/wiki/faq/mixing-c-and-cpp

3 Likes

As it turns out, simply renaming the C file to CPP resolves the compilation problem. (I’ve gone ahead and added the extern C section to the header file, as per the link provided by @suda.)

I admit that it has been eons since I’ve dabbled in C++, and so many of these requirements are somewhat foreign to me.

Thanks much.

1 Like