From a172858db29f056e61cb63e89e5ea4735eb731fd Mon Sep 17 00:00:00 2001 From: Daniel Agar Date: Wed, 20 Nov 2019 20:52:44 -0500 Subject: [PATCH] mixer: move scale() and scale_check() to SimpleMixer --- src/lib/mixer/Mixer.cpp | 41 ----------------------------------- src/lib/mixer/Mixer.hpp | 17 --------------- src/lib/mixer/SimpleMixer.cpp | 41 +++++++++++++++++++++++++++++++++++ src/lib/mixer/SimpleMixer.hpp | 21 +++++++++++++++++- 4 files changed, 61 insertions(+), 59 deletions(-) diff --git a/src/lib/mixer/Mixer.cpp b/src/lib/mixer/Mixer.cpp index 64a23762cf..d5e86fee86 100644 --- a/src/lib/mixer/Mixer.cpp +++ b/src/lib/mixer/Mixer.cpp @@ -64,47 +64,6 @@ Mixer::get_control(uint8_t group, uint8_t index) return value; } -float -Mixer::scale(const mixer_scaler_s &scaler, float input) -{ - float output; - - if (input < 0.0f) { - output = (input * scaler.negative_scale) + scaler.offset; - - } else { - output = (input * scaler.positive_scale) + scaler.offset; - } - - return math::constrain(output, scaler.min_output, scaler.max_output); -} - -int -Mixer::scale_check(struct mixer_scaler_s &scaler) -{ - if (scaler.offset > 1.001f) { - return 1; - } - - if (scaler.offset < -1.001f) { - return 2; - } - - if (scaler.min_output > scaler.max_output) { - return 3; - } - - if (scaler.min_output < -1.001f) { - return 4; - } - - if (scaler.max_output > 1.001f) { - return 5; - } - - return 0; -} - const char * Mixer::findtag(const char *buf, unsigned &buflen, char tag) { diff --git a/src/lib/mixer/Mixer.hpp b/src/lib/mixer/Mixer.hpp index 95e548fdfb..4e3c9c654c 100644 --- a/src/lib/mixer/Mixer.hpp +++ b/src/lib/mixer/Mixer.hpp @@ -153,23 +153,6 @@ protected: */ float get_control(uint8_t group, uint8_t index); - /** - * Perform simpler linear scaling. - * - * @param scaler The scaler configuration. - * @param input The value to be scaled. - * @return The scaled value. - */ - static float scale(const mixer_scaler_s &scaler, float input); - - /** - * Validate a scaler - * - * @param scaler The scaler to be validated. - * @return Zero if good, nonzero otherwise. - */ - static int scale_check(struct mixer_scaler_s &scaler); - /** * Find a tag * diff --git a/src/lib/mixer/SimpleMixer.cpp b/src/lib/mixer/SimpleMixer.cpp index 89bf53d171..8b127fb079 100644 --- a/src/lib/mixer/SimpleMixer.cpp +++ b/src/lib/mixer/SimpleMixer.cpp @@ -314,3 +314,44 @@ SimpleMixer::check() return 0; } + +float +SimpleMixer::scale(const mixer_scaler_s &scaler, float input) +{ + float output; + + if (input < 0.0f) { + output = (input * scaler.negative_scale) + scaler.offset; + + } else { + output = (input * scaler.positive_scale) + scaler.offset; + } + + return math::constrain(output, scaler.min_output, scaler.max_output); +} + +int +SimpleMixer::scale_check(mixer_scaler_s &scaler) +{ + if (scaler.offset > 1.001f) { + return 1; + } + + if (scaler.offset < -1.001f) { + return 2; + } + + if (scaler.min_output > scaler.max_output) { + return 3; + } + + if (scaler.min_output < -1.001f) { + return 4; + } + + if (scaler.max_output > 1.001f) { + return 5; + } + + return 0; +} diff --git a/src/lib/mixer/SimpleMixer.hpp b/src/lib/mixer/SimpleMixer.hpp index 4a08d3295e..d2a971f3ae 100644 --- a/src/lib/mixer/SimpleMixer.hpp +++ b/src/lib/mixer/SimpleMixer.hpp @@ -104,9 +104,28 @@ public: unsigned get_trim(float *trim) override; private: - mixer_simple_s *_pinfo{nullptr}; + + /** + * Perform simpler linear scaling. + * + * @param scaler The scaler configuration. + * @param input The value to be scaled. + * @return The scaled value. + */ + static float scale(const mixer_scaler_s &scaler, float input); + + /** + * Validate a scaler + * + * @param scaler The scaler to be validated. + * @return Zero if good, nonzero otherwise. + */ + static int scale_check(struct mixer_scaler_s &scaler); static int parse_output_scaler(const char *buf, unsigned &buflen, mixer_scaler_s &scaler); static int parse_control_scaler(const char *buf, unsigned &buflen, mixer_scaler_s &scaler, uint8_t &control_group, uint8_t &control_index); + + mixer_simple_s *_pinfo{nullptr}; + };