Various fixes around Companion trainer mode (#7116)
[opentx.git] / radio / src / gvars.h
blobced4c528ab8f39f3c1f913f79b588bd2ca57d006
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 // GVars have one value per flight mode
25 #define GVAR_VALUE(gv, fm) g_model.flightModeData[fm].gvars[gv]
26 #define SET_GVAR_VALUE(idx, phase, value) \
27 GVAR_VALUE(idx, phase) = value; \
28 storageDirty(EE_MODEL); \
29 if (g_model.gvars[idx].popup) { \
30 gvarLastChanged = idx; \
31 gvarDisplayTimer = GVAR_DISPLAY_TIME; \
34 #if defined(GVARS)
35 uint8_t getGVarFlightMode(uint8_t fm, uint8_t gv);
36 int16_t getGVarFieldValue(int16_t x, int16_t min, int16_t max, int8_t fm);
37 int32_t getGVarFieldValuePrec1(int16_t x, int16_t min, int16_t max, int8_t fm);
38 int16_t getGVarValue(int8_t gv, int8_t fm);
39 int32_t getGVarValuePrec1(int8_t gv, int8_t fm);
40 void setGVarValue(uint8_t x, int16_t value, int8_t fm);
41 #define GET_GVAR(x, min, max, fm) getGVarFieldValue(x, min, max, fm)
42 #define SET_GVAR(idx, val, fm) setGVarValue(idx, val, fm)
43 #define GVAR_DISPLAY_TIME 100 /*1 second*/;
44 #define GET_GVAR_PREC1(x, min, max, fm) getGVarFieldValuePrec1(x, min, max, fm)
45 extern uint8_t gvarDisplayTimer;
46 extern uint8_t gvarLastChanged;
47 #else
48 #define GET_GVAR(x, ...) (x)
49 #define GET_GVAR_PREC1(x, ...) (x*10)
50 #endif
52 #define GV_GET_GV1_VALUE(max) ((max<=GV_RANGESMALL && min>=GV_RANGESMALL_NEG) ? GV1_SMALL : GV1_LARGE)
53 #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))
54 #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))
56 #define GV_INDEX_CALC_DELTA(x,delta) ((x&(delta*2-1)) - delta)
58 #define GV_CALC_VALUE_IDX_POS(idx,delta) (-delta+idx)
59 #define GV_CALC_VALUE_IDX_NEG(idx,delta) (delta+idx)
61 #define GV_RANGESMALL (GV1_SMALL - (RESERVE_RANGE_FOR_GVARS+1))
62 #define GV_RANGESMALL_NEG (-GV1_SMALL + (RESERVE_RANGE_FOR_GVARS+1))
63 #define GV_RANGELARGE (GV1_LARGE - (RESERVE_RANGE_FOR_GVARS+1))
64 #define GV_RANGELARGE_NEG (-GV1_LARGE + (RESERVE_RANGE_FOR_GVARS+1))
66 // the define GV1_LARGE marks the highest bit value used for this variables
67 // because this would give too big numbers for ARM, we limit it further for
68 // offset and weight
69 #define GV_RANGELARGE_WEIGHT (GV_RANGE_WEIGHT)
70 #define GV_RANGELARGE_WEIGHT_NEG (-GV_RANGE_WEIGHT)
71 #define GV_RANGELARGE_OFFSET (GV_RANGE_OFFSET)
72 #define GV_RANGELARGE_OFFSET_NEG (-GV_RANGE_OFFSET)
74 #endif // _GVARS_H_