B4R Question Error accessing B4R public variables via embedded C code (INA219)

Cesar_Morisco

Active Member
Licensed User
Longtime User
Could anyone tell me how to correctly access these B4R public variables within the embedded C code?
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
 

Cableguy

Expert
Licensed User
Longtime User
This should give you a push in the right direction:
 
Upvote 0

candide

Active Member
Licensed User
if you have a look at B4Rmain.h in Objects directory, all B4R variables are converted to lowercase :
B4X:
class b4r_main {
public:

static void initializeProcessGlobals();
static void _appstart();
static void _loopina();
static void _process_globals();
static B4R::Serial* _serial1;
static Double _shuntvoltage;
static Double _voltage;
static Double _corrente;
static Double _pontencia;
static Double _loadvoltage;
 
Upvote 0

Cesar_Morisco

Active Member
Licensed User
Longtime User
if you have a look at B4Rmain.h in Objects directory, all B4R variables are converted to lowercase :
B4X:
class b4r_main {
public:

static void initializeProcessGlobals();
static void _appstart();
static void _loopina();
static void _process_globals();
static B4R::Serial* _serial1;
static Double _shuntvoltage;
static Double _voltage;
static Double _corrente;
static Double _pontencia;
static Double _loadvoltage;
Hello Cândido
Thanks for the answer
It has already been resolved
What a wonderful sensor
A hug
 
Upvote 0
Top