Skip to content

Commit

Permalink
Add CBAxisRef and CBButtonRef. Unify CBArcadeDriveMapper and migrate …
Browse files Browse the repository at this point in the history
…into core.
  • Loading branch information
rakar committed Sep 30, 2018
1 parent 7fdb946 commit ef31cb6
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 94 deletions.
2 changes: 1 addition & 1 deletion src/main/java/org/montclairrobotics/cyborg/core
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import edu.wpi.first.wpilibj.smartdashboard.SendableBuilder;
import org.montclairrobotics.cyborg.Cyborg;

public class CBAxis extends CBJoystickIndex implements CBDevice {
public class CBAxis extends CBAxisRef implements CBDevice {
String name, subsystem;

CBJoystick joystick;
Expand All @@ -16,12 +16,12 @@ public class CBAxis extends CBJoystickIndex implements CBDevice {
protected boolean initialized;


public CBAxis(CBJoystickIndex joystickIndex) {
public CBAxis(CBAxisRef joystickIndex) {
this(joystickIndex.stickID, joystickIndex.index);
}

public static CBAxis getDefaulted(CBAxis axis) {
return (axis != null) ? axis : new CBAxis(CBJoystickIndex.undefined());
return (axis != null) ? axis : new CBAxis(CBAxisRef.undefined());
}

public CBAxis(int stickID, int index) {
Expand Down
24 changes: 24 additions & 0 deletions src/main/java/org/montclairrobotics/cyborg/devices/CBAxisRef.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package org.montclairrobotics.cyborg.devices;

public class CBAxisRef {
public int stickID;
public int index;

public CBAxisRef() {
stickID = -1;
index = -1;
}

public CBAxisRef(int stickID, int index) {
this.stickID = stickID;
this.index = index;
}

public boolean isDefined() {
return stickID>=0;
}

public static CBAxisRef undefined() {
return new CBAxisRef(-1,-1);
}
}
16 changes: 8 additions & 8 deletions src/main/java/org/montclairrobotics/cyborg/devices/CBButton.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

public class CBButton extends CBEdgeTrigger implements CBDevice {
String name,subsystem;
private CBJoystickIndex stickIndex;
private CBButtonRef buttonRef;
private CBJoystick joystick;

/*
Expand All @@ -19,28 +19,28 @@ public void deviceInit() {
}
*/

public CBButton(CBJoystickIndex joystickIndex) {
this(joystickIndex.stickID, joystickIndex.index);
public CBButton(CBButtonRef buttonRef) {
this(buttonRef.stickID, buttonRef.index);
}


public CBButton(int stickID, int index) {
super();
stickIndex = new CBJoystickIndex(stickID, index);
buttonRef = new CBButtonRef(stickID, index);
if(stickID>=0) {
joystick = Cyborg.hardwareAdapter.getJoystick(stickIndex.stickID);
joystick = Cyborg.hardwareAdapter.getJoystick(buttonRef.stickID);
} else {
joystick = null;
}
//setName(subsystem, name);
}

public static CBButton getDefaulted(CBButton button) {
return (button!=null)?button:new CBButton(CBJoystickIndex.undefined());
return (button!=null)?button:new CBButton(CBButtonRef.undefined());
}

public boolean isDefined() {
return stickIndex.isDefined();
return buttonRef.isDefined();
}

@Override
Expand Down Expand Up @@ -88,7 +88,7 @@ public void init() {
@Override
public void senseUpdate() {
if (isDefined()) {
update(joystick.getRawButton(stickIndex.index));
update(joystick.getRawButton(buttonRef.index));
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package org.montclairrobotics.cyborg.devices;

public class CBButtonRef{
public int stickID;
public int index;

public CBButtonRef() {
stickID = -1;
index = -1;
}

public CBButtonRef(int stickID, int index) {
this.stickID = stickID;
this.index = index;
}

public boolean isDefined() {
return stickID>=0;
}

public static CBButtonRef undefined() {
return new CBButtonRef(-1,-1);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.montclairrobotics.cyborg.devices;

public class CBJoystickIndex{
public class CBJoystickIndex {
public int stickID;
public int index;

Expand Down

This file was deleted.

0 comments on commit ef31cb6

Please sign in to comment.