Hi!
I’m trying to build an add-on to connect to Phidget devices
Thanks to the examples provided I managed to connect to the device, but now I’m facing my lack of computer science knowledge since the function provided in the framework to retrieve the data is totally out of my scope.
It is the last function listed here. I really don’t get the second parameter. Any advice??
Here is my cpp, so far:
#include "ofxPhidgetSpatial.h"
int CCONV CAttachHandler(CPhidgetHandle spatial, void *userptr)
{
((ofxPhidgetSpatial *)userptr)->AttachHandler(spatial);
return 0;
}
int CCONV CDetachHandler(CPhidgetHandle spatial, void *userptr)
{
((ofxPhidgetSpatial *)userptr)->DetachHandler(spatial);
return 0;
}
int CCONV CErrorHandler(CPhidgetHandle spatial, void *userptr, int ErrorCode, const char *unknown)
{
((ofxPhidgetSpatial *)userptr)->ErrorHandler(spatial,ErrorCode,unknown);
return 0;
}
int CCONV CSpatialDataHandler(CPhidgetHandle spatial, void *userptr, CPhidgetSpatial_SpatialEventDataHandle *data, int count)
{
((ofxPhidgetSpatial *)userptr)->SpatialDataHandler(spatial, data, count);
return 0;
}
void ofxPhidgetSpatial::start(int dataRate)
{
CPhidgetSpatial_create(&spatial);
CPhidget_set_OnAttach_Handler((CPhidgetHandle)spatial, CAttachHandler, this);
CPhidget_set_OnDetach_Handler((CPhidgetHandle)spatial, CDetachHandler, this);
CPhidget_set_OnError_Handler((CPhidgetHandle)spatial, CErrorHandler, this);
CPhidget_open((CPhidgetHandle)spatial, -1);
CPhidgetSpatial_setDataRate(spatial, dataRate);
}
void ofxPhidgetSpatial::read()
{
//CPhidgetSpatial_set_OnSpatialData_Handler((CPhidgetHandle)spatial, CSpatialDataHandler, this);
CPhidgetSpatial_set_OnSpatialData_Handler((CPhidgetSpatialHandle)spatial, CSpatialDataHandler, NULL);
}
void ofxPhidgetSpatial::stop()
{
CPhidget_close((CPhidgetHandle) spatial);
CPhidget_delete((CPhidgetHandle) spatial);
}
int ofxPhidgetSpatial::AttachHandler(CPhidgetHandle spatial)
{
int serialNo;
CPhidget_getSerialNumber(spatial, &serialNo);
printf("Spatial %10d attached!\n", serialNo);
return 0;
}
int ofxPhidgetSpatial::DetachHandler(CPhidgetHandle spatial)
{
int serialNo;
CPhidget_getSerialNumber(spatial, &serialNo);
printf("Spatial %10d detached!\n", serialNo);
return 0;
}
int ofxPhidgetSpatial::ErrorHandler(CPhidgetHandle spatial, int ErrorCode, const char *unknown)
{
printf("Error handled. %d - %s", ErrorCode, unknown);
return 0;
}
int ofxPhidgetSpatial::SpatialDataHandler(CPhidgetHandle spatial, CPhidgetSpatial_SpatialEventDataHandle *data, int count)
{
int i;
printf("Number of Data Packets in this event: %d\n", count);
for(i = 0; i < count; i++)
{
printf("=== Data Set: %d ===\n", i);
printf("Acceleration> x: %6f y: %6f x: %6f\n", data[i]->acceleration[0], data[i]->acceleration[1], data[i]->acceleration[2]);
printf("Angular Rate> x: %6f y: %6f x: %6f\n", data[i]->angularRate[0], data[i]->angularRate[1], data[i]->angularRate[2]);
printf("Magnetic Field> x: %6f y: %6f x: %6f\n", data[i]->magneticField[0], data[i]->magneticField[1], data[i]->magneticField[2]);
printf("Timestamp> seconds: %d -- microseconds: %d\n", data[i]->timestamp.seconds, data[i]->timestamp.microseconds);
}
printf("---------------------------------------------\n");
return 0;
}
The problem is inside the read() function, the second parameter is somehow not correct.
Thanks in advance!