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 * @param handle the module handle 087 * @return the module temperature (celsius) 088 * @see "HAL_GetPowerDistributionTemperature" 089 */ 090 public static native double getTemperature(int handle); 091 092 /** 093 * Gets the PowerDistribution input voltage. 094 * 095 * @param handle the module handle 096 * @return the input voltage (volts) 097 * @see "HAL_GetPowerDistributionVoltage" 098 */ 099 public static native double getVoltage(int handle); 100 101 /** 102 * Gets the current of a specific PowerDistribution channel. 103 * 104 * @param handle the module handle 105 * @param channel the channel 106 * @return the channel current (amps) 107 * @see "HAL_GetPowerDistributionChannelCurrent" 108 */ 109 public static native double getChannelCurrent(int handle, int channel); 110 111 /** 112 * Gets the current of all channels on the PowerDistribution. 113 * 114 * <p>The array must be large enough to hold all channels. 115 * 116 * @param handle the module handle 117 * @param currents the currents 118 * @see "HAL_GetPowerDistributionAllChannelCurrents" 119 */ 120 public static native void getAllCurrents(int handle, double[] currents); 121 122 /** 123 * Gets the total current of the PowerDistribution. 124 * 125 * @param handle the module handle 126 * @return the total current (amps) 127 * @see "HAL_GetPowerDistributionTotalCurrent" 128 */ 129 public static native double getTotalCurrent(int handle); 130 131 /** 132 * Gets the total power of the PowerDistribution. 133 * 134 * @param handle the module handle 135 * @return the total power (watts) 136 * @see "HAL_GetPowerDistributionTotalPower" 137 */ 138 public static native double getTotalPower(int handle); 139 140 /** 141 * Gets the total energy of the PowerDistribution. 142 * 143 * @param handle the module handle 144 * @return the total energy (joules) 145 * @see "HAL_GetPowerDistributionTotalEnergy" 146 */ 147 public static native double getTotalEnergy(int handle); 148 149 /** 150 * Resets the PowerDistribution accumulated energy. 151 * 152 * @param handle the module handle 153 * @see "HAL_ClearPowerDistributionStickyFaults" 154 */ 155 public static native void resetTotalEnergy(int handle); 156 157 /** 158 * Clears any PowerDistribution sticky faults. 159 * 160 * @param handle the module handle 161 * @see "HAL_ClearPowerDistributionStickyFaults" 162 */ 163 public static native void clearStickyFaults(int handle); 164 165 /** 166 * Returns true if switchable channel is powered on. 167 * 168 * <p>This is a REV PDH-specific function. This function will no-op on CTRE PDP. 169 * 170 * @param handle the module handle 171 * @return the state of the switchable channel 172 * @see "HAL_GetPowerDistributionSwitchableChannel" 173 */ 174 public static native boolean getSwitchableChannel(int handle); 175 176 /** 177 * Power on/off switchable channel. 178 * 179 * <p>This is a REV PDH-specific function. This function will no-op on CTRE PDP. 180 * 181 * @param handle the module handle 182 * @param enabled true to turn on switchable channel 183 * @see "HAL_SetPowerDistributionSwitchableChannel" 184 */ 185 public static native void setSwitchableChannel(int handle, boolean enabled); 186 187 /** 188 * Gets the PowerDistribution input voltage without throwing any errors. 189 * 190 * @param handle the module handle 191 * @return the input voltage (volts) 192 * @see "HAL_GetPowerDistributionVoltage" 193 */ 194 public static native double getVoltageNoError(int handle); 195 196 /** 197 * Gets the current of a specific PowerDistribution channel without throwing any errors. 198 * 199 * @param handle the module handle 200 * @param channel the channel 201 * @return the channel current (amps) 202 * @see "HAL_GetPowerDistributionChannelCurrent" 203 */ 204 public static native double getChannelCurrentNoError(int handle, int channel); 205 206 /** 207 * Gets the total current of the PowerDistribution without throwing any errors. 208 * 209 * @param handle the module handle 210 * @return the total current (amps) 211 * @see "HAL_GetPowerDistributionTotalCurrent" 212 */ 213 public static native double getTotalCurrentNoError(int handle); 214 215 /** 216 * Returns true if switchable channel is powered on without throwing any errors. 217 * 218 * <p>This is a REV PDH-specific function. This function will no-op on CTRE PDP. 219 * 220 * @param handle the module handle 221 * @return the state of the switchable channel 222 * @see "HAL_GetPowerDistributionSwitchableChannel" 223 */ 224 public static native boolean getSwitchableChannelNoError(int handle); 225 226 /** 227 * Power on/off switchable channel without throwing any errors. 228 * 229 * <p>This is a REV PDH-specific function. This function will no-op on CTRE PDP. 230 * 231 * @param handle the module handle 232 * @param enabled true to turn on switchable channel 233 * @see "HAL_SetPowerDistributionSwitchableChannel" 234 */ 235 public static native void setSwitchableChannelNoError(int handle, boolean enabled); 236 237 /** 238 * Get the current faults of the PowerDistribution. 239 * 240 * @param handle the module handle 241 * @return the current faults 242 * @see "HAL_GetPowerDistributionFaults" 243 */ 244 public static native int getFaultsNative(int handle); 245 246 /** 247 * Get the current faults of the PowerDistribution. 248 * 249 * @param handle the module handle 250 * @return the current faults 251 * @see "HAL_GetPowerDistributionFaults" 252 */ 253 public static PowerDistributionFaults getFaults(int handle) { 254 return new PowerDistributionFaults(getFaultsNative(handle)); 255 } 256 257 /** 258 * Gets the sticky faults of the PowerDistribution. 259 * 260 * @param handle the module handle 261 * @return the sticky faults 262 * @see "HAL_GetPowerDistributionStickyFaults" 263 */ 264 public static native int getStickyFaultsNative(int handle); 265 266 /** 267 * Gets the sticky faults of the PowerDistribution. 268 * 269 * @param handle the module handle 270 * @return the sticky faults 271 * @see "HAL_GetPowerDistributionStickyFaults" 272 */ 273 public static PowerDistributionStickyFaults getStickyFaults(int handle) { 274 return new PowerDistributionStickyFaults(getStickyFaultsNative(handle)); 275 } 276 277 /** 278 * Get the version of the PowerDistribution. 279 * 280 * @param handle the module handle 281 * @return version 282 * @see "HAL_GetPowerDistributionVersion" 283 */ 284 public static native PowerDistributionVersion getVersion(int handle); 285}