-
Notifications
You must be signed in to change notification settings - Fork 0
/
Spatial.cpp
60 lines (49 loc) · 1.47 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
#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 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);
}
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;
}
}
Spatial::~Spatial(void)
{
}
}