mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-28 02:11:43 +00:00
Moves the HAL priority_ custom types to the hal namespace (#532)
There is a shim for backwards compatibility, just like the frc namespace. As with the frc namespace, the library compiles without the shim.
This commit is contained in:
committed by
Peter Johnson
parent
16e71eac43
commit
efec0c5cc3
@@ -295,7 +295,7 @@ bool DriverStation::WaitForData(double timeout) {
|
||||
std::chrono::steady_clock::now() + std::chrono::duration<double>(timeout);
|
||||
#endif
|
||||
|
||||
std::unique_lock<priority_mutex> lock(m_waitForDataMutex);
|
||||
std::unique_lock<hal::priority_mutex> lock(m_waitForDataMutex);
|
||||
while (!m_updatedControlLoopData) {
|
||||
if (timeout > 0) {
|
||||
auto timedOut = m_waitForDataCond.wait_until(lock, timeoutTime);
|
||||
@@ -368,7 +368,7 @@ void DriverStation::stateCallback(
|
||||
*state = *msg;
|
||||
}
|
||||
{
|
||||
std::lock_guard<priority_mutex> lock(m_waitForDataMutex);
|
||||
std::lock_guard<hal::priority_mutex> lock(m_waitForDataMutex);
|
||||
m_updatedControlLoopData = true;
|
||||
}
|
||||
m_waitForDataCond.notify_all();
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
using namespace frc;
|
||||
|
||||
std::set<MotorSafetyHelper*> MotorSafetyHelper::m_helperList;
|
||||
priority_recursive_mutex MotorSafetyHelper::m_listMutex;
|
||||
hal::priority_recursive_mutex MotorSafetyHelper::m_listMutex;
|
||||
|
||||
/**
|
||||
* The constructor for a MotorSafetyHelper object.
|
||||
@@ -37,12 +37,12 @@ MotorSafetyHelper::MotorSafetyHelper(MotorSafety* safeObject)
|
||||
m_expiration = DEFAULT_SAFETY_EXPIRATION;
|
||||
m_stopTime = Timer::GetFPGATimestamp();
|
||||
|
||||
std::lock_guard<priority_recursive_mutex> sync(m_listMutex);
|
||||
std::lock_guard<hal::priority_recursive_mutex> sync(m_listMutex);
|
||||
m_helperList.insert(this);
|
||||
}
|
||||
|
||||
MotorSafetyHelper::~MotorSafetyHelper() {
|
||||
std::lock_guard<priority_recursive_mutex> sync(m_listMutex);
|
||||
std::lock_guard<hal::priority_recursive_mutex> sync(m_listMutex);
|
||||
m_helperList.erase(this);
|
||||
}
|
||||
|
||||
@@ -52,7 +52,7 @@ MotorSafetyHelper::~MotorSafetyHelper() {
|
||||
* Resets the timer on this object that is used to do the timeouts.
|
||||
*/
|
||||
void MotorSafetyHelper::Feed() {
|
||||
std::lock_guard<priority_recursive_mutex> sync(m_syncMutex);
|
||||
std::lock_guard<hal::priority_recursive_mutex> sync(m_syncMutex);
|
||||
m_stopTime = Timer::GetFPGATimestamp() + m_expiration;
|
||||
}
|
||||
|
||||
@@ -62,7 +62,7 @@ void MotorSafetyHelper::Feed() {
|
||||
* @param expirationTime The timeout value in seconds.
|
||||
*/
|
||||
void MotorSafetyHelper::SetExpiration(double expirationTime) {
|
||||
std::lock_guard<priority_recursive_mutex> sync(m_syncMutex);
|
||||
std::lock_guard<hal::priority_recursive_mutex> sync(m_syncMutex);
|
||||
m_expiration = expirationTime;
|
||||
}
|
||||
|
||||
@@ -72,7 +72,7 @@ void MotorSafetyHelper::SetExpiration(double expirationTime) {
|
||||
* @return the timeout value in seconds.
|
||||
*/
|
||||
double MotorSafetyHelper::GetExpiration() const {
|
||||
std::lock_guard<priority_recursive_mutex> sync(m_syncMutex);
|
||||
std::lock_guard<hal::priority_recursive_mutex> sync(m_syncMutex);
|
||||
return m_expiration;
|
||||
}
|
||||
|
||||
@@ -83,7 +83,7 @@ double MotorSafetyHelper::GetExpiration() const {
|
||||
* timed out.
|
||||
*/
|
||||
bool MotorSafetyHelper::IsAlive() const {
|
||||
std::lock_guard<priority_recursive_mutex> sync(m_syncMutex);
|
||||
std::lock_guard<hal::priority_recursive_mutex> sync(m_syncMutex);
|
||||
return !m_enabled || m_stopTime > Timer::GetFPGATimestamp();
|
||||
}
|
||||
|
||||
@@ -98,7 +98,7 @@ void MotorSafetyHelper::Check() {
|
||||
DriverStation& ds = DriverStation::GetInstance();
|
||||
if (!m_enabled || ds.IsDisabled() || ds.IsTest()) return;
|
||||
|
||||
std::lock_guard<priority_recursive_mutex> sync(m_syncMutex);
|
||||
std::lock_guard<hal::priority_recursive_mutex> sync(m_syncMutex);
|
||||
if (m_stopTime < Timer::GetFPGATimestamp()) {
|
||||
std::ostringstream desc;
|
||||
m_safeObject->GetDescription(desc);
|
||||
@@ -116,7 +116,7 @@ void MotorSafetyHelper::Check() {
|
||||
* @param enabled True if motor safety is enforced for this object
|
||||
*/
|
||||
void MotorSafetyHelper::SetSafetyEnabled(bool enabled) {
|
||||
std::lock_guard<priority_recursive_mutex> sync(m_syncMutex);
|
||||
std::lock_guard<hal::priority_recursive_mutex> sync(m_syncMutex);
|
||||
m_enabled = enabled;
|
||||
}
|
||||
|
||||
@@ -128,7 +128,7 @@ void MotorSafetyHelper::SetSafetyEnabled(bool enabled) {
|
||||
* @return True if motor safety is enforced for this device
|
||||
*/
|
||||
bool MotorSafetyHelper::IsSafetyEnabled() const {
|
||||
std::lock_guard<priority_recursive_mutex> sync(m_syncMutex);
|
||||
std::lock_guard<hal::priority_recursive_mutex> sync(m_syncMutex);
|
||||
return m_enabled;
|
||||
}
|
||||
|
||||
@@ -139,7 +139,7 @@ bool MotorSafetyHelper::IsSafetyEnabled() const {
|
||||
* any that have timed out.
|
||||
*/
|
||||
void MotorSafetyHelper::CheckMotors() {
|
||||
std::lock_guard<priority_recursive_mutex> sync(m_listMutex);
|
||||
std::lock_guard<hal::priority_recursive_mutex> sync(m_listMutex);
|
||||
for (auto elem : m_helperList) {
|
||||
elem->Check();
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
using namespace frc;
|
||||
|
||||
std::list<Notifier*> Notifier::timerQueue;
|
||||
priority_recursive_mutex Notifier::queueMutex;
|
||||
hal::priority_recursive_mutex Notifier::queueMutex;
|
||||
std::atomic<int> Notifier::refcount{0};
|
||||
std::thread Notifier::m_task;
|
||||
std::atomic<bool> Notifier::m_stopped(false);
|
||||
@@ -34,7 +34,7 @@ Notifier::Notifier(TimerEventHandler handler) {
|
||||
m_period = 0;
|
||||
m_queued = false;
|
||||
{
|
||||
std::lock_guard<priority_recursive_mutex> sync(queueMutex);
|
||||
std::lock_guard<hal::priority_recursive_mutex> sync(queueMutex);
|
||||
// do the first time intialization of static variables
|
||||
if (refcount.fetch_add(1) == 0) {
|
||||
m_task = std::thread(Run);
|
||||
@@ -50,7 +50,7 @@ Notifier::Notifier(TimerEventHandler handler) {
|
||||
*/
|
||||
Notifier::~Notifier() {
|
||||
{
|
||||
std::lock_guard<priority_recursive_mutex> sync(queueMutex);
|
||||
std::lock_guard<hal::priority_recursive_mutex> sync(queueMutex);
|
||||
DeleteFromQueue();
|
||||
|
||||
// Delete the static variables when the last one is going away
|
||||
@@ -62,7 +62,7 @@ Notifier::~Notifier() {
|
||||
|
||||
// Acquire the semaphore; this makes certain that the handler is
|
||||
// not being executed by the interrupt manager.
|
||||
std::lock_guard<priority_mutex> lock(m_handlerMutex);
|
||||
std::lock_guard<hal::priority_mutex> lock(m_handlerMutex);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -89,7 +89,7 @@ void Notifier::ProcessQueue(int mask, void* params) {
|
||||
// keep processing events until no more
|
||||
while (true) {
|
||||
{
|
||||
std::lock_guard<priority_recursive_mutex> sync(queueMutex);
|
||||
std::lock_guard<hal::priority_recursive_mutex> sync(queueMutex);
|
||||
double currentTime = GetClock();
|
||||
|
||||
if (timerQueue.empty()) {
|
||||
@@ -120,7 +120,7 @@ void Notifier::ProcessQueue(int mask, void* params) {
|
||||
current->m_handlerMutex.unlock();
|
||||
}
|
||||
// reschedule the first item in the queue
|
||||
std::lock_guard<priority_recursive_mutex> sync(queueMutex);
|
||||
std::lock_guard<hal::priority_recursive_mutex> sync(queueMutex);
|
||||
UpdateAlarm();
|
||||
}
|
||||
|
||||
@@ -202,7 +202,7 @@ void Notifier::DeleteFromQueue() {
|
||||
* @param delay Seconds to wait before the handler is called.
|
||||
*/
|
||||
void Notifier::StartSingle(double delay) {
|
||||
std::lock_guard<priority_recursive_mutex> sync(queueMutex);
|
||||
std::lock_guard<hal::priority_recursive_mutex> sync(queueMutex);
|
||||
m_periodic = false;
|
||||
m_period = delay;
|
||||
DeleteFromQueue();
|
||||
@@ -220,7 +220,7 @@ void Notifier::StartSingle(double delay) {
|
||||
* the call to this method.
|
||||
*/
|
||||
void Notifier::StartPeriodic(double period) {
|
||||
std::lock_guard<priority_recursive_mutex> sync(queueMutex);
|
||||
std::lock_guard<hal::priority_recursive_mutex> sync(queueMutex);
|
||||
m_periodic = true;
|
||||
m_period = period;
|
||||
DeleteFromQueue();
|
||||
@@ -237,12 +237,12 @@ void Notifier::StartPeriodic(double period) {
|
||||
*/
|
||||
void Notifier::Stop() {
|
||||
{
|
||||
std::lock_guard<priority_recursive_mutex> sync(queueMutex);
|
||||
std::lock_guard<hal::priority_recursive_mutex> sync(queueMutex);
|
||||
DeleteFromQueue();
|
||||
}
|
||||
// Wait for a currently executing handler to complete before returning from
|
||||
// Stop()
|
||||
std::lock_guard<priority_mutex> sync(m_handlerMutex);
|
||||
std::lock_guard<hal::priority_mutex> sync(m_handlerMutex);
|
||||
}
|
||||
|
||||
void Notifier::Run() {
|
||||
@@ -250,13 +250,13 @@ void Notifier::Run() {
|
||||
Notifier::ProcessQueue(0, nullptr);
|
||||
bool isEmpty;
|
||||
{
|
||||
std::lock_guard<priority_recursive_mutex> sync(queueMutex);
|
||||
std::lock_guard<hal::priority_recursive_mutex> sync(queueMutex);
|
||||
isEmpty = timerQueue.empty();
|
||||
}
|
||||
if (!isEmpty) {
|
||||
double expirationTime;
|
||||
{
|
||||
std::lock_guard<priority_recursive_mutex> sync(queueMutex);
|
||||
std::lock_guard<hal::priority_recursive_mutex> sync(queueMutex);
|
||||
expirationTime = timerQueue.front()->m_expirationTime;
|
||||
}
|
||||
Wait(expirationTime - GetClock());
|
||||
|
||||
@@ -103,7 +103,7 @@ void PIDController::Calculate() {
|
||||
PIDSource* pidInput;
|
||||
|
||||
{
|
||||
std::lock_guard<priority_recursive_mutex> lock(m_mutex);
|
||||
std::lock_guard<hal::priority_recursive_mutex> lock(m_mutex);
|
||||
if (m_pidInput == 0) return;
|
||||
if (m_pidOutput == 0) return;
|
||||
enabled = m_enabled;
|
||||
@@ -116,7 +116,7 @@ void PIDController::Calculate() {
|
||||
PIDOutput* pidOutput;
|
||||
|
||||
{
|
||||
std::lock_guard<priority_recursive_mutex> sync(m_mutex);
|
||||
std::lock_guard<hal::priority_recursive_mutex> sync(m_mutex);
|
||||
m_error = m_setpoint - input;
|
||||
if (m_continuous) {
|
||||
if (std::fabs(m_error) > (m_maximumInput - m_minimumInput) / 2) {
|
||||
@@ -212,7 +212,7 @@ double PIDController::CalculateFeedForward() {
|
||||
*/
|
||||
void PIDController::SetPID(double p, double i, double d) {
|
||||
{
|
||||
std::lock_guard<priority_recursive_mutex> lock(m_mutex);
|
||||
std::lock_guard<hal::priority_recursive_mutex> lock(m_mutex);
|
||||
m_P = p;
|
||||
m_I = i;
|
||||
m_D = d;
|
||||
@@ -237,7 +237,7 @@ void PIDController::SetPID(double p, double i, double d) {
|
||||
*/
|
||||
void PIDController::SetPID(double p, double i, double d, double f) {
|
||||
{
|
||||
std::lock_guard<priority_recursive_mutex> lock(m_mutex);
|
||||
std::lock_guard<hal::priority_recursive_mutex> lock(m_mutex);
|
||||
m_P = p;
|
||||
m_I = i;
|
||||
m_D = d;
|
||||
@@ -258,7 +258,7 @@ void PIDController::SetPID(double p, double i, double d, double f) {
|
||||
* @return proportional coefficient
|
||||
*/
|
||||
double PIDController::GetP() const {
|
||||
std::lock_guard<priority_recursive_mutex> lock(m_mutex);
|
||||
std::lock_guard<hal::priority_recursive_mutex> lock(m_mutex);
|
||||
return m_P;
|
||||
}
|
||||
|
||||
@@ -268,7 +268,7 @@ double PIDController::GetP() const {
|
||||
* @return integral coefficient
|
||||
*/
|
||||
double PIDController::GetI() const {
|
||||
std::lock_guard<priority_recursive_mutex> lock(m_mutex);
|
||||
std::lock_guard<hal::priority_recursive_mutex> lock(m_mutex);
|
||||
return m_I;
|
||||
}
|
||||
|
||||
@@ -278,7 +278,7 @@ double PIDController::GetI() const {
|
||||
* @return differential coefficient
|
||||
*/
|
||||
double PIDController::GetD() const {
|
||||
std::lock_guard<priority_recursive_mutex> lock(m_mutex);
|
||||
std::lock_guard<hal::priority_recursive_mutex> lock(m_mutex);
|
||||
return m_D;
|
||||
}
|
||||
|
||||
@@ -288,7 +288,7 @@ double PIDController::GetD() const {
|
||||
* @return Feed forward coefficient
|
||||
*/
|
||||
double PIDController::GetF() const {
|
||||
std::lock_guard<priority_recursive_mutex> lock(m_mutex);
|
||||
std::lock_guard<hal::priority_recursive_mutex> lock(m_mutex);
|
||||
return m_F;
|
||||
}
|
||||
|
||||
@@ -300,7 +300,7 @@ double PIDController::GetF() const {
|
||||
* @return the latest calculated output
|
||||
*/
|
||||
double PIDController::Get() const {
|
||||
std::lock_guard<priority_recursive_mutex> lock(m_mutex);
|
||||
std::lock_guard<hal::priority_recursive_mutex> lock(m_mutex);
|
||||
return m_result;
|
||||
}
|
||||
|
||||
@@ -314,7 +314,7 @@ double PIDController::Get() const {
|
||||
* @param continuous Set to true turns on continuous, false turns off continuous
|
||||
*/
|
||||
void PIDController::SetContinuous(bool continuous) {
|
||||
std::lock_guard<priority_recursive_mutex> lock(m_mutex);
|
||||
std::lock_guard<hal::priority_recursive_mutex> lock(m_mutex);
|
||||
m_continuous = continuous;
|
||||
}
|
||||
|
||||
@@ -326,7 +326,7 @@ void PIDController::SetContinuous(bool continuous) {
|
||||
*/
|
||||
void PIDController::SetInputRange(double minimumInput, double maximumInput) {
|
||||
{
|
||||
std::lock_guard<priority_recursive_mutex> lock(m_mutex);
|
||||
std::lock_guard<hal::priority_recursive_mutex> lock(m_mutex);
|
||||
m_minimumInput = minimumInput;
|
||||
m_maximumInput = maximumInput;
|
||||
}
|
||||
@@ -341,7 +341,7 @@ void PIDController::SetInputRange(double minimumInput, double maximumInput) {
|
||||
* @param maximumOutput the maximum value to write to the output
|
||||
*/
|
||||
void PIDController::SetOutputRange(double minimumOutput, double maximumOutput) {
|
||||
std::lock_guard<priority_recursive_mutex> lock(m_mutex);
|
||||
std::lock_guard<hal::priority_recursive_mutex> lock(m_mutex);
|
||||
m_minimumOutput = minimumOutput;
|
||||
m_maximumOutput = maximumOutput;
|
||||
}
|
||||
@@ -353,7 +353,7 @@ void PIDController::SetOutputRange(double minimumOutput, double maximumOutput) {
|
||||
*/
|
||||
void PIDController::SetSetpoint(double setpoint) {
|
||||
{
|
||||
std::lock_guard<priority_recursive_mutex> lock(m_mutex);
|
||||
std::lock_guard<hal::priority_recursive_mutex> lock(m_mutex);
|
||||
|
||||
if (m_maximumInput > m_minimumInput) {
|
||||
if (setpoint > m_maximumInput)
|
||||
@@ -378,7 +378,7 @@ void PIDController::SetSetpoint(double setpoint) {
|
||||
* @return the current setpoint
|
||||
*/
|
||||
double PIDController::GetSetpoint() const {
|
||||
std::lock_guard<priority_recursive_mutex> lock(m_mutex);
|
||||
std::lock_guard<hal::priority_recursive_mutex> lock(m_mutex);
|
||||
return m_setpoint;
|
||||
}
|
||||
|
||||
@@ -388,7 +388,7 @@ double PIDController::GetSetpoint() const {
|
||||
* @return the change in setpoint over time
|
||||
*/
|
||||
double PIDController::GetDeltaSetpoint() const {
|
||||
std::lock_guard<priority_recursive_mutex> sync(m_mutex);
|
||||
std::lock_guard<hal::priority_recursive_mutex> sync(m_mutex);
|
||||
return (m_setpoint - m_prevSetpoint) / m_setpointTimer.Get();
|
||||
}
|
||||
|
||||
@@ -400,7 +400,7 @@ double PIDController::GetDeltaSetpoint() const {
|
||||
double PIDController::GetError() const {
|
||||
double setpoint = GetSetpoint();
|
||||
{
|
||||
std::lock_guard<priority_recursive_mutex> sync(m_mutex);
|
||||
std::lock_guard<hal::priority_recursive_mutex> sync(m_mutex);
|
||||
return GetContinuousError(setpoint - m_pidInput->PIDGet());
|
||||
}
|
||||
}
|
||||
@@ -432,7 +432,7 @@ PIDSourceType PIDController::GetPIDSourceType() const {
|
||||
double PIDController::GetAvgError() const {
|
||||
double avgError = 0;
|
||||
{
|
||||
std::lock_guard<priority_recursive_mutex> sync(m_mutex);
|
||||
std::lock_guard<hal::priority_recursive_mutex> sync(m_mutex);
|
||||
// Don't divide by zero.
|
||||
if (m_buf.size()) avgError = m_bufTotal / m_buf.size();
|
||||
}
|
||||
@@ -446,7 +446,7 @@ double PIDController::GetAvgError() const {
|
||||
* @param percent percentage error which is tolerable
|
||||
*/
|
||||
void PIDController::SetTolerance(double percent) {
|
||||
std::lock_guard<priority_recursive_mutex> lock(m_mutex);
|
||||
std::lock_guard<hal::priority_recursive_mutex> lock(m_mutex);
|
||||
m_toleranceType = kPercentTolerance;
|
||||
m_tolerance = percent;
|
||||
}
|
||||
@@ -458,7 +458,7 @@ void PIDController::SetTolerance(double percent) {
|
||||
* @param absTolerance absolute error which is tolerable
|
||||
*/
|
||||
void PIDController::SetAbsoluteTolerance(double absTolerance) {
|
||||
std::lock_guard<priority_recursive_mutex> lock(m_mutex);
|
||||
std::lock_guard<hal::priority_recursive_mutex> lock(m_mutex);
|
||||
m_toleranceType = kAbsoluteTolerance;
|
||||
m_tolerance = absTolerance;
|
||||
}
|
||||
@@ -470,7 +470,7 @@ void PIDController::SetAbsoluteTolerance(double absTolerance) {
|
||||
* @param percent percentage error which is tolerable
|
||||
*/
|
||||
void PIDController::SetPercentTolerance(double percent) {
|
||||
std::lock_guard<priority_recursive_mutex> lock(m_mutex);
|
||||
std::lock_guard<hal::priority_recursive_mutex> lock(m_mutex);
|
||||
m_toleranceType = kPercentTolerance;
|
||||
m_tolerance = percent;
|
||||
}
|
||||
@@ -486,7 +486,7 @@ void PIDController::SetPercentTolerance(double percent) {
|
||||
* @param bufLength Number of previous cycles to average. Defaults to 1.
|
||||
*/
|
||||
void PIDController::SetToleranceBuffer(int bufLength) {
|
||||
std::lock_guard<priority_recursive_mutex> lock(m_mutex);
|
||||
std::lock_guard<hal::priority_recursive_mutex> lock(m_mutex);
|
||||
m_bufLength = bufLength;
|
||||
|
||||
// Cut the buffer down to size if needed.
|
||||
@@ -506,7 +506,7 @@ void PIDController::SetToleranceBuffer(int bufLength) {
|
||||
* period of time.
|
||||
*/
|
||||
bool PIDController::OnTarget() const {
|
||||
std::lock_guard<priority_recursive_mutex> sync(m_mutex);
|
||||
std::lock_guard<hal::priority_recursive_mutex> sync(m_mutex);
|
||||
if (m_buf.size() == 0) return false;
|
||||
double error = GetError();
|
||||
switch (m_toleranceType) {
|
||||
@@ -528,7 +528,7 @@ bool PIDController::OnTarget() const {
|
||||
*/
|
||||
void PIDController::Enable() {
|
||||
{
|
||||
std::lock_guard<priority_recursive_mutex> lock(m_mutex);
|
||||
std::lock_guard<hal::priority_recursive_mutex> lock(m_mutex);
|
||||
m_enabled = true;
|
||||
}
|
||||
|
||||
@@ -542,7 +542,7 @@ void PIDController::Enable() {
|
||||
*/
|
||||
void PIDController::Disable() {
|
||||
{
|
||||
std::lock_guard<priority_recursive_mutex> lock(m_mutex);
|
||||
std::lock_guard<hal::priority_recursive_mutex> lock(m_mutex);
|
||||
m_pidOutput->PIDWrite(0);
|
||||
m_enabled = false;
|
||||
}
|
||||
@@ -556,7 +556,7 @@ void PIDController::Disable() {
|
||||
* Return true if PIDController is enabled.
|
||||
*/
|
||||
bool PIDController::IsEnabled() const {
|
||||
std::lock_guard<priority_recursive_mutex> lock(m_mutex);
|
||||
std::lock_guard<hal::priority_recursive_mutex> lock(m_mutex);
|
||||
return m_enabled;
|
||||
}
|
||||
|
||||
@@ -566,7 +566,7 @@ bool PIDController::IsEnabled() const {
|
||||
void PIDController::Reset() {
|
||||
Disable();
|
||||
|
||||
std::lock_guard<priority_recursive_mutex> lock(m_mutex);
|
||||
std::lock_guard<hal::priority_recursive_mutex> lock(m_mutex);
|
||||
m_prevError = 0;
|
||||
m_totalError = 0;
|
||||
m_result = 0;
|
||||
|
||||
@@ -98,7 +98,7 @@ double Timer::Get() const {
|
||||
double result;
|
||||
double currentTime = GetFPGATimestamp();
|
||||
|
||||
std::lock_guard<priority_mutex> sync(m_mutex);
|
||||
std::lock_guard<hal::priority_mutex> sync(m_mutex);
|
||||
if (m_running) {
|
||||
// This math won't work if the timer rolled over (71 minutes after boot).
|
||||
// TODO: Check for it and compensate.
|
||||
@@ -117,7 +117,7 @@ double Timer::Get() const {
|
||||
* now.
|
||||
*/
|
||||
void Timer::Reset() {
|
||||
std::lock_guard<priority_mutex> sync(m_mutex);
|
||||
std::lock_guard<hal::priority_mutex> sync(m_mutex);
|
||||
m_accumulatedTime = 0;
|
||||
m_startTime = GetFPGATimestamp();
|
||||
}
|
||||
@@ -129,7 +129,7 @@ void Timer::Reset() {
|
||||
* relative to the system clock.
|
||||
*/
|
||||
void Timer::Start() {
|
||||
std::lock_guard<priority_mutex> sync(m_mutex);
|
||||
std::lock_guard<hal::priority_mutex> sync(m_mutex);
|
||||
if (!m_running) {
|
||||
m_startTime = GetFPGATimestamp();
|
||||
m_running = true;
|
||||
@@ -146,7 +146,7 @@ void Timer::Start() {
|
||||
void Timer::Stop() {
|
||||
double temp = Get();
|
||||
|
||||
std::lock_guard<priority_mutex> sync(m_mutex);
|
||||
std::lock_guard<hal::priority_mutex> sync(m_mutex);
|
||||
if (m_running) {
|
||||
m_accumulatedTime = temp;
|
||||
m_running = false;
|
||||
@@ -163,7 +163,7 @@ void Timer::Stop() {
|
||||
*/
|
||||
bool Timer::HasPeriodPassed(double period) {
|
||||
if (Get() > period) {
|
||||
std::lock_guard<priority_mutex> sync(m_mutex);
|
||||
std::lock_guard<hal::priority_mutex> sync(m_mutex);
|
||||
// Advance the start time by the period.
|
||||
// Don't set it to the current time... we want to avoid drift.
|
||||
m_startTime += period;
|
||||
|
||||
Reference in New Issue
Block a user