mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-22 01:11:42 +00:00
[hal] Add systemcore duty cycle (#7682)
This commit is contained in:
@@ -23,27 +23,20 @@ import edu.wpi.first.util.sendable.SendableRegistry;
|
||||
public class DutyCycle implements Sendable, AutoCloseable {
|
||||
// Explicitly package private
|
||||
final int m_handle;
|
||||
|
||||
private final DigitalSource m_source;
|
||||
private final int m_channel;
|
||||
|
||||
/**
|
||||
* Constructs a DutyCycle input from a DigitalSource input.
|
||||
* Constructs a DutyCycle input from a smartio channel.
|
||||
*
|
||||
* <p>This class does not own the inputted source.
|
||||
*
|
||||
* @param digitalSource The DigitalSource to use.
|
||||
* @param channel The channel to use.
|
||||
*/
|
||||
@SuppressWarnings("this-escape")
|
||||
public DutyCycle(DigitalSource digitalSource) {
|
||||
m_handle =
|
||||
DutyCycleJNI.initialize(
|
||||
digitalSource.getPortHandleForRouting(),
|
||||
digitalSource.getAnalogTriggerTypeForRouting());
|
||||
public DutyCycle(int channel) {
|
||||
m_handle = DutyCycleJNI.initialize(HAL.getPort((byte) channel));
|
||||
|
||||
m_source = digitalSource;
|
||||
int index = getFPGAIndex();
|
||||
HAL.report(tResourceType.kResourceType_DutyCycle, index + 1);
|
||||
SendableRegistry.addLW(this, "Duty Cycle", index);
|
||||
m_channel = channel;
|
||||
HAL.report(tResourceType.kResourceType_DutyCycle, channel + 1);
|
||||
SendableRegistry.addLW(this, "Duty Cycle", channel);
|
||||
}
|
||||
|
||||
/** Close the DutyCycle and free all resources. */
|
||||
@@ -109,7 +102,7 @@ public class DutyCycle implements Sendable, AutoCloseable {
|
||||
* @return the source channel
|
||||
*/
|
||||
public int getSourceChannel() {
|
||||
return m_source.getChannel();
|
||||
return m_channel;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -19,7 +19,6 @@ import edu.wpi.first.util.sendable.SendableRegistry;
|
||||
public class DutyCycleEncoder implements Sendable, AutoCloseable {
|
||||
private final DutyCycle m_dutyCycle;
|
||||
private boolean m_ownsDutyCycle;
|
||||
private DigitalInput m_digitalInput;
|
||||
private int m_frequencyThreshold = 100;
|
||||
private double m_fullRange;
|
||||
private double m_expectedZero;
|
||||
@@ -41,9 +40,8 @@ public class DutyCycleEncoder implements Sendable, AutoCloseable {
|
||||
*/
|
||||
@SuppressWarnings("this-escape")
|
||||
public DutyCycleEncoder(int channel, double fullRange, double expectedZero) {
|
||||
m_digitalInput = new DigitalInput(channel);
|
||||
m_ownsDutyCycle = true;
|
||||
m_dutyCycle = new DutyCycle(m_digitalInput);
|
||||
m_dutyCycle = new DutyCycle(channel);
|
||||
init(fullRange, expectedZero);
|
||||
}
|
||||
|
||||
@@ -60,20 +58,6 @@ public class DutyCycleEncoder implements Sendable, AutoCloseable {
|
||||
init(fullRange, expectedZero);
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct a new DutyCycleEncoder attached to a DigitalSource object.
|
||||
*
|
||||
* @param source the digital source to attach to
|
||||
* @param fullRange the value to report at maximum travel
|
||||
* @param expectedZero the reading where you would expect a 0 from get()
|
||||
*/
|
||||
@SuppressWarnings("this-escape")
|
||||
public DutyCycleEncoder(DigitalSource source, double fullRange, double expectedZero) {
|
||||
m_ownsDutyCycle = true;
|
||||
m_dutyCycle = new DutyCycle(source);
|
||||
init(fullRange, expectedZero);
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct a new DutyCycleEncoder on a specific channel.
|
||||
*
|
||||
@@ -98,18 +82,6 @@ public class DutyCycleEncoder implements Sendable, AutoCloseable {
|
||||
this(dutyCycle, 1.0, 0.0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct a new DutyCycleEncoder attached to a DigitalSource object.
|
||||
*
|
||||
* <p>This has a fullRange of 1 and an expectedZero of 0.
|
||||
*
|
||||
* @param source the digital source to attach to
|
||||
*/
|
||||
@SuppressWarnings("this-escape")
|
||||
public DutyCycleEncoder(DigitalSource source) {
|
||||
this(source, 1.0, 0.0);
|
||||
}
|
||||
|
||||
private void init(double fullRange, double expectedZero) {
|
||||
m_simDevice = SimDevice.create("DutyCycle:DutyCycleEncoder", m_dutyCycle.getSourceChannel());
|
||||
|
||||
@@ -258,9 +230,6 @@ public class DutyCycleEncoder implements Sendable, AutoCloseable {
|
||||
if (m_ownsDutyCycle) {
|
||||
m_dutyCycle.close();
|
||||
}
|
||||
if (m_digitalInput != null) {
|
||||
m_digitalInput.close();
|
||||
}
|
||||
if (m_simDevice != null) {
|
||||
m_simDevice.close();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user