Brian Silverman | 41cdd3e | 2019-01-19 19:48:58 -0800 | [diff] [blame] | 1 | /*----------------------------------------------------------------------------*/ |
| 2 | /* Copyright (c) 2011-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 "frc/ControllerPower.h" |
| 9 | |
| 10 | #include <stdint.h> |
| 11 | |
| 12 | #include <hal/HAL.h> |
| 13 | #include <hal/Power.h> |
| 14 | |
| 15 | #include "frc/ErrorBase.h" |
| 16 | |
| 17 | using namespace frc; |
| 18 | |
| 19 | double ControllerPower::GetInputVoltage() { |
| 20 | int32_t status = 0; |
| 21 | double retVal = HAL_GetVinVoltage(&status); |
| 22 | wpi_setGlobalErrorWithContext(status, HAL_GetErrorMessage(status)); |
| 23 | return retVal; |
| 24 | } |
| 25 | |
| 26 | double ControllerPower::GetInputCurrent() { |
| 27 | int32_t status = 0; |
| 28 | double retVal = HAL_GetVinCurrent(&status); |
| 29 | wpi_setGlobalErrorWithContext(status, HAL_GetErrorMessage(status)); |
| 30 | return retVal; |
| 31 | } |
| 32 | |
| 33 | double ControllerPower::GetVoltage3V3() { |
| 34 | int32_t status = 0; |
| 35 | double retVal = HAL_GetUserVoltage3V3(&status); |
| 36 | wpi_setGlobalErrorWithContext(status, HAL_GetErrorMessage(status)); |
| 37 | return retVal; |
| 38 | } |
| 39 | |
| 40 | double ControllerPower::GetCurrent3V3() { |
| 41 | int32_t status = 0; |
| 42 | double retVal = HAL_GetUserCurrent3V3(&status); |
| 43 | wpi_setGlobalErrorWithContext(status, HAL_GetErrorMessage(status)); |
| 44 | return retVal; |
| 45 | } |
| 46 | |
| 47 | bool ControllerPower::GetEnabled3V3() { |
| 48 | int32_t status = 0; |
| 49 | bool retVal = HAL_GetUserActive3V3(&status); |
| 50 | wpi_setGlobalErrorWithContext(status, HAL_GetErrorMessage(status)); |
| 51 | return retVal; |
| 52 | } |
| 53 | |
| 54 | int ControllerPower::GetFaultCount3V3() { |
| 55 | int32_t status = 0; |
| 56 | int retVal = HAL_GetUserCurrentFaults3V3(&status); |
| 57 | wpi_setGlobalErrorWithContext(status, HAL_GetErrorMessage(status)); |
| 58 | return retVal; |
| 59 | } |
| 60 | |
| 61 | double ControllerPower::GetVoltage5V() { |
| 62 | int32_t status = 0; |
| 63 | double retVal = HAL_GetUserVoltage5V(&status); |
| 64 | wpi_setGlobalErrorWithContext(status, HAL_GetErrorMessage(status)); |
| 65 | return retVal; |
| 66 | } |
| 67 | |
| 68 | double ControllerPower::GetCurrent5V() { |
| 69 | int32_t status = 0; |
| 70 | double retVal = HAL_GetUserCurrent5V(&status); |
| 71 | wpi_setGlobalErrorWithContext(status, HAL_GetErrorMessage(status)); |
| 72 | return retVal; |
| 73 | } |
| 74 | |
| 75 | bool ControllerPower::GetEnabled5V() { |
| 76 | int32_t status = 0; |
| 77 | bool retVal = HAL_GetUserActive5V(&status); |
| 78 | wpi_setGlobalErrorWithContext(status, HAL_GetErrorMessage(status)); |
| 79 | return retVal; |
| 80 | } |
| 81 | |
| 82 | int ControllerPower::GetFaultCount5V() { |
| 83 | int32_t status = 0; |
| 84 | int retVal = HAL_GetUserCurrentFaults5V(&status); |
| 85 | wpi_setGlobalErrorWithContext(status, HAL_GetErrorMessage(status)); |
| 86 | return retVal; |
| 87 | } |
| 88 | |
| 89 | double ControllerPower::GetVoltage6V() { |
| 90 | int32_t status = 0; |
| 91 | double retVal = HAL_GetUserVoltage6V(&status); |
| 92 | wpi_setGlobalErrorWithContext(status, HAL_GetErrorMessage(status)); |
| 93 | return retVal; |
| 94 | } |
| 95 | |
| 96 | double ControllerPower::GetCurrent6V() { |
| 97 | int32_t status = 0; |
| 98 | double retVal = HAL_GetUserCurrent6V(&status); |
| 99 | wpi_setGlobalErrorWithContext(status, HAL_GetErrorMessage(status)); |
| 100 | return retVal; |
| 101 | } |
| 102 | |
| 103 | bool ControllerPower::GetEnabled6V() { |
| 104 | int32_t status = 0; |
| 105 | bool retVal = HAL_GetUserActive6V(&status); |
| 106 | wpi_setGlobalErrorWithContext(status, HAL_GetErrorMessage(status)); |
| 107 | return retVal; |
| 108 | } |
| 109 | |
| 110 | int ControllerPower::GetFaultCount6V() { |
| 111 | int32_t status = 0; |
| 112 | int retVal = HAL_GetUserCurrentFaults6V(&status); |
| 113 | wpi_setGlobalErrorWithContext(status, HAL_GetErrorMessage(status)); |
| 114 | return retVal; |
| 115 | } |