[hal] Fix unfinished/incorrect GetCPUTemp functions (#5598)

This commit is contained in:
Ryan Blue
2023-08-31 14:51:57 -04:00
committed by GitHub
parent 99f66b1e24
commit b2dd59450b
11 changed files with 171 additions and 6 deletions

View File

@@ -284,6 +284,23 @@ void RoboRioSim::SetBrownoutVoltage(units::volt_t vInVoltage) {
HALSIM_SetRoboRioBrownoutVoltage(vInVoltage.value());
}
std::unique_ptr<CallbackStore> RoboRioSim::RegisterCPUTempCallback(
NotifyCallback callback, bool initialNotify) {
auto store = std::make_unique<CallbackStore>(
-1, callback, &HALSIM_CancelRoboRioCPUTempCallback);
store->SetUid(HALSIM_RegisterRoboRioCPUTempCallback(
&CallbackStoreThunk, store.get(), initialNotify));
return store;
}
units::celsius_t RoboRioSim::GetCPUTemp() {
return units::celsius_t{HALSIM_GetRoboRioCPUTemp()};
}
void RoboRioSim::SetCPUTemp(units::celsius_t cpuTemp) {
HALSIM_SetRoboRioCPUTemp(cpuTemp.value());
}
std::string RoboRioSim::GetSerialNumber() {
char serialNum[9];
size_t len = HALSIM_GetRoboRioSerialNumber(serialNum, sizeof(serialNum));

View File

@@ -8,6 +8,7 @@
#include <string>
#include <units/current.h>
#include <units/temperature.h>
#include <units/voltage.h>
#include "frc/simulation/CallbackStore.h"
@@ -435,6 +436,31 @@ class RoboRioSim {
*/
static void SetBrownoutVoltage(units::volt_t brownoutVoltage);
/**
* Register a callback to be run whenever the cpu temp changes.
*
* @param callback the callback
* @param initialNotify whether to call the callback with the initial state
* @return the CallbackStore object associated with this callback
*/
[[nodiscard]]
static std::unique_ptr<CallbackStore> RegisterCPUTempCallback(
NotifyCallback callback, bool initialNotify);
/**
* Get the cpu temp.
*
* @return the cpu temp.
*/
static units::celsius_t GetCPUTemp();
/**
* Define the cpu temp.
*
* @param cpuTemp the new cpu temp.
*/
static void SetCPUTemp(units::celsius_t cpuTemp);
/**
* Get the serial number.
*