• Hardware
  • Adafruit APDS9960 Proximity Sensor to Bela

I'm trying to get Adafruit proximity sensors to work on Bela.
I'm not super experienced with C++, though I've done a fair bit with Arduino.
So far I have created a header and CPP file, taken from the original Adafruit, and got it to build in the Bela IDE without any errors. However, I either commented out or used ChatGPT to try and re-write the I2c interface, which is a bit beyond my understanding to be honest!
I've put the code on GitHub and would really appreciate any pointers to bridging the I2c Vs Wire and AdafruitIO device stuff!
https://github.com/coldesstu/Bela_Adafruit_APDS9960/tree/main

Some more info:
This is the original Adafruit I2C 'begin' function:

boolean begin(uint16_t iTimeMS = 10, apds9960AGain_t = APDS9960_AGAIN_4X,uint8_t addr = APDS9960_ADDRESS, TwoWire *theWire = &Wire);

And this is my modified one:

bool begin(uint16_t iTimeMS = 10, apds9960AGain_t gain = APDS9960_AGAIN_4X, uint8_t addr = APDS9960_ADDRESS);

It's missing the reference to TwoWire as that's the Arduino I2C library. I'm not sure what I should replace that with.

What about your code doesn't work? Is any error printed to the console?

One thing that caught my eye is that you are not initialising the global variable i2c. You have this stuff commented out in begin():

// if (i2c->initI2C_RW(1, addr, 0) != 0) {
//     delete i2c;
//     i2c = nullptr;
//     return false;
// }

But as i2c is an object and not a pointer to an object, it wouldn't work. Something like this should, though:

if (i2c.initI2C_RW(1, addr, 0)) {
     return false;
}