-
Notifications
You must be signed in to change notification settings - Fork 1
/
Controllers.cpp
138 lines (115 loc) · 3.21 KB
/
Controllers.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
128
129
130
131
132
133
134
135
136
137
138
#include "Controllers.h"
#define FIRE_CATAPULT_BUTTON 1
#define SAFE_CATAPULT_BUTTON 9
#define EJECT_BALL_BUTTON 6
#define EJECT_BALL_FRONT 7
#define FEEDER_TOGGLE_BUTTON 3
#define GEAR_SHIFT_DOWN_BUTTON 4
#define GEAR_SHIFT_UP_BUTTON 5
#define CAMERA_LIGHT_BUTTON 11
#define DEBUG_ARM_BUTTON 15
#define SWITCH_DIRECTION_BUTTON 8
Controllers::Controllers(float period, int driverStickNum, int helperStickNum)
{
//helperStick = new Joystick(helperStickNum);
driverStick = new Joystick(driverStickNum);
//DriveCommandLeft = 0;
//DriveCommandRight = 0;
FireCatapult = false;
EjectBall = false;
FeederLeftPressed = false;
FeederRightPressed = false;
HighGearToggle = false;
PrevHighGearButton = false;
LightButtonPressed = false;
PrevLightButtonPressed = false;
this->period = period;
}
void Controllers::GetInputs()
{
FireCatapult = driverStick->GetRawButton(FIRE_CATAPULT_BUTTON);
SafetyFireCatapult = driverStick->GetRawButton(SAFE_CATAPULT_BUTTON);
EjectBall = driverStick->GetRawButton(EJECT_BALL_BUTTON);
EjectBallFront = driverStick->GetRawButton(EJECT_BALL_FRONT);
bool CurrentHighGearToggleButton = driverStick->GetRawButton(GEAR_SHIFT_DOWN_BUTTON) || driverStick->GetRawButton(GEAR_SHIFT_UP_BUTTON);
if (! PrevHighGearButton && CurrentHighGearToggleButton)
{
HighGearToggle = !HighGearToggle;
}
PrevHighGearButton=CurrentHighGearToggleButton;
bool CurrentFeederLeftPressed = driverStick->GetRawButton(FEEDER_TOGGLE_BUTTON);
if( !PrevFeederLeftPressed && CurrentFeederLeftPressed)
FeederLeftPressed=true;
else
FeederLeftPressed=false;
PrevFeederLeftPressed = CurrentFeederLeftPressed;
bool CurrentFeederRightPressed = driverStick->GetRawButton(FEEDER_TOGGLE_BUTTON);
if( !PrevFeederRightPressed && CurrentFeederRightPressed)
FeederRightPressed=true;
else
FeederRightPressed=false;
PrevFeederRightPressed = CurrentFeederRightPressed;
DebugArmButton = driverStick->GetRawButton(DEBUG_ARM_BUTTON);
bool CurrentLightPressed = driverStick->GetRawButton(CAMERA_LIGHT_BUTTON);
if( !PrevLightButtonPressed && CurrentLightPressed)
LightButtonPressed=true;
else
LightButtonPressed=false;
PrevLightButtonPressed = CurrentLightPressed;
bool BackwardDirection = driverStick->GetRawButton(SWITCH_DIRECTION_BUTTON);
if (!ForwardDirection && BackwardDirection){
BackwardButton = true;
}
else {
BackwardButton = false;
}
ForwardDirection = BackwardDirection;
}
bool Controllers::IsHighGearButtonPressed()
{
return HighGearToggle;
}
bool Controllers::IsFireButtonPressed()
{
return FireCatapult;
}
bool Controllers::IsFireSafetyButtonPressed()
{
return SafetyFireCatapult;
}
bool Controllers::IsEjectButtonPressed()
{
return EjectBall;
}
bool Controllers::IsEjectButtonFront()
{
return EjectBallFront;
}
bool Controllers::IsFeederLeftButtonPressed()
{
return FeederLeftPressed;
}
bool Controllers::IsFeederRightButtonPressed()
{
return FeederRightPressed;
}
Joystick* Controllers::GetDriverJoystick()
{
return driverStick;
}
bool Controllers::IsDebugArmButtonPressed()
{
return DebugArmButton;
}
bool Controllers::IsLightButtonPressed()
{
return LightButtonPressed;
}
float Controllers::GetPeriod()
{
return period;
}
bool Controllers::IsBackwardDirectionPressed()
{
return BackwardButton;
}