B4R Question how to use #if / #else / #endif in inline C part?

candide

Active Member
Licensed User
i wanted to used an arduino code in inline C, but i had to remove #if , #else and #endif inside this code...
do we have a way to used Preprocessor Directives in inline C ?

B4X:
#If C
#include <Wire.h>

// --------------------------------------
// i2c_scanner
// Modified from https://playground.arduino.cc/Main/I2cScanner/
// --------------------------------------
TwoWire WIRE;
//#define WIRE Wire;
// Set I2C bus To use: Wire, Wire1, etc.
void setupI2C (B4R::Object* o) {
//  WIRE.begin(5,4);  //Case esp8266 or esp32 
  WIRE.begin();   //sda And scl by default 
}

void scan_I2C (B4R::Object* o) {
  uint16_t address = o->toULong();

  // The i2c_scanner uses the Return value of
  // the Write.endTransmisstion To see If
  // a device did acknowledge To the address.
  WIRE.beginTransmission(address);
  b4r_main::_results = WIRE.endTransmission();
}

// Fast read 8-Bit from register
void scan_MPU (B4R::Object* o) {
    int16_t reg = 0x75;
    int16_t mpuAddress = o->toULong();
    uint8_t value;

    WIRE.beginTransmission(mpuAddress);
//    #if ARDUINO >= 100
        WIRE.write(reg);
//    #else
//        WIRE.send(reg);
//    #endif;
    WIRE.endTransmission();

    WIRE.beginTransmission(mpuAddress);
    WIRE.requestFrom(mpuAddress, 1);
    while(!Wire.available()) {};
//    #if ARDUINO >= 100
        b4r_main::_resultmpu = WIRE.read();
//    #else
//       b4r_main::_resultmpu = WIRE.receive();
//    #endif;
    WIRE.endTransmission();
}
#End if
[end code]
 

teddybear

Well-Known Member
Licensed User
You can use #ifdef to provide conditional compilation in inline C
 
Upvote 0
Top