Formula Student Electronics & Software
The code for the embedded software
Loading...
Searching...
No Matches
Metro Class Reference

Our own implementation of Metro class. More...

#include <metro.h>

Collaboration diagram for Metro:
Collaboration graph

Public Member Functions

 Metro (unsigned long interval_millis, uint8_t autoreset=0)
 Constructor to initialize the timer with a given interval and autoreset behavior.
 
void interval (unsigned long interval_millis)
 Sets a new interval for the timer.
 
bool check ()
 Checks if the interval has passed and resets the timer if true.
 
bool checkWithoutReset () const
 Checks if the interval has passed without resetting the timer.
 
void reset ()
 Resets the timer to the current time.
 

Detailed Description

Our own implementation of Metro class.

This class provides functionality to check if a certain amount of time has passed since the last time the check was true. It adds to the public implementation of the Metro class the possibility to check if the time has passed without resetting the timer.

Definition at line 12 of file metro.h.

Constructor & Destructor Documentation

◆ Metro()

Metro::Metro ( unsigned long  interval_millis,
uint8_t  autoreset = 0 
)
inline

Constructor to initialize the timer with a given interval and autoreset behavior.

Parameters
interval_millisThe interval in milliseconds for the timer
autoresetIf set to non-zero, the timer will reset automatically upon a successful check

This constructor allows the user to specify both the interval and the autoreset behavior. If autoreset is set to zero, the timer will follow Benjamin Soelberg's check behavior where the timer will update based on the interval instead of resetting to the current time.

Definition at line 71 of file metro.h.

Here is the call graph for this function:

Member Function Documentation

◆ check()

bool Metro::check ( )
inline

Checks if the interval has passed and resets the timer if true.

Returns
true if the interval has passed, false otherwise

This method checks whether the specified interval has passed since the last reset. If the interval has passed, the timer is reset according to the autoreset behavior. If autoreset is enabled, the timer resets to the current time; otherwise, it increments by the interval.

Definition at line 91 of file metro.h.

Here is the caller graph for this function:

◆ checkWithoutReset()

bool Metro::checkWithoutReset ( ) const
inline

Checks if the interval has passed without resetting the timer.

Returns
true if the interval has passed, false otherwise

This method performs a check similar to check(), but it does not reset the timer upon a successful check. It is useful when you want to verify the passage of time without affecting the internal state.

Definition at line 116 of file metro.h.

Here is the caller graph for this function:

◆ interval()

void Metro::interval ( unsigned long  interval_millis)
inline

Sets a new interval for the timer.

Parameters
interval_millisThe new interval in milliseconds

This method allows the user to change the interval dynamically at runtime. The interval will be used for subsequent checks.

Definition at line 78 of file metro.h.

Here is the caller graph for this function:

◆ reset()

void Metro::reset ( )

Resets the timer to the current time.

This method resets the timer, updating the internal state to the current time. After calling this method, the timer will begin counting from zero again.

Definition at line 125 of file metro.h.

Here is the caller graph for this function:

The documentation for this class was generated from the following file: