[commands] Replace Command HID inheritance with delegation (#4470)

This commit is contained in:
Starlight220
2022-10-23 22:09:44 +03:00
committed by GitHub
parent 9e1f9c1133
commit 09faf31b67
13 changed files with 1201 additions and 101 deletions

View File

@@ -167,6 +167,134 @@ public class GenericHID {
return getPOV(0);
}
/**
* Constructs a BooleanEvent instance based around this angle of a POV on the HID.
*
* <p>The POV angles start at 0 in the up direction, and increase clockwise (eg right is 90,
* upper-left is 315).
*
* @param angle POV angle in degrees, or -1 for the center / not pressed.
* @param loop the event loop instance to attach the event to.
* @return a BooleanEvent instance based around this angle of a POV on the HID.
*/
public BooleanEvent pov(int angle, EventLoop loop) {
return pov(0, angle, loop);
}
/**
* Constructs a BooleanEvent instance based around this angle of a POV on the HID.
*
* <p>The POV angles start at 0 in the up direction, and increase clockwise (eg right is 90,
* upper-left is 315).
*
* @param pov index of the POV to read (starting at 0). Defaults to 0.
* @param angle POV angle in degrees, or -1 for the center / not pressed.
* @param loop the event loop instance to attach the event to.
* @return a BooleanEvent instance based around this angle of a POV on the HID.
*/
public BooleanEvent pov(int pov, int angle, EventLoop loop) {
return new BooleanEvent(loop, () -> getPOV(pov) == angle);
}
/**
* Constructs a BooleanEvent instance based around the 0-degree angle (up) of the default (index
* 0) POV on the HID.
*
* @param loop the event loop instance to attach the event to.
* @return a BooleanEvent instance based around the 0-degree angle of a POV on the HID.
*/
public BooleanEvent povUp(EventLoop loop) {
return pov(0, loop);
}
/**
* Constructs a BooleanEvent instance based around the 45-degree angle (right up) of the default
* (index 0) POV on the HID.
*
* @param loop the event loop instance to attach the event to.
* @return a BooleanEvent instance based around the 45-degree angle of a POV on the HID.
*/
public BooleanEvent povUpRight(EventLoop loop) {
return pov(45, loop);
}
/**
* Constructs a BooleanEvent instance based around the 90-degree angle (right) of the default
* (index 0) POV on the HID.
*
* @param loop the event loop instance to attach the event to.
* @return a BooleanEvent instance based around the 90-degree angle of a POV on the HID.
*/
public BooleanEvent povRight(EventLoop loop) {
return pov(90, loop);
}
/**
* Constructs a BooleanEvent instance based around the 135-degree angle (right down) of the
* default (index 0) POV on the HID.
*
* @param loop the event loop instance to attach the event to.
* @return a BooleanEvent instance based around the 135-degree angle of a POV on the HID.
*/
public BooleanEvent povDownRight(EventLoop loop) {
return pov(135, loop);
}
/**
* Constructs a BooleanEvent instance based around the 180-degree angle (down) of the default
* (index 0) POV on the HID.
*
* @param loop the event loop instance to attach the event to.
* @return a BooleanEvent instance based around the 180-degree angle of a POV on the HID.
*/
public BooleanEvent povDown(EventLoop loop) {
return pov(180, loop);
}
/**
* Constructs a BooleanEvent instance based around the 225-degree angle (down left) of the default
* (index 0) POV on the HID.
*
* @param loop the event loop instance to attach the event to.
* @return a BooleanEvent instance based around the 225-degree angle of a POV on the HID.
*/
public BooleanEvent povDownLeft(EventLoop loop) {
return pov(225, loop);
}
/**
* Constructs a BooleanEvent instance based around the 270-degree angle (left) of the default
* (index 0) POV on the HID.
*
* @param loop the event loop instance to attach the event to.
* @return a BooleanEvent instance based around the 270-degree angle of a POV on the HID.
*/
public BooleanEvent povLeft(EventLoop loop) {
return pov(270, loop);
}
/**
* Constructs a BooleanEvent instance based around the 315-degree angle (left up) of the default
* (index 0) POV on the HID.
*
* @param loop the event loop instance to attach the event to.
* @return a BooleanEvent instance based around the 315-degree angle of a POV on the HID.
*/
public BooleanEvent povUpLeft(EventLoop loop) {
return pov(315, loop);
}
/**
* Constructs a BooleanEvent instance based around the center (not pressed) of the default (index
* 0) POV on the HID.
*
* @param loop the event loop instance to attach the event to.
* @return a BooleanEvent instance based around the center of a POV on the HID.
*/
public BooleanEvent povCenter(EventLoop loop) {
return pov(-1, loop);
}
/**
* Get the number of axes for the HID.
*