1- /* *
2- * \file devices/battery.cpp
3- *
4- * Contains functions for interacting with the V5 Battery.
5- *
6- * \copyright Copyright (c) 2017-2024, Purdue University ACM SIGBots.
7- * All rights reserved.
8- *
9- * This Source Code Form is subject to the terms of the Mozilla Public
10- * License, v. 2.0. If a copy of the MPL was not distributed with this
11- * file, You can obtain one at http://mozilla.org/MPL/2.0/.
12- */
1+ #include " pros/devices/battery.hpp"
132
14- #include " pros/misc.h"
3+ #include " src/devices/vdml.hpp"
4+ #include " v5_api_patched.h"
155
16- namespace pros {
17- namespace battery {
18- using namespace pros ::c;
6+ #include < mutex>
197
20- double get_capacity (void ) {
21- return battery_get_capacity ();
8+ constexpr uint8_t PORT = 25 ;
9+
10+ namespace zest {
11+ Result<double , UnknownError> Battery::get_capacity () {
12+ std::lock_guard lock (port_mutex_array.at (PORT));
13+ if (auto res = vexBatteryCapacityGet (); res == std::numeric_limits<typeof (res)>::max ()) {
14+ return UnknownError (" An unknown error has occurred" );
15+ } else {
16+ return res;
17+ }
2218}
2319
24- int32_t get_current (void ) {
25- return battery_get_current ();
20+ Result<double , UnknownError> Battery::get_current () {
21+ std::lock_guard lock (port_mutex_array.at (PORT));
22+ if (auto res = vexBatteryCurrentGet (); res == std::numeric_limits<typeof (res)>::max ()) {
23+ return UnknownError (" An unknown error has occurred" );
24+ } else {
25+ return res;
26+ }
2627}
2728
28- double get_temperature (void ) {
29- return battery_get_temperature ();
29+ Result<double , UnknownError> Battery::get_temperature () {
30+ std::lock_guard lock (port_mutex_array.at (PORT));
31+ if (auto res = vexBatteryTemperatureGet (); res == std::numeric_limits<typeof (res)>::max ()) {
32+ return UnknownError (" An unknown error has occurred" );
33+ } else {
34+ return res;
35+ }
3036}
3137
32- int32_t get_voltage (void ) {
33- return battery_get_voltage ();
38+ Result<double , UnknownError> Battery::get_voltage () {
39+ std::lock_guard lock (port_mutex_array.at (PORT));
40+ if (auto res = vexBatteryVoltageGet (); res == std::numeric_limits<typeof (res)>::max ()) {
41+ return UnknownError (" An unknown error has occurred" );
42+ } else {
43+ return res;
44+ }
3445}
35- } // namespace battery
36- } // namespace pros
46+ } // namespace zest
0 commit comments