mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-19 00:41:43 +00:00
[wpilib] Add Timer.isRunning() method (#7220)
This commit is contained in:
@@ -84,6 +84,10 @@ bool Timer::AdvanceIfElapsed(units::second_t period) {
|
||||
}
|
||||
}
|
||||
|
||||
bool Timer::IsRunning() const {
|
||||
return m_running;
|
||||
}
|
||||
|
||||
units::second_t Timer::GetFPGATimestamp() {
|
||||
// FPGA returns the timestamp in microseconds
|
||||
return units::second_t{frc::RobotController::GetFPGATime() * 1.0e-6};
|
||||
|
||||
@@ -111,6 +111,13 @@ class Timer {
|
||||
*/
|
||||
bool AdvanceIfElapsed(units::second_t period);
|
||||
|
||||
/**
|
||||
* Whether the timer is currently running.
|
||||
*
|
||||
* @return true if running.
|
||||
*/
|
||||
bool IsRunning() const;
|
||||
|
||||
/**
|
||||
* Return the FPGA system clock time in seconds.
|
||||
*
|
||||
|
||||
@@ -28,18 +28,22 @@ TEST_F(TimerTest, StartStop) {
|
||||
|
||||
// Verify timer is initialized as stopped
|
||||
EXPECT_EQ(timer.Get(), 0_s);
|
||||
EXPECT_FALSE(timer.IsRunning());
|
||||
frc::sim::StepTiming(500_ms);
|
||||
EXPECT_EQ(timer.Get(), 0_s);
|
||||
EXPECT_FALSE(timer.IsRunning());
|
||||
|
||||
// Verify timer increments after it's started
|
||||
timer.Start();
|
||||
frc::sim::StepTiming(500_ms);
|
||||
EXPECT_EQ(timer.Get(), 500_ms);
|
||||
EXPECT_TRUE(timer.IsRunning());
|
||||
|
||||
// Verify timer stops incrementing after it's stopped
|
||||
timer.Stop();
|
||||
frc::sim::StepTiming(500_ms);
|
||||
EXPECT_EQ(timer.Get(), 500_ms);
|
||||
EXPECT_FALSE(timer.IsRunning());
|
||||
}
|
||||
|
||||
TEST_F(TimerTest, Reset) {
|
||||
|
||||
@@ -151,4 +151,13 @@ public class Timer {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether the timer is currently running.
|
||||
*
|
||||
* @return true if running.
|
||||
*/
|
||||
public boolean isRunning() {
|
||||
return m_running;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,18 +35,22 @@ class TimerTest {
|
||||
|
||||
// Verify timer is initialized as stopped
|
||||
assertEquals(timer.get(), 0.0);
|
||||
assertFalse(timer.isRunning());
|
||||
SimHooks.stepTiming(0.5);
|
||||
assertEquals(timer.get(), 0.0);
|
||||
assertFalse(timer.isRunning());
|
||||
|
||||
// Verify timer increments after it's started
|
||||
timer.start();
|
||||
SimHooks.stepTiming(0.5);
|
||||
assertEquals(timer.get(), 0.5, 1e-9);
|
||||
assertTrue(timer.isRunning());
|
||||
|
||||
// Verify timer stops incrementing after it's stopped
|
||||
timer.stop();
|
||||
SimHooks.stepTiming(0.5);
|
||||
assertEquals(timer.get(), 0.5, 1e-9);
|
||||
assertFalse(timer.isRunning());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user