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