Prusa MINI Firmware overview
Stopwatch Class Reference

Stopwatch class. More...

#include <stopwatch.h>

Inheritance diagram for Stopwatch:

Static Public Member Functions

static FORCE_INLINE void init ()
 Initialize the stopwatch. More...
 
static bool stop ()
 Stop the stopwatch. More...
 
static bool pause ()
 Pause the stopwatch. More...
 
static bool start ()
 Start the stopwatch. More...
 
static void resume (const millis_t with_time)
 Resume the stopwatch. More...
 
static void reset ()
 Reset the stopwatch. More...
 
static FORCE_INLINE bool isRunning ()
 Check if the timer is running. More...
 
static FORCE_INLINE bool isPaused ()
 Check if the timer is paused. More...
 
static millis_t duration ()
 Get the running time. More...
 

Detailed Description

Stopwatch class.

This class acts as a timer proving stopwatch functionality including the ability to pause the running time counter.

Member Function Documentation

◆ init()

static FORCE_INLINE void Stopwatch::init ( )
static

Initialize the stopwatch.

50 { reset(); }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ stop()

bool Stopwatch::stop ( )
static

Stop the stopwatch.

Stop the running timer, it will silently ignore the request if no timer is currently running.

Returns
true on success
36  {
37  #if ENABLED(DEBUG_STOPWATCH)
38  Stopwatch::debug(PSTR("stop"));
39  #endif
40 
41  if (isRunning() || isPaused()) {
42  #if ENABLED(EXTENSIBLE_UI)
44  #endif
45  state = STOPPED;
46  stopTimestamp = millis();
47  return true;
48  }
49  else return false;
50 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ pause()

bool Stopwatch::pause ( )
static

Pause the stopwatch.

Pause the running timer, it will silently ignore the request if no timer is currently running.

Returns
true on success
52  {
53  #if ENABLED(DEBUG_STOPWATCH)
54  Stopwatch::debug(PSTR("pause"));
55  #endif
56 
57  if (isRunning()) {
58  #if ENABLED(EXTENSIBLE_UI)
60  #endif
61  state = PAUSED;
62  stopTimestamp = millis();
63  return true;
64  }
65  else return false;
66 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ start()

bool Stopwatch::start ( )
static

Start the stopwatch.

Start the timer, it will silently ignore the request if the timer is already running.

Returns
true on success
68  {
69  #if ENABLED(DEBUG_STOPWATCH)
70  Stopwatch::debug(PSTR("start"));
71  #endif
72 
73  #if ENABLED(EXTENSIBLE_UI)
75  #endif
76 
77  if (!isRunning()) {
78  if (isPaused()) accumulator = duration();
79  else reset();
80 
81  state = RUNNING;
82  startTimestamp = millis();
83  return true;
84  }
85  else return false;
86 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ resume()

void Stopwatch::resume ( const millis_t  with_time)
static

Resume the stopwatch.

Resume a timer from a given duration

88  {
89  #if ENABLED(DEBUG_STOPWATCH)
90  Stopwatch::debug(PSTR("resume"));
91  #endif
92 
93  reset();
94  if ((accumulator = with_time)) state = RUNNING;
95 }
Here is the call graph for this function:

◆ reset()

void Stopwatch::reset ( )
static

Reset the stopwatch.

Reset all settings to their default values.

97  {
98  #if ENABLED(DEBUG_STOPWATCH)
99  Stopwatch::debug(PSTR("reset"));
100  #endif
101 
102  state = STOPPED;
103  startTimestamp = 0;
104  stopTimestamp = 0;
105  accumulator = 0;
106 }
Here is the caller graph for this function:

◆ isRunning()

static FORCE_INLINE bool Stopwatch::isRunning ( )
static

Check if the timer is running.

Return true if the timer is currently running, false otherwise.

Returns
true if stopwatch is running
93 { return state == RUNNING; }
Here is the caller graph for this function:

◆ isPaused()

static FORCE_INLINE bool Stopwatch::isPaused ( )
static

Check if the timer is paused.

Return true if the timer is currently paused, false otherwise.

Returns
true if stopwatch is paused
100 { return state == PAUSED; }
Here is the caller graph for this function:

◆ duration()

millis_t Stopwatch::duration ( )
static

Get the running time.

Return the total number of seconds the timer has been running.

Returns
the delta since starting the stopwatch
108  {
109  return ((isRunning() ? millis() : stopTimestamp)
110  - startTimestamp) / 1000UL + accumulator;
111 }
Here is the call graph for this function:
Here is the caller graph for this function:
Stopwatch::isRunning
static FORCE_INLINE bool isRunning()
Check if the timer is running.
Definition: stopwatch.h:93
millis
uint32_t millis(void)
Definition: wiring_time.c:29
ExtUI::onPrintTimerPaused
void onPrintTimerPaused()
Definition: marlin_server.cpp:884
PSTR
#define PSTR(str)
Definition: pgmspace.h:31
ExtUI::onPrintTimerStarted
void onPrintTimerStarted()
Definition: marlin_server.cpp:879
Stopwatch::duration
static millis_t duration()
Get the running time.
Definition: stopwatch.cpp:108
Stopwatch::reset
static void reset()
Reset the stopwatch.
Definition: stopwatch.cpp:97
Stopwatch::isPaused
static FORCE_INLINE bool isPaused()
Check if the timer is paused.
Definition: stopwatch.h:100
ExtUI::onPrintTimerStopped
void onPrintTimerStopped()
Definition: marlin_server.cpp:889