-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathSmoothJoystick.cpp
127 lines (114 loc) · 2.75 KB
/
SmoothJoystick.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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#include "SmoothJoystick.h"
#include "controls.h"
#include <vector>
#include <bitset>
#include "612.h"
#include "main.h"
//#include <EmperorKoch.h>
SmoothJoystick::SmoothJoystick(main_robot* robot, uint32_t port): Joystick(port)
{
addButtons();
robot -> update -> addFunctions(&updateHelper, (void*)this);
}
SmoothJoystick::~SmoothJoystick()
{
}
void SmoothJoystick::addJoyFunctions(joyFunctions controlFunction, joyfuncObjects controlObject, uint32_t btn)
{
Objects.push_back(controlObject);
joystickFuncs.push_back(controlFunction);
joyfuncButtons.push_back(btn);
funcBools.push_back(false);
}
void SmoothJoystick::updateJoyFunctions()
{
for(unsigned int k = 0; k < funcBools.size(); k++)
{
/*in the format of f(object)
loop check to see if function was called before so that it runs once*/
if(GetSmoothButton(joyfuncButtons.at(k)))
{
if(!funcBools.at(k))
{
(joystickFuncs.at(k))(Objects.at(k),joyfuncButtons.at(k));
funcBools.at(k)=true;
}
}
else
{
funcBools.at(k)=false;
}
}
}
void SmoothJoystick::addButtons()
{
for(int m = 0; m < NUMBUTTONS; m++)
{
std::bitset<3>* newButton = new std::bitset<3>();
buttons.push_back(newButton);
}
}
bool SmoothJoystick::GetSmoothButton(int Button_number)
{
int value1 = (buttons.at(Button_number))->at(0);
int value2 = (buttons.at(Button_number))->at(1);
int value3 = (buttons.at(Button_number))->at(2);
if(value1 == 1 && value2 == 1 && value3 == 1)
{
return true;
}
else
{
return false;
}
}
void SmoothJoystick::buttonUpdate()
{
for(int k = 0; k < NUMBUTTONS; k++)
{
std::bitset<3>* btnSet = buttons.at(k);
btnSet->at(2) = btnSet->at(1);
btnSet->at(1) = btnSet->at(0);
btnSet->at(0) = GetRawButton(k);
}
}
trigStates SmoothJoystick::GetTriggerState()//accepts axis port, returns 1 or -1 if axis value is in the Trigger tolerance range
{
double a = GetRawAxis(AXIS_TRIGGERS);
if(a < 0)
{
a = (a * -1);
}
if(a > TRIGGER_TOLERANCE)
{
if(GetRawAxis(AXIS_TRIGGERS) > 0)
{
return TRIG_L;
}
else
{
return TRIG_R;
}
}
else
{
return TRIG_NONE;
}
}
bool SmoothJoystick::IsAxisZero(uint32_t axis)
{
if(GetRawAxis(axis) >= (DEADZONE * -1) && GetRawAxis(axis) <= (DEADZONE))
{
return true;
}
else
{
return false;
}
}
void SmoothJoystick::updateHelper(void* instName)
{
SmoothJoystick* smoothObj = (SmoothJoystick*)instName;
smoothObj -> updateJoyFunctions();
smoothObj -> buttonUpdate();
}