Could anyone tell me how to correctly access these B4R public variables within the embedded C code?
I would greatly appreciate any help!
I would greatly appreciate any help!
B4R:
Sub Process_Globals
Public Serial1 As Serial
Public ShuntVoltage As Float
Public Voltage As Float
Public Corrente As Float
Public Pontencia As Float
Public LoadVoltage As Float
End Sub
Private Sub AppStart
Serial1.Initialize(115200)
Log("AppStart")
RunNative("InitINA", Null)
StartReading
End Sub
Sub StartReading
AddLooper("LoopINA")
End Sub
Sub LoopINA
RunNative("ReadINA", Null)
Log("Tensão: ", Voltage, " V | Corrente: ", Corrente, " mA | Potência: ", Pontencia, " mW")
Delay(1000)
End Sub
#If C
#include <Wire.h>
#include <Adafruit_INA219.h>
Adafruit_INA219 ina219;
void InitINA(B4R::Object* o) {
ina219.begin();
}
void ReadINA(B4R::Object* o) {
float shunt = ina219.getShuntVoltage_mV();
float bus = ina219.getBusVoltage_V();
float current = ina219.getCurrent_mA();
float power = ina219.getPower_mW();
float load = bus + (shunt / 1000);
// Atribuindo aos campos públicos declarados no B4R
b4r_main::_ShuntVoltage = shunt;
b4r_main::_Voltage = bus;
b4r_main::_Corrente = current;
b4r_main::_Pontencia = power;
b4r_main::_LoadVoltage = load;
}
#End If