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:
@@ -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; }
|
||||
|
||||
Reference in New Issue
Block a user