mirror of
https://github.com/eried/portapack-mayhem.git
synced 2025-02-22 23:59:57 -05:00
Extract range_t to utility header.
This commit is contained in:
parent
c761d3aaa8
commit
018b54c711
@ -23,30 +23,14 @@
|
|||||||
|
|
||||||
#include "hal.h"
|
#include "hal.h"
|
||||||
|
|
||||||
|
#include "utility.hpp"
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
namespace portapack {
|
namespace portapack {
|
||||||
namespace persistent_memory {
|
namespace persistent_memory {
|
||||||
|
|
||||||
/* TODO: This is widely applicable. Factor this to somewhere useful. */
|
|
||||||
template<class T>
|
|
||||||
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<rf::Frequency>;
|
using tuned_frequency_range_t = range_t<rf::Frequency>;
|
||||||
constexpr tuned_frequency_range_t tuned_frequency_range { rf::tuning_range.min, rf::tuning_range.max };
|
constexpr tuned_frequency_range_t tuned_frequency_range { rf::tuning_range.min, rf::tuning_range.max };
|
||||||
constexpr rf::Frequency tuned_frequency_reset_value { 858750000 };
|
constexpr rf::Frequency tuned_frequency_reset_value { 858750000 };
|
||||||
|
@ -25,6 +25,7 @@
|
|||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
|
#include <algorithm>
|
||||||
#include <complex>
|
#include <complex>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
@ -70,6 +71,23 @@ inline float magnitude_squared(const std::complex<float> c) {
|
|||||||
return r2 + i2;
|
return r2 + i2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<class T>
|
||||||
|
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 {
|
namespace std {
|
||||||
|
|
||||||
/*! Stephan T Lavavej (STL!) implementation of make_unique, which has been accepted into the C++14 standard.
|
/*! Stephan T Lavavej (STL!) implementation of make_unique, which has been accepted into the C++14 standard.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user