mirror of
https://github.com/esphome/esphome.git
synced 2024-11-26 08:55:22 +01:00
Add a simple helper to remap values (#2850)
This commit is contained in:
parent
6a0b343289
commit
f0bcf81a98
1 changed files with 10 additions and 0 deletions
|
@ -415,4 +415,14 @@ optional<T> parse_number(const std::string &str) {
|
||||||
|
|
||||||
///@}
|
///@}
|
||||||
|
|
||||||
|
/// @name Number manipulation
|
||||||
|
///@{
|
||||||
|
|
||||||
|
/// Remap a number from one range to another.
|
||||||
|
template<typename T, typename U> T remap(U value, U min, U max, T min_out, T max_out) {
|
||||||
|
return (value - min) * (max_out - min_out) / (max - min) + min_out;
|
||||||
|
}
|
||||||
|
|
||||||
|
///@}
|
||||||
|
|
||||||
} // namespace esphome
|
} // namespace esphome
|
||||||
|
|
Loading…
Reference in a new issue