* Model Labels Selector * Portrait Layout * Receiver ID Check * Fix Labels .yml format * Companion Initial Commit commit 967ddf3979b4954402fe62c858faba4b7a416bba Author: dlktdr <cblackburn320@gmail.com> Date: Mon Aug 29 01:49:15 2022 -0700 Fix Labels .yml format commit 534221cad9e01146c47a9ac1080a655e04f1f6c8 Author: dlktdr <cblackburn320@gmail.com> Date: Mon Aug 29 01:20:57 2022 -0700 Receiver ID Check commit f32c0939d44e9ae60bc0705a9176354c23fec198 Author: dlktdr <cblackburn320@gmail.com> Date: Sun Aug 28 23:13:25 2022 -0700 Portrait Layout commit 961181217c7841ff3f21299ac6aa419b810f80e9 Author: dlktdr <cblackburn320@gmail.com> Date: Sat Dec 11 16:56:13 2021 -0800 Model Labels Selector commitdc99dd40d2Author: David PHAM-VAN <1387855+DavBfr@users.noreply.github.com> Date: Fri Aug 26 03:04:34 2022 -0300 feat: Allow Lua widget to override built-in widget with same name (#2208) * Allow CPP Widgets Override with LUA * Reset a widget option it the type differs commit4b747caff9Author: eshifri <46511024+eshifri@users.noreply.github.com> Date: Thu Aug 25 19:47:53 2022 -0700 fix: Write model name into models.yml when duplicating model (#2224) * Update model name in the models.yml file (#2214) * Fix the length of the name. commite97f23a305Author: eshifri <46511024+eshifri@users.noreply.github.com> Date: Wed Aug 24 21:19:52 2022 -0700 fix(cpn): Fix full path to model notes for Simulator (#2223) * Correct Highlighted Column * labels .yml indentation * Update da.h New defines translated to Danish * Update dataconstants.h Omit warnings due to difference of LEN_MODEL_FILENAME and LEN_MODEL_NAME in modellist.cpp * Update modelslist.cpp Wonder if this are the right file in PR #1374 (?), seems a lot are changed to the better in #1374 * Update dataconstants.h Restore #define for LEN_MODEL_FILENAME to 16 * Rebase, Correct Issues Delete now deletes instead of select New model stores correct information Duplicate save all information in cell Rework items to use cell over button Reword function variables * CMPN: Add context menu Fix output not functional. Removed Yaml::null at some point :) Fix some compiler warnings * CMPN: Compiler warning, replace ,->_ in list * FW: Various Changes Change view to a grid Don't allow comma in label name Add scroll indicators Save sort order Co-authored-by: HThuren <99370924+HThuren@users.noreply.github.com>
194 lines
4.7 KiB
C++
194 lines
4.7 KiB
C++
/*
|
|
* Copyright (C) EdgeTX
|
|
*
|
|
* Based on code named
|
|
* opentx - https://github.com/opentx/opentx
|
|
* th9x - http://code.google.com/p/th9x
|
|
* er9x - http://code.google.com/p/er9x
|
|
* gruvin9x - http://code.google.com/p/gruvin9x
|
|
*
|
|
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
|
|
*
|
|
* This program is free software; you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License version 2 as
|
|
* published by the Free Software Foundation.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*/
|
|
|
|
#include "opentx.h"
|
|
#include "modelslist.h"
|
|
#include "conversions/conversions.h"
|
|
|
|
const char *writeFileBin(const char *filename, const uint8_t *data,
|
|
uint16_t size, uint8_t version)
|
|
{
|
|
TRACE("writeFileBin(%s)", filename);
|
|
|
|
FIL file;
|
|
unsigned char buf[8];
|
|
UINT written;
|
|
|
|
FRESULT result = f_open(&file, filename, FA_CREATE_ALWAYS | FA_WRITE);
|
|
if (result != FR_OK) {
|
|
return SDCARD_ERROR(result);
|
|
}
|
|
|
|
*(uint32_t*)&buf[0] = ETX_FOURCC;
|
|
buf[4] = version;
|
|
buf[5] = 'M';
|
|
*(uint16_t*)&buf[6] = size;
|
|
|
|
result = f_write(&file, buf, 8, &written);
|
|
if (result != FR_OK || written != 8) {
|
|
f_close(&file);
|
|
return SDCARD_ERROR(result);
|
|
}
|
|
|
|
result = f_write(&file, data, size, &written);
|
|
if (result != FR_OK || written != size) {
|
|
f_close(&file);
|
|
return SDCARD_ERROR(result);
|
|
}
|
|
|
|
f_close(&file);
|
|
return NULL;
|
|
}
|
|
|
|
// TODO: move to "common"
|
|
const char * writeModelBin()
|
|
{
|
|
char path[256];
|
|
getModelPath(path, g_eeGeneral.currModelFilename);
|
|
|
|
sdCheckAndCreateDirectory(MODELS_PATH);
|
|
return writeFileBin(path, (uint8_t *)&g_model, sizeof(g_model));
|
|
}
|
|
|
|
// TODO: move partly to common
|
|
const char * openFile(const char * fullpath, FIL * file)
|
|
{
|
|
FRESULT result = f_open(file, fullpath, FA_OPEN_EXISTING | FA_READ);
|
|
if (result != FR_OK) {
|
|
return SDCARD_ERROR(result);
|
|
}
|
|
|
|
return nullptr;
|
|
}
|
|
|
|
const char* openFileBin(const char * fullpath, FIL * file, uint16_t * size, uint8_t * version)
|
|
{
|
|
const char* err = openFile(fullpath, file);
|
|
if (err) return err;
|
|
|
|
if (f_size(file) < 8) {
|
|
f_close(file);
|
|
return STR_INCOMPATIBLE;
|
|
}
|
|
|
|
UINT read;
|
|
char buf[8];
|
|
|
|
FRESULT result = f_read(file, (uint8_t *)buf, sizeof(buf), &read);
|
|
if ((result != FR_OK) || (read != sizeof(buf))) {
|
|
f_close(file);
|
|
return SDCARD_ERROR(result);
|
|
}
|
|
|
|
*version = (uint8_t)buf[4];
|
|
if (*(uint32_t *)&buf[0] != ETX_FOURCC || *version < FIRST_CONV_EEPROM_VER ||
|
|
*version > EEPROM_VER || buf[5] != 'M') {
|
|
f_close(file);
|
|
return STR_INCOMPATIBLE;
|
|
}
|
|
|
|
*size = *(uint16_t*)&buf[6];
|
|
return nullptr;
|
|
}
|
|
|
|
const char *loadFileBin(const char *fullpath, uint8_t *data,
|
|
uint16_t maxsize, uint8_t *version)
|
|
{
|
|
FIL file;
|
|
UINT read;
|
|
uint16_t size;
|
|
|
|
TRACE("loadFileBin(%s)", fullpath);
|
|
|
|
const char * err = openFileBin(fullpath, &file, &size, version);
|
|
if (err)
|
|
return err;
|
|
|
|
size = min<uint16_t>(maxsize, size);
|
|
FRESULT result = f_read(&file, data, size, &read);
|
|
if (result != FR_OK || read != size) {
|
|
f_close(&file);
|
|
return SDCARD_ERROR(result);
|
|
}
|
|
|
|
f_close(&file);
|
|
return nullptr;
|
|
}
|
|
|
|
#if defined(SDCARD_RAW)
|
|
const char* readModel(const char* filename, uint8_t* buffer, uint32_t size)
|
|
{
|
|
uint8_t version = 0;
|
|
// Conversions from EEPROM are done in batch when converting the radio file.
|
|
// It is not supported on a model by model base when loaded.
|
|
const char *error = readModelBin(filename, buffer, size, &version);
|
|
if (error) return error;
|
|
|
|
#if defined(STORAGE_CONVERSIONS)
|
|
if (version < EEPROM_VER) {
|
|
convertBinModelData(filename, version);
|
|
error = readModelBin(filename, buffer, size, &version);
|
|
}
|
|
#endif
|
|
|
|
return error;
|
|
}
|
|
#endif
|
|
|
|
const char *readModelBin(const char *filename, uint8_t *buffer, uint32_t size,
|
|
uint8_t *version)
|
|
{
|
|
char path[256];
|
|
getModelPath(path, filename);
|
|
return loadFileBin(path, buffer, size, version);
|
|
}
|
|
|
|
const char * loadRadioSettingsBin(const char * path)
|
|
{
|
|
uint8_t version;
|
|
const char * error = loadFileBin(path, (uint8_t *)&g_eeGeneral, sizeof(g_eeGeneral), &version);
|
|
if (error) {
|
|
TRACE("loadRadioSettings error=%s", error);
|
|
return error;
|
|
}
|
|
|
|
#if defined(STORAGE_CONVERSIONS)
|
|
if (version < EEPROM_VER) {
|
|
convertBinRadioData(path, version);
|
|
}
|
|
#endif
|
|
|
|
postRadioSettingsLoad();
|
|
|
|
return nullptr;
|
|
}
|
|
|
|
const char * loadRadioSettingsBin()
|
|
{
|
|
return loadRadioSettingsBin(RADIO_SETTINGS_PATH);
|
|
}
|
|
|
|
const char * writeGeneralSettingsBin()
|
|
{
|
|
return writeFileBin(RADIO_SETTINGS_PATH, (uint8_t *)&g_eeGeneral, sizeof(g_eeGeneral));
|
|
}
|
|
|