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