001/*----------------------------------------------------------------------------*/
002/* Copyright (c) FIRST 2008-2012. All Rights Reserved.                        */
003/* Open Source Software - may be modified and shared by FRC teams. The code   */
004/* must be accompanied by the FIRST BSD license file in the root directory of */
005/* the project.                                                               */
006/*----------------------------------------------------------------------------*/
007
008package edu.wpi.first.wpilibj;
009
010import java.nio.ByteBuffer;
011import java.nio.ByteOrder;
012import java.nio.IntBuffer;
013
014import edu.wpi.first.wpilibj.hal.HALUtil;
015import edu.wpi.first.wpilibj.hal.PowerJNI;
016
017public class ControllerPower
018{
019        /**
020        * Get the input voltage to the robot controller
021        * @return The controller input voltage value in Volts
022        */
023        public static double getInputVoltage()
024        {
025                ByteBuffer status = ByteBuffer.allocateDirect(4);
026                status.order(ByteOrder.LITTLE_ENDIAN);
027                double retVal = PowerJNI.getVinVoltage(status.asIntBuffer());
028                HALUtil.checkStatus(status.asIntBuffer());
029                return retVal;
030        }
031
032        /**
033        * Get the input current to the robot controller
034        * @return The controller input current value in Amps
035        */
036        public static double getInputCurrent()
037        {
038                ByteBuffer status = ByteBuffer.allocateDirect(4);
039                status.order(ByteOrder.LITTLE_ENDIAN);
040                double retVal = PowerJNI.getVinCurrent(status.asIntBuffer());
041                HALUtil.checkStatus(status.asIntBuffer());
042                return retVal;
043        }
044        
045        /**
046        * Get the voltage of the 3.3V rail
047        * @return The controller 3.3V rail voltage value in Volts
048        */
049        public static double getVoltage3V3()
050        {
051                ByteBuffer status = ByteBuffer.allocateDirect(4);
052                status.order(ByteOrder.LITTLE_ENDIAN);
053                double retVal = PowerJNI.getUserVoltage3V3(status.asIntBuffer());
054                HALUtil.checkStatus(status.asIntBuffer());
055                return retVal;
056        }
057        
058        /**
059        * Get the current output of the 3.3V rail
060        * @return The controller 3.3V rail output current value in Volts
061        */
062        public static double getCurrent3V3()
063        {
064                ByteBuffer status = ByteBuffer.allocateDirect(4);
065                status.order(ByteOrder.LITTLE_ENDIAN);
066                double retVal = PowerJNI.getUserCurrent3V3(status.asIntBuffer());
067                HALUtil.checkStatus(status.asIntBuffer());
068                return retVal;
069        }
070        
071        /**
072        * Get the enabled state of the 3.3V rail. The rail may be disabled due to a controller
073        * brownout, a short circuit on the rail, or controller over-voltage
074        * @return The controller 3.3V rail enabled value
075        */
076        public static boolean getEnabled3V3()
077        {
078                ByteBuffer status = ByteBuffer.allocateDirect(4);
079                status.order(ByteOrder.LITTLE_ENDIAN);
080                boolean retVal = PowerJNI.getUserActive3V3(status.asIntBuffer());
081                HALUtil.checkStatus(status.asIntBuffer());
082                return retVal;
083        }
084        
085        /**
086        * Get the count of the total current faults on the 3.3V rail since the controller has booted
087        * @return The number of faults
088        */
089        public static int getFaultCount3V3()
090        {
091                ByteBuffer status = ByteBuffer.allocateDirect(4);
092                status.order(ByteOrder.LITTLE_ENDIAN);
093                int retVal = PowerJNI.getUserCurrentFaults3V3(status.asIntBuffer());
094                HALUtil.checkStatus(status.asIntBuffer());
095                return retVal;
096        }
097        
098        /**
099        * Get the voltage of the 5V rail
100        * @return The controller 5V rail voltage value in Volts
101        */
102        public static double getVoltage5V()
103        {
104                ByteBuffer status = ByteBuffer.allocateDirect(4);
105                status.order(ByteOrder.LITTLE_ENDIAN);
106                double retVal = PowerJNI.getUserVoltage5V(status.asIntBuffer());
107                HALUtil.checkStatus(status.asIntBuffer());
108                return retVal;
109        }
110        
111        /**
112        * Get the current output of the 5V rail
113        * @return The controller 5V rail output current value in Amps
114        */
115        public static double getCurrent5V()
116        {
117                ByteBuffer status = ByteBuffer.allocateDirect(4);
118                status.order(ByteOrder.LITTLE_ENDIAN);
119                double retVal = PowerJNI.getUserCurrent5V(status.asIntBuffer());
120                HALUtil.checkStatus(status.asIntBuffer());
121                return retVal;
122        }
123        
124        /**
125        * Get the enabled state of the 5V rail. The rail may be disabled due to a controller
126        * brownout, a short circuit on the rail, or controller over-voltage
127        * @return The controller 5V rail enabled value
128        */
129        public static boolean getEnabled5V()
130        {
131                ByteBuffer status = ByteBuffer.allocateDirect(4);
132                status.order(ByteOrder.LITTLE_ENDIAN);
133                boolean retVal = PowerJNI.getUserActive5V(status.asIntBuffer());
134                HALUtil.checkStatus(status.asIntBuffer());
135                return retVal;
136        }       
137        
138        /**
139        * Get the count of the total current faults on the 5V rail since the controller has booted
140        * @return The number of faults
141        */
142        public static int getFaultCount5V()
143        {
144                ByteBuffer status = ByteBuffer.allocateDirect(4);
145                status.order(ByteOrder.LITTLE_ENDIAN);
146                int retVal = PowerJNI.getUserCurrentFaults5V(status.asIntBuffer());
147                HALUtil.checkStatus(status.asIntBuffer());
148                return retVal;
149        }
150        
151        /**
152        * Get the voltage of the 6V rail
153        * @return The controller 6V rail voltage value in Volts
154        */
155        public static double getVoltage6V()
156        {
157                ByteBuffer status = ByteBuffer.allocateDirect(4);
158                status.order(ByteOrder.LITTLE_ENDIAN);
159                double retVal = PowerJNI.getUserVoltage6V(status.asIntBuffer());
160                HALUtil.checkStatus(status.asIntBuffer());
161                return retVal;
162        }
163        
164        /**
165        * Get the current output of the 6V rail
166        * @return The controller 6V rail output current value in Amps
167        */
168        public static double getCurrent6V()
169        {
170                ByteBuffer status = ByteBuffer.allocateDirect(4);
171                status.order(ByteOrder.LITTLE_ENDIAN);
172                double retVal = PowerJNI.getUserCurrent6V(status.asIntBuffer());
173                HALUtil.checkStatus(status.asIntBuffer());
174                return retVal;
175        }
176        
177        /**
178        * Get the enabled state of the 6V rail. The rail may be disabled due to a controller
179        * brownout, a short circuit on the rail, or controller over-voltage
180        * @return The controller 6V rail enabled value
181        */      
182        public static boolean getEnabled6V()
183        {
184                ByteBuffer status = ByteBuffer.allocateDirect(4);
185                status.order(ByteOrder.LITTLE_ENDIAN);
186                boolean retVal = PowerJNI.getUserActive6V(status.asIntBuffer());
187                HALUtil.checkStatus(status.asIntBuffer());
188                return retVal;
189        }
190
191        /**
192        * Get the count of the total current faults on the 6V rail since the controller has booted
193        * @return The number of faults
194        */
195        public static int getFaultCount6V()
196        {
197                ByteBuffer status = ByteBuffer.allocateDirect(4);
198                status.order(ByteOrder.LITTLE_ENDIAN);
199                int retVal = PowerJNI.getUserCurrentFaults6V(status.asIntBuffer());
200                HALUtil.checkStatus(status.asIntBuffer());
201                return retVal;
202        }
203}