[hal, wpilib] Remove analog output (#7696)

This commit is contained in:
Thad House
2025-01-16 23:20:44 -08:00
committed by GitHub
parent 5017393b3a
commit ff1b2a205e
45 changed files with 0 additions and 1685 deletions

View File

@@ -1,76 +0,0 @@
// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
package edu.wpi.first.wpilibj;
import edu.wpi.first.hal.AnalogJNI;
import edu.wpi.first.hal.FRCNetComm.tResourceType;
import edu.wpi.first.hal.HAL;
import edu.wpi.first.util.sendable.Sendable;
import edu.wpi.first.util.sendable.SendableBuilder;
import edu.wpi.first.util.sendable.SendableRegistry;
/** Analog output class. */
public class AnalogOutput implements Sendable, AutoCloseable {
private int m_port;
private int m_channel;
/**
* Construct an analog output on a specified MXP channel.
*
* @param channel The channel number to represent.
*/
@SuppressWarnings("this-escape")
public AnalogOutput(final int channel) {
SensorUtil.checkAnalogOutputChannel(channel);
m_channel = channel;
final int portHandle = HAL.getPort((byte) channel);
m_port = AnalogJNI.initializeAnalogOutputPort(portHandle);
HAL.report(tResourceType.kResourceType_AnalogOutput, channel + 1);
SendableRegistry.addLW(this, "AnalogOutput", channel);
}
@Override
public void close() {
SendableRegistry.remove(this);
AnalogJNI.freeAnalogOutputPort(m_port);
m_port = 0;
m_channel = 0;
}
/**
* Get the channel of this AnalogOutput.
*
* @return The channel of this AnalogOutput.
*/
public int getChannel() {
return m_channel;
}
/**
* Set the value of the analog output.
*
* @param voltage The output value in Volts, from 0.0 to +5.0.
*/
public void setVoltage(double voltage) {
AnalogJNI.setAnalogOutput(m_port, voltage);
}
/**
* Get the voltage of the analog output.
*
* @return The value in Volts, from 0.0 to +5.0.
*/
public double getVoltage() {
return AnalogJNI.getAnalogOutput(m_port);
}
@Override
public void initSendable(SendableBuilder builder) {
builder.setSmartDashboardType("Analog Output");
builder.addDoubleProperty("Value", this::getVoltage, this::setVoltage);
}
}

View File

@@ -25,9 +25,6 @@ public final class SensorUtil {
/** Number of analog input channels per roboRIO. */
public static final int kAnalogInputChannels = PortsJNI.getNumAnalogInputs();
/** Number of analog output channels per roboRIO. */
public static final int kAnalogOutputChannels = PortsJNI.getNumAnalogOutputs();
/** Number of solenoid channels per module. */
public static final int kCTRESolenoidChannels = PortsJNI.getNumCTRESolenoidChannels();
@@ -100,23 +97,6 @@ public final class SensorUtil {
}
}
/**
* Check that the analog input number is value. Verify that the analog input number is one of the
* legal channel numbers. Channel numbers are 0-based.
*
* @param channel The channel number to check.
*/
public static void checkAnalogOutputChannel(final int channel) {
if (!AnalogJNI.checkAnalogOutputChannel(channel)) {
String buf =
"Requested analog output channel is out of range. Minimum: 0, Maximum: "
+ kAnalogOutputChannels
+ ", Requested: "
+ channel;
throw new IllegalArgumentException(buf);
}
}
/**
* Get the number of the default solenoid module.
*

View File

@@ -1,97 +0,0 @@
// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
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;
/** Class to control a simulated analog output. */
public class AnalogOutputSim {
private final int m_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;
}
/**
* Register a callback to be run whenever the voltage changes.
*
* @param callback the callback
* @param initialNotify whether to call the callback with the initial state
* @return the {@link CallbackStore} object associated with this callback.
*/
public CallbackStore registerVoltageCallback(NotifyCallback callback, boolean initialNotify) {
int uid = AnalogOutDataJNI.registerVoltageCallback(m_index, callback, initialNotify);
return new CallbackStore(m_index, uid, AnalogOutDataJNI::cancelVoltageCallback);
}
/**
* Read the analog output voltage.
*
* @return the voltage on this analog output
*/
public double getVoltage() {
return AnalogOutDataJNI.getVoltage(m_index);
}
/**
* Set the analog output voltage.
*
* @param voltage the new voltage on this analog output
*/
public void setVoltage(double voltage) {
AnalogOutDataJNI.setVoltage(m_index, voltage);
}
/**
* Register a callback to be run when this analog output is initialized.
*
* @param callback the callback
* @param initialNotify whether to run the callback with the initial state
* @return the {@link CallbackStore} object associated with this callback.
*/
public CallbackStore registerInitializedCallback(NotifyCallback callback, boolean initialNotify) {
int uid = AnalogOutDataJNI.registerInitializedCallback(m_index, callback, initialNotify);
return new CallbackStore(m_index, uid, AnalogOutDataJNI::cancelInitializedCallback);
}
/**
* Check whether this analog output has been initialized.
*
* @return true if initialized
*/
public boolean getInitialized() {
return AnalogOutDataJNI.getInitialized(m_index);
}
/**
* Define whether this analog output has been initialized.
*
* @param initialized whether this object is initialized
*/
public void setInitialized(boolean initialized) {
AnalogOutDataJNI.setInitialized(m_index, initialized);
}
/** Reset all simulation data on this object. */
public void resetData() {
AnalogOutDataJNI.resetData(m_index);
}
}