Brian Silverman | f7f267a | 2017-02-04 16:16:08 -0800 | [diff] [blame^] | 1 | /*----------------------------------------------------------------------------*/ |
| 2 | /* Copyright (c) FIRST 2016-2017. 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 "HAL/ChipObject.h" |
| 13 | |
| 14 | using namespace hal; |
| 15 | |
| 16 | static std::unique_ptr<tPower> power; |
| 17 | |
| 18 | static void initializePower(int32_t* status) { |
| 19 | if (power == nullptr) { |
| 20 | power.reset(tPower::create(status)); |
| 21 | } |
| 22 | } |
| 23 | |
| 24 | extern "C" { |
| 25 | |
| 26 | /** |
| 27 | * Get the roboRIO input voltage |
| 28 | */ |
| 29 | double HAL_GetVinVoltage(int32_t* status) { |
| 30 | initializePower(status); |
| 31 | return power->readVinVoltage(status) / 4.096 * 0.025733 - 0.029; |
| 32 | } |
| 33 | |
| 34 | /** |
| 35 | * Get the roboRIO input current |
| 36 | */ |
| 37 | double HAL_GetVinCurrent(int32_t* status) { |
| 38 | initializePower(status); |
| 39 | return power->readVinCurrent(status) / 4.096 * 0.017042 - 0.071; |
| 40 | } |
| 41 | |
| 42 | /** |
| 43 | * Get the 6V rail voltage |
| 44 | */ |
| 45 | double HAL_GetUserVoltage6V(int32_t* status) { |
| 46 | initializePower(status); |
| 47 | return power->readUserVoltage6V(status) / 4.096 * 0.007019 - 0.014; |
| 48 | } |
| 49 | |
| 50 | /** |
| 51 | * Get the 6V rail current |
| 52 | */ |
| 53 | double HAL_GetUserCurrent6V(int32_t* status) { |
| 54 | initializePower(status); |
| 55 | return power->readUserCurrent6V(status) / 4.096 * 0.005566 - 0.009; |
| 56 | } |
| 57 | |
| 58 | /** |
| 59 | * Get the active state of the 6V rail |
| 60 | */ |
| 61 | HAL_Bool HAL_GetUserActive6V(int32_t* status) { |
| 62 | initializePower(status); |
| 63 | return power->readStatus_User6V(status) == 4; |
| 64 | } |
| 65 | |
| 66 | /** |
| 67 | * Get the fault count for the 6V rail |
| 68 | */ |
| 69 | int32_t HAL_GetUserCurrentFaults6V(int32_t* status) { |
| 70 | initializePower(status); |
| 71 | return static_cast<int32_t>( |
| 72 | power->readFaultCounts_OverCurrentFaultCount6V(status)); |
| 73 | } |
| 74 | |
| 75 | /** |
| 76 | * Get the 5V rail voltage |
| 77 | */ |
| 78 | double HAL_GetUserVoltage5V(int32_t* status) { |
| 79 | initializePower(status); |
| 80 | return power->readUserVoltage5V(status) / 4.096 * 0.005962 - 0.013; |
| 81 | } |
| 82 | |
| 83 | /** |
| 84 | * Get the 5V rail current |
| 85 | */ |
| 86 | double HAL_GetUserCurrent5V(int32_t* status) { |
| 87 | initializePower(status); |
| 88 | return power->readUserCurrent5V(status) / 4.096 * 0.001996 - 0.002; |
| 89 | } |
| 90 | |
| 91 | /** |
| 92 | * Get the active state of the 5V rail |
| 93 | */ |
| 94 | HAL_Bool HAL_GetUserActive5V(int32_t* status) { |
| 95 | initializePower(status); |
| 96 | return power->readStatus_User5V(status) == 4; |
| 97 | } |
| 98 | |
| 99 | /** |
| 100 | * Get the fault count for the 5V rail |
| 101 | */ |
| 102 | int32_t HAL_GetUserCurrentFaults5V(int32_t* status) { |
| 103 | initializePower(status); |
| 104 | return static_cast<int32_t>( |
| 105 | power->readFaultCounts_OverCurrentFaultCount5V(status)); |
| 106 | } |
| 107 | |
| 108 | /** |
| 109 | * Get the 3.3V rail voltage |
| 110 | */ |
| 111 | double HAL_GetUserVoltage3V3(int32_t* status) { |
| 112 | initializePower(status); |
| 113 | return power->readUserVoltage3V3(status) / 4.096 * 0.004902 - 0.01; |
| 114 | } |
| 115 | |
| 116 | /** |
| 117 | * Get the 3.3V rail current |
| 118 | */ |
| 119 | double HAL_GetUserCurrent3V3(int32_t* status) { |
| 120 | initializePower(status); |
| 121 | return power->readUserCurrent3V3(status) / 4.096 * 0.002486 - 0.003; |
| 122 | } |
| 123 | |
| 124 | /** |
| 125 | * Get the active state of the 3.3V rail |
| 126 | */ |
| 127 | HAL_Bool HAL_GetUserActive3V3(int32_t* status) { |
| 128 | initializePower(status); |
| 129 | return power->readStatus_User3V3(status) == 4; |
| 130 | } |
| 131 | |
| 132 | /** |
| 133 | * Get the fault count for the 3.3V rail |
| 134 | */ |
| 135 | int32_t HAL_GetUserCurrentFaults3V3(int32_t* status) { |
| 136 | initializePower(status); |
| 137 | return static_cast<int32_t>( |
| 138 | power->readFaultCounts_OverCurrentFaultCount3V3(status)); |
| 139 | } |
| 140 | |
| 141 | } // extern "C" |