mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-19 00:41:43 +00:00
[wpilib] Wait for expansion hub connected for up to half a second during boot (#8715)
Closes #8714
This commit is contained in:
@@ -4,7 +4,9 @@
|
||||
|
||||
#include "wpi/hardware/expansionhub/ExpansionHub.hpp"
|
||||
|
||||
#include <chrono>
|
||||
#include <memory>
|
||||
#include <thread>
|
||||
|
||||
#include "wpi/hal/UsageReporting.hpp"
|
||||
#include "wpi/hardware/expansionhub/ExpansionHubMotor.hpp"
|
||||
@@ -12,6 +14,7 @@
|
||||
#include "wpi/nt/BooleanTopic.hpp"
|
||||
#include "wpi/system/Errors.hpp"
|
||||
#include "wpi/system/SystemServer.hpp"
|
||||
#include "wpi/system/Timer.hpp"
|
||||
|
||||
using namespace wpi;
|
||||
|
||||
@@ -26,6 +29,16 @@ class ExpansionHub::DataStore {
|
||||
m_hubConnectedSubscriber =
|
||||
systemServer.GetBooleanTopic(fmt::format("/rhsp/{}/connected", usbId))
|
||||
.Subscribe(false);
|
||||
|
||||
// Wait up to half a second for connected to come up, using a poll loop to
|
||||
// ensure we don't block.
|
||||
auto startTime = Timer::GetMonotonicTimestamp();
|
||||
while (Timer::GetMonotonicTimestamp() - startTime < 0.5_s) {
|
||||
if (m_hubConnectedSubscriber.Get(false)) {
|
||||
break;
|
||||
}
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(10));
|
||||
}
|
||||
}
|
||||
|
||||
DataStore(DataStore&) = delete;
|
||||
|
||||
Reference in New Issue
Block a user