1
0
mirror of https://github.com/esphome/esphome.git synced 2025-11-18 07:45:56 +00:00

Introduce clamp as a template function (#1953)

This commit is contained in:
Stefan Agner
2021-07-14 07:08:18 +02:00
committed by GitHub
parent 08b67e7aea
commit 5cb0c11feb
13 changed files with 17 additions and 14 deletions

View File

@@ -287,13 +287,16 @@ void HighFrequencyLoopRequester::stop() {
}
bool HighFrequencyLoopRequester::is_high_frequency() { return high_freq_num_requests > 0; }
float clamp(float val, float min, float max) {
template<typename T> T clamp(const T val, const T min, const T max) {
if (val < min)
return min;
if (val > max)
return max;
return val;
}
template float clamp(float, float, float);
template int clamp(int, int, int);
float lerp(float completion, float start, float end) { return start + (end - start) * completion; }
bool str_startswith(const std::string &full, const std::string &start) { return full.rfind(start, 0) == 0; }