blob: ea508afabd83a238262b1198ec553407120d91c3 [file] [log] [blame]
Brian Silverman26e4e522015-12-17 01:56:40 -05001/*----------------------------------------------------------------------------*/
2/* Copyright (c) FIRST 2011. All Rights Reserved.
3 */
4/* Open Source Software - may be modified and shared by FRC teams. The code */
5/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */
6/*----------------------------------------------------------------------------*/
7
8#include "ControllerPower.h"
9
10#include <stdint.h>
11#include <HAL/Power.hpp>
12#include <HAL/HAL.hpp>
13#include "ErrorBase.h"
14
15/**
16 * Get the input voltage to the robot controller
17 * @return The controller input voltage value in Volts
18 */
19double ControllerPower::GetInputVoltage() {
20 int32_t status = 0;
21 double retVal = getVinVoltage(&status);
22 wpi_setGlobalErrorWithContext(status, getHALErrorMessage(status));
23 return retVal;
24}
25
26/**
27 * Get the input current to the robot controller
28 * @return The controller input current value in Amps
29 */
30double ControllerPower::GetInputCurrent() {
31 int32_t status = 0;
32 double retVal = getVinCurrent(&status);
33 wpi_setGlobalErrorWithContext(status, getHALErrorMessage(status));
34 return retVal;
35}
36
37/**
38 * Get the voltage of the 6V rail
39 * @return The controller 6V rail voltage value in Volts
40 */
41double ControllerPower::GetVoltage6V() {
42 int32_t status = 0;
43 double retVal = getUserVoltage6V(&status);
44 wpi_setGlobalErrorWithContext(status, getHALErrorMessage(status));
45 return retVal;
46}
47
48/**
49 * Get the current output of the 6V rail
50 * @return The controller 6V rail output current value in Amps
51 */
52double ControllerPower::GetCurrent6V() {
53 int32_t status = 0;
54 double retVal = getUserCurrent6V(&status);
55 wpi_setGlobalErrorWithContext(status, getHALErrorMessage(status));
56 return retVal;
57}
58
59/**
60 * Get the enabled state of the 6V rail. The rail may be disabled due to a
61 * controller
62 * brownout, a short circuit on the rail, or controller over-voltage
63 * @return The controller 6V rail enabled value. True for enabled.
64 */
65bool ControllerPower::GetEnabled6V() {
66 int32_t status = 0;
67 bool retVal = getUserActive6V(&status);
68 wpi_setGlobalErrorWithContext(status, getHALErrorMessage(status));
69 return retVal;
70}
71
72/**
73 * Get the count of the total current faults on the 6V rail since the controller
74 * has booted
75 * @return The number of faults.
76 */
77int ControllerPower::GetFaultCount6V() {
78 int32_t status = 0;
79 int retVal = getUserCurrentFaults6V(&status);
80 wpi_setGlobalErrorWithContext(status, getHALErrorMessage(status));
81 return retVal;
82}
83
84/**
85 * Get the voltage of the 5V rail
86 * @return The controller 5V rail voltage value in Volts
87 */
88double ControllerPower::GetVoltage5V() {
89 int32_t status = 0;
90 double retVal = getUserVoltage5V(&status);
91 wpi_setGlobalErrorWithContext(status, getHALErrorMessage(status));
92 return retVal;
93}
94
95/**
96 * Get the current output of the 5V rail
97 * @return The controller 5V rail output current value in Amps
98 */
99double ControllerPower::GetCurrent5V() {
100 int32_t status = 0;
101 double retVal = getUserCurrent5V(&status);
102 wpi_setGlobalErrorWithContext(status, getHALErrorMessage(status));
103 return retVal;
104}
105
106/**
107 * Get the enabled state of the 5V rail. The rail may be disabled due to a
108 * controller
109 * brownout, a short circuit on the rail, or controller over-voltage
110 * @return The controller 5V rail enabled value. True for enabled.
111 */
112bool ControllerPower::GetEnabled5V() {
113 int32_t status = 0;
114 bool retVal = getUserActive5V(&status);
115 wpi_setGlobalErrorWithContext(status, getHALErrorMessage(status));
116 return retVal;
117}
118
119/**
120 * Get the count of the total current faults on the 5V rail since the controller
121 * has booted
122 * @return The number of faults
123 */
124int ControllerPower::GetFaultCount5V() {
125 int32_t status = 0;
126 int retVal = getUserCurrentFaults5V(&status);
127 wpi_setGlobalErrorWithContext(status, getHALErrorMessage(status));
128 return retVal;
129}
130
131/**
132 * Get the voltage of the 3.3V rail
133 * @return The controller 3.3V rail voltage value in Volts
134 */
135double ControllerPower::GetVoltage3V3() {
136 int32_t status = 0;
137 double retVal = getUserVoltage3V3(&status);
138 wpi_setGlobalErrorWithContext(status, getHALErrorMessage(status));
139 return retVal;
140}
141
142/**
143 * Get the current output of the 3.3V rail
144 * @return The controller 3.3V rail output current value in Amps
145 */
146double ControllerPower::GetCurrent3V3() {
147 int32_t status = 0;
148 double retVal = getUserCurrent3V3(&status);
149 wpi_setGlobalErrorWithContext(status, getHALErrorMessage(status));
150 return retVal;
151}
152
153/**
154 * Get the enabled state of the 3.3V rail. The rail may be disabled due to a
155 * controller
156 * brownout, a short circuit on the rail, or controller over-voltage
157 * @return The controller 3.3V rail enabled value. True for enabled.
158 */
159bool ControllerPower::GetEnabled3V3() {
160 int32_t status = 0;
161 bool retVal = getUserActive3V3(&status);
162 wpi_setGlobalErrorWithContext(status, getHALErrorMessage(status));
163 return retVal;
164}
165
166/**
167 * Get the count of the total current faults on the 3.3V rail since the
168 * controller has booted
169 * @return The number of faults
170 */
171int ControllerPower::GetFaultCount3V3() {
172 int32_t status = 0;
173 int retVal = getUserCurrentFaults3V3(&status);
174 wpi_setGlobalErrorWithContext(status, getHALErrorMessage(status));
175 return retVal;
176}