X10 extra switches sticks (#6423)

[X10] 2 extra sticks switches + 2 extra pots
This commit is contained in:
Bertrand Songis
2019-05-17 20:42:41 +02:00
committed by GitHub
parent 11cb2ea29b
commit 794fe32006
27 changed files with 390 additions and 166 deletions
+1 -1
View File
@@ -11,7 +11,7 @@ if(PCB STREQUAL X7 OR PCB STREQUAL XLITE OR PCB STREQUAL X9E)
endif()
if(PCB STREQUAL X12S OR PCB STREQUAL X10)
# TODO set(EEPROM_CONVERSIONS 218)
set(EEPROM_CONVERSIONS 218)
endif()
if(EEPROM_CONVERSIONS)
+10 -6
View File
@@ -21,10 +21,8 @@
#include "opentx.h"
#include "conversions.h"
void convertModelData(int id, int version)
void convertModelData(int version)
{
eeLoadModelData(id);
#if EEPROM_CONVERSIONS < 217
if (version == 216) {
version = 217;
@@ -45,7 +43,13 @@ void convertModelData(int id, int version)
convertModelData_218_to_219(g_model);
}
#endif
}
#if defined(EEPROM)
void eeConvertModel(int id, int version)
{
eeLoadModelData(id);
convertModelData(version);
uint8_t currModel = g_eeGeneral.currModel;
g_eeGeneral.currModel = id;
storageDirty(EE_MODEL);
@@ -106,8 +110,7 @@ bool eeConvert()
#if EEPROM_CONVERSIONS < 219
if (version == 218) {
version = 219;
g_eeGeneral.version = 219;
// no conversion needed for now
convertRadioData_218_to_219(g_eeGeneral);
}
#endif
@@ -131,9 +134,10 @@ bool eeConvert()
#endif
lcdRefresh();
if (eeModelExists(id)) {
convertModelData(id, conversionVersionStart);
eeConvertModel(id, conversionVersionStart);
}
}
return true;
}
#endif
+3 -1
View File
@@ -18,8 +18,10 @@
* GNU General Public License for more details.
*/
void convertModelData(int version);
bool eeConvert();
void convertModelData(int id, int version);
void eeConvertModel(int id, int version);
// Conversions 216 to 217
void convertModelData_216_to_217(ModelData &model);
@@ -614,7 +614,7 @@ PACK(typedef struct {
}) GVarData_v217;
PACK(typedef struct {
ModelHeader header;
ModelHeader_v218 header;
TimerData_v217 timers[MAX_TIMERS_218];
uint8_t telemetryProtocol:3;
uint8_t thrTrim:1; // Enable Throttle Trim
@@ -41,6 +41,11 @@ int convertSource_218_to_219(int source)
source += 2;
#endif
#if defined(PCBHORUS)
if (source >= MIXSRC_GMBL)
source += 2;
#endif
return source;
}
@@ -48,12 +53,21 @@ int convertSwitch_218_to_219(int swtch)
{
// on X7: 2 additional switches
#if defined(PCBX7)
#if defined(PCBX7) || defined(PCBHORUS)
if (swtch < 0)
return -convertSwitch_218_to_219(-swtch);
#endif
#if defined(PCBX7)
if (swtch >= SWSRC_SI0)
return swtch + 2 * 3;
swtch += 2 * 3;
#endif
#if defined(PCBHORUS)
if (swtch >= SWSRC_GMBL0)
swtch += 2 * 3;
if (swtch >= SWSRC_FIRST_MULTIPOS_SWITCH + 3 * XPOTS_MULTIPOS_COUNT)
swtch += 2 * XPOTS_MULTIPOS_COUNT;
#endif
return swtch;
@@ -63,8 +77,14 @@ void convertModelData_218_to_219(ModelData &model)
{
static_assert(sizeof(ModelData_v218) <= sizeof(ModelData), "ModelData size has been reduced");
#if defined(STM32)
ModelData_v218 * oldModelAllocated = (ModelData_v218 *)malloc(sizeof(ModelData_v218));
ModelData_v218 &oldModel = *oldModelAllocated;
#else
ModelData_v218 oldModel;
memcpy(&oldModel, &model, sizeof(oldModel));
#endif
memcpy(&oldModel, &model, sizeof(ModelData_v218));
ModelData_v219 & newModel = (ModelData_v219 &) model;
memclear(newModel.mixData, sizeof(ModelData_v219) - offsetof(ModelData_v219, mixData));
@@ -215,13 +235,14 @@ void convertModelData_218_to_219(ModelData &model)
#endif
#if defined(PCBHORUS)
memcpy(newModel.screenData, oldModel.screenData,
sizeof(newModel.screenData) +
sizeof(newModel.topbarData))
#endif
// memcpy(newModel.screenData, oldModel.screenData,
// sizeof(newModel.screenData) +
// sizeof(newModel.topbarData))
#else
newModel.screensType = oldModel.frsky.screensType;
memmove(&newModel.screens, &oldModel.frsky.screens, sizeof(newModel.screens));
#endif
#if defined(PCBX7)
for (int i=0; i<MAX_TELEMETRY_SCREENS; i++) {
uint8_t screenType = (newModel.screensType >> (2*i)) & 0x03;
@@ -239,4 +260,35 @@ void convertModelData_218_to_219(ModelData &model)
}
}
#endif
#if defined(PCBHORUS)
free(oldModelAllocated);
#endif
}
void convertRadioData_218_to_219(RadioData & settings)
{
settings.version = 219;
#if defined(PCBHORUS)
RadioData_v218 settings_v218 = (RadioData_v218 &)settings;
memcpy(&settings.chkSum, &settings_v218.chkSum, offsetof(RadioData, serial2Mode) - offsetof(RadioData, chkSum));
memcpy(&settings.calib[NUM_STICKS + 5], &settings_v218.calib[NUM_STICKS + 3], sizeof(CalibData) * (STORAGE_NUM_SLIDERS + STORAGE_NUM_MOUSE_ANALOGS));
memclear(&settings.calib[NUM_STICKS + 3], sizeof(CalibData) * 2);
settings.serial2Mode = settings_v218.serial2Mode;
settings.switchConfig = settings_v218.switchConfig;
settings.potsConfig = settings_v218.potsConfig;
settings.slidersConfig = settings_v218.slidersConfig;
memcpy(&settings.switchNames[0], &settings_v218.switchNames[0], 8 * LEN_SWITCH_NAME);
memclear(&settings.switchNames[8], 2 * LEN_SWITCH_NAME);
memcpy(&settings.anaNames[0], &settings_v218.anaNames[0], (NUM_STICKS + 3) * LEN_ANA_NAME);
memclear(&settings.anaNames[NUM_STICKS + 3], 2 * LEN_SWITCH_NAME);
memcpy(&settings.anaNames[NUM_STICKS + 5], &settings_v218.anaNames[NUM_STICKS + 3], STORAGE_NUM_SLIDERS * LEN_ANA_NAME);
memcpy(&settings.currModelFilename[0], &settings_v218.currModelFilename[0], sizeof(RadioData_v218) - offsetof(RadioData_v218, currModelFilename[0]));
#endif
}
+58 -26
View File
@@ -18,7 +18,6 @@
* GNU General Public License for more details.
*/
#ifndef OPENTX_DATASTRUCTS_218_H
#define OPENTX_DATASTRUCTS_218_H
@@ -192,7 +191,7 @@ PACK(typedef struct {
#endif
PACK(typedef struct {
trim_t trim[NUM_STICKS];
trim_t trim[NUM_TRIMS];
char name[LEN_FLIGHT_MODE_NAME_218];
int16_t swtch:9; // swtch of phase[0] is not used
int16_t spare:7;
@@ -289,7 +288,7 @@ PACK(typedef struct {
uint8_t active;
}) CustomFunctionData_v218;
PACK(typedef struct {
PACK(struct GVarData_v218 {
char name[LEN_GVAR_NAME_218];
uint32_t min:12;
uint32_t max:12;
@@ -297,7 +296,7 @@ PACK(typedef struct {
uint32_t prec:1;
uint32_t unit:2;
uint32_t spare:4;
}) GVarData_v218;
});
#if defined(COLORLCD)
PACK(struct FrSkyTelemetryData_v217 {
@@ -330,16 +329,12 @@ PACK(struct FrSkyTelemetryData_v217 {
});
#endif
#if defined(PCBX12S)
#define MODELDATA_EXTRA_218 uint8_t spare:3;uint8_t trainerMode:3;uint8_t potsWarnMode:2; ModuleData_v218 moduleData[NUM_MODULES+1];ScriptData scriptsData[MAX_SCRIPTS_218];char inputNames[MAX_INPUTS_218][LEN_INPUT_NAME_218];;uint8_t potsWarnEnabled;;int8_t potsWarnPosition[NUM_POTS+NUM_SLIDERS];;
#elif defined(PCBX10)
#define MODELDATA_EXTRA_218 uint8_t spare:3;;uint8_t trainerMode:3;;uint8_t potsWarnMode:2;; ModuleData_v218 moduleData[NUM_MODULES+1];ScriptData scriptsData[MAX_SCRIPTS_218];;char inputNames[MAX_INPUTS_218][LEN_INPUT_NAME_218];;uint8_t potsWarnEnabled;;int8_t potsWarnPosition[NUM_POTS+NUM_SLIDERS];;uint8_t potsWarnSpares[NUM_DUMMY_ANAS];;
#if defined(PCBHORUS)
#define MODELDATA_EXTRA_218 uint8_t spare:3; uint8_t trainerMode:3; uint8_t potsWarnMode:2; ModuleData_v218 moduleData[NUM_MODULES+1]; ScriptData scriptsData[MAX_SCRIPTS_218]; char inputNames[MAX_INPUTS_218][LEN_INPUT_NAME_218]; uint8_t potsWarnEnabled; int8_t potsWarnPosition[3 + 4];
#elif defined(PCBTARANIS)
#define MODELDATA_EXTRA_218 uint8_t spare:3; uint8_t trainerMode:3; uint8_t potsWarnMode:2; ModuleData_v218 moduleData[NUM_MODULES+1]; ScriptData scriptsData[MAX_SCRIPTS_218]; char inputNames[MAX_INPUTS_218][LEN_INPUT_NAME_218]; uint8_t potsWarnEnabled; int8_t potsWarnPosition[NUM_POTS+NUM_SLIDERS];
#define MODELDATA_EXTRA_218 uint8_t spare:3; uint8_t trainerMode:3; uint8_t potsWarnMode:2; ModuleData_v218 moduleData[NUM_MODULES+1]; ScriptData scriptsData[MAX_SCRIPTS_218]; char inputNames[MAX_INPUTS_218][LEN_INPUT_NAME_218]; uint8_t potsWarnEnabled; int8_t potsWarnPosition[STORAGE_NUM_POTS + STORAGE_NUM_SLIDERS];
#elif defined(PCBSKY9X)
#define MODELDATA_EXTRA_218 uint8_t spare:6; uint8_t potsWarnMode:2; ModuleData_v218 moduleData[NUM_MODULES+1]; char inputNames[MAX_INPUTS_218][LEN_INPUT_NAME_218]; uint8_t potsWarnEnabled; int8_t potsWarnPosition[NUM_POTS+NUM_SLIDERS]; uint8_t rxBattAlarms[2];
#else
#define MODELDATA_EXTRA_218
#define MODELDATA_EXTRA_218 uint8_t spare:6; uint8_t potsWarnMode:2; ModuleData_v218 moduleData[NUM_MODULES+1]; char inputNames[MAX_INPUTS_218][LEN_INPUT_NAME_218]; uint8_t potsWarnEnabled; int8_t potsWarnPosition[STORAGE_NUM_POTS + STORAGE_NUM_SLIDERS]; uint8_t rxBattAlarms[2];
#endif
PACK(struct TelemetrySensor_218 {
@@ -391,14 +386,35 @@ PACK(struct TelemetrySensor_218 {
};
});
#if defined(PCBTARANIS)
#if defined(PCBHORUS)
PACK(struct CustomScreenData_v218 {
char layoutName[10];
Layout::PersistentData layoutData;
});
#define VIEW_DATA \
CustomScreenData screenData[MAX_CUSTOM_SCREENS]; \
Topbar::PersistentData topbarData; \
uint8_t view;
#elif defined(PCBTARANIS)
#define VIEW_DATA uint8_t view;
#else
#define VIEW_DATA
#endif
PACK(typedef struct {
ModelHeader header;
#if LEN_BITMAP_NAME > 0
#define MODEL_HEADER_BITMAP_FIELD_218 char bitmap[10];
#else
#define MODEL_HEADER_BITMAP_FIELD_218
#endif
PACK(struct ModelHeader_v218 {
char name[LEN_MODEL_NAME]; // must be first for eeLoadModelName
uint8_t modelId[NUM_MODULES];
MODEL_HEADER_BITMAP_FIELD_218
});
PACK(struct ModelData_v218 {
ModelHeader_v218 header;
TimerData_v218 timers[MAX_TIMERS_218];
uint8_t telemetryProtocol:3;
uint8_t thrTrim:1; // Enable Throttle Trim
@@ -427,7 +443,10 @@ PACK(typedef struct {
uint8_t thrTraceSrc;
swarnstate_t switchWarningState;
#if !defined(COLORLCD)
swarnenable_t switchWarningEnable;
#endif
GVarData_v218 gvars[MAX_GVARS_218];
@@ -442,19 +461,22 @@ PACK(typedef struct {
// TODO conversion for custom screens?
VIEW_DATA
}) ModelData_v218;
});
#include "chksize.h"
#define CHKSIZE(x, y) check_size<struct x, y>()
static inline void check_struct_218()
{
#if defined(PCBHORUS)
static_assert(sizeof(ModelData_v218) == 9380, "ModelData size changed");
CHKSIZE(ModelData_v218, 9380);
#elif defined(PCBX9E)
static_assert(sizeof(ModelData_v218) == 6520, "ModelData size changed");
#elif defined(PCBX9D)
static_assert(sizeof(ModelData_v218) == 6507, "ModelData size changed");
#elif defined(PCBXLITE) || defined(PCBX7)
static_assert(sizeof(ModelData_v218) == 6025, "ModelData size changed");
#elif defined(PCBSKY9X)
static_assert(sizeof(ModelData_v218) == 5188, "ModelData size changed");
CHKSIZE(ModelData_v218, 6520);
#endif
}
#undef CHKSIZE
#define EXTRA_GENERAL_FIELDS_GENERAL_218 \
uint8_t backlightBright; \
@@ -485,7 +507,7 @@ static_assert(sizeof(ModelData_v218) == 5188, "ModelData size changed");
uint32_t switchConfig; \
uint8_t potsConfig; /* two bits per pot */ \
char switchNames[NUM_SWITCHES_218][LEN_SWITCH_NAME_218]; \
char anaNames[NUM_STICKS+NUM_POTS+NUM_SLIDERS+NUM_DUMMY_ANAS][LEN_ANA_NAME_218]; \
char anaNames[NUM_STICKS+3+4][LEN_ANA_NAME_218]; \
char currModelFilename[LEN_MODEL_FILENAME_218+1]; \
uint8_t spare:1; \
uint8_t blOffBright:7; \
@@ -534,10 +556,20 @@ static_assert(sizeof(ModelData_v218) == 5188, "ModelData size changed");
#define SPLASH_MODE_218 int8_t splashMode:3
#endif
#if defined(COLORLCD)
#include "gui/480x272/theme.h"
#define THEME_NAME_LEN 8
#define THEME_DATA \
char themeName[THEME_NAME_LEN]; \
Theme::PersistentData themeData;
#else
#define THEME_DATA
#endif
PACK(typedef struct {
uint8_t version;
uint16_t variant;
CalibData calib[NUM_STICKS+NUM_POTS+NUM_SLIDERS+NUM_MOUSE_ANALOGS+NUM_DUMMY_ANAS];
CalibData calib[NUM_STICKS+STORAGE_NUM_POTS+STORAGE_NUM_SLIDERS+STORAGE_NUM_MOUSE_ANALOGS];
uint16_t chkSum;
N_HORUS_FIELD(int8_t currModel);
N_HORUS_FIELD(uint8_t contrast);
+1 -1
View File
@@ -585,7 +585,7 @@ const char * eeRestoreModel(uint8_t i_fileDst, char *model_name)
#if defined(EEPROM_CONVERSIONS)
if (version < EEPROM_VER) {
convertModelData(i_fileDst, version);
eeConvertModel(i_fileDst, version);
eeLoadModel(g_eeGeneral.currModel);
}
#endif
+1 -1
View File
@@ -599,7 +599,7 @@ const char * eeRestoreModel(uint8_t i_fileDst, char *model_name)
#if defined(EEPROM_CONVERSIONS)
if (version < EEPROM_VER) {
storageCheck(true);
convertModelData(i_fileDst, version);
eeConvertModel(i_fileDst, version);
eeLoadModel(g_eeGeneral.currModel);
}
#endif
+4 -4
View File
@@ -164,14 +164,14 @@ bool ModelCell::fetchRfData()
getModelPath(buf, modelFilename);
FIL file;
uint16_t file_size;
uint16_t size;
uint8_t version;
const char* err = openFile(buf,&file,&file_size);
if (err) return false;
const char * err = openFile(buf, &file, &size, &version);
if (err || version != EEPROM_VER) return false;
FSIZE_t start_offset = f_tell(&file);
UINT read;
if ((f_read(&file, buf, LEN_MODEL_NAME, &read) != FR_OK) || (read != LEN_MODEL_NAME))
goto error;
+14 -7
View File
@@ -20,6 +20,7 @@
#include "opentx.h"
#include "modelslist.h"
#include "conversions/conversions.h"
void getModelPath(char * path, const char * filename)
{
@@ -69,7 +70,7 @@ const char * writeModel()
return writeFile(path, (uint8_t *)&g_model, sizeof(g_model));
}
const char * openFile(const char * fullpath, FIL* file, uint16_t* size)
const char * openFile(const char * fullpath, FIL * file, uint16_t * size, uint8_t * version)
{
FRESULT result = f_open(file, fullpath, FA_OPEN_EXISTING | FA_READ);
if (result != FR_OK) {
@@ -90,14 +91,14 @@ const char * openFile(const char * fullpath, FIL* file, uint16_t* size)
return SDCARD_ERROR(result);
}
uint8_t version = (uint8_t)buf[4];
if ((*(uint32_t*)&buf[0] != OTX_FOURCC && *(uint32_t*)&buf[0] != O9X_FOURCC) || version < FIRST_CONV_EEPROM_VER || version > EEPROM_VER || buf[5] != 'M') {
*version = (uint8_t)buf[4];
if ((*(uint32_t*)&buf[0] != OTX_FOURCC && *(uint32_t*)&buf[0] != O9X_FOURCC) || *version < FIRST_CONV_EEPROM_VER || *version > EEPROM_VER || buf[5] != 'M') {
f_close(file);
return STR_INCOMPATIBLE;
}
*size = *(uint16_t*)&buf[6];
return NULL;
return nullptr;
}
const char * loadFile(const char * fullpath, uint8_t * data, uint16_t maxsize)
@@ -105,11 +106,13 @@ const char * loadFile(const char * fullpath, uint8_t * data, uint16_t maxsize)
FIL file;
UINT read;
uint16_t size;
uint8_t version;
TRACE("loadFile(%s)", fullpath);
const char* err = openFile(fullpath, &file, &size);
if (err) return err;
const char * err = openFile(fullpath, &file, &size, &version);
if (err)
return err;
size = min<uint16_t>(maxsize, size);
FRESULT result = f_read(&file, data, size, &read);
@@ -118,8 +121,12 @@ const char * loadFile(const char * fullpath, uint8_t * data, uint16_t maxsize)
return SDCARD_ERROR(result);
}
if (version < EEPROM_VER) {
convertModelData(version);
}
f_close(&file);
return NULL;
return nullptr;
}
const char * readModel(const char * filename, uint8_t * buffer, uint32_t size)
+1 -1
View File
@@ -27,7 +27,7 @@
#define DEFAULT_MODEL_FILENAME "model1.bin"
// opens radio.bin or model file
const char * openFile(const char * fullpath, FIL* file, uint16_t* size);
const char * openFile(const char * fullpath, FIL * file, uint16_t * size, uint8_t * version);
void getModelPath(char * path, const char * filename);