mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-21 01:01:43 +00:00
[hal] Replace const char* with std::string_view in Driver Station sim functions (#4532)
This commit is contained in:
@@ -339,14 +339,17 @@ void DriverStationData::SetJoystickType(int32_t stick, int32_t type) {
|
||||
m_joystickDescriptorCallbacks(stick, &m_joystickData[stick].descriptor);
|
||||
}
|
||||
|
||||
void DriverStationData::SetJoystickName(int32_t stick, const char* name) {
|
||||
void DriverStationData::SetJoystickName(int32_t stick, const char* name,
|
||||
size_t size) {
|
||||
if (stick < 0 || stick >= kNumJoysticks) {
|
||||
return;
|
||||
}
|
||||
std::scoped_lock lock(m_joystickDataMutex);
|
||||
std::strncpy(m_joystickData[stick].descriptor.name, name,
|
||||
sizeof(m_joystickData[stick].descriptor.name) - 1);
|
||||
*(std::end(m_joystickData[stick].descriptor.name) - 1) = '\0';
|
||||
if (size > sizeof(m_joystickData[stick].descriptor.name) - 1) {
|
||||
size = sizeof(m_joystickData[stick].descriptor.name) - 1;
|
||||
}
|
||||
std::strncpy(m_joystickData[stick].descriptor.name, name, size);
|
||||
m_joystickData[stick].descriptor.name[size] = '\0';
|
||||
m_joystickDescriptorCallbacks(stick, &m_joystickData[stick].descriptor);
|
||||
}
|
||||
|
||||
@@ -363,19 +366,27 @@ void DriverStationData::SetJoystickAxisType(int32_t stick, int32_t axis,
|
||||
m_joystickDescriptorCallbacks(stick, &m_joystickData[stick].descriptor);
|
||||
}
|
||||
|
||||
void DriverStationData::SetGameSpecificMessage(const char* message) {
|
||||
void DriverStationData::SetGameSpecificMessage(const char* message,
|
||||
size_t size) {
|
||||
std::scoped_lock lock(m_matchInfoMutex);
|
||||
if (size > sizeof(m_matchInfo.gameSpecificMessage) - 1) {
|
||||
size = sizeof(m_matchInfo.gameSpecificMessage) - 1;
|
||||
}
|
||||
std::strncpy(reinterpret_cast<char*>(m_matchInfo.gameSpecificMessage),
|
||||
message, sizeof(m_matchInfo.gameSpecificMessage) - 1);
|
||||
*(std::end(m_matchInfo.gameSpecificMessage) - 1) = '\0';
|
||||
m_matchInfo.gameSpecificMessageSize = std::strlen(message);
|
||||
message, size);
|
||||
m_matchInfo.gameSpecificMessage[size] = '\0';
|
||||
m_matchInfo.gameSpecificMessageSize =
|
||||
std::strlen(reinterpret_cast<char*>(m_matchInfo.gameSpecificMessage));
|
||||
m_matchInfoCallbacks(&m_matchInfo);
|
||||
}
|
||||
|
||||
void DriverStationData::SetEventName(const char* name) {
|
||||
void DriverStationData::SetEventName(const char* name, size_t size) {
|
||||
std::scoped_lock lock(m_matchInfoMutex);
|
||||
std::strncpy(m_matchInfo.eventName, name, sizeof(m_matchInfo.eventName) - 1);
|
||||
*(std::end(m_matchInfo.eventName) - 1) = '\0';
|
||||
if (size > sizeof(m_matchInfo.eventName) - 1) {
|
||||
size = sizeof(m_matchInfo.eventName) - 1;
|
||||
}
|
||||
std::strncpy(m_matchInfo.eventName, name, size);
|
||||
m_matchInfo.eventName[size] = '\0';
|
||||
m_matchInfoCallbacks(&m_matchInfo);
|
||||
}
|
||||
|
||||
@@ -540,20 +551,20 @@ void HALSIM_SetJoystickType(int32_t stick, int32_t type) {
|
||||
SimDriverStationData->SetJoystickType(stick, type);
|
||||
}
|
||||
|
||||
void HALSIM_SetJoystickName(int32_t stick, const char* name) {
|
||||
SimDriverStationData->SetJoystickName(stick, name);
|
||||
void HALSIM_SetJoystickName(int32_t stick, const char* name, size_t size) {
|
||||
SimDriverStationData->SetJoystickName(stick, name, size);
|
||||
}
|
||||
|
||||
void HALSIM_SetJoystickAxisType(int32_t stick, int32_t axis, int32_t type) {
|
||||
SimDriverStationData->SetJoystickAxisType(stick, axis, type);
|
||||
}
|
||||
|
||||
void HALSIM_SetGameSpecificMessage(const char* message) {
|
||||
SimDriverStationData->SetGameSpecificMessage(message);
|
||||
void HALSIM_SetGameSpecificMessage(const char* message, size_t size) {
|
||||
SimDriverStationData->SetGameSpecificMessage(message, size);
|
||||
}
|
||||
|
||||
void HALSIM_SetEventName(const char* name) {
|
||||
SimDriverStationData->SetEventName(name);
|
||||
void HALSIM_SetEventName(const char* name, size_t size) {
|
||||
SimDriverStationData->SetEventName(name, size);
|
||||
}
|
||||
|
||||
void HALSIM_SetMatchType(HAL_MatchType type) {
|
||||
|
||||
@@ -107,11 +107,11 @@ class DriverStationData {
|
||||
|
||||
void SetJoystickIsXbox(int32_t stick, HAL_Bool isXbox);
|
||||
void SetJoystickType(int32_t stick, int32_t type);
|
||||
void SetJoystickName(int32_t stick, const char* name);
|
||||
void SetJoystickName(int32_t stick, const char* name, size_t size);
|
||||
void SetJoystickAxisType(int32_t stick, int32_t axis, int32_t type);
|
||||
|
||||
void SetGameSpecificMessage(const char* message);
|
||||
void SetEventName(const char* name);
|
||||
void SetGameSpecificMessage(const char* message, size_t size);
|
||||
void SetEventName(const char* name, size_t size);
|
||||
void SetMatchType(HAL_MatchType type);
|
||||
void SetMatchNumber(int32_t matchNumber);
|
||||
void SetReplayNumber(int32_t replayNumber);
|
||||
|
||||
Reference in New Issue
Block a user