Add key listener to runFlyWheel
[3501/2017steamworks] / src / org / usfirst / frc / team3501 / robot / OI.java
index c608b86b8d1767a8eeab2c2b268693ef6ce74d0e..3929af241277c3f207465503bdb5e4a51eedd922 100644 (file)
@@ -1,5 +1,10 @@
 package org.usfirst.frc.team3501.robot;
 
+import java.awt.event.KeyAdapter;
+import java.awt.event.KeyEvent;
+
+import javax.swing.JButton;
+
 import org.usfirst.frc.team3501.robot.commands.climber.ToggleWinch;
 import org.usfirst.frc.team3501.robot.commands.driving.ToggleGear;
 import org.usfirst.frc.team3501.robot.commands.intake.ReverseIntakeContinuous;
@@ -22,7 +27,8 @@ public class OI {
 
   public static Button runIndexWheel;
   public static Button reverseIndexWheel;
-  public static Button toggleFlyWheel;
+  // public static Button toggleFlyWheel;
+  public static JButton toggleFlyWheel;
 
   public static Button toggleGear;
 
@@ -32,6 +38,8 @@ public class OI {
   public static Button increaseShooterSpeed;
   public static Button decreaseShooterSpeed;
 
+  // private static Key a;
+
   public OI() {
     leftJoystick = new Joystick(Constants.OI.LEFT_STICK_PORT);
     rightJoystick = new Joystick(Constants.OI.RIGHT_STICK_PORT);
@@ -44,9 +52,37 @@ public class OI {
         Constants.OI.REVERSE_INDEXWHEEL_PORT);
     reverseIndexWheel.whileHeld(new ReverseIndexWheelContinuous());
 
-    toggleFlyWheel = new JoystickButton(rightJoystick,
-        Constants.OI.TOGGLE_FLYWHEEL_PORT);
-    toggleFlyWheel.toggleWhenPressed(new RunFlyWheelContinuous());
+    /*
+     * toggleFlyWheel = new JoystickButton(rightJoystick,
+     * Constants.OI.TOGGLE_FLYWHEEL_PORT); toggleFlyWheel.toggleWhenPressed(new
+     * RunFlyWheelContinuous());
+     */
+
+    toggleFlyWheel = new JButton();
+    toggleFlyWheel.addKeyListener(new KeyAdapter() {
+      RunFlyWheelContinuous runflywheel = new RunFlyWheelContinuous();
+
+      /***
+       * Starts the run index wheel continuous function
+       */
+      @Override
+      public void keyPressed(KeyEvent e) {
+        if (e.getKeyCode() == KeyEvent.VK_0) {
+          runflywheel.start();
+        }
+      }
+
+      /***
+       * Ends the run index wheel continuous function
+       */
+      @Override
+      public void keyReleased(KeyEvent e) {
+        if (e.getKeyCode() == KeyEvent.VK_0) {
+          runflywheel.cancel();
+        }
+      }
+
+    });
 
     toggleGear = new JoystickButton(leftJoystick,
         Constants.OI.TOGGLE_GEAR_PORT);