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.
27 void eeLoadModel(uint8_t index
)
29 if (index
< MAX_MODELS
) {
33 uint16_t size
= eeLoadModelData(index
);
35 #if defined(SIMU) && defined(EEPROM_ZONE_SIZE)
36 if (sizeof(uint16_t) + sizeof(g_model
) > EEPROM_ZONE_SIZE
) {
37 TRACE("Model data size can't exceed %d bytes (%d bytes)", int(EEPROM_ZONE_SIZE
-sizeof(uint16_t)), (int)sizeof(g_model
));
42 if (size
> 0 && size
!= sizeof(g_model
)) {
43 TRACE("Model data read=%d bytes vs %d bytes\n", size
, (int)sizeof(ModelData
));
48 if (size
< EEPROM_MIN_MODEL_SIZE
) { // if not loaded a fair amount
54 postModelLoad(alarms
);
58 uint8_t eeFindEmptyModel(uint8_t id
, bool down
)
62 i
= (MAX_MODELS
+ (down
? i
+1 : i
-1)) % MAX_MODELS
;
63 if (!eeModelExists(i
)) break;
64 if (i
== id
) return 0xff; // no free space in directory left
69 void selectModel(uint8_t sub
)
71 #if !defined(COLORLCD)
72 showMessageBox(STR_LOADINGMODEL
);
74 storageFlushCurrentModel();
75 storageCheck(true); // force writing of current model data before this is changed
76 g_eeGeneral
.currModel
= sub
;
77 storageDirty(EE_GENERAL
);
82 ModelHeader modelHeaders
[MAX_MODELS
];
83 void eeLoadModelHeaders()
85 for (uint32_t i
=0; i
<MAX_MODELS
; i
++) {
86 eeLoadModelHeader(i
, &modelHeaders
[i
]);
91 void storageReadRadioSettings()
93 if (!eepromOpen() || !eeLoadGeneral()) {
94 storageEraseAll(true);
101 for (uint8_t i
=0; languagePacks
[i
]!=NULL
; i
++) {
102 if (!strncmp(g_eeGeneral
.ttsLanguage
, languagePacks
[i
]->id
, 2)) {
103 currentLanguagePackIdx
= i
;
104 currentLanguagePack
= languagePacks
[i
];
110 void storageReadCurrentModel()
112 eeLoadModel(g_eeGeneral
.currModel
);
115 void storageReadAll()
117 storageReadRadioSettings();
118 storageReadCurrentModel();
121 void storageEraseAll(bool warn
)
123 TRACE("storageEraseAll");
129 ALERT(STR_STORAGE_WARNING
, STR_BAD_RADIO_DATA
, AU_BAD_RADIODATA
);
132 RAISE_ALERT(STR_STORAGE_WARNING
, STR_STORAGE_FORMAT
, NULL
, AU_NONE
);
135 storageDirty(EE_GENERAL
|EE_MODEL
);