blob: 2cf4d332920a773391f6e8648315e40a0f9c6c09 [file] [log] [blame]
Brian Silverman41cdd3e2019-01-19 19:48:58 -08001/*----------------------------------------------------------------------------*/
2/* Copyright (c) 2016-2018 FIRST. All Rights Reserved. */
3/* Open Source Software - may be modified and shared by FRC teams. The code */
4/* must be accompanied by the FIRST BSD license file in the root directory of */
5/* the project. */
6/*----------------------------------------------------------------------------*/
7
8#include "hal/Power.h"
9
10#include <memory>
11
12#include "HALInitializer.h"
13#include "hal/ChipObject.h"
14
15using namespace hal;
16
17namespace hal {
18
19static std::unique_ptr<tPower> power{nullptr};
20
21static void initializePower(int32_t* status) {
22 hal::init::CheckInit();
23 if (power == nullptr) {
24 power.reset(tPower::create(status));
25 }
26}
27
28} // namespace hal
29
30namespace hal {
31namespace init {
32void InitializePower() {}
33} // namespace init
34} // namespace hal
35
36extern "C" {
37
38double HAL_GetVinVoltage(int32_t* status) {
39 initializePower(status);
40 return power->readVinVoltage(status) / 4.096 * 0.025733 - 0.029;
41}
42
43double HAL_GetVinCurrent(int32_t* status) {
44 initializePower(status);
45 return power->readVinCurrent(status) / 4.096 * 0.017042 - 0.071;
46}
47
48double HAL_GetUserVoltage6V(int32_t* status) {
49 initializePower(status);
50 return power->readUserVoltage6V(status) / 4.096 * 0.007019 - 0.014;
51}
52
53double HAL_GetUserCurrent6V(int32_t* status) {
54 initializePower(status);
55 return power->readUserCurrent6V(status) / 4.096 * 0.005566 - 0.009;
56}
57
58HAL_Bool HAL_GetUserActive6V(int32_t* status) {
59 initializePower(status);
60 return power->readStatus_User6V(status) == 4;
61}
62
63int32_t HAL_GetUserCurrentFaults6V(int32_t* status) {
64 initializePower(status);
65 return static_cast<int32_t>(
66 power->readFaultCounts_OverCurrentFaultCount6V(status));
67}
68
69double HAL_GetUserVoltage5V(int32_t* status) {
70 initializePower(status);
71 return power->readUserVoltage5V(status) / 4.096 * 0.005962 - 0.013;
72}
73
74double HAL_GetUserCurrent5V(int32_t* status) {
75 initializePower(status);
76 return power->readUserCurrent5V(status) / 4.096 * 0.001996 - 0.002;
77}
78
79HAL_Bool HAL_GetUserActive5V(int32_t* status) {
80 initializePower(status);
81 return power->readStatus_User5V(status) == 4;
82}
83
84int32_t HAL_GetUserCurrentFaults5V(int32_t* status) {
85 initializePower(status);
86 return static_cast<int32_t>(
87 power->readFaultCounts_OverCurrentFaultCount5V(status));
88}
89
90double HAL_GetUserVoltage3V3(int32_t* status) {
91 initializePower(status);
92 return power->readUserVoltage3V3(status) / 4.096 * 0.004902 - 0.01;
93}
94
95double HAL_GetUserCurrent3V3(int32_t* status) {
96 initializePower(status);
97 return power->readUserCurrent3V3(status) / 4.096 * 0.002486 - 0.003;
98}
99
100HAL_Bool HAL_GetUserActive3V3(int32_t* status) {
101 initializePower(status);
102 return power->readStatus_User3V3(status) == 4;
103}
104
105int32_t HAL_GetUserCurrentFaults3V3(int32_t* status) {
106 initializePower(status);
107 return static_cast<int32_t>(
108 power->readFaultCounts_OverCurrentFaultCount3V3(status));
109}
110
111} // extern "C"