5 * th9x - http://code.google.com/p/th9x
6 * er9x - http://code.google.com/p/er9x
7 * gruvin9x - http://code.google.com/p/gruvin9x
9 * License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License version 2 as
13 * published by the Free Software Foundation.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
24 int16_t getGVarFieldValue(int16_t x
, int16_t min
, int16_t max
)
26 if (GV_IS_GV_VALUE(x
, min
, max
)) {
27 int8_t idx
= GV_INDEX_CALCULATION(x
, max
);
35 x
= GVAR_VALUE(idx
, -1) * mul
;
38 return limit(min
, x
, max
);
41 void setGVarValue(uint8_t idx
, int8_t value
)
43 if (GVAR_VALUE(idx
, -1) != value
) {
44 SET_GVAR_VALUE(idx
, -1, value
);
48 uint8_t gvarDisplayTimer
= 0;
49 uint8_t gvarLastChanged
= 0;
51 uint8_t getGVarFlightMode(uint8_t fm
, uint8_t gv
) // TODO change params order to be consistent!
53 for (uint8_t i
=0; i
<MAX_FLIGHT_MODES
; i
++) {
54 if (fm
== 0) return 0;
55 int16_t val
= GVAR_VALUE(gv
, fm
);
56 if (val
<= GVAR_MAX
) return fm
;
57 uint8_t result
= val
-GVAR_MAX
-1;
58 if (result
>= fm
) result
++;
64 int16_t getGVarValue(int8_t gv
, int8_t fm
)
71 return GVAR_VALUE(gv
, getGVarFlightMode(fm
, gv
)) * mul
;
74 int32_t getGVarValuePrec1(int8_t gv
, int8_t fm
)
77 uint8_t prec
= g_model
.gvars
[abs((int)gv
)].prec
; // explicit cast to `int` needed, othervise gv is promoted to double!
87 return GVAR_VALUE(gv
, getGVarFlightMode(fm
, gv
)) * mul
;
90 void setGVarValue(uint8_t gv
, int16_t value
, int8_t fm
)
92 fm
= getGVarFlightMode(fm
, gv
);
93 if (GVAR_VALUE(gv
, fm
) != value
) {
94 SET_GVAR_VALUE(gv
, fm
, value
);
98 int16_t getGVarFieldValue(int16_t val
, int16_t min
, int16_t max
, int8_t fm
)
100 if (GV_IS_GV_VALUE(val
, min
, max
)) {
101 int8_t gv
= GV_INDEX_CALCULATION(val
, max
);
102 val
= getGVarValue(gv
, fm
);
104 return limit(min
, val
, max
);
107 int32_t getGVarFieldValuePrec1(int16_t val
, int16_t min
, int16_t max
, int8_t fm
)
109 if (GV_IS_GV_VALUE(val
, min
, max
)) {
110 int8_t gv
= GV_INDEX_CALCULATION(val
, max
);
111 val
= getGVarValuePrec1(gv
, fm
);
116 return limit
<int>(min
*10, val
, max
*10);