forked from selste/TwoStepperControl
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathqencoderphidgets.cpp
More file actions
88 lines (68 loc) · 2.27 KB
/
qencoderphidgets.cpp
File metadata and controls
88 lines (68 loc) · 2.27 KB
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
#include <phidget21.h>
#include "qencoderphidgets.h"
#include <unistd.h>
#include <stdlib.h>
//-----------------------------------------------------------------------------
QEncoderPhidgets::QEncoderPhidgets(void){
int sernum, version, numEncs, numInps;
this->EH = NULL;
this->errorCreate = CPhidgetEncoder_create(&EH);
this->errorOpen = CPhidget_open((CPhidgetHandle)EH, -1);
sleep(1);
CPhidgetEncoder_setEnabled((CPhidgetEncoderHandle)EH,0,1);
CPhidget_getSerialNumber((CPhidgetHandle)EH, &sernum);
CPhidget_getDeviceVersion((CPhidgetHandle)EH, &version);
CPhidgetEncoder_getEncoderCount (EH, &numEncs);
CPhidgetEncoder_getInputCount (EH, &numInps);
this->snumifk=sernum;
this->vifk=version;
this->EncoderNum=numEncs;
this->InputNum=numInps;
this->calFactor=2.222222222;
}
//-----------------------------------------------------------------------------
QEncoderPhidgets::~QEncoderPhidgets(void){
CPhidgetEncoder_setEnabled((CPhidgetEncoderHandle)EH,0,0);
CPhidget_close((CPhidgetHandle)EH);
CPhidget_delete((CPhidgetHandle)EH);
sleep(1);
}
//-----------------------------------------------------------------------------
int QEncoderPhidgets::getTopicalReadingFromEncoder(void) {
int stepsDone;
CPhidgetEncoder_getPosition(EH, 0, &stepsDone);
return stepsDone;
}
//-----------------------------------------------------------------------------
void QEncoderPhidgets::resetEncoder(void) {
CPhidgetEncoder_setPosition(EH, 0, 0);
}
//-----------------------------------------------------------------------------
int QEncoderPhidgets::retrievePhidgetEncoderData(int what) {
int retval;
switch (what) {
case 1:
retval=this->snumifk;
break;
case 2:
retval=this->vifk;
break;
case 3:
retval=this->EncoderNum;
break;
case 4:
retval=this->InputNum;
break;
default:
retval=-1;
}
return retval;
}
//-----------------------------------------------------------------------------
void QEncoderPhidgets::setCalibrationFactor(float cf) {
this->calFactor = cf;
}
//-----------------------------------------------------------------------------
float QEncoderPhidgets::getCalibrationFactor(void) {
return calFactor;
}