forked from rbmj/612-guillotine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjoysmooth.cpp
90 lines (72 loc) · 1.86 KB
/
joysmooth.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
#include <bitset>
#include <GenericHID.h>
#include "612.h"
#include "update.h"
#include "joysmooth.h"
//provide definition of constants:
const int joysmooth::HOLDBACK;
const int joysmooth::NUMBUTTONS;
const int joysmooth::NUMAXES;
void register_callback(void*);
void update_callback_joysmooth(void*);
joysmooth::joysmooth(GenericHID* ghid) : joy(ghid) {
register_callback((void*)this);
}
joysmooth::joysmooth(GenericHID& ghid) : joy(&ghid) {
register_callback((void*)this);
}
joysmooth::~joysmooth() {
registry().unregister_func(update_callback_joysmooth, (void*)this);
}
void joysmooth::update() {
for (int d = 0; d < NUMBUTTONS; d++) {
for (int i = 1; i < HOLDBACK; i++) {
buttons[d][i - 1] = buttons[d][i];
}
buttons[d][HOLDBACK - 1] = joy->GetRawButton(d);
}
for(int d = 0; d < NUMAXES; d++) {
axes[d] = joy->GetRawAxis(d);
}
}
float joysmooth::GetX(JoystickHand h) {
return axes[X_AXIS];
}
float joysmooth::GetY(JoystickHand h) {
return axes[Y_AXIS];
}
float joysmooth::GetZ(){
return axes[Z_AXIS];
}
float joysmooth::GetTwist(){
return axes[TWIST_AXIS];
}
float joysmooth::GetThrottle(){
return axes[THROTTLE_AXIS];
}
float joysmooth::GetRawAxis(UINT32 axisId){
return axes[axisId];
}
bool joysmooth::GetTrigger(JoystickHand hand){
return GetRawButton(1);
}
bool joysmooth::GetTop(JoystickHand hand){
return GetRawButton(2);
}
bool joysmooth::GetBumper(JoystickHand hand){
return joy->GetBumper();
}
bool joysmooth::GetRawButton(UINT32 btnId){
for(int i = 0; i < HOLDBACK; i++) {
if(!buttons[btnId][i]) {
return false;
}
}
return true;
}
void register_callback(void* thisPtr) {
registry().register_func(update_callback_joysmooth, thisPtr);
}
void update_callback_joysmooth(void* thisPtr) {
((joysmooth*)thisPtr)->update();
}