From 018b54c71126285cf94c7fa69994f2f58bc14cad Mon Sep 17 00:00:00 2001 From: Jared Boone Date: Wed, 27 Jan 2016 12:09:36 -0800 Subject: [PATCH] Extract range_t to utility header. --- .../common/portapack_persistent_memory.cpp | 20 ++----------------- firmware/common/utility.hpp | 18 +++++++++++++++++ 2 files changed, 20 insertions(+), 18 deletions(-) diff --git a/firmware/common/portapack_persistent_memory.cpp b/firmware/common/portapack_persistent_memory.cpp index 6c44f0fd..63ace663 100644 --- a/firmware/common/portapack_persistent_memory.cpp +++ b/firmware/common/portapack_persistent_memory.cpp @@ -23,30 +23,14 @@ #include "hal.h" +#include "utility.hpp" + #include #include namespace portapack { namespace persistent_memory { -/* TODO: This is widely applicable. Factor this to somewhere useful. */ -template -struct range_t { - const T minimum; - const T maximum; - - const T& clip(const T& value) const { - return std::max(std::min(value, maximum), minimum); - } - - void reset_if_outside(T& value, const T& reset_value) const { - if( (value < minimum ) || - (value > maximum ) ) { - value = reset_value; - } - } -}; - using tuned_frequency_range_t = range_t; constexpr tuned_frequency_range_t tuned_frequency_range { rf::tuning_range.min, rf::tuning_range.max }; constexpr rf::Frequency tuned_frequency_reset_value { 858750000 }; diff --git a/firmware/common/utility.hpp b/firmware/common/utility.hpp index b1d00b65..fc8a3b3c 100644 --- a/firmware/common/utility.hpp +++ b/firmware/common/utility.hpp @@ -25,6 +25,7 @@ #include #include #include +#include #include #include @@ -70,6 +71,23 @@ inline float magnitude_squared(const std::complex c) { return r2 + i2; } +template +struct range_t { + const T minimum; + const T maximum; + + const T& clip(const T& value) const { + return std::max(std::min(value, maximum), minimum); + } + + void reset_if_outside(T& value, const T& reset_value) const { + if( (value < minimum ) || + (value > maximum ) ) { + value = reset_value; + } + } +}; + namespace std { /*! Stephan T Lavavej (STL!) implementation of make_unique, which has been accepted into the C++14 standard.