Use static classes for job timers (#9938)

This commit is contained in:
Scott Lahteine
2018-03-04 21:23:43 -06:00
committed by GitHub
parent 930720bbbb
commit 36262a0479
5 changed files with 171 additions and 166 deletions

View File

@@ -23,11 +23,12 @@
#ifndef STOPWATCH_H
#define STOPWATCH_H
#include "../core/types.h"
// Print debug messages with M111 S2 (Uses 156 bytes of PROGMEM)
//#define DEBUG_STOPWATCH
#include "../core/macros.h"
#include "../core/types.h"
/**
* @brief Stopwatch class
* @details This class acts as a timer proving stopwatch functionality including
@@ -41,21 +42,16 @@ class Stopwatch {
PAUSED
};
Stopwatch::State state;
millis_t accumulator;
millis_t startTimestamp;
millis_t stopTimestamp;
static Stopwatch::State state;
static millis_t accumulator;
static millis_t startTimestamp;
static millis_t stopTimestamp;
public:
/**
* @brief Class constructor
*/
Stopwatch();
/**
* @brief Initialize the stopwatch
*/
inline void init() {}
FORCE_INLINE static void init() { reset(); }
/**
* @brief Stops the stopwatch
@@ -63,56 +59,56 @@ class Stopwatch {
* no timer is currently running.
* @return true is method was successful
*/
bool stop();
static bool stop();
/**
* @brief Pause the stopwatch
* @details Pauses the running timer, it will silently ignore the request if
* @details Pause the running timer, it will silently ignore the request if
* no timer is currently running.
* @return true is method was successful
*/
bool pause();
static bool pause();
/**
* @brief Starts the stopwatch
* @details Starts the timer, it will silently ignore the request if the
* @brief Start the stopwatch
* @details Start the timer, it will silently ignore the request if the
* timer is already running.
* @return true is method was successful
*/
bool start();
static bool start();
/**
* @brief Resets the stopwatch
* @details Resets all settings to their default values.
* @brief Reset the stopwatch
* @details Reset all settings to their default values.
*/
void reset();
static void reset();
/**
* @brief Checks if the timer is running
* @details Returns true if the timer is currently running, false otherwise.
* @brief Check if the timer is running
* @details Return true if the timer is currently running, false otherwise.
* @return true if stopwatch is running
*/
bool isRunning();
static bool isRunning();
/**
* @brief Checks if the timer is paused
* @details Returns true if the timer is currently paused, false otherwise.
* @brief Check if the timer is paused
* @details Return true if the timer is currently paused, false otherwise.
* @return true if stopwatch is paused
*/
bool isPaused();
static bool isPaused();
/**
* @brief Gets the running time
* @details Returns the total number of seconds the timer has been running.
* @brief Get the running time
* @details Return the total number of seconds the timer has been running.
* @return the delta since starting the stopwatch
*/
millis_t duration();
static millis_t duration();
#ifdef DEBUG_STOPWATCH
/**
* @brief Prints a debug message
* @details Prints a simple debug message "Stopwatch::function"
* @brief Print a debug message
* @details Print a simple debug message "Stopwatch::function"
*/
static void debug(const char func[]);