placing API definitions in separate include file ?? #26
aintgotnoname
started this conversation in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Let's move this into general discussion (and delete if you wish).
I'm happily using a modified version of the library include file in multiple .cpp files throughout a larger (15 file) platform io project.
In my project, various files perform adc reads, led operations, gpio and io stuff locally in each of the files using various library calls. Thus, the library file (or its api definitions) need to be included in multiple source files. I cannot use the heltec_unofficial.h as originally written without encountering two errors in PlatformIO/VSC/cpp.
The first error, reported in issue #24, is the duplicate definitions from pins_arduino.h. These could simply be #ifdef'd (//'d) out in the heltec_unoffical.h to avoid the redefinition. The PLATFORMIO define is defined and contains (I think) their version number. Creating our own USING_PLATFORMIO define and setting it before the include would follow your original scheme.
The second error that occurs is a linker error for the duplicate code blocks and declarations within heltec_unofficial.h when multiply included. In my little world, I needed to include API calls (function prototypes) for the library in multiple source files. However, using the heltec_unoffical.h unmodified, this gave me linker errors for duplicate definitions (PrintSplitter for example) and declarations.
I can overcome this second error by using two files. First, a new file heltec_unofficial_api.h that contains all of the function prototypes and PrintSplitter class definitions, that extern's the various constants and declarations. Including this heltec_unofficial_api.h file allows all of my sources to compile without any (duplicate) declarations when including the original heltec_unoffical.h. After all, this is just duplicating the prototypes and definitions.
The simple inclusion of such an API definition file (for those who wish to use it) in your library would go a long way in solving the problems I've encountered with PlatformIO. As a standalone companion to the original file, nothing else "needs to" change.
Going beyond, it is appropriate as good practice to link the original include and API declarations to avoid mismatch. To that end, I have modified the heltec_unofficial.h to include the ...api.h file to ensure the prototypes and definitions match between the two files. In doing so, I've created my own can of worms, though a little one. I've had to remove some of the default parameter specifications from the heltec_unofficial.h; though they are in the (included) ..._api.h file. I then must use one instance of the modified heltec_official.h file to declare the consts and objects used. For me, this is main.c. All other files simply include the ..._api.h file instead.
As the main.c pulls in (essentially) the same heltec_unoffical.h (and internally the heltec_unoffical_api.h), all functions work the same. I have no problem with HotButton or heltec_loop() inside loop, or display/serial/both anywhere in any file. This is really just a different compilation exercise. Of course, I get to modify everything to follow your updates since I'm going at it on my own.
Is it worth it for me to create a fork just to show this?
and again, thanks for all this.
Beta Was this translation helpful? Give feedback.
All reactions