Files
allwpilib/hal/src/main/native/systemcore/Power.cpp

111 lines
2.4 KiB
C++
Raw Normal View History

// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
2025-11-07 19:56:21 -05:00
#include "wpi/hal/Power.h"
#include <memory>
#include "HALInitializer.h"
#include "SystemServerInternal.h"
#include "mrc/NtNetComm.h"
2025-11-07 19:57:55 -05:00
#include "wpi/hal/Errors.h"
#include "wpi/nt/DoubleTopic.hpp"
2025-11-07 20:00:05 -05:00
using namespace wpi::hal;
2025-11-07 20:00:05 -05:00
namespace wpi::hal {
static void initializePower(int32_t* status) {
2025-11-07 20:00:05 -05:00
wpi::hal::init::CheckInit();
}
2025-11-07 20:00:05 -05:00
} // namespace wpi::hal
namespace {
struct SystemServerPower {
2025-11-07 20:00:05 -05:00
wpi::nt::NetworkTableInstance ntInst;
2025-11-07 20:00:05 -05:00
wpi::nt::DoubleSubscriber batterySubscriber;
2025-11-07 20:00:05 -05:00
explicit SystemServerPower(wpi::nt::NetworkTableInstance inst) {
ntInst = inst;
batterySubscriber =
ntInst.GetDoubleTopic(ROBOT_BATTERY_VOLTAGE_PATH).Subscribe(0.0);
}
};
} // namespace
static ::SystemServerPower* systemServerPower;
2025-11-07 20:00:05 -05:00
namespace wpi::hal::init {
void InitializePower() {
2025-11-07 20:00:05 -05:00
systemServerPower = new ::SystemServerPower{wpi::hal::GetSystemServer()};
}
2025-11-07 20:00:05 -05:00
} // namespace wpi::hal::init
extern "C" {
double HAL_GetVinVoltage(int32_t* status) {
initializePower(status);
return systemServerPower->batterySubscriber.Get();
}
double HAL_GetUserVoltage3V3(int32_t* status) {
initializePower(status);
// Until we have a value, make this work, as lots of other
// code depends on it.
return 3.3;
}
double HAL_GetUserCurrent3V3(int32_t* status) {
initializePower(status);
*status = HAL_HANDLE_ERROR;
return 0;
}
HAL_Bool HAL_GetUserActive3V3(int32_t* status) {
initializePower(status);
*status = HAL_HANDLE_ERROR;
return 0;
}
int32_t HAL_GetUserCurrentFaults3V3(int32_t* status) {
initializePower(status);
*status = HAL_HANDLE_ERROR;
return 0;
}
void HAL_SetUserRailEnabled3V3(HAL_Bool enabled, int32_t* status) {
initializePower(status);
*status = HAL_HANDLE_ERROR;
return;
}
void HAL_ResetUserCurrentFaults(int32_t* status) {
initializePower(status);
*status = HAL_HANDLE_ERROR;
return;
}
void HAL_SetBrownoutVoltage(double voltage, int32_t* status) {
initializePower(status);
*status = HAL_HANDLE_ERROR;
return;
}
double HAL_GetBrownoutVoltage(int32_t* status) {
initializePower(status);
*status = HAL_HANDLE_ERROR;
return 0;
}
double HAL_GetCPUTemp(int32_t* status) {
initializePower(status);
*status = HAL_HANDLE_ERROR;
return 0;
}
} // extern "C"