mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-21 01:01:43 +00:00
[sim] Add WPILib-class-taking constructors (#2538)
When not direct mapped, make index constructors private and add factory functions for channel and index. Co-authored-by: GabrielDeml <gabrielddeml@gmail.com>
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2008-2019 FIRST. All Rights Reserved. */
|
||||
/* Copyright (c) 2008-2020 FIRST. All Rights Reserved. */
|
||||
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
||||
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
||||
/* the project. */
|
||||
@@ -184,7 +184,16 @@ public class AnalogGyro extends GyroBase implements Gyro, PIDSource, Sendable, A
|
||||
*
|
||||
* @param volts The size of the deadband in volts
|
||||
*/
|
||||
void setDeadband(double volts) {
|
||||
public void setDeadband(double volts) {
|
||||
AnalogGyroJNI.setAnalogGyroDeadband(m_gyroHandle, volts);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the analog input for the gyro.
|
||||
*
|
||||
* @return AnalogInput
|
||||
*/
|
||||
public AnalogInput getAnalogInput() {
|
||||
return m_analog;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2016-2019 FIRST. All Rights Reserved. */
|
||||
/* Copyright (c) 2016-2020 FIRST. All Rights Reserved. */
|
||||
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
||||
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
||||
/* the project. */
|
||||
@@ -196,6 +196,15 @@ public class Compressor implements Sendable, AutoCloseable {
|
||||
CompressorJNI.clearAllPCMStickyFaults(m_module);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the module number (CAN ID).
|
||||
*
|
||||
* @return Module number
|
||||
*/
|
||||
public int getModule() {
|
||||
return m_module;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initSendable(SendableBuilder builder) {
|
||||
builder.setSmartDashboardType("Compressor");
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2014-2019 FIRST. All Rights Reserved. */
|
||||
/* Copyright (c) 2014-2020 FIRST. All Rights Reserved. */
|
||||
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
||||
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
||||
/* the project. */
|
||||
@@ -19,6 +19,7 @@ import edu.wpi.first.wpilibj.smartdashboard.SendableRegistry;
|
||||
*/
|
||||
public class PowerDistributionPanel implements Sendable, AutoCloseable {
|
||||
private final int m_handle;
|
||||
private final int m_module;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
@@ -28,6 +29,7 @@ public class PowerDistributionPanel implements Sendable, AutoCloseable {
|
||||
public PowerDistributionPanel(int module) {
|
||||
SensorUtil.checkPDPModule(module);
|
||||
m_handle = PDPJNI.initializePDP(module);
|
||||
m_module = module;
|
||||
|
||||
HAL.report(tResourceType.kResourceType_PDP, module + 1);
|
||||
SendableRegistry.addLW(this, "PowerDistributionPanel", module);
|
||||
@@ -117,6 +119,13 @@ public class PowerDistributionPanel implements Sendable, AutoCloseable {
|
||||
PDPJNI.clearPDPStickyFaults(m_handle);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets module number (CAN ID).
|
||||
*/
|
||||
public int getModule() {
|
||||
return m_module;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initSendable(SendableBuilder builder) {
|
||||
builder.setSmartDashboardType("PowerDistributionPanel");
|
||||
|
||||
@@ -10,14 +10,63 @@ package edu.wpi.first.wpilibj.simulation;
|
||||
import edu.wpi.first.hal.simulation.AddressableLEDDataJNI;
|
||||
import edu.wpi.first.hal.simulation.ConstBufferCallback;
|
||||
import edu.wpi.first.hal.simulation.NotifyCallback;
|
||||
import edu.wpi.first.wpilibj.AddressableLED;
|
||||
import java.util.NoSuchElementException;
|
||||
|
||||
/**
|
||||
* Class to control a simulated addressable LED.
|
||||
*/
|
||||
public class AddressableLEDSim {
|
||||
private final int m_index;
|
||||
|
||||
public AddressableLEDSim(int index) {
|
||||
/**
|
||||
* Constructs for the first addressable LED.
|
||||
*/
|
||||
public AddressableLEDSim() {
|
||||
m_index = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs from an AddressableLED object.
|
||||
*
|
||||
* @param addressableLED AddressableLED to simulate
|
||||
*/
|
||||
@SuppressWarnings("PMD.UnusedFormalParameter")
|
||||
public AddressableLEDSim(AddressableLED addressableLED) {
|
||||
// there is only support for a single AddressableLED, so no lookup
|
||||
m_index = 0;
|
||||
}
|
||||
|
||||
private AddressableLEDSim(int index) {
|
||||
m_index = index;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an AddressableLEDSim for a PWM channel.
|
||||
*
|
||||
* @param pwmChannel PWM channel
|
||||
* @return Simulated object
|
||||
* @throws NoSuchElementException if no AddressableLED is configured for that channel
|
||||
*/
|
||||
public static AddressableLEDSim createForChannel(int pwmChannel) {
|
||||
int index = AddressableLEDDataJNI.findForChannel(pwmChannel);
|
||||
if (index < 0) {
|
||||
throw new NoSuchElementException("no addressable LED found for PWM channel " + pwmChannel);
|
||||
}
|
||||
return new AddressableLEDSim(index);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an AddressableLEDSim for a simulated index.
|
||||
* The index is incremented for each simulated AddressableLED.
|
||||
*
|
||||
* @param index simulator index
|
||||
* @return Simulated object
|
||||
*/
|
||||
public static AddressableLEDSim createForIndex(int index) {
|
||||
return new AddressableLEDSim(index);
|
||||
}
|
||||
|
||||
public CallbackStore registerInitializedCallback(NotifyCallback callback, boolean initialNotify) {
|
||||
int uid = AddressableLEDDataJNI.registerInitializedCallback(m_index, callback, initialNotify);
|
||||
return new CallbackStore(m_index, uid, AddressableLEDDataJNI::cancelInitializedCallback);
|
||||
|
||||
@@ -9,12 +9,30 @@ package edu.wpi.first.wpilibj.simulation;
|
||||
|
||||
import edu.wpi.first.hal.simulation.AnalogGyroDataJNI;
|
||||
import edu.wpi.first.hal.simulation.NotifyCallback;
|
||||
import edu.wpi.first.wpilibj.AnalogGyro;
|
||||
|
||||
/**
|
||||
* Class to control a simulated analog gyro.
|
||||
*/
|
||||
public class AnalogGyroSim {
|
||||
private final int m_index;
|
||||
|
||||
public AnalogGyroSim(int index) {
|
||||
m_index = index;
|
||||
/**
|
||||
* Constructs from an AnalogGyro object.
|
||||
*
|
||||
* @param gyro AnalogGyro to simulate
|
||||
*/
|
||||
public AnalogGyroSim(AnalogGyro gyro) {
|
||||
m_index = gyro.getAnalogInput().getChannel();
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs from an analog input channel number.
|
||||
*
|
||||
* @param channel Channel number
|
||||
*/
|
||||
public AnalogGyroSim(int channel) {
|
||||
m_index = channel;
|
||||
}
|
||||
|
||||
public CallbackStore registerAngleCallback(NotifyCallback callback, boolean initialNotify) {
|
||||
|
||||
@@ -9,12 +9,31 @@ package edu.wpi.first.wpilibj.simulation;
|
||||
|
||||
import edu.wpi.first.hal.simulation.AnalogInDataJNI;
|
||||
import edu.wpi.first.hal.simulation.NotifyCallback;
|
||||
import edu.wpi.first.wpilibj.AnalogInput;
|
||||
|
||||
public class AnalogInSim {
|
||||
/**
|
||||
* Class to control a simulated analog input.
|
||||
*/
|
||||
@SuppressWarnings("PMD.TooManyMethods")
|
||||
public class AnalogInputSim {
|
||||
private final int m_index;
|
||||
|
||||
public AnalogInSim(int index) {
|
||||
m_index = index;
|
||||
/**
|
||||
* Constructs from an AnalogInput object.
|
||||
*
|
||||
* @param analogInput AnalogInput to simulate
|
||||
*/
|
||||
public AnalogInputSim(AnalogInput analogInput) {
|
||||
m_index = analogInput.getChannel();
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs from an analog input channel number.
|
||||
*
|
||||
* @param channel Channel number
|
||||
*/
|
||||
public AnalogInputSim(int channel) {
|
||||
m_index = channel;
|
||||
}
|
||||
|
||||
public CallbackStore registerInitializedCallback(NotifyCallback callback, boolean initialNotify) {
|
||||
@@ -9,12 +9,30 @@ package edu.wpi.first.wpilibj.simulation;
|
||||
|
||||
import edu.wpi.first.hal.simulation.AnalogOutDataJNI;
|
||||
import edu.wpi.first.hal.simulation.NotifyCallback;
|
||||
import edu.wpi.first.wpilibj.AnalogOutput;
|
||||
|
||||
public class AnalogOutSim {
|
||||
/**
|
||||
* Class to control a simulated analog output.
|
||||
*/
|
||||
public class AnalogOutputSim {
|
||||
private final int m_index;
|
||||
|
||||
public AnalogOutSim(int index) {
|
||||
m_index = index;
|
||||
/**
|
||||
* Constructs from an AnalogOutput object.
|
||||
*
|
||||
* @param analogOutput AnalogOutput to simulate
|
||||
*/
|
||||
public AnalogOutputSim(AnalogOutput analogOutput) {
|
||||
m_index = analogOutput.getChannel();
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs from an analog output channel number.
|
||||
*
|
||||
* @param channel Channel number
|
||||
*/
|
||||
public AnalogOutputSim(int channel) {
|
||||
m_index = channel;
|
||||
}
|
||||
|
||||
public CallbackStore registerVoltageCallback(NotifyCallback callback, boolean initialNotify) {
|
||||
@@ -9,14 +9,54 @@ package edu.wpi.first.wpilibj.simulation;
|
||||
|
||||
import edu.wpi.first.hal.simulation.AnalogTriggerDataJNI;
|
||||
import edu.wpi.first.hal.simulation.NotifyCallback;
|
||||
import edu.wpi.first.wpilibj.AnalogTrigger;
|
||||
import java.util.NoSuchElementException;
|
||||
|
||||
/**
|
||||
* Class to control a simulated analog trigger.
|
||||
*/
|
||||
public class AnalogTriggerSim {
|
||||
private final int m_index;
|
||||
|
||||
public AnalogTriggerSim(int index) {
|
||||
/**
|
||||
* Constructs from an AnalogTrigger object.
|
||||
*
|
||||
* @param analogTrigger AnalogTrigger to simulate
|
||||
*/
|
||||
public AnalogTriggerSim(AnalogTrigger analogTrigger) {
|
||||
m_index = analogTrigger.getIndex();
|
||||
}
|
||||
|
||||
private AnalogTriggerSim(int index) {
|
||||
m_index = index;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an AnalogTriggerSim for an analog input channel.
|
||||
*
|
||||
* @param channel analog input channel
|
||||
* @return Simulated object
|
||||
* @throws NoSuchElementException if no AnalogTrigger is configured for that channel
|
||||
*/
|
||||
public static AnalogTriggerSim createForChannel(int channel) {
|
||||
int index = AnalogTriggerDataJNI.findForChannel(channel);
|
||||
if (index < 0) {
|
||||
throw new NoSuchElementException("no analog trigger found for channel " + channel);
|
||||
}
|
||||
return new AnalogTriggerSim(index);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an AnalogTriggerSim for a simulated index.
|
||||
* The index is incremented for each simulated AnalogTrigger.
|
||||
*
|
||||
* @param index simulator index
|
||||
* @return Simulated object
|
||||
*/
|
||||
public static AnalogTriggerSim createForIndex(int index) {
|
||||
return new AnalogTriggerSim(index);
|
||||
}
|
||||
|
||||
public CallbackStore registerInitializedCallback(NotifyCallback callback, boolean initialNotify) {
|
||||
int uid = AnalogTriggerDataJNI.registerInitializedCallback(m_index, callback, initialNotify);
|
||||
return new CallbackStore(m_index, uid, AnalogTriggerDataJNI::cancelInitializedCallback);
|
||||
|
||||
@@ -9,11 +9,28 @@ package edu.wpi.first.wpilibj.simulation;
|
||||
|
||||
import edu.wpi.first.hal.simulation.AccelerometerDataJNI;
|
||||
import edu.wpi.first.hal.simulation.NotifyCallback;
|
||||
import edu.wpi.first.wpilibj.BuiltInAccelerometer;
|
||||
|
||||
public class AccelerometerSim {
|
||||
/**
|
||||
* Class to control a simulated built-in accelerometer.
|
||||
*/
|
||||
public class BuiltInAccelerometerSim {
|
||||
private final int m_index;
|
||||
|
||||
public AccelerometerSim() {
|
||||
/**
|
||||
* Constructs for the first built-in accelerometer.
|
||||
*/
|
||||
public BuiltInAccelerometerSim() {
|
||||
m_index = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs from a BuiltInAccelerometer object.
|
||||
*
|
||||
* @param accel BuiltInAccelerometer to simulate
|
||||
*/
|
||||
@SuppressWarnings("PMD.UnusedFormalParameter")
|
||||
public BuiltInAccelerometerSim(BuiltInAccelerometer accel) {
|
||||
m_index = 0;
|
||||
}
|
||||
|
||||
@@ -9,12 +9,40 @@ package edu.wpi.first.wpilibj.simulation;
|
||||
|
||||
import edu.wpi.first.hal.simulation.DIODataJNI;
|
||||
import edu.wpi.first.hal.simulation.NotifyCallback;
|
||||
import edu.wpi.first.wpilibj.DigitalInput;
|
||||
import edu.wpi.first.wpilibj.DigitalOutput;
|
||||
|
||||
/**
|
||||
* Class to control a simulated digital input or output.
|
||||
*/
|
||||
public class DIOSim {
|
||||
private final int m_index;
|
||||
|
||||
public DIOSim(int index) {
|
||||
m_index = index;
|
||||
/**
|
||||
* Constructs from a DigitalInput object.
|
||||
*
|
||||
* @param input DigitalInput to simulate
|
||||
*/
|
||||
public DIOSim(DigitalInput input) {
|
||||
m_index = input.getChannel();
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs from a DigitalOutput object.
|
||||
*
|
||||
* @param output DigitalOutput to simulate
|
||||
*/
|
||||
public DIOSim(DigitalOutput output) {
|
||||
m_index = output.getChannel();
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs from an digital I/O channel number.
|
||||
*
|
||||
* @param channel Channel number
|
||||
*/
|
||||
public DIOSim(int channel) {
|
||||
m_index = channel;
|
||||
}
|
||||
|
||||
public CallbackStore registerInitializedCallback(NotifyCallback callback, boolean initialNotify) {
|
||||
|
||||
@@ -9,14 +9,57 @@ package edu.wpi.first.wpilibj.simulation;
|
||||
|
||||
import edu.wpi.first.hal.simulation.DigitalPWMDataJNI;
|
||||
import edu.wpi.first.hal.simulation.NotifyCallback;
|
||||
import edu.wpi.first.wpilibj.DigitalOutput;
|
||||
import java.util.NoSuchElementException;
|
||||
|
||||
/**
|
||||
* Class to control a simulated digital PWM output.
|
||||
*
|
||||
* <p>This is for duty cycle PWM outputs on a DigitalOutput, not for the servo
|
||||
* style PWM outputs on a PWM channel.
|
||||
*/
|
||||
public class DigitalPWMSim {
|
||||
private final int m_index;
|
||||
|
||||
public DigitalPWMSim(int index) {
|
||||
/**
|
||||
* Constructs from a DigitalOutput object.
|
||||
*
|
||||
* @param digitalOutput DigitalOutput to simulate
|
||||
*/
|
||||
public DigitalPWMSim(DigitalOutput digitalOutput) {
|
||||
m_index = digitalOutput.getChannel();
|
||||
}
|
||||
|
||||
private DigitalPWMSim(int index) {
|
||||
m_index = index;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an DigitalPWMSim for a digital I/O channel.
|
||||
*
|
||||
* @param channel DIO channel
|
||||
* @return Simulated object
|
||||
* @throws NoSuchElementException if no Digital PWM is configured for that channel
|
||||
*/
|
||||
public static DigitalPWMSim createForChannel(int channel) {
|
||||
int index = DigitalPWMDataJNI.findForChannel(channel);
|
||||
if (index < 0) {
|
||||
throw new NoSuchElementException("no digital PWM found for channel " + channel);
|
||||
}
|
||||
return new DigitalPWMSim(index);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an DigitalPWMSim for a simulated index.
|
||||
* The index is incremented for each simulated DigitalPWM.
|
||||
*
|
||||
* @param index simulator index
|
||||
* @return Simulated object
|
||||
*/
|
||||
public static DigitalPWMSim createForIndex(int index) {
|
||||
return new DigitalPWMSim(index);
|
||||
}
|
||||
|
||||
public CallbackStore registerInitializedCallback(NotifyCallback callback, boolean initialNotify) {
|
||||
int uid = DigitalPWMDataJNI.registerInitializedCallback(m_index, callback, initialNotify);
|
||||
return new CallbackStore(m_index, uid, DigitalPWMDataJNI::cancelInitializedCallback);
|
||||
|
||||
@@ -10,73 +10,77 @@ package edu.wpi.first.wpilibj.simulation;
|
||||
import edu.wpi.first.hal.simulation.DriverStationDataJNI;
|
||||
import edu.wpi.first.hal.simulation.NotifyCallback;
|
||||
|
||||
/**
|
||||
* Class to control a simulated driver station.
|
||||
*/
|
||||
@SuppressWarnings("PMD.UseUtilityClass")
|
||||
public class DriverStationSim {
|
||||
public CallbackStore registerEnabledCallback(NotifyCallback callback, boolean initialNotify) {
|
||||
public static CallbackStore registerEnabledCallback(NotifyCallback callback, boolean initialNotify) {
|
||||
int uid = DriverStationDataJNI.registerEnabledCallback(callback, initialNotify);
|
||||
return new CallbackStore(uid, DriverStationDataJNI::cancelEnabledCallback);
|
||||
}
|
||||
public boolean getEnabled() {
|
||||
public static boolean getEnabled() {
|
||||
return DriverStationDataJNI.getEnabled();
|
||||
}
|
||||
public void setEnabled(boolean enabled) {
|
||||
public static void setEnabled(boolean enabled) {
|
||||
DriverStationDataJNI.setEnabled(enabled);
|
||||
}
|
||||
|
||||
public CallbackStore registerAutonomousCallback(NotifyCallback callback, boolean initialNotify) {
|
||||
public static CallbackStore registerAutonomousCallback(NotifyCallback callback, boolean initialNotify) {
|
||||
int uid = DriverStationDataJNI.registerAutonomousCallback(callback, initialNotify);
|
||||
return new CallbackStore(uid, DriverStationDataJNI::cancelAutonomousCallback);
|
||||
}
|
||||
public boolean getAutonomous() {
|
||||
public static boolean getAutonomous() {
|
||||
return DriverStationDataJNI.getAutonomous();
|
||||
}
|
||||
public void setAutonomous(boolean autonomous) {
|
||||
public static void setAutonomous(boolean autonomous) {
|
||||
DriverStationDataJNI.setAutonomous(autonomous);
|
||||
}
|
||||
|
||||
public CallbackStore registerTestCallback(NotifyCallback callback, boolean initialNotify) {
|
||||
public static CallbackStore registerTestCallback(NotifyCallback callback, boolean initialNotify) {
|
||||
int uid = DriverStationDataJNI.registerTestCallback(callback, initialNotify);
|
||||
return new CallbackStore(uid, DriverStationDataJNI::cancelTestCallback);
|
||||
}
|
||||
public boolean getTest() {
|
||||
public static boolean getTest() {
|
||||
return DriverStationDataJNI.getTest();
|
||||
}
|
||||
public void setTest(boolean test) {
|
||||
public static void setTest(boolean test) {
|
||||
DriverStationDataJNI.setTest(test);
|
||||
}
|
||||
|
||||
public CallbackStore registerEStopCallback(NotifyCallback callback, boolean initialNotify) {
|
||||
public static CallbackStore registerEStopCallback(NotifyCallback callback, boolean initialNotify) {
|
||||
int uid = DriverStationDataJNI.registerEStopCallback(callback, initialNotify);
|
||||
return new CallbackStore(uid, DriverStationDataJNI::cancelEStopCallback);
|
||||
}
|
||||
public boolean getEStop() {
|
||||
public static boolean getEStop() {
|
||||
return DriverStationDataJNI.getEStop();
|
||||
}
|
||||
public void setEStop(boolean eStop) {
|
||||
public static void setEStop(boolean eStop) {
|
||||
DriverStationDataJNI.setEStop(eStop);
|
||||
}
|
||||
|
||||
public CallbackStore registerFmsAttachedCallback(NotifyCallback callback, boolean initialNotify) {
|
||||
public static CallbackStore registerFmsAttachedCallback(NotifyCallback callback, boolean initialNotify) {
|
||||
int uid = DriverStationDataJNI.registerFmsAttachedCallback(callback, initialNotify);
|
||||
return new CallbackStore(uid, DriverStationDataJNI::cancelFmsAttachedCallback);
|
||||
}
|
||||
public boolean getFmsAttached() {
|
||||
public static boolean getFmsAttached() {
|
||||
return DriverStationDataJNI.getFmsAttached();
|
||||
}
|
||||
public void setFmsAttached(boolean fmsAttached) {
|
||||
public static void setFmsAttached(boolean fmsAttached) {
|
||||
DriverStationDataJNI.setFmsAttached(fmsAttached);
|
||||
}
|
||||
|
||||
public CallbackStore registerDsAttachedCallback(NotifyCallback callback, boolean initialNotify) {
|
||||
public static CallbackStore registerDsAttachedCallback(NotifyCallback callback, boolean initialNotify) {
|
||||
int uid = DriverStationDataJNI.registerDsAttachedCallback(callback, initialNotify);
|
||||
return new CallbackStore(uid, DriverStationDataJNI::cancelDsAttachedCallback);
|
||||
}
|
||||
public boolean getDsAttached() {
|
||||
public static boolean getDsAttached() {
|
||||
return DriverStationDataJNI.getDsAttached();
|
||||
}
|
||||
public void setDsAttached(boolean dsAttached) {
|
||||
public static void setDsAttached(boolean dsAttached) {
|
||||
DriverStationDataJNI.setDsAttached(dsAttached);
|
||||
}
|
||||
public void notifyNewData() {
|
||||
public static void notifyNewData() {
|
||||
DriverStationDataJNI.notifyNewData();
|
||||
}
|
||||
|
||||
@@ -85,11 +89,11 @@ public class DriverStationSim {
|
||||
*
|
||||
* @param shouldSend If false then messages will will be suppressed.
|
||||
*/
|
||||
public void setSendError(boolean shouldSend) {
|
||||
public static void setSendError(boolean shouldSend) {
|
||||
DriverStationDataJNI.setSendError(shouldSend);
|
||||
}
|
||||
|
||||
public void resetData() {
|
||||
public static void resetData() {
|
||||
DriverStationDataJNI.resetData();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,14 +9,54 @@ package edu.wpi.first.wpilibj.simulation;
|
||||
|
||||
import edu.wpi.first.hal.simulation.DutyCycleDataJNI;
|
||||
import edu.wpi.first.hal.simulation.NotifyCallback;
|
||||
import edu.wpi.first.wpilibj.DutyCycle;
|
||||
import java.util.NoSuchElementException;
|
||||
|
||||
/**
|
||||
* Class to control a simulated duty cycle digital input.
|
||||
*/
|
||||
public class DutyCycleSim {
|
||||
private final int m_index;
|
||||
|
||||
public DutyCycleSim(int index) {
|
||||
/**
|
||||
* Constructs from a DutyCycle object.
|
||||
*
|
||||
* @param dutyCycle DutyCycle to simulate
|
||||
*/
|
||||
public DutyCycleSim(DutyCycle dutyCycle) {
|
||||
m_index = dutyCycle.getFPGAIndex();
|
||||
}
|
||||
|
||||
private DutyCycleSim(int index) {
|
||||
m_index = index;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a DutyCycleSim for a digital input channel.
|
||||
*
|
||||
* @param channel digital input channel
|
||||
* @return Simulated object
|
||||
* @throws NoSuchElementException if no DutyCycle is configured for that channel
|
||||
*/
|
||||
public static DutyCycleSim createForChannel(int channel) {
|
||||
int index = DutyCycleDataJNI.findForChannel(channel);
|
||||
if (index < 0) {
|
||||
throw new NoSuchElementException("no duty cycle found for channel " + channel);
|
||||
}
|
||||
return new DutyCycleSim(index);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a DutyCycleSim for a simulated index.
|
||||
* The index is incremented for each simulated DutyCycle.
|
||||
*
|
||||
* @param index simulator index
|
||||
* @return Simulated object
|
||||
*/
|
||||
public static DutyCycleSim createForIndex(int index) {
|
||||
return new DutyCycleSim(index);
|
||||
}
|
||||
|
||||
public CallbackStore registerInitializedCallback(NotifyCallback callback, boolean initialNotify) {
|
||||
int uid = DutyCycleDataJNI.registerInitializedCallback(m_index, callback, initialNotify);
|
||||
return new CallbackStore(m_index, uid, DutyCycleDataJNI::cancelInitializedCallback);
|
||||
|
||||
@@ -9,14 +9,56 @@ package edu.wpi.first.wpilibj.simulation;
|
||||
|
||||
import edu.wpi.first.hal.simulation.EncoderDataJNI;
|
||||
import edu.wpi.first.hal.simulation.NotifyCallback;
|
||||
import edu.wpi.first.wpilibj.Encoder;
|
||||
import java.util.NoSuchElementException;
|
||||
|
||||
/**
|
||||
* Class to control a simulated encoder.
|
||||
*/
|
||||
@SuppressWarnings("PMD.TooManyMethods")
|
||||
public class EncoderSim {
|
||||
private final int m_index;
|
||||
|
||||
public EncoderSim(int index) {
|
||||
/**
|
||||
* Constructs from an Encoder object.
|
||||
*
|
||||
* @param encoder Encoder to simulate
|
||||
*/
|
||||
public EncoderSim(Encoder encoder) {
|
||||
m_index = encoder.getFPGAIndex();
|
||||
}
|
||||
|
||||
private EncoderSim(int index) {
|
||||
m_index = index;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an EncoderSim for a digital input channel. Encoders take two
|
||||
* channels, so either one may be specified.
|
||||
*
|
||||
* @param channel digital input channel
|
||||
* @return Simulated object
|
||||
* @throws NoSuchElementException if no Encoder is configured for that channel
|
||||
*/
|
||||
public static EncoderSim createForChannel(int channel) {
|
||||
int index = EncoderDataJNI.findForChannel(channel);
|
||||
if (index < 0) {
|
||||
throw new NoSuchElementException("no encoder found for channel " + channel);
|
||||
}
|
||||
return new EncoderSim(index);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an EncoderSim for a simulated index.
|
||||
* The index is incremented for each simulated Encoder.
|
||||
*
|
||||
* @param index simulator index
|
||||
* @return Simulated object
|
||||
*/
|
||||
public static EncoderSim createForIndex(int index) {
|
||||
return new EncoderSim(index);
|
||||
}
|
||||
|
||||
public CallbackStore registerInitializedCallback(NotifyCallback callback, boolean initialNotify) {
|
||||
int uid = EncoderDataJNI.registerInitializedCallback(m_index, callback, initialNotify);
|
||||
return new CallbackStore(m_index, uid, EncoderDataJNI::cancelInitializedCallback);
|
||||
|
||||
@@ -9,14 +9,27 @@ package edu.wpi.first.wpilibj.simulation;
|
||||
|
||||
import edu.wpi.first.hal.simulation.NotifierDataJNI;
|
||||
|
||||
/**
|
||||
* Class to control simulated notifiers.
|
||||
*/
|
||||
public final class NotifierSim {
|
||||
private NotifierSim() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the timeout of the next notifier.
|
||||
*
|
||||
* @return Timestamp
|
||||
*/
|
||||
public static long getNextTimeout() {
|
||||
return NotifierDataJNI.getNextTimeout();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the total number of notifiers.
|
||||
*
|
||||
* @return Count
|
||||
*/
|
||||
public static int getNumNotifiers() {
|
||||
return NotifierDataJNI.getNumNotifiers();
|
||||
}
|
||||
|
||||
@@ -9,12 +9,38 @@ package edu.wpi.first.wpilibj.simulation;
|
||||
|
||||
import edu.wpi.first.hal.simulation.NotifyCallback;
|
||||
import edu.wpi.first.hal.simulation.PCMDataJNI;
|
||||
import edu.wpi.first.wpilibj.Compressor;
|
||||
import edu.wpi.first.wpilibj.SensorUtil;
|
||||
|
||||
/**
|
||||
* Class to control a simulated Pneumatic Control Module (PCM).
|
||||
*/
|
||||
public class PCMSim {
|
||||
private final int m_index;
|
||||
|
||||
public PCMSim(int index) {
|
||||
m_index = index;
|
||||
/**
|
||||
* Constructs for the default PCM.
|
||||
*/
|
||||
public PCMSim() {
|
||||
m_index = SensorUtil.getDefaultSolenoidModule();
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs from a PCM module number (CAN ID).
|
||||
*
|
||||
* @param module module number
|
||||
*/
|
||||
public PCMSim(int module) {
|
||||
m_index = module;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs from a Compressor object.
|
||||
*
|
||||
* @param compressor Compressor connected to PCM to simulate
|
||||
*/
|
||||
public PCMSim(Compressor compressor) {
|
||||
m_index = compressor.getModule();
|
||||
}
|
||||
|
||||
public CallbackStore registerSolenoidInitializedCallback(int channel, NotifyCallback callback, boolean initialNotify) {
|
||||
|
||||
@@ -9,12 +9,37 @@ package edu.wpi.first.wpilibj.simulation;
|
||||
|
||||
import edu.wpi.first.hal.simulation.NotifyCallback;
|
||||
import edu.wpi.first.hal.simulation.PDPDataJNI;
|
||||
import edu.wpi.first.wpilibj.PowerDistributionPanel;
|
||||
|
||||
/**
|
||||
* Class to control a simulated Power Distribution Panel (PDP).
|
||||
*/
|
||||
public class PDPSim {
|
||||
private final int m_index;
|
||||
|
||||
public PDPSim(int index) {
|
||||
m_index = index;
|
||||
/**
|
||||
* Constructs for the default PDP.
|
||||
*/
|
||||
public PDPSim() {
|
||||
m_index = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs from a PDP module number (CAN ID).
|
||||
*
|
||||
* @param module module number
|
||||
*/
|
||||
public PDPSim(int module) {
|
||||
m_index = module;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs from a PowerDistributionPanel object.
|
||||
*
|
||||
* @param pdp PowerDistributionPanel to simulate
|
||||
*/
|
||||
public PDPSim(PowerDistributionPanel pdp) {
|
||||
m_index = pdp.getModule();
|
||||
}
|
||||
|
||||
public CallbackStore registerInitializedCallback(NotifyCallback callback, boolean initialNotify) {
|
||||
|
||||
@@ -9,12 +9,30 @@ package edu.wpi.first.wpilibj.simulation;
|
||||
|
||||
import edu.wpi.first.hal.simulation.NotifyCallback;
|
||||
import edu.wpi.first.hal.simulation.PWMDataJNI;
|
||||
import edu.wpi.first.wpilibj.PWM;
|
||||
|
||||
/**
|
||||
* Class to control a simulated PWM output.
|
||||
*/
|
||||
public class PWMSim {
|
||||
private final int m_index;
|
||||
|
||||
public PWMSim(int index) {
|
||||
m_index = index;
|
||||
/**
|
||||
* Constructs from a PWM object.
|
||||
*
|
||||
* @param pwm PWM to simulate
|
||||
*/
|
||||
public PWMSim(PWM pwm) {
|
||||
m_index = pwm.getChannel();
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs from a PWM channel number.
|
||||
*
|
||||
* @param channel Channel number
|
||||
*/
|
||||
public PWMSim(int channel) {
|
||||
m_index = channel;
|
||||
}
|
||||
|
||||
public CallbackStore registerInitializedCallback(NotifyCallback callback, boolean initialNotify) {
|
||||
|
||||
@@ -9,12 +9,30 @@ package edu.wpi.first.wpilibj.simulation;
|
||||
|
||||
import edu.wpi.first.hal.simulation.NotifyCallback;
|
||||
import edu.wpi.first.hal.simulation.RelayDataJNI;
|
||||
import edu.wpi.first.wpilibj.Relay;
|
||||
|
||||
/**
|
||||
* Class to control a simulated relay.
|
||||
*/
|
||||
public class RelaySim {
|
||||
private final int m_index;
|
||||
|
||||
public RelaySim(int index) {
|
||||
m_index = index;
|
||||
/**
|
||||
* Constructs from a Relay object.
|
||||
*
|
||||
* @param relay Relay to simulate
|
||||
*/
|
||||
public RelaySim(Relay relay) {
|
||||
m_index = relay.getChannel();
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs from a relay channel number.
|
||||
*
|
||||
* @param channel Channel number
|
||||
*/
|
||||
public RelaySim(int channel) {
|
||||
m_index = channel;
|
||||
}
|
||||
|
||||
public CallbackStore registerInitializedForwardCallback(NotifyCallback callback, boolean initialNotify) {
|
||||
|
||||
@@ -16,8 +16,8 @@ import edu.wpi.first.hal.simulation.SpiReadAutoReceiveBufferCallback;
|
||||
public class SPISim {
|
||||
private final int m_index;
|
||||
|
||||
public SPISim(int index) {
|
||||
m_index = index;
|
||||
public SPISim() {
|
||||
m_index = 0;
|
||||
}
|
||||
|
||||
public CallbackStore registerInitializedCallback(NotifyCallback callback, boolean initialNotify) {
|
||||
|
||||
@@ -15,9 +15,17 @@ import edu.wpi.first.hal.simulation.SimDeviceCallback;
|
||||
import edu.wpi.first.hal.simulation.SimDeviceDataJNI;
|
||||
import edu.wpi.first.hal.simulation.SimValueCallback;
|
||||
|
||||
/**
|
||||
* Class to control the simulation side of a SimDevice.
|
||||
*/
|
||||
public class SimDeviceSim {
|
||||
private final int m_handle;
|
||||
|
||||
/**
|
||||
* Constructs a SimDeviceSim.
|
||||
*
|
||||
* @param name name of the SimDevice
|
||||
*/
|
||||
public SimDeviceSim(String name) {
|
||||
m_handle = SimDeviceDataJNI.getSimDeviceHandle(name);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user