Mercurial > hg > beaglert
view core/Utilities.cpp @ 39:638bc1ae2500 staging
Improved readibility of the DIGITAL code in the PRU, using register names instead of aliases and expanding some of the macros, removing unused macros. Binaries were not modified
author | Giulio Moro <giuliomoro@yahoo.it> |
---|---|
date | Wed, 13 May 2015 12:18:10 +0100 |
parents | 8a575ba3ab52 |
children | 579c86316008 |
line wrap: on
line source
/* * Utilities.cpp * * Created on: Oct 27, 2014 * Author: parallels */ #include "../include/Utilities.h" // map() // // Scale an input value from one range to another. Works like its Wiring language equivalent. // x is the value to scale; in_min and in_max are the input range; out_min and out_max // are the output range. float map(float x, float in_min, float in_max, float out_min, float out_max) { return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min; } // constrain() // // Clips an input value to be between two end points // x is the value to constrain; min_val and max_val are the range float constrain(float x, float min_val, float max_val) { if(x < min_val) return min_val; if(x > max_val) return max_val; return x; }