-
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.
Return old data if not ready upto some interval (#30)
- Loading branch information
Showing
9 changed files
with
95 additions
and
91 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
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 |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#pragma once | ||
|
||
#include "util/misc.h" | ||
#include <optional> | ||
#include <type_traits> | ||
|
||
template <class T, unsigned long max_interval_ms> | ||
requires std::is_copy_assignable_v<T> | ||
class last_measurement_helper | ||
{ | ||
public: | ||
constexpr static unsigned long max_value_interval_ms = max_interval_ms; | ||
|
||
void store(const T &value) | ||
{ | ||
last_measurement_value_ = value; | ||
last_measurement_value_taken_ = esp32::millis(); | ||
} | ||
|
||
bool update(T &value) | ||
{ | ||
if ((esp32::millis() - last_measurement_value_taken_) <= max_interval_ms) | ||
{ | ||
if (last_measurement_value_.has_value()) | ||
{ | ||
value = last_measurement_value_.value(); | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
|
||
private: | ||
std::optional<T> last_measurement_value_; | ||
uint64_t last_measurement_value_taken_; | ||
}; |
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
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
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,5 +1,6 @@ | ||
#pragma once | ||
|
||
#include <cmath> | ||
#include <esp_timer.h> | ||
|
||
namespace esp32 | ||
|
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