Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added button Classes #2

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions Command Buttons/AndJoystickButton.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package org.usfirst.frc3244.Jupiter2019.util;

import edu.wpi.first.wpilibj.GenericHID;
import edu.wpi.first.wpilibj.buttons.Button;

public class AndJoystickButton extends Button {
GenericHID joystick1;
GenericHID joystick2;
int buttonNumber1;
int buttonNumber2;

public AndJoystickButton(GenericHID joystick1, int buttonNumber1, GenericHID joystick2, int buttonNumber2) {
this.joystick1 = joystick1;
this.buttonNumber1 = buttonNumber1;
this.joystick2 = joystick2;
this.buttonNumber2 = buttonNumber2;
}

public boolean get() {
return joystick1.getRawButton(buttonNumber1) && joystick2.getRawButton(buttonNumber2);
}

}
29 changes: 29 additions & 0 deletions Command Buttons/AndNOTJoystickButton2.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package org.usfirst.frc3244.Jupiter2019.util;

import edu.wpi.first.wpilibj.GenericHID;
import edu.wpi.first.wpilibj.buttons.Button;

/**
*
* @author Copied From Team #1519 (Mechanical Mayhem)
* But changed to and Not Joystick
*
*/
public class AndNOTJoystickButton2 extends Button {
GenericHID joystick1;
GenericHID joystick2;
int buttonNumber1;
int buttonNumber2;

public AndNOTJoystickButton2(GenericHID joystick1, int buttonNumber1, GenericHID joystick2, int buttonNumber2) {
this.joystick1 = joystick1;
this.buttonNumber1 = buttonNumber1;
this.joystick2 = joystick2;
this.buttonNumber2 = buttonNumber2;
}

public boolean get() {
return joystick1.getRawButton(buttonNumber1) && !joystick2.getRawButton(buttonNumber2);
}

}
26 changes: 26 additions & 0 deletions Command Buttons/DisabledOnlyJoystickButton.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package org.usfirst.frc3244.Jupiter2019.util;

import edu.wpi.first.wpilibj.DriverStation;
import edu.wpi.first.wpilibj.GenericHID;
import edu.wpi.first.wpilibj.buttons.Button;

/**
*
* @author Ken Streeter
*/
public class DisabledOnlyJoystickButton extends Button {

private GenericHID joystick;
private int buttonNumber;
private DriverStation ds;

public DisabledOnlyJoystickButton(GenericHID joystick, int buttonNumber) {
this.joystick = joystick;
this.buttonNumber = buttonNumber;
ds = DriverStation.getInstance();
}

public boolean get() {
return joystick.getRawButton(buttonNumber) && ds.isDisabled();
}
}
26 changes: 26 additions & 0 deletions Command Buttons/EnabledOnlyJoystickButton.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package org.usfirst.frc3244.Jupiter2019.util;

import edu.wpi.first.wpilibj.DriverStation;
import edu.wpi.first.wpilibj.GenericHID;
import edu.wpi.first.wpilibj.buttons.Button;

/**
*
* @author Noel
*/
public class EnabledOnlyJoystickButton extends Button {

private GenericHID joystick;
private int buttonNumber;
private DriverStation ds;

public EnabledOnlyJoystickButton(GenericHID joystick, int buttonNumber) {
this.joystick = joystick;
this.buttonNumber = buttonNumber;
ds = DriverStation.getInstance();
}

public boolean get() {
return joystick.getRawButton(buttonNumber) && ds.isEnabled();
}
}
26 changes: 26 additions & 0 deletions Command Buttons/IOButton.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package org.usfirst.frc3244.Jupiter2019.util;

import edu.wpi.first.wpilibj.DigitalInput;
import edu.wpi.first.wpilibj.buttons.Button;


