mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-23 08:15:30 +03:00
Made 'scaleRange' agnostic to order of ranges.
This commit is contained in:
parent
d6de0c9e24
commit
edc44bd830
3 changed files with 25 additions and 6 deletions
|
@ -152,10 +152,10 @@ float degreesToRadians(int16_t degrees)
|
|||
return degrees * RAD;
|
||||
}
|
||||
|
||||
int scaleRange(int x, int srcMin, int srcMax, int destMin, int destMax) {
|
||||
long int a = ((long int) destMax - (long int) destMin) * ((long int) x - (long int) srcMin);
|
||||
long int b = (long int) srcMax - (long int) srcMin;
|
||||
return (a / b) + destMin;
|
||||
int scaleRange(int x, int srcFrom, int srcTo, int destFrom, int destTo) {
|
||||
long int a = ((long int) destTo - (long int) destFrom) * ((long int) x - (long int) srcFrom);
|
||||
long int b = (long int) srcTo - (long int) srcFrom;
|
||||
return (a / b) + destFrom;
|
||||
}
|
||||
|
||||
// Normalize a vector
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue