diff --git a/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/AnalogTrigger.java b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/AnalogTrigger.java index e14934f61f..1316beb874 100644 --- a/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/AnalogTrigger.java +++ b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/AnalogTrigger.java @@ -12,6 +12,8 @@ import java.nio.ByteBuffer; //import com.sun.jna.Pointer; + +import edu.wpi.first.wpilibj.AnalogTriggerOutput.AnalogTriggerType; import edu.wpi.first.wpilibj.communication.FRCNetworkCommunicationsLibrary.tResourceType; import edu.wpi.first.wpilibj.communication.UsageReporting; import edu.wpi.first.wpilibj.hal.AnalogJNI; @@ -214,7 +216,7 @@ public class AnalogTrigger { * An enum of the type of output object to create. * @return A pointer to a new AnalogTriggerOutput object. */ - AnalogTriggerOutput createOutput(int type) { + AnalogTriggerOutput createOutput(AnalogTriggerType type) { return new AnalogTriggerOutput(this, type); } } diff --git a/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/AnalogTriggerOutput.java b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/AnalogTriggerOutput.java index f6f0788c81..43abc713e1 100644 --- a/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/AnalogTriggerOutput.java +++ b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/AnalogTriggerOutput.java @@ -65,7 +65,7 @@ public class AnalogTriggerOutput extends DigitalSource { } private AnalogTrigger m_trigger; - private int m_outputType; // define in HALLibrary.AnalogTriggerType + private AnalogTriggerType m_outputType; /** * Create an object that represents one of the four outputs from an analog @@ -79,14 +79,14 @@ public class AnalogTriggerOutput extends DigitalSource { * @param outputType * An enum that specifies the output on the trigger to represent. */ - public AnalogTriggerOutput(AnalogTrigger trigger, final int outputType) { + public AnalogTriggerOutput(AnalogTrigger trigger, final AnalogTriggerType outputType) { if (trigger == null) throw new NullPointerException("Analog Trigger given was null"); m_trigger = trigger; m_outputType = outputType; UsageReporting.report(tResourceType.kResourceType_AnalogTriggerOutput, - trigger.getIndex(), outputType); + trigger.getIndex(), outputType.value); } public void free() { @@ -100,13 +100,13 @@ public class AnalogTriggerOutput extends DigitalSource { public boolean get() { IntBuffer status = IntBuffer.allocate(1); byte value = AnalogJNI.getAnalogTriggerOutput(m_trigger.m_port, - m_outputType, status); + m_outputType.value, status); HALUtil.checkStatus(status); return value != 0; } public int getChannelForRouting() { - return (m_trigger.m_index << 2) + m_outputType; + return (m_trigger.m_index << 2) + m_outputType.value; } public int getModuleForRouting() { @@ -137,4 +137,21 @@ public class AnalogTriggerOutput extends DigitalSource { // public void requestInterrupts() { // TODO: throw exception // } + + /** + * Defines the state in which the AnalogTrigger triggers + * @author jonathanleitschuh + */ + public enum AnalogTriggerType{ + IN_WINDOW(AnalogJNI.AnalogTriggerType.kInWindow), + STATE(AnalogJNI.AnalogTriggerType.kState), + RISING_PULSE(AnalogJNI.AnalogTriggerType.kRisingPulse), + FALLING_PULSE(AnalogJNI.AnalogTriggerType.kFallingPulse); + + private final int value; + + private AnalogTriggerType(int value){ + this.value = value; + } + } } diff --git a/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/Counter.java b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/Counter.java index 26bcf6b2c0..ece858cf99 100644 --- a/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/Counter.java +++ b/wpilibj/wpilibJavaDevices/src/main/java/edu/wpi/first/wpilibj/Counter.java @@ -10,6 +10,7 @@ package edu.wpi.first.wpilibj; import java.nio.ByteBuffer; import java.nio.ByteOrder; +import edu.wpi.first.wpilibj.AnalogTriggerOutput.AnalogTriggerType; import edu.wpi.first.wpilibj.communication.FRCNetworkCommunicationsLibrary.tResourceType; import edu.wpi.first.wpilibj.communication.UsageReporting; import edu.wpi.first.wpilibj.hal.AnalogJNI; @@ -198,7 +199,7 @@ public class Counter extends SensorBase implements CounterBase, */ public Counter(AnalogTrigger trigger) { initCounter(Mode.kTwoPulse); - setUpSource(trigger.createOutput(AnalogJNI.AnalogTriggerType.kState)); + setUpSource(trigger.createOutput(AnalogTriggerType.STATE)); } public void free() { @@ -258,7 +259,7 @@ public class Counter extends SensorBase implements CounterBase, * @param triggerType * The analog trigger output that will trigger the counter. */ - public void setUpSource(AnalogTrigger analogTrigger, int triggerType) { + public void setUpSource(AnalogTrigger analogTrigger, AnalogTriggerType triggerType) { analogTrigger.createOutput(triggerType); m_allocatedUpSource = true; } @@ -345,7 +346,7 @@ public class Counter extends SensorBase implements CounterBase, * @param triggerType * The analog trigger output that will trigger the counter. */ - public void setDownSource(AnalogTrigger analogTrigger, int triggerType) { + public void setDownSource(AnalogTrigger analogTrigger, AnalogTriggerType triggerType) { setDownSource(analogTrigger.createOutput(triggerType)); m_allocatedDownSource = true; }