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 * CTRE Pneumatic Control Module (PCM) Functions.
009 *
010 * @see "CTREPCM.h"
011 */
012public class CTREPCMJNI extends JNIWrapper {
013  /**
014   * Initializes a PCM.
015   *
016   * @param busId the bus id
017   * @param module the CAN ID to initialize
018   * @return the created PH handle
019   * @see "HAL_InitializeCTREPCM"
020   */
021  public static native int initialize(int busId, int module);
022
023  /**
024   * Frees a PCM handle.
025   *
026   * @param handle the PCMhandle
027   * @see "HAL_FreeCTREPCM"
028   */
029  public static native void free(int handle);
030
031  /**
032   * Checks if a solenoid channel number is valid.
033   *
034   * @param channel the channel to check
035   * @return true if the channel is valid, otherwise false
036   */
037  public static native boolean checkSolenoidChannel(int channel);
038
039  /**
040   * Get whether compressor is turned on.
041   *
042   * @param handle the PCM handle
043   * @return true if the compressor is turned on
044   * @see "HAL_GetCTREPCMCompressor"
045   */
046  public static native boolean getCompressor(int handle);
047
048  /**
049   * Enables the compressor closed loop control using the digital pressure switch. The compressor
050   * will turn on when the pressure switch indicates that the system is not full, and will turn off
051   * when the pressure switch indicates that the system is full.
052   *
053   * @param handle the PCM handle
054   * @param enabled true to enable closed loop control
055   * @see "HAL_SetCTREPCMClosedLoopControl"
056   */
057  public static native void setClosedLoopControl(int handle, boolean enabled);
058
059  /**
060   * Get whether the PCM closed loop control is enabled.
061   *
062   * @param handle the PCM handle
063   * @return True if closed loop control is enabled, otherwise false.
064   */
065  public static native boolean getClosedLoopControl(int handle);
066
067  /**
068   * Returns the state of the pressure switch.
069   *
070   * @param handle the PCM handle
071   * @return True if pressure switch indicates that the system is full, otherwise false.
072   * @see "HAL_GetCTREPCMPressureSwitch"
073   */
074  public static native boolean getPressureSwitch(int handle);
075
076  /**
077   * Returns the current drawn by the compressor.
078   *
079   * @param handle the PCM handle
080   * @return The current drawn by the compressor in amps.
081   * @see "HAL_GetCTREPCMCompressorCurrent"
082   */
083  public static native double getCompressorCurrent(int handle);
084
085  /**
086   * Return whether the compressor current is currently too high.
087   *
088   * @param handle the PCM handle
089   * @return True if the compressor current is too high, otherwise false.
090   * @see getCompressorCurrentTooHighStickyFault
091   * @see "HAL_GetCTREPCMCompressorCurrentTooHighFault"
092   */
093  public static native boolean getCompressorCurrentTooHighFault(int handle);
094
095  /**
096   * Returns whether the compressor current has been too high since sticky faults were last cleared.
097   * This fault is persistent and can be cleared by clearAllStickyFaults()
098   *
099   * @param handle the PCM handle
100   * @return True if the compressor current has been too high since sticky faults were last cleared.
101   * @see getCompressorCurrentTooHighFault
102   * @see "HAL_GetCTREPCMCompressorCurrentTooHighStickyFault("
103   */
104  public static native boolean getCompressorCurrentTooHighStickyFault(int handle);
105
106  /**
107   * Returns whether the compressor is currently shorted.
108   *
109   * @param handle the PCM handle
110   * @return True if the compressor is currently shorted, otherwise false.
111   * @see getCompressorCurrentTooHighStickyFault
112   * @see "HAL_GetCTREPCMCompressorShortedStickyFault"
113   */
114  public static native boolean getCompressorShortedFault(int handle);
115
116  /**
117   * Returns whether the compressor has been shorted since sticky faults were last cleared. This
118   * fault is persistent and can be cleared by clearAllStickyFaults()
119   *
120   * @param handle the PCM handle
121   * @return True if the compressor has been shorted since sticky faults were last cleared,
122   *     otherwise false.
123   * @see getCompressorShortedFault
124   * @see "HAL_GetCTREPCMCompressorShortedFault"
125   */
126  public static native boolean getCompressorShortedStickyFault(int handle);
127
128  /**
129   * Returns whether the compressor is currently disconnected.
130   *
131   * @param handle the PCM handle
132   * @return True if compressor is currently disconnected, otherwise false.
133   * @see getCompressorShortedStickyFault
134   * @see "HAL_GetCTREPCMCompressorNotConnectedFault"
135   */
136  public static native boolean getCompressorNotConnectedFault(int handle);
137
138  /**
139   * Returns whether the compressor has been disconnected since sticky faults were last cleared.
140   * This fault is persistent and can be cleared by clearAllStickyFaults()
141   *
142   * @param handle the PCM handle
143   * @return True if the compressor has been disconnected since sticky faults were last cleared,
144   *     otherwise false.
145   * @see getCompressorNotConnectedFault
146   * @see "HAL_GetCTREPCMCompressorNotConnectedStickyFault"
147   */
148  public static native boolean getCompressorNotConnectedStickyFault(int handle);
149
150  /**
151   * Gets a bitmask of solenoid values.
152   *
153   * @param handle the PCM handle
154   * @return Bitmask containing the state of the solenoids. The LSB represents solenoid 0.
155   * @see "HAL_GetCTREPCMSolenoids"
156   */
157  public static native int getSolenoids(int handle);
158
159  /**
160   * Sets solenoids on a pneumatics module.
161   *
162   * @param handle the PCM handle
163   * @param mask Bitmask indicating which solenoids to set. The LSB represents solenoid 0.
164   * @param values Bitmask indicating the desired states of the solenoids. The LSB represents
165   *     solenoid 0.
166   * @see "HAL_SetCTREPCMSolenoids"
167   */
168  public static native void setSolenoids(int handle, int mask, int values);
169
170  /**
171   * Get a bitmask of disabled solenoids.
172   *
173   * @param handle the PCM handle
174   * @return Bitmask indicating disabled solenoids. The LSB represents solenoid 0.
175   * @see "HAL_GetCTREPCMSolenoidDisabledList"
176   */
177  public static native int getSolenoidDisabledList(int handle);
178
179  /**
180   * Returns whether the solenoid is currently reporting a voltage fault.
181   *
182   * @param handle the PCM handle
183   * @return True if solenoid is reporting a fault, otherwise false.
184   * @see getSolenoidVoltageStickyFault
185   * @see "HAL_GetCTREPCMSolenoidVoltageFault"
186   */
187  public static native boolean getSolenoidVoltageFault(int handle);
188
189  /**
190   * Returns whether the solenoid has reported a voltage fault since sticky faults were last
191   * cleared. This fault is persistent and can be cleared by clearAllStickyFaults()
192   *
193   * @param handle the PCM handle
194   * @return True if solenoid is reporting a fault, otherwise false.
195   * @see getSolenoidVoltageFault
196   * @see "HAL_GetCTREPCMSolenoidVoltageStickyFault"
197   */
198  public static native boolean getSolenoidVoltageStickyFault(int handle);
199
200  /**
201   * Clears all sticky faults on this device.
202   *
203   * @param handle the PCM handle
204   * @see "HAL_ClearAllCTREPCMStickyFaults"
205   */
206  public static native void clearAllStickyFaults(int handle);
207
208  /**
209   * Fire a single solenoid shot.
210   *
211   * @param handle the PCM handle
212   * @param index solenoid index
213   * @see "HAL_FireCTREPCMOneShot"
214   */
215  public static native void fireOneShot(int handle, int index);
216
217  /**
218   * Set the duration for a single solenoid shot.
219   *
220   * @param handle the PCM handle
221   * @param index solenoid index
222   * @param durMs shot duration in ms
223   * @see "HAL_SetCTREPCMOneShotDuration"
224   */
225  public static native void setOneShotDuration(int handle, int index, int durMs);
226
227  /** Utility class. */
228  private CTREPCMJNI() {}
229}