mirror of
https://github.com/esphome/esphome.git
synced 2024-09-07 00:59:08 +02:00
Add a simple helper to remap values (#2850)
This commit is contained in:
parent
6a0b343289
commit
f0bcf81a98
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user