make so does not crash
[3501/3501-spark-go] / src / org / usfirst / frc / team3501 / robot / Joystick.java
1 package org.usfirst.frc.team3501.robot;
2
3 import java.util.HashMap;
4 import java.util.stream.IntStream;
5
6 import edu.wpi.first.wpilibj.buttons.JoystickButton;
7 import edu.wpi.first.wpilibj.command.Command;
8
9 public class Joystick extends edu.wpi.first.wpilibj.Joystick {
10
11 private HashMap<Integer, JoystickButton> buttons;
12
13 public Joystick(int port) {
14 super(port);
15
16 buttons = new HashMap<Integer, JoystickButton>();
17
18 IntStream.rangeClosed(1, getButtonCount()).forEach((b) -> {
19 buttons.put(b, new JoystickButton(this, b));
20 });
21 }
22
23 public void whenPressed(int button, Command c) {
24 buttons.get(button).whenPressed(c);
25 }
26
27 public void whenReleased(int button, Command c) {
28 buttons.get(button).whenReleased(c);
29 }
30
31 public void whileHeld(int button, Command c) {
32 buttons.get(button).whileHeld(c);
33 }
34
35 public boolean get(int button) {
36 return getRawButton(button);
37 }
38 }