Hello Blynks,
I am a C++ and Blynk newbie, so my question might be answered before, but I have not found anything. I am not sure I can even explain my problem in the right C++ terms
I am using a Particle Photon board.
I would like to call Blynk functions from different classes defined in different libraries.
Ex. Parse the Blynk object to another object, that takes care of my DS18B20 sensors, so this object can update my Blynk App. Or implement all my Blynk stuff in one library, and expose the Blynk objects.
I can make a pointer variable to the main Blynk object defined in âBlynkSimpleParticle_hâ
// myBlynkTest.h
#include "blynk/BlynkParticle.h"
class BlynkPrtTestClass {
public:
BlynkParticle *BlynkPrt;
BlynkPrtTestClass(BlynkParticle *_BlynkPrt);
void testBlynk();
};
// end - myBlynkTest.h
// myBlynkTest.cpp
#include " myBlynkTest.h "
BlynkPrtTestClass::BlynkPrtTestClass(BlynkParticle *_BlynkPrt) {
BlynkPrt = _BlynkPrt;
}
void BlynkPrtTestClass::testBlynk() {
BlynkPrt->virtualWrite(V8,millis());
}
// end - myBlynkTest.cpp
// test.ino
#include "myBlynkTest.h"
#include "blynk/blynk.h"
char auth[] = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
BlynkPrtTestClass ObjWithBlynk(&Blynk);
void setup() {
Blynk.begin(auth);
while (Blynk.connect() == false) {
}
}
uint32_t lastBlynkMillis=0;
void loop() {
Blynk.run();
if(millis()-lastBlynkMillis>2000) {
lastBlynkMillis=millis();
ObjWithBlynk.testBlynk();
}
}
// end - test.ino
But I would like to do the same for the widget objects. For example define a pointer-variable to a led, terminal or LCD object in a âcustomâ class declared in separate .h file. For example having a DS18B20 class with a pointer-variable pointing at a WidgetTerminal object.
In the WidgetXXX.h files, the Blynk object is expected to be âknownâ, but that happens in âBlynkSimpleParticle_hâ, which I can not include in a library file be course âBlynkâ is already defined ?
I have âsolvedâ the problem by making my own versions of the WidgetXXX.h files and use a BlynkParticle pointer as argument for the constructor event â and move the declaration of:
static BlynkTransportParticle _blynkTransport;
BlynkParticle Blynk(_blynkTransport);
to the .ino file, so I donât use âBlynk.hâ & âBlynkSimpleParticle.hâ.
This seems to work, but now I am not using the standard Blynk libraries and will have to update manually when new Blynk libraries are deployed !
Is this really stupid and is there a smarter solution ?
Br Michael