@@ -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) {
|
||||
|
||||
@@ -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);
|
||||
|
||||
+47
-5
@@ -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,15 +602,56 @@ 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;
|
||||
}
|
||||
|
||||
static int luaModelGetTimer(lua_State *L)
|
||||
{
|
||||
unsigned int idx = luaL_checkunsigned(L, 1);
|
||||
@@ -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 },
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
+16
-7
@@ -374,12 +374,20 @@ void applyDefaultTemplate()
|
||||
#endif
|
||||
|
||||
#if defined(CPUARM)
|
||||
void checkModelIdUnique(uint8_t id)
|
||||
void checkModelIdUnique(uint8_t index, uint8_t module)
|
||||
{
|
||||
for (uint8_t i=0; i<MAX_MODELS; i++) {
|
||||
if (i!=id && g_model.header.modelId!=0 && g_model.header.modelId==modelHeaders[i].modelId) {
|
||||
POPUP_WARNING(STR_MODELIDUSED);
|
||||
break;
|
||||
uint8_t modelId = g_model.header.modelId[module];
|
||||
if (modelId != 0) {
|
||||
for (uint8_t i=0; i<MAX_MODELS; i++) {
|
||||
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);
|
||||
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)
|
||||
|
||||
+1
-1
@@ -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)
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user