-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Silence unnecessary GCC warning about string truncation
- Loading branch information
Showing
2 changed files
with
18 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,25 @@ | ||
#pragma once | ||
|
||
#include "freertos/FreeRTOS.h" | ||
#include <chrono> | ||
#include <numeric> | ||
|
||
class Timer { | ||
public: | ||
// creates and starts the timer | ||
Timer() { ticks = xTaskGetTickCount(); } | ||
Timer() { start = xTaskGetTickCount(); } | ||
|
||
// returns passed time in seconds | ||
TickType_t seconds() { | ||
return (xTaskGetTickCount() - ticks) / configTICK_RATE_HZ; | ||
const TickType_t now = xTaskGetTickCount(); | ||
|
||
const TickType_t passed = | ||
now >= start | ||
? now - start | ||
: std::numeric_limits<decltype(start)>::max() - start + now; | ||
|
||
return passed / configTICK_RATE_HZ; | ||
} | ||
|
||
private: | ||
TickType_t ticks; | ||
TickType_t start; | ||
}; |