-
Notifications
You must be signed in to change notification settings - Fork 0
/
Spatial.cpp
84 lines (69 loc) · 2.03 KB
/
Spatial.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#include "Spatial.h"
#include <iostream>
using namespace phidgets;
using namespace std;
namespace phidgets {
Spatial::Spatial(void):
Phidget(),
spatial_handle_(0)
{
int result;
CPhidgetSpatial_create(&spatial_handle_);
Phidget::init((CPhidgetHandle) spatial_handle_);
Phidget::registerHandlers();
CPhidgetSpatial_set_OnSpatialData_Handler(spatial_handle_, SpatialDataHandler, this);
Phidget::open();
printf("Waiting for spatial to be attached.... \n");
if((result = waitForAttachment(10000)))
{
printf("Problem waiting for attachment \n");
}
}
void Spatial::zero()
{
// zero (calibrate) gyro
CPhidgetSpatial_zeroGyro(spatial_handle_);
}
int Spatial::getAcceleration(int axis)
{
double acceleration;
CPhidgetSpatial_getAcceleration(spatial_handle_, axis, &acceleration);
return acceleration;
}
int CCONV Spatial::SpatialDataHandler(CPhidgetSpatialHandle handle, void *userptr, CPhidgetSpatial_SpatialEventDataHandle *data, int count)
{
((Spatial*)userptr)->dataHandler(data, count);
return 0;
}
void Spatial::setDataRate(int rate)
{
CPhidgetSpatial_setDataRate(spatial_handle_, rate);
}
int Spatial::getDataRate()
{
int milliseconds;
CPhidgetSpatial_getDataRate(spatial_handle_, &milliseconds);
return milliseconds;
}
void Spatial::printData()
{
cout << arr[0] << " " << arr[1] << " " << arr[2] << endl;
}
void Spatial::dataHandler(CPhidgetSpatial_SpatialEventDataHandle *data, int count)
{
// cout << "Number of Data Packets in this event: " << count << endl;
/*for(int i = 0; i < count; i++)
{
cout << "=== Data Set:" << i << "===" << endl;
cout <<"Acceleration> x: " << data[i]->acceleration[0] << " y: " << data[i]->acceleration[1] << " z: " << data[i]->acceleration[2] << endl;
cout << "Timestamp> seconds: " << data[i]->timestamp.seconds << "-- microseconds: " << data[i]->timestamp.microseconds << endl;
}*/
for(int i = 0; i < 3; i++)
{
arr[i] = data[0]->acceleration[i];
}
}
Spatial::~Spatial(void)
{
}
}