-
Notifications
You must be signed in to change notification settings - Fork 1
/
core_interp.c
60 lines (56 loc) · 1.8 KB
/
core_interp.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/*
* $Id: core_interp.c,v 1.2 2010/06/15 00:48:59 clivewebster Exp $
*
* Revision History
* ================
* $Log: core_interp.c,v $
* Revision 1.2 2010/06/15 00:48:59 clivewebster
* Add copyright license info
*
* Revision 1.1 2009/10/26 18:50:49 clivewebster
* *** empty log message ***
*
* ===========
*
* Copyright (C) 2010 Clive Webster ([email protected])
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*
*
* core_interp.c
*
* Created on: 26-Oct-2009
* Author: Clive Webster
*/
#include "core.h"
/*
* Interpolate between two signed numbers
* value - the current value to be used
* minVal - the minimum that 'value' can be
* maxVal - the maximum that 'value' can be
* minRtn - the return value if 'value = minVal'
* maxRtn - the return value if 'value = maxVal'
* return a value in the range minRtn to maxRtn
*/
int16_t interpolate(int16_t value, int16_t minVal, int16_t maxVal, int16_t minRtn, int16_t maxRtn){
register int32_t lRtnRange;
register int32_t lValRange;
register int32_t lRelVal;
lRtnRange = maxRtn - minRtn;
lValRange = maxVal - minVal;
lRelVal = value - minVal;
lRtnRange = minRtn + ( lRtnRange * lRelVal / lValRange );
return (int16_t)lRtnRange;
}