2024-11-30 18:04:00 +00:00
|
|
|
// 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.
|
|
|
|
|
|
|
|
|
|
#include "hal/Power.h"
|
|
|
|
|
|
|
|
|
|
#include <memory>
|
|
|
|
|
|
2025-05-31 10:53:11 -07:00
|
|
|
#include <networktables/DoubleTopic.h>
|
|
|
|
|
|
2024-11-30 18:04:00 +00:00
|
|
|
#include "HALInitializer.h"
|
2025-05-31 10:53:11 -07:00
|
|
|
#include "SystemServerInternal.h"
|
2024-11-30 18:04:00 +00:00
|
|
|
#include "hal/Errors.h"
|
2025-05-31 10:53:11 -07:00
|
|
|
#include "mrc/NtNetComm.h"
|
2024-11-30 18:04:00 +00:00
|
|
|
|
|
|
|
|
using namespace hal;
|
|
|
|
|
|
|
|
|
|
namespace hal {
|
|
|
|
|
|
|
|
|
|
static void initializePower(int32_t* status) {
|
|
|
|
|
hal::init::CheckInit();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace hal
|
|
|
|
|
|
2025-05-31 10:53:11 -07:00
|
|
|
namespace {
|
|
|
|
|
struct SystemServerPower {
|
|
|
|
|
nt::NetworkTableInstance ntInst;
|
|
|
|
|
|
|
|
|
|
nt::DoubleSubscriber batterySubscriber;
|
|
|
|
|
|
|
|
|
|
explicit SystemServerPower(nt::NetworkTableInstance inst) {
|
|
|
|
|
ntInst = inst;
|
|
|
|
|
|
|
|
|
|
batterySubscriber =
|
|
|
|
|
ntInst.GetDoubleTopic(ROBOT_BATTERY_VOLTAGE_PATH).Subscribe(0.0);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
|
|
static ::SystemServerPower* systemServerPower;
|
|
|
|
|
|
2024-11-30 18:04:00 +00:00
|
|
|
namespace hal::init {
|
2025-05-31 10:53:11 -07:00
|
|
|
void InitializePower() {
|
|
|
|
|
systemServerPower = new ::SystemServerPower{hal::GetSystemServer()};
|
|
|
|
|
}
|
2024-11-30 18:04:00 +00:00
|
|
|
} // namespace hal::init
|
|
|
|
|
|
|
|
|
|
extern "C" {
|
|
|
|
|
|
|
|
|
|
double HAL_GetVinVoltage(int32_t* status) {
|
|
|
|
|
initializePower(status);
|
2025-05-31 10:53:11 -07:00
|
|
|
return systemServerPower->batterySubscriber.Get();
|
2024-11-30 18:04:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
double HAL_GetUserVoltage3V3(int32_t* status) {
|
|
|
|
|
initializePower(status);
|
2025-06-01 22:23:51 -07:00
|
|
|
// Until we have a value, make this work, as lots of other
|
|
|
|
|
// code depends on it.
|
|
|
|
|
return 3.3;
|
2024-11-30 18:04:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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"
|