mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-23 01:21:42 +00:00
[hal, wpilib] Add RobotController.getComments() (#4463)
This commit is contained in:
@@ -33,6 +33,7 @@ void RoboRioData::ResetData() {
|
||||
userFaults3V3.Reset(0);
|
||||
brownoutVoltage.Reset(6.75);
|
||||
m_serialNumber = "";
|
||||
m_comments = "";
|
||||
}
|
||||
|
||||
int32_t RoboRioData::RegisterSerialNumberCallback(
|
||||
@@ -72,6 +73,40 @@ void RoboRioData::SetSerialNumber(const char* serialNumber, size_t size) {
|
||||
m_serialNumberCallbacks(m_serialNumber.c_str(), m_serialNumber.size());
|
||||
}
|
||||
|
||||
int32_t RoboRioData::RegisterCommentsCallback(
|
||||
HAL_RoboRioStringCallback callback, void* param, HAL_Bool initialNotify) {
|
||||
std::scoped_lock lock(m_commentsMutex);
|
||||
int32_t uid = m_commentsCallbacks.Register(callback, param);
|
||||
if (initialNotify) {
|
||||
callback(GetCommentsName(), param, m_comments.c_str(),
|
||||
m_serialNumber.size());
|
||||
}
|
||||
return uid;
|
||||
}
|
||||
|
||||
void RoboRioData::CancelCommentsCallback(int32_t uid) {
|
||||
m_commentsCallbacks.Cancel(uid);
|
||||
}
|
||||
|
||||
size_t RoboRioData::GetComments(char* buffer, size_t size) {
|
||||
std::scoped_lock lock(m_commentsMutex);
|
||||
size_t copied = m_comments.copy(buffer, size);
|
||||
// Null terminate if there is room
|
||||
if (copied < size) {
|
||||
buffer[copied] = '\0';
|
||||
}
|
||||
return copied;
|
||||
}
|
||||
|
||||
void RoboRioData::SetComments(const char* comments, size_t size) {
|
||||
if (size > 64) {
|
||||
size = 64;
|
||||
}
|
||||
std::scoped_lock lock(m_commentsMutex);
|
||||
m_comments = std::string(comments, size);
|
||||
m_commentsCallbacks(m_comments.c_str(), m_comments.size());
|
||||
}
|
||||
|
||||
extern "C" {
|
||||
void HALSIM_ResetRoboRioData(void) {
|
||||
SimRoboRioData->ResetData();
|
||||
@@ -113,6 +148,21 @@ void HALSIM_SetRoboRioSerialNumber(const char* serialNumber, size_t size) {
|
||||
SimRoboRioData->SetSerialNumber(serialNumber, size);
|
||||
}
|
||||
|
||||
int32_t HALSIM_RegisterRoboRioCommentsCallback(
|
||||
HAL_RoboRioStringCallback callback, void* param, HAL_Bool initialNotify) {
|
||||
return SimRoboRioData->RegisterCommentsCallback(callback, param,
|
||||
initialNotify);
|
||||
}
|
||||
void HALSIM_CancelRoboRioCommentsCallback(int32_t uid) {
|
||||
SimRoboRioData->CancelCommentsCallback(uid);
|
||||
}
|
||||
size_t HALSIM_GetRoboRioComments(char* buffer, size_t size) {
|
||||
return SimRoboRioData->GetComments(buffer, size);
|
||||
}
|
||||
void HALSIM_SetRoboRioComments(const char* comments, size_t size) {
|
||||
SimRoboRioData->SetComments(comments, size);
|
||||
}
|
||||
|
||||
void HALSIM_RegisterRoboRioAllCallbacks(HAL_NotifyCallback callback,
|
||||
void* param, HAL_Bool initialNotify);
|
||||
|
||||
|
||||
@@ -32,6 +32,7 @@ class RoboRioData {
|
||||
HAL_SIMDATAVALUE_DEFINE_NAME(BrownoutVoltage)
|
||||
|
||||
HAL_SIMCALLBACKREGISTRY_DEFINE_NAME(SerialNumber)
|
||||
HAL_SIMCALLBACKREGISTRY_DEFINE_NAME(Comments);
|
||||
|
||||
public:
|
||||
SimDataValue<HAL_Bool, HAL_MakeBoolean, GetFPGAButtonName> fpgaButton{false};
|
||||
@@ -63,14 +64,26 @@ class RoboRioData {
|
||||
size_t GetSerialNumber(char* buffer, size_t size);
|
||||
void SetSerialNumber(const char* serialNumber, size_t size);
|
||||
|
||||
int32_t RegisterCommentsCallback(HAL_RoboRioStringCallback callback,
|
||||
void* param, HAL_Bool initialNotify);
|
||||
void CancelCommentsCallback(int32_t uid);
|
||||
size_t GetComments(char* buffer, size_t size);
|
||||
void SetComments(const char* comments, size_t size);
|
||||
|
||||
virtual void ResetData();
|
||||
|
||||
private:
|
||||
wpi::spinlock m_serialNumberMutex;
|
||||
std::string m_serialNumber;
|
||||
|
||||
wpi::spinlock m_commentsMutex;
|
||||
std::string m_comments;
|
||||
|
||||
SimCallbackRegistry<HAL_RoboRioStringCallback, GetSerialNumberName>
|
||||
m_serialNumberCallbacks;
|
||||
|
||||
SimCallbackRegistry<HAL_RoboRioStringCallback, GetCommentsName>
|
||||
m_commentsCallbacks;
|
||||
};
|
||||
extern RoboRioData* SimRoboRioData;
|
||||
} // namespace hal
|
||||
|
||||
Reference in New Issue
Block a user