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