allow splash image to be loaded from SD on Horus (#5463)
[opentx.git] / radio / src / gui / gui_common.h
blobaceca9f0029761a16e30df38fe52d3a5dfbb87c8
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 _GUI_COMMON_H_
22 #define _GUI_COMMON_H_
24 #include "lcd.h"
25 #include "keys.h"
27 #if defined(ROTARY_ENCODER_NAVIGATION)
28 #define CASE_EVT_ROTARY_LEFT case EVT_ROTARY_LEFT:
29 #define CASE_EVT_ROTARY_RIGHT case EVT_ROTARY_RIGHT:
30 #else
31 #define CASE_EVT_ROTARY_LEFT
32 #define CASE_EVT_ROTARY_RIGHT
33 #endif
35 #if defined(CPUARM)
36 typedef bool (*IsValueAvailable)(int);
38 int circularIncDec(int current, int inc, int min, int max, IsValueAvailable isValueAvailable=NULL);
39 int getFirstAvailable(int min, int max, IsValueAvailable isValueAvailable);
41 bool isTrimModeAvailable(int mode);
42 bool isInputAvailable(int input);
43 bool isInputSourceAvailable(int source);
44 bool isThrottleSourceAvailable(int source);
45 bool isLogicalSwitchFunctionAvailable(int function);
46 bool isLogicalSwitchAvailable(int index);
47 bool isAssignableFunctionAvailable(int function);
48 bool isSourceAvailable(int source);
49 bool isSourceAvailableInGlobalFunctions(int source);
50 bool isSourceAvailableInCustomSwitches(int source);
51 bool isSourceAvailableInResetSpecialFunction(int index);
52 bool isSourceAvailableInGlobalResetSpecialFunction(int index);
53 bool isSwitchAvailableInLogicalSwitches(int swtch);
54 bool isSwitchAvailableInCustomFunctions(int swtch);
55 bool isSwitchAvailableInMixes(int swtch);
56 bool isSwitchAvailableInTimers(int swtch);
57 bool isModuleAvailable(int module);
58 bool isRfProtocolAvailable(int protocol);
59 bool isTelemetryProtocolAvailable(int protocol);
60 bool isTrainerModeAvailable(int mode);
62 bool isSensorUnit(int sensor, uint8_t unit);
63 bool isCellsSensor(int sensor);
64 bool isGPSSensor(int sensor);
65 bool isAltSensor(int sensor);
66 bool isVoltsSensor(int sensor);
67 bool isCurrentSensor(int sensor);
68 bool isTelemetryFieldAvailable(int index);
69 bool isTelemetryFieldComparisonAvailable(int index);
70 bool isSensorAvailable(int sensor);
72 bool modelHasNotes();
73 #endif
75 #if defined(COLORLCD)
76 bool isSwitch2POSWarningStateAvailable(int state);
77 #endif
79 #if defined(GUI)
80 #define IS_INSTANT_TRIM_ALLOWED() (IS_MAIN_VIEW_DISPLAYED() || IS_TELEMETRY_VIEW_DISPLAYED() || IS_OTHER_VIEW_DISPLAYED())
81 #else
82 #define IS_INSTANT_TRIM_ALLOWED() true
83 #endif
85 #if defined(FLIGHT_MODES)
86 void drawFlightMode(coord_t x, coord_t y, int8_t idx, LcdFlags att=0);
87 #endif
89 swsrc_t checkIncDecMovedSwitch(swsrc_t val);
91 #if defined(CPUARM)
92 #include "telemetry/telemetry_sensors.h"
93 void drawValueWithUnit(coord_t x, coord_t y, int32_t val, uint8_t unit, LcdFlags flags);
94 void drawCurveRef(coord_t x, coord_t y, CurveRef & curve, LcdFlags flags=0);
95 void drawDate(coord_t x, coord_t y, TelemetryItem & telemetryItem, LcdFlags flags=0);
96 void drawTelemScreenDate(coord_t x, coord_t y, source_t sensor, LcdFlags flags=0);
97 void drawGPSPosition(coord_t x, coord_t y, int32_t longitude, int32_t latitude, LcdFlags flags=0);
98 void drawGPSSensorValue(coord_t x, coord_t y, TelemetryItem & telemetryItem, LcdFlags flags=0);
99 void drawSensorCustomValue(coord_t x, coord_t y, uint8_t sensor, int32_t value, LcdFlags flags=0);
100 void drawSourceCustomValue(coord_t x, coord_t y, source_t channel, int32_t val, LcdFlags flags=0);
101 void drawSourceValue(coord_t x, coord_t y, source_t channel, LcdFlags flags=0);
102 #endif
104 void drawCurve(coord_t offset=0);
106 #if defined(COLORLCD)
107 void drawStringWithIndex(coord_t x, coord_t y, const char * str, int idx, LcdFlags flags=0, const char * prefix=NULL, const char * suffix=NULL);
108 int editChoice(coord_t x, coord_t y, const char * values, int value, int min, int max, LcdFlags flags, event_t event);
109 uint8_t editCheckBox(uint8_t value, coord_t x, coord_t y, LcdFlags flags, event_t event);
110 swsrc_t editSwitch(coord_t x, coord_t y, swsrc_t value, LcdFlags flags, event_t event);
111 void drawFatalErrorScreen(const char * message);
112 void runFatalErrorScreen(const char * message);
113 #endif
115 void lcdDrawMMM(coord_t x, coord_t y, LcdFlags flags=0);
117 // model_setup Defines that are used in all uis in the same way
118 #define EXTERNAL_MODULE_CHANNELS_ROWS IF_EXTERNAL_MODULE_ON((IS_MODULE_DSM2(EXTERNAL_MODULE) || IS_MODULE_CROSSFIRE(EXTERNAL_MODULE) || IS_MODULE_SBUS(EXTERNAL_MODULE) || (IS_MODULE_MULTIMODULE(EXTERNAL_MODULE) && g_model.moduleData[EXTERNAL_MODULE].getMultiProtocol(true) != MM_RF_PROTO_DSM2)) ? (uint8_t)0 : (uint8_t)1)
121 #if defined(MULTIMODULE)
122 #define MULTIMODULE_STATUS_ROWS IS_MODULE_MULTIMODULE(EXTERNAL_MODULE) ? TITLE_ROW : HIDDEN_ROW, (IS_MODULE_MULTIMODULE(EXTERNAL_MODULE) && multiSyncStatus.isValid()) ? TITLE_ROW : HIDDEN_ROW,
123 #define MULTIMODULE_MODULE_ROWS IS_MODULE_MULTIMODULE(EXTERNAL_MODULE) ? (uint8_t) 0 : HIDDEN_ROW,
124 #define MULTIMODULE_MODE_ROWS(x) (g_model.moduleData[x].multi.customProto) ? (uint8_t) 3 :MULTIMODULE_HAS_SUBTYPE(g_model.moduleData[x].getMultiProtocol(true)) ? (uint8_t)2 : (uint8_t)1
125 #define MULTIMODULE_RFPROTO_ROWS(x) (g_model.moduleData[x].multi.customProto) ? (uint8_t) 1 :MULTIMODULE_HAS_SUBTYPE(g_model.moduleData[x].getMultiProtocol(true)) ? (uint8_t) 0 : HIDDEN_ROW
126 #define MULTIMODULE_SUBTYPE_ROWS(x) IS_MODULE_MULTIMODULE(x) ? MULTIMODULE_RFPROTO_ROWS(x) : HIDDEN_ROW,
127 #define MULTIMODULE_HAS_SUBTYPE(x) (getMultiProtocolDefinition(x)->maxSubtype > 0)
128 #define MULTIMODULE_HASOPTIONS(x) (getMultiProtocolDefinition(x)->optionsstr != nullptr)
129 #define MULTI_MAX_RX_NUM(x) (g_model.moduleData[x].getMultiProtocol(true) == MM_RF_PROTO_OLRS ? 4 : 15)
130 #define MULTIMODULE_HASFAILSAFE(x) (IS_MODULE_MULTIMODULE(x) && multiModuleStatus.isValid() && multiModuleStatus.supportsFailsafe())
131 #define MULTIMODULE_OPTIONS_ROW (IS_MODULE_MULTIMODULE(EXTERNAL_MODULE) && MULTIMODULE_HASOPTIONS(g_model.moduleData[EXTERNAL_MODULE].getMultiProtocol(true))) ? (uint8_t) 0: HIDDEN_ROW
133 // When using packed, the pointer in here end up not being aligned, which clang and gcc complain about
134 // Keep the order of the fields that the so that the size stays small
135 struct mm_protocol_definition {
136 uint8_t protocol;
137 uint8_t maxSubtype;
138 bool failsafe;
139 const pm_char *subTypeString;
140 const char *optionsstr;
143 const mm_protocol_definition *getMultiProtocolDefinition (uint8_t protocol);
144 #else
145 #define MULTIMODULE_STATUS_ROWS
146 #define MULTIMODULE_MODULE_ROWS
147 #define MULTIMODULE_HASFAILSAFE(x) false
148 #define MULTIMODULE_SUBTYPE_ROWS(x)
149 #define MULTIMODULE_MODE_ROWS(x) (uint8_t)0
150 #define MULTI_MAX_RX_NUM(x) 15
151 #define MULTIMODULE_OPTIONS_ROW HIDDEN_ROW
152 #endif
155 #define MAX_RX_NUM(x) (IS_MODULE_DSM2(x) ? 20 : IS_MODULE_MULTIMODULE(x) ? MULTI_MAX_RX_NUM(x) : 63)
156 #define IS_D8_RX(x) (g_model.moduleData[x].rfProtocol == RF_PROTO_D8)
157 #define IS_R9M_OR_XJTD16(x) ((IS_MODULE_XJT(x) && g_model.moduleData[x].rfProtocol== RF_PROTO_X16) || IS_MODULE_R9M(x))
159 #define FAILSAFE_ROWS(x) ((IS_MODULE_XJT(x) && HAS_RF_PROTOCOL_FAILSAFE(g_model.moduleData[x].rfProtocol)) || MULTIMODULE_HASFAILSAFE(x) || IS_MODULE_R9M(x)) ? (g_model.moduleData[x].failsafeMode==FAILSAFE_CUSTOM ? (uint8_t)1 : (uint8_t)0) : HIDDEN_ROW
160 #define R9M_FCC_OPTION_ROW (IS_TELEMETRY_INTERNAL_MODULE() ? TITLE_ROW : (uint8_t)0)
161 #define R9M_OPTION_ROW (IS_MODULE_R9M_FCC(EXTERNAL_MODULE) ? R9M_FCC_OPTION_ROW : TITLE_ROW)
162 #define EXTERNAL_MODULE_OPTION_ROW (IS_MODULE_R9M(EXTERNAL_MODULE) ? R9M_OPTION_ROW : (IS_MODULE_SBUS(EXTERNAL_MODULE) ? TITLE_ROW : MULTIMODULE_OPTIONS_ROW))
163 #define EXTERNAL_MODULE_POWER_ROW (IS_MODULE_MULTIMODULE(EXTERNAL_MODULE) || IS_MODULE_R9M_FCC(EXTERNAL_MODULE)) ? (uint8_t) 0 : HIDDEN_ROW
165 void editStickHardwareSettings(coord_t x, coord_t y, int idx, event_t event, LcdFlags flags);
169 #endif // _GUI_COMMON_H_