/**
*
*/
public class IOButton extends Button {

private DigitalInput button;


public IOButton(DigitalInput digitalInput){
button = digitalInput;

}

/**
* Returns the status of a Normaly Open Switch connected to the RoboRio
*/
public boolean get() {
return !button.get();
}
}
26 changes: 26 additions & 0 deletions Command Buttons/IOButtonOrButton.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package org.usfirst.frc3244.Jupiter2019.util;

import edu.wpi.first.wpilibj.DigitalInput;
import edu.wpi.first.wpilibj.buttons.Button;


/**
*
*/
public class IOButtonOrButton extends Button {

private DigitalInput button1;
private DigitalInput button2;

public IOButtonOrButton(DigitalInput digitalInput1,DigitalInput digitalInput2){
button1 = digitalInput1;
button2 = digitalInput2;
}

/**
* Returns True if switch is closed
*/
public boolean get() {
return !button1.get()||!button2.get();
}
}
76 changes: 76 additions & 0 deletions Command Buttons/JoystickAxisButton.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package org.usfirst.frc3244.Jupiter2019.util;

import edu.wpi.first.wpilibj.Joystick;
import edu.wpi.first.wpilibj.buttons.Button;

/**
*
* @author Noel
*/
public class JoystickAxisButton extends Button {
public static final int BOTH_WAYS = 1;
public static final int POSITIVE_ONLY = 2;
public static final int NEGATIVE_ONLY = 3;

private static final double AXIS_THRESHOLD = 0.2;

private Joystick joystick;
private Joystick.AxisType axis;
private int axisInt;
private int direction;

public JoystickAxisButton(Joystick stick, Joystick.AxisType axis) {
this(stick, axis, BOTH_WAYS);
}

public JoystickAxisButton(Joystick stick, Joystick.AxisType axis, int direction) {
joystick = stick;
this.axis = axis;
this.direction = direction;
}

public JoystickAxisButton(Joystick stick, int axis) {
this(stick, axis, BOTH_WAYS);
}

public JoystickAxisButton(Joystick stick, int axis, int direction) {
joystick = stick;
this.axis = null;
axisInt = axis;
this.direction = direction;
}

public boolean get() {
switch (direction) {
case BOTH_WAYS:
if (axis != null) {
return Math.abs(joystick.getAxis(axis)) > AXIS_THRESHOLD;
}
else {
return Math.abs(joystick.getRawAxis(axisInt)) > AXIS_THRESHOLD;
}

case POSITIVE_ONLY:
if (axis != null) {
return joystick.getAxis(axis) > AXIS_THRESHOLD;
}
else {
return joystick.getRawAxis(axisInt) > AXIS_THRESHOLD;
}

case NEGATIVE_ONLY:
if (axis != null) {
return joystick.getAxis(axis) < -AXIS_THRESHOLD;
}
else {
return joystick.getRawAxis(axisInt) < -AXIS_THRESHOLD;
}
}

return false;
}
}
34 changes: 34 additions & 0 deletions Command Buttons/JoystickPOVButton.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package org.usfirst.frc3244.Jupiter2019.util;

import edu.wpi.first.wpilibj.Joystick;
import edu.wpi.first.wpilibj.buttons.Button;

/**
* @author Ken Streeter (1519)
*/
public class JoystickPOVButton extends Button {
public static final int NORTH = 0;
public static final int NORTHEAST = 45;
public static final int EAST = 90;
public static final int SOUTHEAST = 135;
public static final int SOUTH = 180;
public static final int SOUTHWEST = 225;
public static final int WEST = 270;
public static final int NORTHWEST = 315;

private Joystick joystick;
private int desiredPOV;

public JoystickPOVButton(Joystick stick, int newDesiredPOV) {
joystick = stick;
desiredPOV = newDesiredPOV;
}

public boolean get() {
return (joystick.getPOV() == desiredPOV);
}
}
79 changes: 79 additions & 0 deletions Command Buttons/OrAxisTriggerButton.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
package org.usfirst.frc3244.Jupiter2019.util;

