Spatial Sensor Error
Posted: Sun Oct 23, 2016 7:28 am
Hello Everyone,
I've just got my hands on a Phidgets Spatial 3/3/3 and began to play around with it, I'm trying to create a class that will encapsulate it somewhat and clean up my main method. I'm relatively new to C++ and am having trouble figuring out where I've gone wrong.
Visual Studio is giving me the following errors
https://i.imgur.com/GfUMyaB.png
If anyone could give me a hand I would really appreciate it.
Thanks!
SpatialSensor.h
SpatialSensor.cpp
Main.cpp
I've just got my hands on a Phidgets Spatial 3/3/3 and began to play around with it, I'm trying to create a class that will encapsulate it somewhat and clean up my main method. I'm relatively new to C++ and am having trouble figuring out where I've gone wrong.
Visual Studio is giving me the following errors
https://i.imgur.com/GfUMyaB.png
If anyone could give me a hand I would really appreciate it.
Thanks!
SpatialSensor.h
Code: Select all
#pragma once
#include <phidget21.h>
#include <iostream>
class SpatialSensor {
CPhidgetSpatialHandle spatial = nullptr;
int CCONV attachHandler(CPhidgetHandle spatial, void *userPtr);
int CCONV detachHandler(CPhidgetHandle spatial, void *userPtr);
int CCONV errorHandler(CPhidgetHandle spatial, void *userPtr, int errorCode, const char *unknown);
int CCONV dataHandler(CPhidgetSpatialHandle spatial, void *userPtr, CPhidgetSpatial_SpatialEventDataHandle *data, int dataPackets);
void Terminate();
public:
double acceleration[3] = { 0.0 };
double angularRate[3] = { 0.0 };
double magneticField[3] = { 0.0 };
int Initialize();
};
Code: Select all
#include "SpatialSensor.h"
int SpatialSensor::attachHandler(CPhidgetHandle spatial, void* userPtr)
{
int serialNo;
CPhidget_getSerialNumber(spatial, &serialNo);
std::cout << "Spatial " << serialNo << " attatched!" << std::endl;
return 0;
}
int SpatialSensor::detachHandler(CPhidgetHandle spatial, void* userPtr)
{
int serialNo;
CPhidget_getSerialNumber(spatial, &serialNo);
std::cout << "Spatial " << serialNo << " detatched!" << std::endl;
return 0;
}
int SpatialSensor::errorHandler(CPhidgetHandle spatial, void* userPtr, int errorCode, const char* unknown)
{
std::cout << "Error: " << errorCode << std::endl;
return 0;
}
int SpatialSensor::dataHandler(CPhidgetSpatialHandle spatial, void* userPtr, CPhidgetSpatial_SpatialEventDataHandle* data, int dataPackets)
{
for (auto i = 0; i < dataPackets; i++)
{
for(int j = 0; j <= 2; ++j)
{
acceleration[j] = data[i]->acceleration[j];
angularRate[j] = data[i]->angularRate[j];
magneticField[j] = data[i]->magneticField[j];
}
}
return 0;
}
void SpatialSensor::Terminate()
{
CPhidget_close((CPhidgetHandle)spatial);
CPhidget_delete((CPhidgetHandle)spatial);
}
int SpatialSensor::Initialize()
{
int result;
const char *err;
CPhidgetSpatial_create(&spatial);
CPhidget_set_OnAttach_Handler((CPhidgetHandle)spatial, attachHandler, NULL);
CPhidget_set_OnDetach_Handler((CPhidgetHandle)spatial, detachHandler, NULL);
CPhidget_set_OnError_Handler((CPhidgetHandle)spatial, errorHandler, NULL);
CPhidgetSpatial_set_OnSpatialData_Handler(spatial, dataHandler, NULL);
CPhidget_open((CPhidgetHandle)spatial, -1);
if ((result = CPhidget_waitForAttachment((CPhidgetHandle)spatial, 0)))
{
return 0;
}
CPhidgetSpatial_setDataRate(spatial, 16);
return 1;
}
Code: Select all
#include "SpatialSensor.h"
int main(int argc, char* argv[])
{
SpatialSensor Sensor;
if(!Sensor.Initialize())
{
return 1;
}
// Do stuff
return 0;
}