Closed EnduIf closed 4 years ago
We ran into a lot of compiling problems when we tried to seperate. Thats why we keept it the easy way.
But, why do you need multiple includes? This makes no sense to me. SinricPro is designed to run multiple devices (simultaneusly)with just one instance of SinricProClass.
For very special situations, you can run multiple instances of the SinricProClass. But again: this is not necessary to run multiple devices.
I don't want to have multible instances of the SinricProClass. I want the class declaration of the SinricProClass so that i am able to pass an instance of the SinricProClass to function for example. But you can't import SinricPro twice for the declaration because of the definitions in the header file.
Yeah, that's right. The SinricProClass is rather designed as a global object. A transfer as function parameter was not intended. May I ask what exactly do you intend to do?
As a work-around: The SinricProClass inherits from the SinricProInterface. You can extend the interface by the required methods of the SinricProClass and pass the interface class as function parameter. Maybe this is an option for you?
I just want to create some custom classes in other files and pass an instance of the SinricProClass to those classes. But because of that I also need the declaration of the SinricProClass in those files where the classes are.
Ok, got it. For this you can write a simple "include wrapper":
//sp_include_wrapper.h
#ifndef _sp_include_wrapper_h_
#define _sp_include_wrapper_h_
#include "SinricPro.h"
#endif
Now you can include this sp_include_wrapper.h
to the main file and your extra files like this:
//test.h
#ifndef _test_h_
#define _test_h_
#include "sp_include_wrapper.h"
void test(SinricProClass &sp) {
unsigned long timestamp = sp.getTimestamp();
}
#endif
//main.cpp
include <Arduino.h>
#include "sp_include_wrapper.h"
#include "SinricProSwitch.h"
#include "test.h"
...
Did this work for you?
Yes thank you.
Hello,
I want to help a Friend with some home automation and at the same time encourage him to write good code. But because of the not existing separation of declaration and definition of your library multible imports of SinricPro are not possible and so its hard to outsource code into other files that need declarations of SinricPro.
Now i'm wondering why everything has been put into header files and if i am overlooking something that still allows to include SinricPro twice.