Skip to content

Commit

Permalink
[#166] doesnt extend XboxController
Browse files Browse the repository at this point in the history
  • Loading branch information
Vilok1 committed Apr 22, 2024
1 parent 75a5082 commit af3d734
Showing 1 changed file with 71 additions and 22 deletions.
93 changes: 71 additions & 22 deletions shuffleboard/LightningController.java
Original file line number Diff line number Diff line change
@@ -1,19 +1,32 @@
package frc.thunder.shuffleboard;

import edu.wpi.first.wpilibj.GenericHID.RumbleType;
import edu.wpi.first.wpilibj.XboxController;

public class LightningController extends XboxController{
public class LightningController{

String name;
private String name;
public boolean portFound = true;
public XboxController realController;

public LightningController(String name, int port){
super(port);
this.name = name;
try {
realController = new XboxController(port);
} catch (Exception e){
portFound = false;
} finally {
this.name = name;
}
}

public LightningController(int port){
super(port);
this.name = "Controller " + port + " ";
try {
realController = new XboxController(port);
} catch (Exception e){
portFound = false;
} finally {
this.name = "Controller " + port + " ";
}
}

public boolean simController(){
Expand All @@ -28,7 +41,7 @@ public double getLeftX(){
if (simController()){
return LightningShuffleboard.getDouble(name, name + "LeftX", 0d);
} else {
return super.getLeftX();
return realController.getLeftX();
}
}

Expand All @@ -39,7 +52,7 @@ public double getLeftY(){
if (simController()){
return LightningShuffleboard.getDouble(name, name + "LeftY", 0d);
} else {
return super.getLeftY();
return realController.getLeftY();
}
}

Expand All @@ -50,7 +63,7 @@ public double getRightX(){
if (simController()){
return LightningShuffleboard.getDouble(name, name + "RightX", 0d);
} else {
return super.getRightX();
return realController.getRightX();
}
}

Expand All @@ -61,7 +74,7 @@ public double getRightY(){
if (simController()){
return LightningShuffleboard.getDouble(name, name + "RightY", 0d);
} else {
return super.getRightY();
return realController.getRightY();
}
}

Expand All @@ -72,7 +85,7 @@ public double getLeftTriggerAxis(){
if (simController()){
return LightningShuffleboard.getDouble(name, name + "LeftTriggerAxis", 0d);
} else {
return super.getLeftTriggerAxis();
return realController.getLeftTriggerAxis();
}
}

Expand All @@ -83,7 +96,7 @@ public double getRightTriggerAxis(){
if (simController()){
return LightningShuffleboard.getDouble(name, name + "RightTriggerAxis", 0d);
} else {
return super.getRightTriggerAxis();
return realController.getRightTriggerAxis();
}
}

Expand All @@ -94,7 +107,7 @@ public boolean getLeftBumper(){
if (simController()){
return LightningShuffleboard.getBool(name, name + "LeftBumper", false);
} else {
return super.getLeftBumper();
return realController.getLeftBumper();
}
}

Expand All @@ -105,7 +118,7 @@ public boolean getRightBumper(){
if (simController()){
return LightningShuffleboard.getBool(name, name + "RightBumper", false);
} else {
return super.getRightBumper();
return realController.getRightBumper();
}
}

Expand All @@ -116,7 +129,7 @@ public boolean getLeftStickButton(){
if (simController()){
return LightningShuffleboard.getBool(name, name + "LeftStickButton", false);
} else {
return super.getLeftStickButton();
return realController.getLeftStickButton();
}
}

Expand All @@ -127,7 +140,7 @@ public boolean getRightStickButton(){
if (simController()){
return LightningShuffleboard.getBool(name, name + "RightStickButton", false);
} else {
return super.getRightStickButton();
return realController.getRightStickButton();
}
}

Expand All @@ -138,7 +151,7 @@ public boolean getAButton(){
if (simController()){
return LightningShuffleboard.getBool(name, name + "AButton", false);
} else {
return super.getAButton();
return realController.getAButton();
}
}

Expand All @@ -149,7 +162,7 @@ public boolean getBButton(){
if (simController()){
return LightningShuffleboard.getBool(name, name + "BButton", false);
} else {
return super.getBButton();
return realController.getBButton();
}
}

Expand All @@ -160,7 +173,7 @@ public boolean getXButton(){
if (simController()){
return LightningShuffleboard.getBool(name, name + "XButton", false);
} else {
return super.getXButton();
return realController.getXButton();
}
}

Expand All @@ -171,7 +184,7 @@ public boolean getYButton(){
if (simController()){
return LightningShuffleboard.getBool(name, name + "YButton", false);
} else {
return super.getYButton();
return realController.getYButton();
}
}

Expand All @@ -182,7 +195,7 @@ public boolean getBackButton(){
if (simController()){
return LightningShuffleboard.getBool(name, name + "BackButton", false);
} else {
return super.getBackButton();
return realController.getBackButton();
}
}

Expand All @@ -193,7 +206,42 @@ public boolean getStartButton(){
if (simController()){
return LightningShuffleboard.getBool(name, name + "StartButton", false);
} else {
return super.getStartButton();
return realController.getStartButton();
}
}

/**
* @return the POV value from the controller/shuffleboard
*/
public double getPOV(){
if (simController()){
return LightningShuffleboard.getDouble(name, name + "POV", 0d);
} else {
return realController.getPOV();
}
}

/**
* @return set controller rumble
*/
public void setRumble(RumbleType type, double rumble){
if (simController()){
LightningShuffleboard.setDouble(name, name + "Rumble", rumble);
} else {
realController.setRumble(type, rumble);
}
}



/**
* @return get controller
*/
public XboxController getController(){
if (simController()){
return null;
} else {
return realController;
}
}

Expand All @@ -218,5 +266,6 @@ public void initValues(){
LightningShuffleboard.getBool(name, name + "YButton", false);
LightningShuffleboard.getBool(name, name + "BackButton", false);
LightningShuffleboard.getBool(name, name + "StartButton", false);
LightningShuffleboard.getDouble(name, name + "POV", 0d);
}
}

0 comments on commit af3d734

Please sign in to comment.