Various fixes around Companion trainer mode (#7116)
[opentx.git] / radio / src / storage / conversions / conversions.cpp
blobfa97a4edf7179609b1cfadfa059bb25a58ebbf7d
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 #include "opentx.h"
22 #include "conversions.h"
24 void convertRadioData(int version)
26 TRACE("convertRadioData(%d)", version);
28 #if EEPROM_CONVERSIONS < 217
29 if (version == 216) {
30 version = 217;
31 convertRadioData_216_to_217(g_eeGeneral);
33 #endif
35 #if EEPROM_CONVERSIONS < 218
36 if (version == 217) {
37 version = 218;
38 convertRadioData_217_to_218(g_eeGeneral);
40 #endif
42 #if EEPROM_CONVERSIONS < 219
43 if (version == 218) {
44 version = 219;
45 convertRadioData_218_to_219(g_eeGeneral);
47 #endif
50 void convertModelData(int version)
52 TRACE("convertModelData(%d)", version);
54 #if EEPROM_CONVERSIONS < 217
55 if (version == 216) {
56 version = 217;
57 convertModelData_216_to_217(g_model);
59 #endif
61 #if EEPROM_CONVERSIONS < 218
62 if (version == 217) {
63 version = 218;
64 convertModelData_217_to_218(g_model);
66 #endif
68 #if EEPROM_CONVERSIONS < 219
69 if (version == 218) {
70 version = 219;
71 convertModelData_218_to_219(g_model);
73 #endif
76 #if defined(EEPROM)
77 void eeConvertModel(int id, int version)
79 eeLoadModelData(id);
80 convertModelData(version);
81 uint8_t currModel = g_eeGeneral.currModel;
82 g_eeGeneral.currModel = id;
83 storageDirty(EE_MODEL);
84 storageCheck(true);
85 g_eeGeneral.currModel = currModel;
88 bool eeConvert()
90 const char *msg = NULL;
92 switch (g_eeGeneral.version) {
93 case 216:
94 msg = "EEprom Data v216";
95 break;
96 case 217:
97 msg = "EEprom Data v217";
98 break;
99 case 218:
100 msg = "EEprom Data v218";
101 break;
102 default:
103 return false;
106 int conversionVersionStart = g_eeGeneral.version;
108 // Information to the user and wait for key press
109 #if defined(PCBSKY9X)
110 g_eeGeneral.optrexDisplay = 0;
111 #endif
112 g_eeGeneral.backlightMode = e_backlight_mode_on;
113 g_eeGeneral.backlightBright = 0;
114 g_eeGeneral.contrast = 25;
116 ALERT(STR_STORAGE_WARNING, msg, AU_BAD_RADIODATA);
118 RAISE_ALERT(STR_STORAGE_WARNING, STR_EEPROM_CONVERTING, NULL, AU_NONE);
120 // General Settings conversion
121 eeLoadGeneralSettingsData();
122 int version = conversionVersionStart;
124 #if EEPROM_CONVERSIONS < 217
125 if (version == 216) {
126 version = 217;
127 convertRadioData_216_to_217(g_eeGeneral);
129 #endif
131 #if EEPROM_CONVERSIONS < 218
132 if (version == 217) {
133 version = 218;
134 convertRadioData_217_to_218(g_eeGeneral);
136 #endif
138 #if EEPROM_CONVERSIONS < 219
139 if (version == 218) {
140 version = 219;
141 convertRadioData_218_to_219(g_eeGeneral);
143 #endif
145 storageDirty(EE_GENERAL);
146 storageCheck(true);
148 #if defined(COLORLCD)
149 #elif LCD_W >= 212
150 lcdDrawRect(60, 6*FH+4, 132, 3);
151 #else
152 lcdDrawRect(10, 6*FH+4, 102, 3);
153 #endif
155 // Models conversion
156 for (uint8_t id=0; id<MAX_MODELS; id++) {
157 #if defined(COLORLCD)
158 #elif LCD_W >= 212
159 lcdDrawSolidHorizontalLine(61, 6*FH+5, 10+id*2, FORCE);
160 #else
161 lcdDrawSolidHorizontalLine(11, 6*FH+5, 10+(id*3)/2, FORCE);
162 #endif
163 lcdRefresh();
164 if (eeModelExists(id)) {
165 eeConvertModel(id, conversionVersionStart);
169 return true;
171 #endif