blob: cde96ead43698c9f1a6e5d919116124b7bc4ec76 [file] [log] [blame]
Brian Silverman26e4e522015-12-17 01:56:40 -05001#include "HAL/Power.hpp"
2#include "ChipObject.h"
3
4static tPower *power = NULL;
5
6static void initializePower(int32_t *status) {
7 if(power == NULL) {
8 power = tPower::create(status);
9 }
10}
11
12/**
13 * Get the roboRIO input voltage
14 */
15float getVinVoltage(int32_t *status) {
16 initializePower(status);
17 return power->readVinVoltage(status) / 4.096f * 0.025733f - 0.029f;
18}
19
20/**
21 * Get the roboRIO input current
22 */
23float getVinCurrent(int32_t *status) {
24 initializePower(status);
25 return power->readVinCurrent(status) / 4.096f * 0.017042 - 0.071f;
26}
27
28/**
29 * Get the 6V rail voltage
30 */
31float getUserVoltage6V(int32_t *status) {
32 initializePower(status);
33 return power->readUserVoltage6V(status) / 4.096f * 0.007019f - 0.014f;
34}
35
36/**
37 * Get the 6V rail current
38 */
39float getUserCurrent6V(int32_t *status) {
40 initializePower(status);
41 return power->readUserCurrent6V(status) / 4.096f * 0.005566f - 0.009f;
42}
43
44/**
45 * Get the active state of the 6V rail
46 */
47bool getUserActive6V(int32_t *status) {
48 initializePower(status);
49 return power->readStatus_User6V(status) == 4;
50}
51
52/**
53 * Get the fault count for the 6V rail
54 */
55int getUserCurrentFaults6V(int32_t *status) {
56 initializePower(status);
57 return (int)power->readFaultCounts_OverCurrentFaultCount6V(status);
58}
59
60/**
61 * Get the 5V rail voltage
62 */
63float getUserVoltage5V(int32_t *status) {
64 initializePower(status);
65 return power->readUserVoltage5V(status) / 4.096f * 0.005962f - 0.013f;
66}
67
68/**
69 * Get the 5V rail current
70 */
71float getUserCurrent5V(int32_t *status) {
72 initializePower(status);
73 return power->readUserCurrent5V(status) / 4.096f * 0.001996f - 0.002f;
74}
75
76/**
77 * Get the active state of the 5V rail
78 */
79bool getUserActive5V(int32_t *status) {
80 initializePower(status);
81 return power->readStatus_User5V(status) == 4;
82}
83
84/**
85 * Get the fault count for the 5V rail
86 */
87int getUserCurrentFaults5V(int32_t *status) {
88 initializePower(status);
89 return (int)power->readFaultCounts_OverCurrentFaultCount5V(status);
90}
91
92unsigned char getUserStatus5V(int32_t *status) {
93 initializePower(status);
94 return power->readStatus_User5V(status);
95}
96
97/**
98 * Get the 3.3V rail voltage
99 */
100float getUserVoltage3V3(int32_t *status) {
101 initializePower(status);
102 return power->readUserVoltage3V3(status) / 4.096f * 0.004902f - 0.01f;
103}
104
105/**
106 * Get the 3.3V rail current
107 */
108float getUserCurrent3V3(int32_t *status) {
109 initializePower(status);
110 return power->readUserCurrent3V3(status) / 4.096f * 0.002486f - 0.003f;
111}
112
113/**
114 * Get the active state of the 3.3V rail
115 */
116bool getUserActive3V3(int32_t *status) {
117 initializePower(status);
118 return power->readStatus_User3V3(status) == 4;
119}
120
121/**
122 * Get the fault count for the 3.3V rail
123 */
124int getUserCurrentFaults3V3(int32_t *status) {
125 initializePower(status);
126 return (int)power->readFaultCounts_OverCurrentFaultCount3V3(status);
127}