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