Spatial Sensor Error

C, C++, and Visual C++
Post Reply
Hobgoblin
Fresh meat
Posts: 2
Joined: Sun Oct 23, 2016 7:15 am
Contact:

Spatial Sensor Error

Post by Hobgoblin »

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

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();

};
SpatialSensor.cpp

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;
}
Main.cpp

Code: Select all

#include "SpatialSensor.h"

int main(int argc, char* argv[])
{
	SpatialSensor Sensor;
	if(!Sensor.Initialize())
	{
		return 1;
	}

	// Do stuff

	return 0;
}
Hobgoblin
Fresh meat
Posts: 2
Joined: Sun Oct 23, 2016 7:15 am
Contact:

Re: Spatial Sensor Error

Post by Hobgoblin »

It seems the handler methods needed to be static! :o
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 0 guests