import edu.wpi.first.wpilibj.GenericHID;
import edu.wpi.first.wpilibj.Joystick;
import edu.wpi.first.wpilibj.buttons.Button;

public class OrAxisTriggerButton extends Button {
//Button Variables
GenericHID joystick1;
int buttonNumber1;

//Axis Variables
public static final int BOTH_WAYS = 1;
public static final int POSITIVE_ONLY = 2;
public static final int NEGATIVE_ONLY = 3;

private static final double AXIS_THRESHOLD = 0.2;

private Joystick joystick;
private Joystick.AxisType axis;
private int axisInt;
private int direction;

public OrAxisTriggerButton(GenericHID joystick1, int buttonNumber1, Joystick stick, Joystick.AxisType axis) {
this(joystick1, buttonNumber1,stick, axis, BOTH_WAYS);
}

public OrAxisTriggerButton(GenericHID joystick1, int buttonNumber1, Joystick stick, Joystick.AxisType axis, int direction) {
this.joystick1 = joystick1;
this.buttonNumber1 = buttonNumber1;
joystick = stick;
this.axis = axis;
this.direction = direction;
}

public OrAxisTriggerButton(GenericHID joystick1, int buttonNumber1, Joystick stick, int axis) {
this(joystick1, buttonNumber1, stick, axis, BOTH_WAYS);
}

public OrAxisTriggerButton(GenericHID joystick1, int buttonNumber1, Joystick stick, int axis, int direction) {
this.joystick1 = joystick1;
this.buttonNumber1 = buttonNumber1;
joystick = stick;
this.axis = null;
axisInt = axis;
this.direction = direction;
}

public boolean get() {

switch (direction) {
case BOTH_WAYS:
if (axis != null) {
return joystick1.getRawButton(buttonNumber1) || Math.abs(joystick.getAxis(axis)) > AXIS_THRESHOLD;
}
else {
return joystick1.getRawButton(buttonNumber1) || Math.abs(joystick.getRawAxis(axisInt)) > AXIS_THRESHOLD;
}

case POSITIVE_ONLY:
if (axis != null) {
return joystick1.getRawButton(buttonNumber1) || joystick.getAxis(axis) > AXIS_THRESHOLD;
}
else {
return joystick1.getRawButton(buttonNumber1) || joystick.getRawAxis(axisInt) > AXIS_THRESHOLD;
}

case NEGATIVE_ONLY:
if (axis != null) {
return joystick1.getRawButton(buttonNumber1) || joystick.getAxis(axis) < -AXIS_THRESHOLD;
}
else {
return joystick1.getRawButton(buttonNumber1) || joystick.getRawAxis(axisInt) < -AXIS_THRESHOLD;
}
}

return false;
}
}
23 changes: 23 additions & 0 deletions Command Buttons/OrJoystickButton.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package org.usfirst.frc3244.Jupiter2019.util;

import edu.wpi.first.wpilibj.GenericHID;
import edu.wpi.first.wpilibj.buttons.Button;

public class OrJoystickButton extends Button {
GenericHID joystick1;
GenericHID joystick2;
int buttonNumber1;
int buttonNumber2;

public OrJoystickButton(GenericHID joystick1, int buttonNumber1, GenericHID joystick2, int buttonNumber2) {
this.joystick1 = joystick1;
this.buttonNumber1 = buttonNumber1;
this.joystick2 = joystick2;
this.buttonNumber2 = buttonNumber2;
}

public boolean get() {
return joystick1.getRawButton(buttonNumber1) || joystick2.getRawButton(buttonNumber2);
}

}
2 changes: 1 addition & 1 deletion enhance_wpi_classes/MecanumDrive.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
/* the project. */
/*----------------------------------------------------------------------------*/

package com.granitecitygearhead.frc3244.enhance_wpi_classes;
//package com.granitecitygearhead.frc3244.enhance_wpi_classes;

import java.util.StringJoiner;
import java.util.function.DoubleSupplier;
Expand Down