From cb7f39afa1525ddc83a2a4d0c8ad80a2699f8464 Mon Sep 17 00:00:00 2001 From: Tyler Veness Date: Tue, 16 Feb 2021 18:03:25 -0800 Subject: [PATCH] [wpilibc] Add RobotController::GetBatteryVoltage() to C++ (#3179) This function already exists in Java. --- wpilibc/src/main/native/cpp/RobotController.cpp | 7 +++++++ wpilibc/src/main/native/include/frc/RobotController.h | 9 +++++++++ 2 files changed, 16 insertions(+) diff --git a/wpilibc/src/main/native/cpp/RobotController.cpp b/wpilibc/src/main/native/cpp/RobotController.cpp index 9fad56c9ad..ac49cfa225 100644 --- a/wpilibc/src/main/native/cpp/RobotController.cpp +++ b/wpilibc/src/main/native/cpp/RobotController.cpp @@ -42,6 +42,13 @@ bool RobotController::GetUserButton() { return value; } +units::volt_t RobotController::GetBatteryVoltage() { + int32_t status = 0; + double retVal = HAL_GetVinVoltage(&status); + wpi_setGlobalHALError(status); + return units::volt_t{retVal}; +} + bool RobotController::IsSysActive() { int32_t status = 0; bool retVal = HAL_GetSystemActive(&status); diff --git a/wpilibc/src/main/native/include/frc/RobotController.h b/wpilibc/src/main/native/include/frc/RobotController.h index 6352659d88..22023d1219 100644 --- a/wpilibc/src/main/native/include/frc/RobotController.h +++ b/wpilibc/src/main/native/include/frc/RobotController.h @@ -6,6 +6,8 @@ #include +#include + namespace frc { struct CANStatus { @@ -55,6 +57,13 @@ class RobotController { */ static bool GetUserButton(); + /** + * Read the battery voltage. + * + * @return The battery voltage in Volts. + */ + static units::volt_t GetBatteryVoltage(); + /** * Check if the FPGA outputs are enabled. *