1
0
Fork 0
mirror of https://github.com/opentx/opentx.git synced 2025-07-19 06:15:10 +03:00
Also provides a lua function to retrieve module settings
This commit is contained in:
bsongis 2015-05-05 20:02:02 +02:00
parent f4c3610a8c
commit eb6ba88f5a
18 changed files with 109 additions and 57 deletions

View file

@ -1366,7 +1366,7 @@ void ModelData::setDefaultValues(unsigned int id, const GeneralSettings & settin
clear();
used = true;
sprintf(name, "MODEL%02d", id+1);
modelId = id+1;
moduleData[0].modelId = id+1;
setDefaultMixes(settings);
}

View file

@ -814,6 +814,7 @@ enum Protocol {
class ModuleData {
public:
ModuleData() { clear(); }
unsigned int modelId;
int protocol;
unsigned int channelsStart;
int channelsCount; // 0=8 channels
@ -973,7 +974,6 @@ class ModelData {
CustomFunctionData customFn[C9X_MAX_CUSTOM_FUNCTIONS];
SwashRingData swashRingData;
unsigned int thrTraceSrc;
unsigned int modelId;
uint64_t switchWarningStates;
unsigned int switchWarningEnable;
unsigned int potsWarningMode;

View file

@ -501,7 +501,7 @@ t_Open9xGruvin9xModelData_v207::operator ModelData ()
c9x.frsky = frsky;
c9x.moduleData[0].ppmFrameLength = ppmFrameLength;
c9x.thrTraceSrc = thrTraceSrc;
c9x.modelId = modelId;
c9x.moduleData[0].modelId = modelId;
for (int line=0; line<4; line++) {
for (int col=0; col<2; col++) {
c9x.frsky.screens[1].body.lines[line].source[col] = (col==0 ? (frskyLines[line] & 0x0f) : ((frskyLines[line] & 0xf0) / 16));
@ -587,7 +587,7 @@ t_Open9xGruvin9xModelData_v208::operator ModelData ()
c9x.frsky.varioCenterMin = varioSpeedDownMin;
c9x.moduleData[0].ppmFrameLength = ppmFrameLength;
c9x.thrTraceSrc = thrTraceSrc;
c9x.modelId = modelId;
c9x.moduleData[0].modelId = modelId;
for (int line=0; line<4; line++) {
for (int col=0; col<2; col++) {
c9x.frsky.screens[1].body.lines[line].source[col] = (col==0 ? (frskyLines[line] & 0x0f) : ((frskyLines[line] & 0xf0) / 16));
@ -677,7 +677,7 @@ t_Open9xGruvin9xModelData_v209::operator ModelData ()
c9x.switchWarningStates = switchWarningStates;
c9x.moduleData[0].ppmFrameLength = ppmFrameLength;
c9x.thrTraceSrc = thrTraceSrc;
c9x.modelId = modelId;
c9x.moduleData[0].modelId = modelId;
for (int line=0; line<4; line++) {
for (int col=0; col<2; col++) {
c9x.frsky.screens[1].body.lines[line].source[col] = (col==0 ? (frskyLines[line] & 0x0f) : ((frskyLines[line] & 0xf0) / 16));
@ -767,7 +767,7 @@ t_Open9xGruvin9xModelData_v210::operator ModelData ()
c9x.switchWarningStates = switchWarningStates;
c9x.moduleData[0].ppmFrameLength = ppmFrameLength;
c9x.thrTraceSrc = thrTraceSrc;
c9x.modelId = modelId;
c9x.moduleData[0].modelId = modelId;
for (int i=0; i<16; i++) {
c9x.limitData[i].ppmCenter = servoCenter[i];
}
@ -854,6 +854,6 @@ t_Open9xGruvin9xModelData_v211::operator ModelData ()
c9x.switchWarningStates = switchWarningStates;
c9x.moduleData[0].ppmFrameLength = ppmFrameLength;
c9x.thrTraceSrc = thrTraceSrc;
c9x.modelId = modelId;
c9x.moduleData[0].modelId = modelId;
return c9x;
}

View file

@ -808,7 +808,7 @@ t_Open9xArmModelData_v208::operator ModelData ()
c9x.frsky.varioCenterMin = varioSpeedDownMin;
c9x.moduleData[0].ppmFrameLength = ppmFrameLength;
c9x.thrTraceSrc = thrTraceSrc;
c9x.modelId = modelId;
c9x.moduleData[0].modelId = modelId;
for (int line=0; line<4; line++) {
for (int col=0; col<2; col++) {
c9x.frsky.screens[1].body.lines[line].source[col] = (col==0 ? (frskyLines[line] & 0x0f) : ((frskyLines[line] & 0xf0) / 16));
@ -898,7 +898,7 @@ t_Open9xArmModelData_v209::operator ModelData ()
c9x.switchWarningStates = switchWarningStates;
c9x.moduleData[0].ppmFrameLength = ppmFrameLength;
c9x.thrTraceSrc = thrTraceSrc;
c9x.modelId = modelId;
c9x.moduleData[0].modelId = modelId;
for (int line=0; line<4; line++) {
for (int col=0; col<2; col++) {
c9x.frsky.screens[1].body.lines[line].source[col] = (col==0 ? (frskyLines[line] & 0x0f) : ((frskyLines[line] & 0xf0) / 16));
@ -988,7 +988,7 @@ t_Open9xArmModelData_v210::operator ModelData ()
c9x.switchWarningStates = switchWarningStates;
c9x.moduleData[0].ppmFrameLength = ppmFrameLength;
c9x.thrTraceSrc = thrTraceSrc;
c9x.modelId = modelId;
c9x.moduleData[0].modelId = modelId;
for (int i=0; i<16; i++) {
c9x.limitData[i].ppmCenter = servoCenter[i];
}
@ -1072,7 +1072,7 @@ t_Open9xArmModelData_v211::operator ModelData ()
c9x.switchWarningStates = switchWarningStates;
c9x.moduleData[0].ppmFrameLength = ppmFrameLength;
c9x.thrTraceSrc = thrTraceSrc;
c9x.modelId = modelId;
c9x.moduleData[0].modelId = modelId;
for (int i=0; i<16; i++) {
c9x.limitData[i].ppmCenter = servoCenter[i];
}
@ -1159,6 +1159,6 @@ t_Open9xArmModelData_v212::operator ModelData ()
c9x.switchWarningStates = switchWarningStates;
c9x.moduleData[0].ppmFrameLength = ppmFrameLength;
c9x.thrTraceSrc = thrTraceSrc;
c9x.modelId = modelId;
c9x.moduleData[0].modelId = modelId;
return c9x;
}

View file

@ -1060,7 +1060,7 @@ t_Open9xModelData_v202::operator ModelData ()
c9x.frsky = frsky;
c9x.moduleData[0].ppmFrameLength = ppmFrameLength;
c9x.thrTraceSrc = thrTraceSrc;
c9x.modelId=modelId;
c9x.moduleData[0].modelId = modelId;
return c9x;
}
@ -1134,7 +1134,7 @@ t_Open9xModelData_v203::operator ModelData ()
c9x.frsky = frsky;
c9x.moduleData[0].ppmFrameLength = ppmFrameLength;
c9x.thrTraceSrc = thrTraceSrc;
c9x.modelId = modelId;
c9x.moduleData[0].modelId = modelId;
return c9x;
}
@ -1210,7 +1210,7 @@ t_Open9xModelData_v204::operator ModelData ()
c9x.frsky.rssiAlarms[1] = frskyRssiAlarms[1].get(1);
c9x.moduleData[0].ppmFrameLength = ppmFrameLength;
c9x.thrTraceSrc = thrTraceSrc;
c9x.modelId = modelId;
c9x.moduleData[0].modelId = modelId;
return c9x;
}
@ -1287,7 +1287,7 @@ t_Open9xModelData_v205::operator ModelData ()
c9x.frsky = frsky;
c9x.moduleData[0].ppmFrameLength = ppmFrameLength;
c9x.thrTraceSrc = thrTraceSrc;
c9x.modelId = modelId;
c9x.moduleData[0]. modelId = modelId;
c9x.frsky.screens[1].type = 0;
for (int line=0; line<4; line++) {
for (int col=0; col<2; col++) {
@ -1377,7 +1377,7 @@ t_Open9xModelData_v208::operator ModelData ()
c9x.moduleData[0].ppmFrameLength = ppmFrameLength;
c9x.thrTraceSrc = thrTraceSrc;
c9x.modelId = modelId;
c9x.moduleData[0].modelId = modelId;
c9x.frsky.screens[1].type = 0;
for (int line=0; line<4; line++) {
for (int col=0; col<2; col++) {
@ -1471,7 +1471,7 @@ t_Open9xModelData_v209::operator ModelData ()
c9x.moduleData[0].ppmFrameLength = ppmFrameLength;
c9x.thrTraceSrc = thrTraceSrc;
c9x.modelId = modelId;
c9x.moduleData[0].modelId = modelId;
c9x.frsky.screens[1].type = 0;
for (int line=0; line<4; line++) {
for (int col=0; col<2; col++) {
@ -1565,7 +1565,7 @@ t_Open9xModelData_v210::operator ModelData ()
c9x.moduleData[0].ppmFrameLength = ppmFrameLength;
c9x.thrTraceSrc = thrTraceSrc;
c9x.modelId = modelId;
c9x.moduleData[0].modelId = modelId;
for (int i=0; i<16; i++) {
c9x.limitData[i].ppmCenter=servoCenter[i];
@ -1653,7 +1653,7 @@ t_Open9xModelData_v211::operator ModelData ()
c9x.moduleData[0].ppmFrameLength = ppmFrameLength;
c9x.thrTraceSrc = thrTraceSrc;
c9x.modelId = modelId;
c9x.moduleData[0].modelId = modelId;
return c9x;
}

View file

@ -2781,8 +2781,12 @@ OpenTxModelData::OpenTxModelData(ModelData & modelData, BoardEnum board, unsigne
bool afterrelease21March2013 = IS_AFTER_RELEASE_21_MARCH_2013(board, version);
if (afterrelease21March2013)
internalField.Append(new UnsignedField<8>(modelData.modelId));
if (afterrelease21March2013) {
internalField.Append(new UnsignedField<8>(modelData.moduleData[0].modelId));
}
if (IS_ARM(board) && version >= 217) {
internalField.Append(new UnsignedField<8>(modelData.moduleData[1].modelId));
}
if (IS_TARANIS(board) && version >= 215) {
internalField.Append(new CharField<10>(modelData.bitmap));
@ -2902,7 +2906,7 @@ OpenTxModelData::OpenTxModelData(ModelData & modelData, BoardEnum board, unsigne
internalField.Append(new ConversionField< UnsignedField<8> >(modelData.thrTraceSrc, &throttleSourceConversionTable, "Throttle Source"));
if (!afterrelease21March2013) {
internalField.Append(new UnsignedField<8>(modelData.modelId));
internalField.Append(new UnsignedField<8>(modelData.moduleData[0].modelId));
}
if (IS_TARANIS_X9E(board) && version >= 217)

View file

@ -73,7 +73,6 @@ CustomFunctionsPanel::CustomFunctionsPanel(QWidget * parent, ModelData * model,
}
}
}
qDebug() << tracksSet;
}
if (IS_TARANIS(firmware->getBoard())) {
@ -86,7 +85,6 @@ CustomFunctionsPanel::CustomFunctionsPanel(QWidget * parent, ModelData * model,
}
}
}
qDebug() << scriptsSet;
}
CompanionIcon playIcon("play.png");

View file

@ -249,7 +249,7 @@ void ModulePanel::update()
ui->label_rxNumber->setVisible(mask & MASK_RX_NUMBER);
ui->rxNumber->setVisible(mask & MASK_RX_NUMBER);
ui->rxNumber->setMaximum(max_rx_num);
ui->rxNumber->setValue(model->modelId);
ui->rxNumber->setValue(module.modelId);
ui->label_channelsStart->setVisible(mask & MASK_CHANNELS_RANGE);
ui->channelsStart->setVisible(mask & MASK_CHANNELS_RANGE);
ui->channelsStart->setValue(module.channelsStart+1);
@ -348,7 +348,7 @@ void ModulePanel::on_ppmDelay_editingFinished()
void ModulePanel::on_rxNumber_editingFinished()
{
model->modelId = ui->rxNumber->value();
module.modelId = ui->rxNumber->value();
emit modified();
}

View file

@ -86,7 +86,7 @@ WizMix::operator ModelData()
ModelData model;
model.used = true;
model.modelId = modelId;
model.moduleData[0].modelId = modelId;
model.setDefaultInputs(settings);
int mixIndex = 0;

View file

@ -601,16 +601,16 @@ void menuModelSetup(uint8_t event)
lcd_putsLeft(y, STR_RXNUM);
}
if (IS_MODULE_XJT(moduleIdx) || IS_MODULE_DSM2(moduleIdx)) {
if (xOffsetBind) lcd_outdezNAtt(MODEL_SETUP_2ND_COLUMN, y, g_model.header.modelId, (l_posHorz==0 ? attr : 0) | LEADING0|LEFT, 2);
if (xOffsetBind) lcd_outdezNAtt(MODEL_SETUP_2ND_COLUMN, y, g_model.header.modelId[moduleIdx], (l_posHorz==0 ? attr : 0) | LEADING0|LEFT, 2);
if (attr && l_posHorz==0) {
if (editMode>0 || p1valdiff) {
CHECK_INCDEC_MODELVAR_ZERO(event, g_model.header.modelId, IS_MODULE_DSM2(moduleIdx) ? 20 : 63);
CHECK_INCDEC_MODELVAR_ZERO(event, g_model.header.modelId[moduleIdx], IS_MODULE_DSM2(moduleIdx) ? 20 : 63);
if (checkIncDec_Ret) {
modelHeaders[g_eeGeneral.currModel].modelId = g_model.header.modelId;
modelHeaders[g_eeGeneral.currModel].modelId[moduleIdx] = g_model.header.modelId[moduleIdx];
}
}
if (editMode==0 && event==EVT_KEY_BREAK(KEY_ENTER)) {
checkModelIdUnique(g_eeGeneral.currModel);
checkModelIdUnique(g_eeGeneral.currModel, moduleIdx);
}
}
lcd_putsAtt(MODEL_SETUP_2ND_COLUMN+xOffsetBind, y, STR_MODULE_BIND, l_posHorz==1 ? attr : 0);
@ -771,11 +771,10 @@ void menuModelSetup(uint8_t event)
if (attr && m_posHorz > 1) {
REPEAT_LAST_CURSOR_MOVE(); // limit 3 column row to 2 colums (Rx_Num and RANGE fields)
}
lcd_putsLeft(y, STR_RXNUM);
lcd_outdezNAtt(MODEL_SETUP_2ND_COLUMN, y, g_model.header.modelId, (m_posHorz<=0 ? attr : 0) | LEADING0|LEFT, 2);
lcd_outdezNAtt(MODEL_SETUP_2ND_COLUMN, y, g_model.header.modelId[0], (m_posHorz<=0 ? attr : 0) | LEADING0|LEFT, 2);
if (attr && (m_posHorz==0 && (editMode>0 || p1valdiff))) {
CHECK_INCDEC_MODELVAR_ZERO(event, g_model.header.modelId, 99);
CHECK_INCDEC_MODELVAR_ZERO(event, g_model.header.modelId[0], 99);
}
#if defined(PXX)
if (protocol == PROTO_PXX) {

View file

@ -700,16 +700,16 @@ void menuModelSetup(uint8_t event)
lcd_putsLeft(y, STR_RXNUM);
}
if (IS_MODULE_XJT(moduleIdx) || IS_MODULE_DSM2(moduleIdx)) {
if (xOffsetBind) lcd_outdezNAtt(MODEL_SETUP_2ND_COLUMN, y, g_model.header.modelId, (l_posHorz==0 ? attr : 0) | LEADING0|LEFT, 2);
if (xOffsetBind) lcd_outdezNAtt(MODEL_SETUP_2ND_COLUMN, y, g_model.header.modelId[moduleIdx], (l_posHorz==0 ? attr : 0) | LEADING0|LEFT, 2);
if (attr && l_posHorz==0) {
if (s_editMode>0) {
CHECK_INCDEC_MODELVAR_ZERO(event, g_model.header.modelId, IS_MODULE_DSM2(moduleIdx) ? 20 : 63);
CHECK_INCDEC_MODELVAR_ZERO(event, g_model.header.modelId[moduleIdx], IS_MODULE_DSM2(moduleIdx) ? 20 : 63);
if (checkIncDec_Ret) {
modelHeaders[g_eeGeneral.currModel].modelId = g_model.header.modelId;
modelHeaders[g_eeGeneral.currModel].modelId[moduleIdx] = g_model.header.modelId[moduleIdx];
}
}
if (s_editMode==0 && event==EVT_KEY_BREAK(KEY_ENTER)) {
checkModelIdUnique(g_eeGeneral.currModel);
checkModelIdUnique(g_eeGeneral.currModel, moduleIdx);
}
}
lcd_putsAtt(MODEL_SETUP_2ND_COLUMN+xOffsetBind, y, STR_MODULE_BIND, l_posHorz==1 ? attr : 0);

View file

@ -584,7 +584,6 @@ static int luaModelGetInfo(lua_State *L)
lua_newtable(L);
lua_pushtablezstring(L, "name", g_model.header.name);
lua_pushtablenzstring(L, "bitmap", g_model.header.bitmap);
lua_pushtableinteger(L, "id", g_model.header.modelId);
return 1;
}
@ -603,12 +602,53 @@ static int luaModelSetInfo(lua_State *L)
const char * name = luaL_checkstring(L, -1);
strncpy(g_model.header.bitmap, name, sizeof(g_model.header.bitmap));
}
else if (!strcmp(key, "id")) {
g_model.header.modelId = luaL_checkinteger(L, -1);
modelHeaders[g_eeGeneral.currModel].modelId = g_model.header.modelId;
}
eeDirty(EE_MODEL);
return 0;
}
static int luaModelGetModule(lua_State *L)
{
unsigned int idx = luaL_checkunsigned(L, 1);
if (idx < NUM_MODULES) {
ModuleData & module = g_model.moduleData[idx];
lua_newtable(L);
lua_pushtableinteger(L, "rfProtocol", module.rfProtocol);
lua_pushtableinteger(L, "modelId", g_model.header.modelId[idx]);
lua_pushtableinteger(L, "firstChannel", module.channelsStart);
lua_pushtableinteger(L, "channelsCount", module.channelsCount + 8);
}
else {
lua_pushnil(L);
}
return 1;
}
static int luaModelSetModule(lua_State *L)
{
unsigned int idx = luaL_checkunsigned(L, 1);
if (idx < NUM_MODULES) {
ModuleData & module = g_model.moduleData[idx];
luaL_checktype(L, -1, LUA_TTABLE);
for (lua_pushnil(L); lua_next(L, -2); lua_pop(L, 1)) {
luaL_checktype(L, -2, LUA_TSTRING); // key is string
const char * key = luaL_checkstring(L, -2);
if (!strcmp(key, "rfProtocol")) {
module.rfProtocol = luaL_checkinteger(L, -1);
}
else if (!strcmp(key, "modelId")) {
g_model.header.modelId[idx] = luaL_checkinteger(L, -1);
}
else if (!strcmp(key, "firstChannel")) {
module.channelsStart = luaL_checkinteger(L, -1);
}
else if (!strcmp(key, "channelsCount")) {
module.channelsCount = luaL_checkinteger(L, -1) - 8;
}
}
eeDirty(EE_MODEL);
}
return 0;
}
@ -1401,6 +1441,8 @@ const luaR_value_entry opentxConstants[] = {
const luaL_Reg modelLib[] = {
{ "getInfo", luaModelGetInfo },
{ "setInfo", luaModelSetInfo },
{ "getModule", luaModelGetModule },
{ "setModule", luaModelSetModule },
{ "getTimer", luaModelGetTimer },
{ "setTimer", luaModelSetTimer },
{ "resetTimer", luaModelResetTimer },

View file

@ -2067,7 +2067,7 @@ enum FailsafeModes {
PACK(typedef struct {
char name[LEN_MODEL_NAME]; // must be first for eeLoadModelName
uint8_t modelId;
uint8_t modelId[NUM_MODULES];
MODELDATA_BITMAP
}) ModelHeader;

View file

@ -374,12 +374,20 @@ void applyDefaultTemplate()
#endif
#if defined(CPUARM)
void checkModelIdUnique(uint8_t id)
void checkModelIdUnique(uint8_t index, uint8_t module)
{
uint8_t modelId = g_model.header.modelId[module];
if (modelId != 0) {
for (uint8_t i=0; i<MAX_MODELS; i++) {
if (i!=id && g_model.header.modelId!=0 && g_model.header.modelId==modelHeaders[i].modelId) {
for (uint8_t j=0; j<NUM_MODULES; j++) {
if (i == index && module == j) {
continue;
}
else if (modelId == modelHeaders[i].modelId[j]) {
POPUP_WARNING(STR_MODELIDUSED);
break;
return;
}
}
}
}
}
@ -414,8 +422,9 @@ void modelDefault(uint8_t id)
#endif
#if defined(PXX) && defined(CPUARM)
modelHeaders[id].modelId = g_model.header.modelId = id+1;
checkModelIdUnique(id);
modelHeaders[id].modelId[1] = g_model.header.modelId[1] = 0;
modelHeaders[id].modelId[0] = g_model.header.modelId[0] = id+1;
checkModelIdUnique(id, 0);
#endif
#if defined(CPUARM) && defined(FLIGHT_MODES) && defined(GVARS)

View file

@ -1048,7 +1048,7 @@ void modelDefault(uint8_t id);
#if defined(CPUARM)
bool isFileAvailable(const char * filename);
void checkModelIdUnique(uint8_t id);
void checkModelIdUnique(uint8_t index, uint8_t module);
#endif
#if defined(CPUARM)

View file

@ -175,7 +175,7 @@ void setupPulsesDSM2(unsigned int port)
}
#endif
dsmDat[1] = g_model.header.modelId; // DSM2 Header second byte for model match
dsmDat[1] = g_model.header.modelId[port]; // DSM2 Header second byte for model match
for (int i=0; i<DSM2_CHANS; i++) {
uint16_t pulse = limit(0, ((channelOutputs[g_model.moduleData[port].channelsStart+i]*13)>>5)+512, 1023);

View file

@ -338,7 +338,7 @@ void setupPulsesPXX()
PcmBitCount = PcmByte = 0 ;
PcmOnesCount = 0 ;
putPcmHead() ;
putPcmByte( g_model.header.modelId ) ; // putPcmByte( g_model.rxnum ) ; //
putPcmByte(g_model.header.modelId[0]);
uint8_t flag1 = 0;
if (moduleFlag[0] == MODULE_BIND)
flag1 |= (g_eeGeneral.countryCode << 1) | PXX_SEND_BIND;
@ -554,7 +554,7 @@ void setupPulsesDSM2()
moduleFlag[0] = 0;
}
dsmDat[1] = g_model.header.modelId; // DSM2 Header second byte for model match
dsmDat[1] = g_model.header.modelId[0];
for (uint8_t i=0; i<DSM2_CHANS; i++) {
uint16_t pulse = limit(0, ((channelOutputs[i]*13)>>5)+512, 1023);

View file

@ -190,7 +190,7 @@ void setupPulsesPXX(unsigned int port)
putPcmHead(port);
/* Rx Number */
putPcmByte(g_model.header.modelId, port);
putPcmByte(g_model.header.modelId[port], port);
/* FLAG1 */
uint8_t flag1 = (g_model.moduleData[port].rfProtocol << 6);