EDIT: Solved = See post #6. Note: Removed the attachement as the reworked B4R library will be shared in the B4R Libraries forum.
This is question is related to the partial wrapping of the ESP32 lib Legoino to B4R lib rLegoinoBoost.
The lib Legoino requires callbacks to access device property values. These are defined as local functions in the rLegoinoBoost.cpp.
In the header rLegoinoBoost.h, property members are defined, like batteryLevel.
Q: How to assign the batteryLevel from the local callback functions defined in the cpp file?
This is the error message from the code below:
See code snippets.
rLegoinoBoost.h
rLegoinoBoost.cpp
See ==> for the problem.
This is question is related to the partial wrapping of the ESP32 lib Legoino to B4R lib rLegoinoBoost.
The lib Legoino requires callbacks to access device property values. These are defined as local functions in the rLegoinoBoost.cpp.
In the header rLegoinoBoost.h, property members are defined, like batteryLevel.
Q: How to assign the batteryLevel from the local callback functions defined in the cpp file?
This is the error message from the code below:
C++:
rLegoinoBoost.cpp:241:68: error: cannot call member function 'void B4R::B4RLegoinoBoost::SetBatteryLevel(Byte)' without object
rLegoinoBoost.h
C++:
namespace B4R {
//~shortname: LegoinoBoost
class B4RLegoinoBoost {
private:
SubVoidBool StateChangedSub;
Byte batteryLevel; <== how to update via local callback?
static void checkForData(void* b);
PollerNode pnode;
public:
...
void SetBatteryLevel(Byte level);
Byte getBatteryLevel();
...
};
}
rLegoinoBoost.cpp
See ==> for the problem.
C++:
namespace B4R {
...
Byte batteryLevelLocal;
void B4RLegoinoBoost::SetBatteryLevel(Byte level) { batteryLevel = level; }
Byte B4RLegoinoBoost::getBatteryLevel() { return batteryLevel; }
// Callbacks for properties Battery Level & Voltage
void hubPropertyChangeCallback(void *hub, HubPropertyReference hubProperty, uint8_t *pData) {
Lpf2Hub *myHub = (Lpf2Hub *)hub;
if (hubProperty == HubPropertyReference::BATTERY_VOLTAGE) {
==> // ERROR = How to assign the batterylevel to the class member batteryLevel
rLegoinoBoost.cpp:241:68: error: cannot call member function 'void B4R::B4RLegoinoBoost::SetBatteryLevel(Byte)' without object
==> B4RLegoinoBoost::SetBatteryLevel(myHub->parseBatteryLevel(pData));
// Woraround using local var
batteryLevelLocal = myHub->parseBatteryLevel(pData);
return;
}
}
// Looper handling movehub connection
void B4RLegoinoBoost::checkForData(void* b) {
B4RLegoinoBoost* me = (B4RLegoinoBoost*)b;
if (MoveHub.isConnecting()){
MoveHub.connectHub();
if (MoveHub.isConnected() && !isInitialized){
// Delay needed because otherwise the message is to fast after the connection procedure and the message will get lost
delay(50);
MoveHub.activateHubPropertyUpdate(HubPropertyReference::BATTERY_VOLTAGE, hubPropertyChangeCallback);
isInitialized = true;
}
}
// Update battery state and other hub properties
if (MoveHub.isConnected()) {
// Assing the local var values to the b4r class values
// TODO: need to find a way how to assign the updated values using the local callback functions and not use below line on every loop
me->batteryLevel = batteryLevelLocal;
}
}
}
Last edited: