Connecting and Detecting Multiple Trill
This example scans the I2C bus for Trill sensors and will then generate a GUI element for each one.
NOTE: as this example scans several addresses on the i2c bus it could cause non-Trill peripherals connected to it to malfunction.
#include <libraries/Trill/Trill.h>
#include <libraries/Gui/Gui.h>
std::vector<Trill*> gTouchSensors;
unsigned int gSampleCount = 0;
float gSendInterval = 0.1;
unsigned int gSendIntervalSamples;
bool controlCallback(JSONObject& json, void*)
{
JSONObject root;
root[L
"event"] =
new JSONValue(L
"connectedDevices");
JSONArray devices;
for(auto t : gTouchSensors) {
}
return true;
}
void readLoop(void*)
{
{
for(unsigned int n = 0; n < gTouchSensors.size(); ++n)
{
Trill* t = gTouchSensors[n];
}
usleep(50000);
}
}
{
unsigned int i2cBus = 1;
for(uint8_t addr = 0x20; addr <= 0x50; ++addr)
{
{
gTouchSensors.push_back(
new Trill(i2cBus, device, addr));
gTouchSensors.back()->printDetails();
}
}
return true;
}
{
{
gSampleCount++;
if(gSampleCount == gSendIntervalSamples)
{
gSampleCount = 0;
float arr[3];
for(unsigned int t = 0; t < gTouchSensors.size(); ++t) {
arr[0] = gTouchSensors[t]->compoundTouchSize();
arr[1] = gTouchSensors[t]->compoundTouchLocation();
arr[2] = gTouchSensors[t]->compoundTouchHorizontalLocation();
rt_printf("[%d] %2.3f %.3f %.3f ", t, arr[0], arr[1], arr[2]);
}
rt_printf("\n");
}
}
}
{
for(auto t : gTouchSensors)
delete t;
}