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 * Power Distribution JNI Functions.
009 *
010 * @see "hal/PowerDistribution.h"
011 */
012public class PowerDistributionJNI extends JNIWrapper {
013  public static final int AUTOMATIC_TYPE = 0;
014  public static final int CTRE_TYPE = 1;
015  public static final int REV_TYPE = 2;
016  public static final int DEFAULT_MODULE = -1;
017
018  /**
019   * Initializes a Power Distribution Panel.
020   *
021   * @param module the module number to initialize
022   * @param type the type of module to initialize
023   * @return the created PowerDistribution handle
024   * @see "HAL_InitializePowerDistribution"
025   */
026  public static native int initialize(int module, int type);
027
028  /**
029   * Cleans a PowerDistribution module.
030   *
031   * @param handle the module handle
032   * @see "HAL_CleanPowerDistribution"
033   */
034  public static native void free(int handle);
035
036  /**
037   * Gets the module number for a specific handle.
038   *
039   * @param handle the module handle
040   * @return the module number
041   * @see "HAL_GetPowerDistributionModuleNumber"
042   */
043  public static native int getModuleNumber(int handle);
044
045  /**
046   * Checks if a PowerDistribution module is valid.
047   *
048   * @param module the module to check
049   * @param type the type of module
050   * @return true if the module is valid, otherwise false
051   * @see "HAL_CheckPowerDistributionModule"
052   */
053  public static native boolean checkModule(int module, int type);
054
055  /**
056   * Checks if a PowerDistribution channel is valid.
057   *
058   * @param handle the module handle
059   * @param channel the channel to check
060   * @return true if the channel is valid, otherwise false
061   * @see "HAL_CheckPowerDistributionChannel"
062   */
063  public static native boolean checkChannel(int handle, int channel);
064
065  /**
066   * Gets the type of PowerDistribution module.
067   *
068   * @param handle the module handle
069   * @return the type of module
070   * @see "HAL_GetPowerDistributionType"
071   */
072  public static native int getType(int handle);
073
074  /**
075   * Gets the number of channels for this handle.
076   *
077   * @param handle the handle
078   * @return number of channels
079   * @see "HAL_GetPowerDistributionNumChannels"
080   */
081  public static native int getNumChannels(int handle);
082
083  /**
084   * Gets the temperature of the PowerDistribution.
085   *
086   * <p>Not supported on the Rev PDH and returns 0.
087   *
088   * @param handle the module handle
089   * @return the module temperature (celsius)
090   * @see "HAL_GetPowerDistributionTemperature"
091   */
092  public static native double getTemperature(int handle);
093
094  /**
095   * Gets the PowerDistribution input voltage.
096   *
097   * @param handle the module handle
098   * @return the input voltage (volts)
099   * @see "HAL_GetPowerDistributionVoltage"
100   */
101  public static native double getVoltage(int handle);
102
103  /**
104   * Gets the current of a specific PowerDistribution channel.
105   *
106   * @param handle the module handle
107   * @param channel the channel
108   * @return the channel current (amps)
109   * @see "HAL_GetPowerDistributionChannelCurrent"
110   */
111  public static native double getChannelCurrent(int handle, int channel);
112
113  /**
114   * Gets the current of all channels on the PowerDistribution.
115   *
116   * <p>The array must be large enough to hold all channels.
117   *
118   * @param handle the module handle
119   * @param currents the currents
120   * @see "HAL_GetPowerDistributionAllChannelCurrents"
121   */
122  public static native void getAllCurrents(int handle, double[] currents);
123
124  /**
125   * Gets the total current of the PowerDistribution.
126   *
127   * @param handle the module handle
128   * @return the total current (amps)
129   * @see "HAL_GetPowerDistributionTotalCurrent"
130   */
131  public static native double getTotalCurrent(int handle);
132
133  /**
134   * Gets the total power of the Power Distribution Panel.
135   *
136   * <p>Not supported on the Rev PDH and returns 0.
137   *
138   * @param handle the module handle
139   * @return the total power (watts)
140   * @see "HAL_GetPowerDistributionTotalPower"
141   */
142  public static native double getTotalPower(int handle);
143
144  /**
145   * Gets the total energy of the Power Distribution Panel.
146   *
147   * <p>Not supported on the Rev PDH and does nothing.
148   *
149   * @param handle the module handle
150   * @return the total energy (joules)
151   * @see "HAL_GetPowerDistributionTotalEnergy"
152   */
153  public static native double getTotalEnergy(int handle);
154
155  /**
156   * Resets the Power Distribution Panel accumulated energy.
157   *
158   * <p>Not supported on the Rev PDH and returns 0.
159   *
160   * @param handle the module handle
161   * @see "HAL_ClearPowerDistributionStickyFaults"
162   */
163  public static native void resetTotalEnergy(int handle);
164
165  /**
166   * Clears any PowerDistribution sticky faults.
167   *
168   * @param handle the module handle
169   * @see "HAL_ClearPowerDistributionStickyFaults"
170   */
171  public static native void clearStickyFaults(int handle);
172
173  /**
174   * Returns true if switchable channel is powered on.
175   *
176   * <p>This is a REV PDH-specific function. This function will no-op on CTRE PDP.
177   *
178   * @param handle the module handle
179   * @return the state of the switchable channel
180   * @see "HAL_GetPowerDistributionSwitchableChannel"
181   */
182  public static native boolean getSwitchableChannel(int handle);
183
184  /**
185   * Power on/off switchable channel.
186   *
187   * <p>This is a REV PDH-specific function. This function will no-op on CTRE PDP.
188   *
189   * @param handle the module handle
190   * @param enabled true to turn on switchable channel
191   * @see "HAL_SetPowerDistributionSwitchableChannel"
192   */
193  public static native void setSwitchableChannel(int handle, boolean enabled);
194
195  /**
196   * Gets the PowerDistribution input voltage without throwing any errors.
197   *
198   * @param handle the module handle
199   * @return the input voltage (volts)
200   * @see "HAL_GetPowerDistributionVoltage"
201   */
202  public static native double getVoltageNoError(int handle);
203
204  /**
205   * Gets the current of a specific PowerDistribution channel without throwing any errors.
206   *
207   * @param handle the module handle
208   * @param channel the channel
209   * @return the channel current (amps)
210   * @see "HAL_GetPowerDistributionChannelCurrent"
211   */
212  public static native double getChannelCurrentNoError(int handle, int channel);
213
214  /**
215   * Gets the total current of the PowerDistribution without throwing any errors.
216   *
217   * @param handle the module handle
218   * @return the total current (amps)
219   * @see "HAL_GetPowerDistributionTotalCurrent"
220   */
221  public static native double getTotalCurrentNoError(int handle);
222
223  /**
224   * Returns true if switchable channel is powered on without throwing any errors.
225   *
226   * <p>This is a REV PDH-specific function. This function will no-op on CTRE PDP.
227   *
228   * @param handle the module handle
229   * @return the state of the switchable channel
230   * @see "HAL_GetPowerDistributionSwitchableChannel"
231   */
232  public static native boolean getSwitchableChannelNoError(int handle);
233
234  /**
235   * Power on/off switchable channel without throwing any errors.
236   *
237   * <p>This is a REV PDH-specific function. This function will no-op on CTRE PDP.
238   *
239   * @param handle the module handle
240   * @param enabled true to turn on switchable channel
241   * @see "HAL_SetPowerDistributionSwitchableChannel"
242   */
243  public static native void setSwitchableChannelNoError(int handle, boolean enabled);
244
245  /**
246   * Get the current faults of the PowerDistribution.
247   *
248   * @param handle the module handle
249   * @return the current faults
250   * @see "HAL_GetPowerDistributionFaults"
251   */
252  public static native int getFaultsNative(int handle);
253
254  /**
255   * Get the current faults of the PowerDistribution.
256   *
257   * @param handle the module handle
258   * @return the current faults
259   * @see "HAL_GetPowerDistributionFaults"
260   */
261  public static PowerDistributionFaults getFaults(int handle) {
262    return new PowerDistributionFaults(getFaultsNative(handle));
263  }
264
265  /**
266   * Gets the sticky faults of the PowerDistribution.
267   *
268   * @param handle the module handle
269   * @return the sticky faults
270   * @see "HAL_GetPowerDistributionStickyFaults"
271   */
272  public static native int getStickyFaultsNative(int handle);
273
274  /**
275   * Gets the sticky faults of the PowerDistribution.
276   *
277   * @param handle the module handle
278   * @return the sticky faults
279   * @see "HAL_GetPowerDistributionStickyFaults"
280   */
281  public static PowerDistributionStickyFaults getStickyFaults(int handle) {
282    return new PowerDistributionStickyFaults(getStickyFaultsNative(handle));
283  }
284
285  /**
286   * Get the version of the PowerDistribution.
287   *
288   * @param handle the module handle
289   * @return version
290   * @see "HAL_GetPowerDistributionVersion"
291   */
292  public static native PowerDistributionVersion getVersion(int handle);
293
294  /** Utility class. */
295  private PowerDistributionJNI() {}
296}