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.
23 uint8_t gvarDisplayTimer
= 0;
24 uint8_t gvarLastChanged
= 0;
26 uint8_t getGVarFlightMode(uint8_t fm
, uint8_t gv
) // TODO change params order to be consistent!
28 for (uint8_t i
=0; i
<MAX_FLIGHT_MODES
; i
++) {
29 if (fm
== 0) return 0;
30 int16_t val
= GVAR_VALUE(gv
, fm
);
31 if (val
<= GVAR_MAX
) return fm
;
32 uint8_t result
= val
-GVAR_MAX
-1;
33 if (result
>= fm
) result
++;
39 int16_t getGVarValue(int8_t gv
, int8_t fm
)
46 return GVAR_VALUE(gv
, getGVarFlightMode(fm
, gv
)) * mul
;
49 int32_t getGVarValuePrec1(int8_t gv
, int8_t fm
)
51 int8_t idx
= (gv
>= 0 ? gv
: -gv
- 1);
52 int8_t mul
= (g_model
.gvars
[idx
].prec
== 0 ? 10 : 1); // explicit cast to `int` needed, othervise gv is promoted to double!
56 return GVAR_VALUE(idx
, getGVarFlightMode(fm
, idx
)) * mul
;
59 void setGVarValue(uint8_t gv
, int16_t value
, int8_t fm
)
61 fm
= getGVarFlightMode(fm
, gv
);
62 if (GVAR_VALUE(gv
, fm
) != value
) {
63 SET_GVAR_VALUE(gv
, fm
, value
);
67 int16_t getGVarFieldValue(int16_t val
, int16_t min
, int16_t max
, int8_t fm
)
69 if (GV_IS_GV_VALUE(val
, min
, max
)) {
70 int8_t gv
= GV_INDEX_CALCULATION(val
, max
);
71 val
= getGVarValue(gv
, fm
);
73 return limit(min
, val
, max
);
76 int32_t getGVarFieldValuePrec1(int16_t val
, int16_t min
, int16_t max
, int8_t fm
)
78 if (GV_IS_GV_VALUE(val
, min
, max
)) {
79 int8_t gv
= GV_INDEX_CALCULATION(val
, max
);
80 val
= getGVarValuePrec1(gv
, fm
);
85 return limit
<int>(min
*10, val
, max
*10);