just get the relevant code from the osc-test.cpp file and use it in your project, you'll need to include the .hh files as well. It's mostly about calling createAllDevicesOnBus() ( or manually populating gTouchSensors). Then put the for loop that is currently inside while(!shouldStop) into a while(!Bela_stopRequested()) loop inside an AuxiliaryTask.
However, that code may be too complicated for that, as it was designed to be generic. You may be better off with something simpler like this:
#include <Bela.h>
#include <cmath>
#include <libraries/Trill/Trill.h>
#include <libraries/OscSender/OscSender.h>
#include <oscpkt.hh>
#define NUM_TOUCH 5 // Number of touches on Trill sensor
OscSender oscSender;
Trill touchSensor;
float gTouchLocation[NUM_TOUCH] = { 0.0, 0.0, 0.0, 0.0, 0.0 };
float gTouchSize[NUM_TOUCH] = { 0.0, 0.0, 0.0, 0.0, 0.0 };
int gNumActiveTouches = 0;
unsigned int gTaskSleepTime = 7500; // microseconds
void loop(void*)
{
std::string addr = "/trill/readings/0/touches";
while(!Bela_stopRequested())
{
// Read locations from Trill sensor
touchSensor.readI2C();
oscpkt::Message msg(addr);
gNumActiveTouches = touchSensor.getNumTouches();
msg.pushFloat(gNumActiveTouches);
for(unsigned int i = 0; i < gNumActiveTouches; i++) {
gTouchLocation[i] = touchSensor.touchLocation(i);
gTouchSize[i] = touchSensor.touchSize(i);
msg.pushFloat(gTouchLocation[i]);
msg.pushFloat(gTouchSize[i]);
}
oscSender.sendNonRt(msg);
// For all inactive touches, set location and size to 0
for(unsigned int i = gNumActiveTouches; i < NUM_TOUCH; i++) {
gTouchLocation[i] = 0.0;
gTouchSize[i] = 0.0;
}
usleep(gTaskSleepTime);
}
}
bool setup(BelaContext *context, void *userData)
{
if(touchSensor.setup(1, Trill::HEX, 0x40) != 0) {
fprintf(stderr, "Unable to initialise Trill Bar\n");
return false;
}
touchSensor.printDetails();
oscSender.setup(5678, "192.168.7.1");
// Set and schedule auxiliary task for reading sensor data from the I2C bus
Bela_runAuxiliaryTask(loop);
return true;
}
void render(BelaContext *context, void *userData)
{
// your stuff
}
void cleanup(BelaContext *context, void *userData)
{}