001// Copyright (c) FIRST and other WPILib contributors.
002// Open Source Software; you can modify and/or share it under the terms of
003// the WPILib BSD license file in the root directory of this project.
004
005package edu.wpi.first.hal;
006
007/**
008 * REV Pneumatic Hub (PH) HAL JNI functions.
009 *
010 * @see "REVPH.h"
011 */
012public class REVPHJNI extends JNIWrapper {
013  public static final int COMPRESSOR_CONFIG_TYPE_DISABLED = 0;
014  public static final int COMPRESSOR_CONFIG_TYPE_DIGITAL = 1;
015  public static final int COMPRESSOR_CONFIG_TYPE_ANALOG = 2;
016  public static final int COMPRESSOR_CONFIG_TYPE_HYBRID = 3;
017
018  /**
019   * Initializes a PH.
020   *
021   * @param module the CAN ID to initialize
022   * @return the created PH handle
023   * @see "HAL_InitializeREVP"
024   */
025  public static native int initialize(int module);
026
027  /**
028   * Frees a PH handle.
029   *
030   * @param handle the PH handle
031   * @see "HAL_FreeREVPH"
032   */
033  public static native void free(int handle);
034
035  /**
036   * Checks if a solenoid channel number is valid.
037   *
038   * @param channel the channel to check
039   * @return true if the channel is valid, otherwise false
040   * @see "HAL_CheckREVPHSolenoidChannel"
041   */
042  public static native boolean checkSolenoidChannel(int channel);
043
044  /**
045   * Get whether compressor is turned on.
046   *
047   * @param handle the PH handle
048   * @return true if the compressor is turned on
049   * @see "HAL_GetREVPHCompressor"
050   */
051  public static native boolean getCompressor(int handle);
052
053  /**
054   * Send compressor configuration to the PH.
055   *
056   * @param handle the PH handle
057   * @param minAnalogVoltage The compressor will turn on when the analog pressure sensor voltage
058   *     drops below this value
059   * @param maxAnalogVoltage The compressor will turn off when the analog pressure sensor reaches
060   *     this value.
061   * @param forceDisable Disable Compressor
062   * @param useDigital use the digital pressure switch
063   * @see "HAL_SetREVPHCompressorConfig"
064   */
065  public static native void setCompressorConfig(
066      int handle,
067      double minAnalogVoltage,
068      double maxAnalogVoltage,
069      boolean forceDisable,
070      boolean useDigital);
071
072  /**
073   * Disable Compressor.
074   *
075   * @param handle the PH handle
076   * @see "HAL_SetREVPHClosedLoopControlDisabled"
077   */
078  public static native void setClosedLoopControlDisabled(int handle);
079
080  /**
081   * Enables the compressor in digital mode using the digital pressure switch. The compressor will
082   * turn on when the pressure switch indicates that the system is not full, and will turn off when
083   * the pressure switch indicates that the system is full.
084   *
085   * @param handle the PH handle
086   * @see "HAL_SetREVPHClosedLoopControlDigital"
087   */
088  public static native void setClosedLoopControlDigital(int handle);
089
090  /**
091   * Enables the compressor in analog mode. This mode uses an analog pressure sensor connected to
092   * analog channel 0 to cycle the compressor. The compressor will turn on when the pressure drops
093   * below minAnalogVoltage and will turn off when the pressure reaches maxAnalogVoltage. This mode
094   * is only supported by the REV PH with the REV Analog Pressure Sensor connected to analog channel
095   * 0.
096   *
097   * @param handle the PH handle
098   * @param minAnalogVoltage The compressor will turn on when the analog pressure sensor voltage
099   *     drops below this value
100   * @param maxAnalogVoltage The compressor will turn off when the analog pressure sensor reaches
101   *     this value.
102   * @see "HAL_SetREVPHClosedLoopControlAnalog"
103   */
104  public static native void setClosedLoopControlAnalog(
105      int handle, double minAnalogVoltage, double maxAnalogVoltage);
106
107  /**
108   * Enables the compressor in hybrid mode. This mode uses both a digital pressure switch and an
109   * analog pressure sensor connected to analog channel 0 to cycle the compressor.
110   *
111   * <p>The compressor will turn on when \a both:
112   *
113   * <p>- The digital pressure switch indicates the system is not full AND - The analog pressure
114   * sensor indicates that the pressure in the system is below the specified minimum pressure.
115   *
116   * <p>The compressor will turn off when \a either:
117   *
118   * <p>- The digital pressure switch is disconnected or indicates that the system is full OR - The
119   * pressure detected by the analog sensor is greater than the specified maximum pressure.
120   *
121   * @param handle the PH handle
122   * @param minAnalogVoltage The compressor will turn on when the analog pressure sensor voltage
123   *     drops below this value and the pressure switch indicates that the system is not full.
124   * @param maxAnalogVoltage The compressor will turn off when the analog pressure sensor reaches
125   *     this value or the pressure switch is disconnected or indicates that the system is full.
126   * @see "HAL_SetREVPHClosedLoopControlHybrid"
127   */
128  public static native void setClosedLoopControlHybrid(
129      int handle, double minAnalogVoltage, double maxAnalogVoltage);
130
131  /**
132   * Get compressor configuration from the PH.
133   *
134   * @param handle the PH handle
135   * @return compressor configuration
136   * @see "HAL_GetREVPHCompressorConfig"
137   */
138  public static native int getCompressorConfig(int handle);
139
140  /**
141   * Returns the state of the digital pressure switch.
142   *
143   * @param handle the PH handle
144   * @return True if pressure switch indicates that the system is full, otherwise false.
145   * @see "HAL_GetREVPHPressureSwitch"
146   */
147  public static native boolean getPressureSwitch(int handle);
148
149  /**
150   * Returns the raw voltage of the specified analog input channel.
151   *
152   * @param handle the PH handle
153   * @param channel The analog input channel to read voltage from.
154   * @return The voltage of the specified analog input channel in volts.
155   * @see "HAL_GetREVPHAnalogVoltage"
156   */
157  public static native double getAnalogVoltage(int handle, int channel);
158
159  /**
160   * Returns the current drawn by the compressor.
161   *
162   * @param handle the PH handle
163   * @return The current drawn by the compressor in amps.
164   * @see "HAL_GetREVPHCompressorCurrent"
165   */
166  public static native double getCompressorCurrent(int handle);
167
168  /**
169   * Gets a bitmask of solenoid values.
170   *
171   * @param handle the PH handle
172   * @return solenoid values
173   * @see "HAL_GetREVPHSolenoids"
174   */
175  public static native int getSolenoids(int handle);
176
177  /**
178   * Sets solenoids on a PH.
179   *
180   * @param handle the PH handle
181   * @param mask bitmask to set
182   * @param values solenoid values
183   * @see "HAL_SetREVPHSolenoids"
184   */
185  public static native void setSolenoids(int handle, int mask, int values);
186
187  /**
188   * Fire a single solenoid shot for the specified duration.
189   *
190   * @param handle the PH handle
191   * @param index solenoid index
192   * @param durMs shot duration in ms
193   * @see "HAL_FireREVPHOneShot"
194   */
195  public static native void fireOneShot(int handle, int index, int durMs);
196
197  /**
198   * Clears the sticky faults.
199   *
200   * @param handle the PH handle
201   * @see "HAL_ClearREVPHStickyFaults"
202   */
203  public static native void clearStickyFaults(int handle);
204
205  /**
206   * Returns the current input voltage for the PH.
207   *
208   * @param handle the PH handle
209   * @return The input voltage in volts.
210   * @see "HAL_GetREVPHVoltage"
211   */
212  public static native double getInputVoltage(int handle);
213
214  /**
215   * Returns the current voltage of the regulated 5v supply.
216   *
217   * @param handle the PH handle
218   * @return The current voltage of the 5v supply in volts.
219   * @see "HAL_GetREVPH5VVoltage"
220   */
221  public static native double get5VVoltage(int handle);
222
223  /**
224   * Returns the total current drawn by all solenoids.
225   *
226   * @param handle the PH handle
227   * @return Total current drawn by all solenoids in amps.
228   * @see "HAL_GetREVPHSolenoidCurrent"
229   */
230  public static native double getSolenoidCurrent(int handle);
231
232  /**
233   * Returns the current voltage of the solenoid power supply.
234   *
235   * @param handle the PH handle
236   * @return The current voltage of the solenoid power supply in volts.
237   * @see "HAL_GetREVPHSolenoidVoltage"
238   */
239  public static native double getSolenoidVoltage(int handle);
240
241  /**
242   * Returns the sticky faults currently active on this device.
243   *
244   * @param handle the PH handle
245   * @return The sticky faults.
246   * @see "HAL_GetREVPHStickyFaults"
247   */
248  public static native int getStickyFaultsNative(int handle);
249
250  /**
251   * Returns the sticky faults currently active on this device.
252   *
253   * @param handle the PH handle
254   * @return The sticky faults.
255   * @see "HAL_GetREVPHStickyFaults"
256   */
257  public static REVPHStickyFaults getStickyFaults(int handle) {
258    return new REVPHStickyFaults(getStickyFaultsNative(handle));
259  }
260
261  /**
262   * Returns the faults currently active on the PH.
263   *
264   * @param handle the PH handle
265   * @return The faults.
266   * @see "HAL_GetREVPHFaults"
267   */
268  public static native int getFaultsNative(int handle);
269
270  /**
271   * Returns the faults currently active on the PH.
272   *
273   * @param handle the PH handle
274   * @return The faults.
275   * @see "HAL_GetREVPHFaults"
276   */
277  public static REVPHFaults getFaults(int handle) {
278    return new REVPHFaults(getFaultsNative(handle));
279  }
280
281  /**
282   * Returns the hardware and firmware versions of the PH.
283   *
284   * @param handle the PH handle
285   * @return The hardware and firmware versions.
286   * @see "HAL_GetREVPHVersion"
287   */
288  public static native REVPHVersion getVersion(int handle);
289
290  /** Utility class. */
291  private REVPHJNI() {}
292}