Skip to content

Commit

Permalink
Add POV button support
Browse files Browse the repository at this point in the history
Signed-off-by: Alex Saveau <[email protected]>
  • Loading branch information
SUPERCILEX committed Feb 25, 2018
1 parent 5db00c7 commit e0755b1
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions core/src/main/kotlin/org/sertain/hardware/Joysticks.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,15 @@ import org.sertain.command.CommandBridgeMirror
// Minus because `throttle` is 1 when at the bottom...sigh WPI
public val Joystick.scaledThrottle get() = (throttle - 1) / 2

/** @return currently pressed POV button or null if unknown */
public val GenericHID.povButton get() = PovButton.values().find { isPovButtonPressed(it) }

/**
* @param button the POV button
* @return true if the POV button is pressed, false otherwise
*/
public fun GenericHID.isPovButtonPressed(button: PovButton) = pov == button.angle

/**
* @param button the number of the button to listen for
* @param command the command to execute
Expand Down Expand Up @@ -45,3 +54,16 @@ public inline fun GenericHID.whileActive(
) = whileActive(button, object : Command() {
override fun execute() = block()
})

/** Represents the most common POV buttons. */
public enum class PovButton(val angle: Int) {
CENTER(-1),
TOP(0),
TOP_RIGHT(45),
RIGHT(90),
BOTTOM_RIGHT(135),
BOTTOM(180),
BOTTOM_LEFT(225),
LEFT(270),
TOP_LEFT(315)
}

0 comments on commit e0755b1

Please sign in to comment.