fix models list reload after USB mass storage connection (#5963)
[opentx.git] / radio / src / gvars.h
blob176a7cf93178b174bc95f3289380f4ccde6da9c7
1 /*
2 * Copyright (C) OpenTX
4 * Based on code named
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.
21 #ifndef _GVARS_H_
22 #define _GVARS_H_
24 #if defined(PCBSTD)
25 // GVars are common to all flight modes
26 #define GVAR_VALUE(x, p) g_model.gvars[x]
27 #define SET_GVAR_VALUE(idx, phase, value) \
28 (GVAR_VALUE(idx, phase) = value, storageDirty(EE_MODEL))
29 #else
30 // GVars have one value per flight mode
31 #define GVAR_VALUE(gv, fm) g_model.flightModeData[fm].gvars[gv]
32 #define SET_GVAR_VALUE(idx, phase, value) \
33 GVAR_VALUE(idx, phase) = value; \
34 storageDirty(EE_MODEL); \
35 if (g_model.gvars[idx].popup) { \
36 gvarLastChanged = idx; \
37 gvarDisplayTimer = GVAR_DISPLAY_TIME; \
39 #endif
41 #if defined(GVARS)
42 #if defined(PCBSTD)
43 int16_t getGVarFieldValue(int16_t x, int16_t min, int16_t max);
44 void setGVarValue(uint8_t x, int8_t value);
45 #define GET_GVAR(x, min, max, fm) getGVarFieldValue(x, min, max)
46 #define SET_GVAR(idx, val, fm) setGVarValue(idx, val)
47 #else
48 uint8_t getGVarFlightMode(uint8_t fm, uint8_t gv);
49 int16_t getGVarFieldValue(int16_t x, int16_t min, int16_t max, int8_t fm);
50 int32_t getGVarFieldValuePrec1(int16_t x, int16_t min, int16_t max, int8_t fm);
51 int16_t getGVarValue(int8_t gv, int8_t fm);
52 int32_t getGVarValuePrec1(int8_t gv, int8_t fm);
53 void setGVarValue(uint8_t x, int16_t value, int8_t fm);
54 #define GET_GVAR(x, min, max, fm) getGVarFieldValue(x, min, max, fm)
55 #define SET_GVAR(idx, val, fm) setGVarValue(idx, val, fm)
56 #define GVAR_DISPLAY_TIME 100 /*1 second*/;
57 #define GET_GVAR_PREC1(x, min, max, fm) getGVarFieldValuePrec1(x, min, max, fm)
58 extern uint8_t gvarDisplayTimer;
59 extern uint8_t gvarLastChanged;
60 #endif
61 #else
62 #define GET_GVAR(x, ...) (x)
63 #define GET_GVAR_PREC1(x, ...) (x*10)
64 #endif
66 #if defined(CPUARM)
67 #define GV_GET_GV1_VALUE(max) ((max<=GV_RANGESMALL && min>=GV_RANGESMALL_NEG) ? GV1_SMALL : GV1_LARGE)
68 #define GV_INDEX_CALCULATION(x,max) ((max<=GV_RANGESMALL && min>=GV_RANGESMALL_NEG) ? (uint8_t) x-GV1_SMALL : ((x&(GV1_LARGE*2-1))-GV1_LARGE))
69 #define GV_IS_GV_VALUE(x,min,max) ((max>GV1_SMALL || min<-GV1_SMALL) ? (x>GV_RANGELARGE || x<GV_RANGELARGE_NEG) : (x>max) || (x<min))
70 #else
71 #define GV_GET_GV1_VALUE(max) ((max<=GV_RANGESMALL) ? GV1_SMALL : GV1_LARGE)
72 #define GV_INDEX_CALCULATION(x,max) ((max<=GV1_SMALL) ? (uint8_t) x-GV1_SMALL : ((x&(GV1_LARGE*2-1))-GV1_LARGE))
73 #define GV_IS_GV_VALUE(x,min,max) ((x>max) || (x<min) )
74 #endif
76 #define GV_INDEX_CALC_DELTA(x,delta) ((x&(delta*2-1)) - delta)
78 #define GV_CALC_VALUE_IDX_POS(idx,delta) (-delta+idx)
79 #define GV_CALC_VALUE_IDX_NEG(idx,delta) (delta+idx)
81 #define GV_RANGESMALL (GV1_SMALL - (RESERVE_RANGE_FOR_GVARS+1))
82 #define GV_RANGESMALL_NEG (-GV1_SMALL + (RESERVE_RANGE_FOR_GVARS+1))
83 #define GV_RANGELARGE (GV1_LARGE - (RESERVE_RANGE_FOR_GVARS+1))
84 #define GV_RANGELARGE_NEG (-GV1_LARGE + (RESERVE_RANGE_FOR_GVARS+1))
86 #if defined(CPUARM)
87 // the define GV1_LARGE marks the highest bit value used for this variables
88 // because this would give too big numbers for ARM, we limit it further for
89 // offset and weight
90 #define GV_RANGELARGE_WEIGHT (GV_RANGE_WEIGHT)
91 #define GV_RANGELARGE_WEIGHT_NEG (-GV_RANGE_WEIGHT)
92 #define GV_RANGELARGE_OFFSET (GV_RANGE_OFFSET)
93 #define GV_RANGELARGE_OFFSET_NEG (-GV_RANGE_OFFSET)
94 #else
95 // for stock we just use as much as possible
96 #define GV_RANGELARGE_WEIGHT GV_RANGELARGE
97 #define GV_RANGELARGE_WEIGHT_NEG GV_RANGELARGE_NEG
98 #define GV_RANGELARGE_OFFSET GV_RANGELARGE
99 #define GV_RANGELARGE_OFFSET_NEG GV_RANGELARGE_NEG
100 #endif
102 #endif // _GVARS_H_