Add key listener to runFlyWheel
[3501/2017steamworks] / src / org / usfirst / frc / team3501 / robot / OI.java
1 package org.usfirst.frc.team3501.robot;
2
3 import java.awt.event.KeyAdapter;
4 import java.awt.event.KeyEvent;
5
6 import javax.swing.JButton;
7
8 import org.usfirst.frc.team3501.robot.commands.climber.ToggleWinch;
9 import org.usfirst.frc.team3501.robot.commands.driving.ToggleGear;
10 import org.usfirst.frc.team3501.robot.commands.intake.ReverseIntakeContinuous;
11 import org.usfirst.frc.team3501.robot.commands.intake.RunIntakeContinuous;
12 import org.usfirst.frc.team3501.robot.commands.shooter.DecreaseShootingSpeed;
13 import org.usfirst.frc.team3501.robot.commands.shooter.IncreaseShootingSpeed;
14 import org.usfirst.frc.team3501.robot.commands.shooter.ReverseIndexWheelContinuous;
15 import org.usfirst.frc.team3501.robot.commands.shooter.RunFlyWheelContinuous;
16 import org.usfirst.frc.team3501.robot.commands.shooter.RunIndexWheelContinuous;
17
18 import edu.wpi.first.wpilibj.Joystick;
19 import edu.wpi.first.wpilibj.buttons.Button;
20 import edu.wpi.first.wpilibj.buttons.JoystickButton;
21
22 public class OI {
23 private static OI oi;
24 public static Joystick leftJoystick;
25 public static Joystick rightJoystick;
26 public static Button toggleWinch;
27
28 public static Button runIndexWheel;
29 public static Button reverseIndexWheel;
30 // public static Button toggleFlyWheel;
31 public static JButton toggleFlyWheel;
32
33 public static Button toggleGear;
34
35 public static Button runIntake;
36 public static Button reverseIntake;
37
38 public static Button increaseShooterSpeed;
39 public static Button decreaseShooterSpeed;
40
41 // private static Key a;
42
43 public OI() {
44 leftJoystick = new Joystick(Constants.OI.LEFT_STICK_PORT);
45 rightJoystick = new Joystick(Constants.OI.RIGHT_STICK_PORT);
46
47 runIndexWheel = new JoystickButton(rightJoystick,
48 Constants.OI.RUN_INDEXWHEEL_PORT);
49 runIndexWheel.whileHeld(new RunIndexWheelContinuous());
50
51 reverseIndexWheel = new JoystickButton(rightJoystick,
52 Constants.OI.REVERSE_INDEXWHEEL_PORT);
53 reverseIndexWheel.whileHeld(new ReverseIndexWheelContinuous());
54
55 /*
56 * toggleFlyWheel = new JoystickButton(rightJoystick,
57 * Constants.OI.TOGGLE_FLYWHEEL_PORT); toggleFlyWheel.toggleWhenPressed(new
58 * RunFlyWheelContinuous());
59 */
60
61 toggleFlyWheel = new JButton();
62 toggleFlyWheel.addKeyListener(new KeyAdapter() {
63 RunFlyWheelContinuous runflywheel = new RunFlyWheelContinuous();
64
65 /***
66 * Starts the run index wheel continuous function
67 */
68 @Override
69 public void keyPressed(KeyEvent e) {
70 if (e.getKeyCode() == KeyEvent.VK_0) {
71 runflywheel.start();
72 }
73 }
74
75 /***
76 * Ends the run index wheel continuous function
77 */
78 @Override
79 public void keyReleased(KeyEvent e) {
80 if (e.getKeyCode() == KeyEvent.VK_0) {
81 runflywheel.cancel();
82 }
83 }
84
85 });
86
87 toggleGear = new JoystickButton(leftJoystick,
88 Constants.OI.TOGGLE_GEAR_PORT);
89 toggleGear.whenPressed(new ToggleGear());
90
91 runIntake = new JoystickButton(leftJoystick, Constants.OI.RUN_INTAKE_PORT);
92 runIntake.whileHeld(new RunIntakeContinuous());
93
94 reverseIntake = new JoystickButton(leftJoystick,
95 Constants.OI.REVERSE_INTAKE_PORT);
96 reverseIntake.whileHeld(new ReverseIntakeContinuous());
97
98 toggleWinch = new JoystickButton(leftJoystick,
99 Constants.OI.TOGGLE_WINCH_PORT);
100 toggleWinch.whenPressed(new ToggleWinch());
101
102 increaseShooterSpeed = new JoystickButton(leftJoystick,
103 Constants.OI.INCREASE_SHOOTER_SPEED_PORT);
104 increaseShooterSpeed.whenPressed(new IncreaseShootingSpeed());
105
106 decreaseShooterSpeed = new JoystickButton(leftJoystick,
107 Constants.OI.DECREASE_SHOOTER_SPEED_PORT);
108 decreaseShooterSpeed.whenPressed(new DecreaseShootingSpeed());
109 }
110
111 public static OI getOI() {
112 if (oi == null)
113 oi = new OI();
114 return oi;
115 }
116 }