mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-19 00:41:43 +00:00
Removes statics from hal sim (#825)
Based off of #824, the equivelent in sim.
This commit is contained in:
committed by
Peter Johnson
parent
8bd48d6c34
commit
d2e7a90f41
@@ -23,10 +23,19 @@
|
||||
#include "MockData/MockHooks.h"
|
||||
|
||||
static wpi::mutex msgMutex;
|
||||
static wpi::condition_variable newDSDataAvailableCond;
|
||||
static wpi::condition_variable* newDSDataAvailableCond;
|
||||
static wpi::mutex newDSDataAvailableMutex;
|
||||
static int newDSDataAvailableCounter{0};
|
||||
|
||||
namespace hal {
|
||||
namespace init {
|
||||
void InitializeDriverStation() {
|
||||
static wpi::condition_variable nddaC;
|
||||
newDSDataAvailableCond = &nddaC;
|
||||
}
|
||||
} // namespace init
|
||||
} // namespace hal
|
||||
|
||||
using namespace hal;
|
||||
|
||||
extern "C" {
|
||||
@@ -85,33 +94,33 @@ int32_t HAL_SendError(HAL_Bool isError, int32_t errorCode, HAL_Bool isLVCode,
|
||||
}
|
||||
|
||||
int32_t HAL_GetControlWord(HAL_ControlWord* controlWord) {
|
||||
controlWord->enabled = SimDriverStationData.GetEnabled();
|
||||
controlWord->autonomous = SimDriverStationData.GetAutonomous();
|
||||
controlWord->test = SimDriverStationData.GetTest();
|
||||
controlWord->eStop = SimDriverStationData.GetEStop();
|
||||
controlWord->fmsAttached = SimDriverStationData.GetFmsAttached();
|
||||
controlWord->dsAttached = SimDriverStationData.GetDsAttached();
|
||||
controlWord->enabled = SimDriverStationData->GetEnabled();
|
||||
controlWord->autonomous = SimDriverStationData->GetAutonomous();
|
||||
controlWord->test = SimDriverStationData->GetTest();
|
||||
controlWord->eStop = SimDriverStationData->GetEStop();
|
||||
controlWord->fmsAttached = SimDriverStationData->GetFmsAttached();
|
||||
controlWord->dsAttached = SimDriverStationData->GetDsAttached();
|
||||
return 0;
|
||||
}
|
||||
|
||||
HAL_AllianceStationID HAL_GetAllianceStation(int32_t* status) {
|
||||
*status = 0;
|
||||
return SimDriverStationData.GetAllianceStationId();
|
||||
return SimDriverStationData->GetAllianceStationId();
|
||||
}
|
||||
|
||||
int32_t HAL_GetJoystickAxes(int32_t joystickNum, HAL_JoystickAxes* axes) {
|
||||
SimDriverStationData.GetJoystickAxes(joystickNum, axes);
|
||||
SimDriverStationData->GetJoystickAxes(joystickNum, axes);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t HAL_GetJoystickPOVs(int32_t joystickNum, HAL_JoystickPOVs* povs) {
|
||||
SimDriverStationData.GetJoystickPOVs(joystickNum, povs);
|
||||
SimDriverStationData->GetJoystickPOVs(joystickNum, povs);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t HAL_GetJoystickButtons(int32_t joystickNum,
|
||||
HAL_JoystickButtons* buttons) {
|
||||
SimDriverStationData.GetJoystickButtons(joystickNum, buttons);
|
||||
SimDriverStationData->GetJoystickButtons(joystickNum, buttons);
|
||||
return 0;
|
||||
}
|
||||
/**
|
||||
@@ -127,25 +136,25 @@ int32_t HAL_GetJoystickButtons(int32_t joystickNum,
|
||||
*/
|
||||
int32_t HAL_GetJoystickDescriptor(int32_t joystickNum,
|
||||
HAL_JoystickDescriptor* desc) {
|
||||
SimDriverStationData.GetJoystickDescriptor(joystickNum, desc);
|
||||
SimDriverStationData->GetJoystickDescriptor(joystickNum, desc);
|
||||
return 0;
|
||||
}
|
||||
|
||||
HAL_Bool HAL_GetJoystickIsXbox(int32_t joystickNum) {
|
||||
HAL_JoystickDescriptor desc;
|
||||
SimDriverStationData.GetJoystickDescriptor(joystickNum, &desc);
|
||||
SimDriverStationData->GetJoystickDescriptor(joystickNum, &desc);
|
||||
return desc.isXbox;
|
||||
}
|
||||
|
||||
int32_t HAL_GetJoystickType(int32_t joystickNum) {
|
||||
HAL_JoystickDescriptor desc;
|
||||
SimDriverStationData.GetJoystickDescriptor(joystickNum, &desc);
|
||||
SimDriverStationData->GetJoystickDescriptor(joystickNum, &desc);
|
||||
return desc.type;
|
||||
}
|
||||
|
||||
char* HAL_GetJoystickName(int32_t joystickNum) {
|
||||
HAL_JoystickDescriptor desc;
|
||||
SimDriverStationData.GetJoystickDescriptor(joystickNum, &desc);
|
||||
SimDriverStationData->GetJoystickDescriptor(joystickNum, &desc);
|
||||
size_t len = std::strlen(desc.name);
|
||||
char* name = static_cast<char*>(std::malloc(len + 1));
|
||||
std::strncpy(name, desc.name, len);
|
||||
@@ -159,22 +168,22 @@ int32_t HAL_GetJoystickAxisType(int32_t joystickNum, int32_t axis) { return 0; }
|
||||
|
||||
int32_t HAL_SetJoystickOutputs(int32_t joystickNum, int64_t outputs,
|
||||
int32_t leftRumble, int32_t rightRumble) {
|
||||
SimDriverStationData.SetJoystickOutputs(joystickNum, outputs, leftRumble,
|
||||
rightRumble);
|
||||
SimDriverStationData->SetJoystickOutputs(joystickNum, outputs, leftRumble,
|
||||
rightRumble);
|
||||
return 0;
|
||||
}
|
||||
|
||||
double HAL_GetMatchTime(int32_t* status) {
|
||||
return SimDriverStationData.GetMatchTime();
|
||||
return SimDriverStationData->GetMatchTime();
|
||||
}
|
||||
|
||||
int HAL_GetMatchInfo(HAL_MatchInfo* info) {
|
||||
SimDriverStationData.GetMatchInfo(info);
|
||||
SimDriverStationData->GetMatchInfo(info);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void HAL_FreeMatchInfo(HAL_MatchInfo* info) {
|
||||
SimDriverStationData.FreeMatchInfo(info);
|
||||
SimDriverStationData->FreeMatchInfo(info);
|
||||
}
|
||||
|
||||
void HAL_ObserveUserProgramStarting(void) { HALSIM_SetProgramStarted(); }
|
||||
@@ -249,12 +258,12 @@ HAL_Bool HAL_WaitForDSDataTimeout(double timeout) {
|
||||
int currentCount = newDSDataAvailableCounter;
|
||||
while (newDSDataAvailableCounter == currentCount) {
|
||||
if (timeout > 0) {
|
||||
auto timedOut = newDSDataAvailableCond.wait_until(lock, timeoutTime);
|
||||
auto timedOut = newDSDataAvailableCond->wait_until(lock, timeoutTime);
|
||||
if (timedOut == std::cv_status::timeout) {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
newDSDataAvailableCond.wait(lock);
|
||||
newDSDataAvailableCond->wait(lock);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
@@ -270,7 +279,7 @@ static int32_t newDataOccur(uint32_t refNum) {
|
||||
std::lock_guard<wpi::mutex> lock(newDSDataAvailableMutex);
|
||||
// Nofify all threads
|
||||
newDSDataAvailableCounter++;
|
||||
newDSDataAvailableCond.notify_all();
|
||||
newDSDataAvailableCond->notify_all();
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -289,7 +298,7 @@ void HAL_InitializeDriverStation(void) {
|
||||
// Second check in case another thread was waiting
|
||||
if (initialized) return;
|
||||
|
||||
SimDriverStationData.ResetData();
|
||||
SimDriverStationData->ResetData();
|
||||
|
||||
initialized = true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user