Hello,
one issue with your code is that you are creating an AuxiliaryTask
but you never actually run it.
Auxiliary tasks need to be scheduled in order for the callback function to be executed. You have two options here.
If you want to check the state of your sensor at regular intervals, your callback should include an infinite loop such as:
void readTCS34725(){
// init code here , if any, for the resources used in the loop
while(!gShouldStop){
/// your code to be run periodically here,
/// it may well be the entire content of your current
/// implementation of readTCS34725()
usleep(10000); // interval often should it run, in microseconds
}
/// cleanup code, if any, for the resources used in the loop
}
doing so, you can schedule the task only once (e.g.: in setup()
) with
Bela_scheduleAuxiliaryTask(i2cTask)
and the inner loop will run forever (until the global variable gShouldStop
is set upon program termination).
Probably the above is what you want.
If - instead - you have to check at irregular intervals, or want to manually trigger each scan of the sensor then you can keep your current implementation of readTCS34725()
and run
Bela_scheduleAuxiliaryTask(i2cTask);
from the render()
function every time you need it.
NOTE: with the second approach you, you may end up scheduling the task while the older instance of it is still running. If that is the case, the call to Bela_scheduleAuxiliaryTask()
will be ignored. I believe an I2C transaction could take up to a few milliseconds (upper limit: unbound), so it would make little sense to call Bela_scheduleAuxiliaryTask()
too often (e.g.: once per every audio block).
Note that I did not have a look at your I2C code / library (I don't know much about that!)
See if this works