Commit | Line | Data |
---|---|---|
b449387d LH |
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 | ||
299be031 LH |
16 | buttons = new HashMap<Integer, JoystickButton>(); |
17 | ||
18 | IntStream.rangeClosed(1, getButtonCount()).forEach((b) -> { | |
b449387d LH |
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 | } | |
d24e8611 LH |
30 | |
31 | public void whileHeld(int button, Command c) { | |
32 | buttons.get(button).whileHeld(c); | |
33 | } | |
e81578e3 LH |
34 | |
35 | public boolean get(int button) { | |
36 | return getRawButton(button); | |
37 | } | |
b449387d | 38 | } |