[hal, wpilib] Load joystick values upon code initialization (#4950)

During HAL_Initialize, wait up to 100ms for a DS packet to be received. Then in RobotBase, right after calling HAL_Initialize, call each language's RefreshData function to force a high level DS update. If the DS is connected, will get joystick data. If there is no data, nothing different will happen, but in that case there's no joysticks anyway.
This commit is contained in:
Thad House
2023-01-15 16:36:44 -08:00
committed by GitHub
parent ab0e8c37a7
commit 5cb0340a8c
8 changed files with 28 additions and 10 deletions

View File

@@ -75,7 +75,7 @@ static HAL_ControlWord newestControlWord;
static JoystickDataCache caches[3];
static JoystickDataCache* currentRead = &caches[0];
static JoystickDataCache* currentReadLocal = &caches[0];
static std::atomic<JoystickDataCache*> currentCache{&caches[1]};
static std::atomic<JoystickDataCache*> currentCache{nullptr};
static JoystickDataCache* lastGiven = &caches[1];
static JoystickDataCache* cacheToUpdate = &caches[2];
@@ -318,9 +318,9 @@ void HAL_ObserveUserProgramTest(void) {
// TODO
}
void HAL_RefreshDSData(void) {
HAL_Bool HAL_RefreshDSData(void) {
if (gShutdown) {
return;
return false;
}
HAL_ControlWord controlWord;
std::memset(&controlWord, 0, sizeof(controlWord));
@@ -336,6 +336,7 @@ void HAL_RefreshDSData(void) {
currentRead = prev;
}
newestControlWord = controlWord;
return prev != nullptr;
}
void HAL_ProvideNewDataEventHandle(WPI_EventHandle handle) {