-
Notifications
You must be signed in to change notification settings - Fork 0
/
Phidget.cpp
94 lines (77 loc) · 1.81 KB
/
Phidget.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
85
86
87
88
89
90
91
92
93
94
#include "Phidget.h"
#include <iostream>
using namespace std;
namespace phidgets {
Phidget::Phidget(void)
{
}
Phidget::~Phidget(void)
{
CPhidget_delete(handle_);
}
int Phidget::AttachHandler(CPhidgetHandle spatial, void *userptr)
{
((Phidget*)userptr)->attachHandler();
return 0;
}
int Phidget::DetachHandler(CPhidgetHandle spatial, void *userptr)
{
((Phidget*)userptr)->detachHandler();
return 0;
}
int Phidget::ErrorHandler(CPhidgetHandle handle, void *userptr, int ErrorCode, const char *unknown)
{
((Phidget*)userptr)->errorHandler(ErrorCode);
return 0;
}
void Phidget::init(CPhidgetHandle handle)
{
handle_ = handle;
cout << "Initialized" << endl;
}
void Phidget::registerHandlers(void)
{
CPhidget_set_OnAttach_Handler(handle_, AttachHandler, this);
CPhidget_set_OnDetach_Handler(handle_, DetachHandler, this);
CPhidget_set_OnError_Handler(handle_, ErrorHandler, this);
cout << "Registered handles" << endl;
}
int Phidget::open()
{
return CPhidget_open(handle_,-1);
}
int Phidget::close()
{
cout << "Closing Phidget Device" << endl;
return(CPhidget_close(handle_));
}
int Phidget::waitForAttachment(int timeout)
{
return CPhidget_waitForAttachment(handle_, timeout);
}
std::string Phidget::getErrorDescription(int errorCode)
{
char a[1000];
const char * errorPtr = a;
CPhidget_getErrorDescription(errorCode, &errorPtr);
return std::string(errorPtr);
}
int Phidget::getDeviceSerialNumber()
{
int serNum;
CPhidget_getSerialNumber(handle_, &serNum);
return serNum;
}
void Phidget::attachHandler()
{
cout << "Phidget attached : " << getDeviceSerialNumber() << endl;
}
void Phidget::detachHandler()
{
cout << "Phidget detached : " << getDeviceSerialNumber() << endl;
}
void Phidget::errorHandler(int error)
{
cout << "Phidget error " << error << getErrorDescription(error).c_str();
}
}