Bsongis/wizard issue when model id already used (#7259)
Wizard: popup displayed when modelID already used, but screen not refreshed
This commit is contained in:
@@ -14,8 +14,6 @@
|
|||||||
---- # GNU General Public License for more details. #
|
---- # GNU General Public License for more details. #
|
||||||
---- # #
|
---- # #
|
||||||
---- #########################################################################
|
---- #########################################################################
|
||||||
-- Navigation variables
|
|
||||||
local dirty = true
|
|
||||||
|
|
||||||
-- Model types
|
-- Model types
|
||||||
local modelType = 0
|
local modelType = 0
|
||||||
@@ -27,10 +25,8 @@ local MODELTYPE_QUAD = 2
|
|||||||
local function fieldIncDec(event, value, max)
|
local function fieldIncDec(event, value, max)
|
||||||
if event == EVT_ROT_LEFT or event == EVT_UP_BREAK then
|
if event == EVT_ROT_LEFT or event == EVT_UP_BREAK then
|
||||||
value = (value + max)
|
value = (value + max)
|
||||||
dirty = true
|
|
||||||
elseif event == EVT_ROT_RIGHT or event == EVT_DOWN_BREAK then
|
elseif event == EVT_ROT_RIGHT or event == EVT_DOWN_BREAK then
|
||||||
value = (value + max + 2)
|
value = (value + max + 2)
|
||||||
dirty = true
|
|
||||||
end
|
end
|
||||||
value = (value % (max+1))
|
value = (value % (max+1))
|
||||||
return value
|
return value
|
||||||
@@ -38,7 +34,7 @@ end
|
|||||||
|
|
||||||
-- Model Type Menu
|
-- Model Type Menu
|
||||||
local function modelTypeSurround(index)
|
local function modelTypeSurround(index)
|
||||||
if(index<=1) then
|
if index <= 1 then
|
||||||
lcd.drawFilledRectangle(59*(index%2)+12, 13, 43, 23)
|
lcd.drawFilledRectangle(59*(index%2)+12, 13, 43, 23)
|
||||||
else
|
else
|
||||||
lcd.drawFilledRectangle(59*(index%2)+12, 34, 40, 20)
|
lcd.drawFilledRectangle(59*(index%2)+12, 34, 40, 20)
|
||||||
@@ -56,10 +52,7 @@ local function drawModelChoiceMenu()
|
|||||||
end
|
end
|
||||||
|
|
||||||
local function modelTypeMenu(event)
|
local function modelTypeMenu(event)
|
||||||
if dirty == true then
|
drawModelChoiceMenu()
|
||||||
drawModelChoiceMenu()
|
|
||||||
dirty = false
|
|
||||||
end
|
|
||||||
if event == EVT_ENTER_BREAK then
|
if event == EVT_ENTER_BREAK then
|
||||||
if modelType == MODELTYPE_PLANE then
|
if modelType == MODELTYPE_PLANE then
|
||||||
return "plane.lua"
|
return "plane.lua"
|
||||||
@@ -68,7 +61,6 @@ local function modelTypeMenu(event)
|
|||||||
elseif modelType == MODELTYPE_QUAD then
|
elseif modelType == MODELTYPE_QUAD then
|
||||||
return "multi.lua"
|
return "multi.lua"
|
||||||
end
|
end
|
||||||
dirty = true
|
|
||||||
else
|
else
|
||||||
modelType = fieldIncDec(event, modelType, 2)
|
modelType = fieldIncDec(event, modelType, 2)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1410,15 +1410,15 @@ void menuModelSetup(event_t event)
|
|||||||
|
|
||||||
if (old_editMode > 0 && s_editMode == 0) {
|
if (old_editMode > 0 && s_editMode == 0) {
|
||||||
switch(menuVerticalPosition) {
|
switch(menuVerticalPosition) {
|
||||||
case ITEM_MODEL_SETUP_INTERNAL_MODULE_NOT_ACCESS_BIND:
|
case ITEM_MODEL_SETUP_INTERNAL_MODULE_NOT_ACCESS_BIND:
|
||||||
if (menuHorizontalPosition == 0)
|
if (menuHorizontalPosition == 0)
|
||||||
checkModelIdUnique(g_eeGeneral.currModel, INTERNAL_MODULE);
|
checkModelIdUnique(g_eeGeneral.currModel, INTERNAL_MODULE);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ITEM_MODEL_SETUP_EXTERNAL_MODULE_NOT_ACCESS_BIND:
|
case ITEM_MODEL_SETUP_EXTERNAL_MODULE_NOT_ACCESS_BIND:
|
||||||
if (menuHorizontalPosition == 0)
|
if (menuHorizontalPosition == 0)
|
||||||
checkModelIdUnique(g_eeGeneral.currModel, EXTERNAL_MODULE);
|
checkModelIdUnique(g_eeGeneral.currModel, EXTERNAL_MODULE);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -397,7 +397,7 @@ void checkModelIdUnique(uint8_t moduleIdx)
|
|||||||
|
|
||||||
// cannot rely exactly on WARNING_LINE_LEN so using WARNING_LINE_LEN-2
|
// cannot rely exactly on WARNING_LINE_LEN so using WARNING_LINE_LEN-2
|
||||||
size_t warn_buf_len = sizeof(reusableBuffer.moduleSetup.msg) - WARNING_LINE_LEN - 2;
|
size_t warn_buf_len = sizeof(reusableBuffer.moduleSetup.msg) - WARNING_LINE_LEN - 2;
|
||||||
if (!modelslist.isModelIdUnique(moduleIdx,warn_buf,warn_buf_len)) {
|
if (!modelslist.isModelIdUnique(moduleIdx, warn_buf, warn_buf_len)) {
|
||||||
if (warn_buf[0] != 0) {
|
if (warn_buf[0] != 0) {
|
||||||
POPUP_WARNING(STR_MODELIDUSED);
|
POPUP_WARNING(STR_MODELIDUSED);
|
||||||
SET_WARNING_INFO(warn_buf, sizeof(reusableBuffer.moduleSetup.msg), 0);
|
SET_WARNING_INFO(warn_buf, sizeof(reusableBuffer.moduleSetup.msg), 0);
|
||||||
@@ -1754,7 +1754,7 @@ bool menuModelSetup(event_t event)
|
|||||||
|
|
||||||
// some field just finished being edited
|
// some field just finished being edited
|
||||||
if (old_editMode > 0 && s_editMode == 0) {
|
if (old_editMode > 0 && s_editMode == 0) {
|
||||||
ModelCell* mod_cell = modelslist.getCurrentModel();
|
ModelCell * mod_cell = modelslist.getCurrentModel();
|
||||||
if (mod_cell) {
|
if (mod_cell) {
|
||||||
switch(menuVerticalPosition) {
|
switch(menuVerticalPosition) {
|
||||||
case ITEM_MODEL_SETUP_NAME:
|
case ITEM_MODEL_SETUP_NAME:
|
||||||
|
|||||||
+2
-2
@@ -469,9 +469,9 @@ void guiMain(event_t evt)
|
|||||||
|
|
||||||
lcdRefresh();
|
lcdRefresh();
|
||||||
|
|
||||||
if (mainRequestFlags & (1 << REQUEST_SCREENSHOT)) {
|
if (mainRequestFlags & (1u << REQUEST_SCREENSHOT)) {
|
||||||
writeScreenshot();
|
writeScreenshot();
|
||||||
mainRequestFlags &= ~(1 << REQUEST_SCREENSHOT);
|
mainRequestFlags &= ~(1u << REQUEST_SCREENSHOT);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
+18
-30
@@ -437,36 +437,27 @@ void checkModelIdUnique(uint8_t index, uint8_t module)
|
|||||||
|
|
||||||
uint8_t findNextUnusedModelId(uint8_t index, uint8_t module)
|
uint8_t findNextUnusedModelId(uint8_t index, uint8_t module)
|
||||||
{
|
{
|
||||||
// assume 63 is the highest Model ID
|
uint8_t usedModelIds[(MAX_RXNUM + 7) / 8];
|
||||||
// and use 64 bits
|
|
||||||
uint8_t usedModelIds[8];
|
|
||||||
memset(usedModelIds, 0, sizeof(usedModelIds));
|
memset(usedModelIds, 0, sizeof(usedModelIds));
|
||||||
|
|
||||||
for (uint8_t mod_i = 0; mod_i < MAX_MODELS; mod_i++) {
|
for (uint8_t modelIndex = 0; modelIndex < MAX_MODELS; modelIndex++) {
|
||||||
|
if (modelIndex == index)
|
||||||
if (mod_i == index)
|
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
uint8_t id = modelHeaders[mod_i].modelId[module];
|
uint8_t id = modelHeaders[modelIndex].modelId[module];
|
||||||
if (id == 0)
|
if (id == 0)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
uint8_t mask = 1;
|
uint8_t mask = 1u << (id & 7u);
|
||||||
for (uint8_t i = 1; i < (id & 7); i++)
|
usedModelIds[id >> 3u] |= mask;
|
||||||
mask <<= 1;
|
|
||||||
|
|
||||||
usedModelIds[id >> 3] |= mask;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t new_id = 1;
|
for (uint8_t id = 1; id <= getMaxRxNum(module); id++) {
|
||||||
uint8_t tst_mask = 1;
|
uint8_t mask = 1u << (id & 7u);
|
||||||
for (;new_id < getMaxRxNum(module); new_id++) {
|
if (!(usedModelIds[id >> 3u] & mask)) {
|
||||||
if (!(usedModelIds[new_id >> 3] & tst_mask)) {
|
|
||||||
// found free ID
|
// found free ID
|
||||||
return new_id;
|
return id;
|
||||||
}
|
}
|
||||||
if ((tst_mask <<= 1) == 0)
|
|
||||||
tst_mask = 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// failed finding something...
|
// failed finding something...
|
||||||
@@ -482,7 +473,7 @@ void modelDefault(uint8_t id)
|
|||||||
|
|
||||||
memcpy(g_model.modelRegistrationID, g_eeGeneral.ownerRegistrationID, PXX2_LEN_REGISTRATION_ID);
|
memcpy(g_model.modelRegistrationID, g_eeGeneral.ownerRegistrationID, PXX2_LEN_REGISTRATION_ID);
|
||||||
|
|
||||||
#if defined(LUA) && defined(PCBTARANIS) //Horus uses menuModelWizard() for wizard
|
#if defined(LUA) && defined(PCBTARANIS) // Horus uses menuModelWizard() for wizard
|
||||||
if (isFileAvailable(WIZARD_PATH "/" WIZARD_NAME)) {
|
if (isFileAvailable(WIZARD_PATH "/" WIZARD_NAME)) {
|
||||||
f_chdir(WIZARD_PATH);
|
f_chdir(WIZARD_PATH);
|
||||||
luaExec(WIZARD_NAME);
|
luaExec(WIZARD_NAME);
|
||||||
@@ -492,23 +483,20 @@ void modelDefault(uint8_t id)
|
|||||||
#if defined(FRSKY_RELEASE)
|
#if defined(FRSKY_RELEASE)
|
||||||
g_model.moduleData[INTERNAL_MODULE].type = IS_PXX2_INTERNAL_ENABLED() ? MODULE_TYPE_ISRM_PXX2 : MODULE_TYPE_XJT_PXX1;
|
g_model.moduleData[INTERNAL_MODULE].type = IS_PXX2_INTERNAL_ENABLED() ? MODULE_TYPE_ISRM_PXX2 : MODULE_TYPE_XJT_PXX1;
|
||||||
g_model.moduleData[INTERNAL_MODULE].channelsCount = defaultModuleChannels_M8(INTERNAL_MODULE);
|
g_model.moduleData[INTERNAL_MODULE].channelsCount = defaultModuleChannels_M8(INTERNAL_MODULE);
|
||||||
|
#if defined(EEPROM)
|
||||||
|
g_model.header.modelId[INTERNAL_MODULE] = findNextUnusedModelId(id, INTERNAL_MODULE);
|
||||||
|
modelHeaders[id].modelId[INTERNAL_MODULE] = g_model.header.modelId[INTERNAL_MODULE]
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(PCBXLITE)
|
#if defined(PCBXLITE)
|
||||||
g_model.trainerData.mode = TRAINER_MODE_MASTER_BLUETOOTH;
|
g_model.trainerData.mode = TRAINER_MODE_MASTER_BLUETOOTH;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(EEPROM)
|
|
||||||
for (int i=0; i<NUM_MODULES; i++) {
|
|
||||||
modelHeaders[id].modelId[i] = g_model.header.modelId[i] = id+1;
|
|
||||||
}
|
|
||||||
checkModelIdUnique(id, 0);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(FLIGHT_MODES) && defined(GVARS)
|
#if defined(FLIGHT_MODES) && defined(GVARS)
|
||||||
for (int p=1; p<MAX_FLIGHT_MODES; p++) {
|
for (int fmIdx = 1; fmIdx < MAX_FLIGHT_MODES; fmIdx++) {
|
||||||
for (int i=0; i<MAX_GVARS; i++) {
|
for (int gvarIdx = 0; gvarIdx < MAX_GVARS; gvarIdx++) {
|
||||||
g_model.flightModeData[p].gvars[i] = GVAR_MAX+1;
|
g_model.flightModeData[fmIdx].gvars[gvarIdx] = GVAR_MAX + 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -416,14 +416,15 @@ inline bool isModuleBindRangeAvailable(uint8_t moduleIdx)
|
|||||||
return isModulePXX2(moduleIdx) || isModulePXX1(moduleIdx) || isModuleDSM2(moduleIdx) || isModuleMultimodule(moduleIdx);
|
return isModulePXX2(moduleIdx) || isModulePXX1(moduleIdx) || isModuleDSM2(moduleIdx) || isModuleMultimodule(moduleIdx);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
constexpr uint8_t MAX_RXNUM = 63;
|
||||||
|
|
||||||
inline uint8_t getMaxRxNum(uint8_t idx)
|
inline uint8_t getMaxRxNum(uint8_t idx)
|
||||||
{
|
{
|
||||||
if (isModuleDSM2(idx))
|
if (isModuleDSM2(idx))
|
||||||
return 20;
|
return 20;
|
||||||
|
|
||||||
#if defined(MULTIMODULE)
|
#if defined(MULTIMODULE)
|
||||||
if (isModuleMultimodule(idx))
|
if (isModuleMultimodule(idx)) {
|
||||||
{
|
|
||||||
switch (g_model.moduleData[idx].getMultiProtocol()) {
|
switch (g_model.moduleData[idx].getMultiProtocol()) {
|
||||||
case MODULE_SUBTYPE_MULTI_OLRS:
|
case MODULE_SUBTYPE_MULTI_OLRS:
|
||||||
return 4;
|
return 4;
|
||||||
@@ -434,7 +435,7 @@ inline uint8_t getMaxRxNum(uint8_t idx)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return 63;
|
return MAX_RXNUM;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline const char * getModuleDelay(uint8_t idx)
|
inline const char * getModuleDelay(uint8_t idx)
|
||||||
|
|||||||
@@ -442,15 +442,15 @@ void ModelsList::moveModel(ModelCell * model, ModelsCategory * previous_category
|
|||||||
|
|
||||||
bool ModelsList::isModelIdUnique(uint8_t moduleIdx, char* warn_buf, size_t warn_buf_len)
|
bool ModelsList::isModelIdUnique(uint8_t moduleIdx, char* warn_buf, size_t warn_buf_len)
|
||||||
{
|
{
|
||||||
ModelCell* mod_cell = modelslist.getCurrentModel();
|
ModelCell* modelCell = modelslist.getCurrentModel();
|
||||||
if (!mod_cell || !mod_cell->valid_rfData) {
|
if (!modelCell || !modelCell->valid_rfData) {
|
||||||
// in doubt, pretend it's unique
|
// in doubt, pretend it's unique
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t modelId = mod_cell->modelId[moduleIdx];
|
uint8_t modelId = modelCell->modelId[moduleIdx];
|
||||||
uint8_t type = mod_cell->moduleData[moduleIdx].type;
|
uint8_t type = modelCell->moduleData[moduleIdx].type;
|
||||||
uint8_t rfProtocol = mod_cell->moduleData[moduleIdx].rfProtocol;
|
uint8_t rfProtocol = modelCell->moduleData[moduleIdx].rfProtocol;
|
||||||
|
|
||||||
uint8_t additionalOnes = 0;
|
uint8_t additionalOnes = 0;
|
||||||
char* curr = warn_buf;
|
char* curr = warn_buf;
|
||||||
@@ -458,10 +458,10 @@ bool ModelsList::isModelIdUnique(uint8_t moduleIdx, char* warn_buf, size_t warn_
|
|||||||
|
|
||||||
bool hit_found = false;
|
bool hit_found = false;
|
||||||
const std::list<ModelsCategory*>& cats = modelslist.getCategories();
|
const std::list<ModelsCategory*>& cats = modelslist.getCategories();
|
||||||
std::list<ModelsCategory*>::const_iterator cat_it = cats.begin();
|
std::list<ModelsCategory*>::const_iterator catIt = cats.begin();
|
||||||
for (;cat_it != cats.end(); cat_it++) {
|
for (;catIt != cats.end(); catIt++) {
|
||||||
for (ModelsCategory::const_iterator it = (*cat_it)->begin(); it != (*cat_it)->end(); it++) {
|
for (ModelsCategory::const_iterator it = (*catIt)->begin(); it != (*catIt)->end(); it++) {
|
||||||
if (mod_cell == *it)
|
if (modelCell == *it)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (!(*it)->valid_rfData)
|
if (!(*it)->valid_rfData)
|
||||||
@@ -507,24 +507,21 @@ bool ModelsList::isModelIdUnique(uint8_t moduleIdx, char* warn_buf, size_t warn_
|
|||||||
|
|
||||||
uint8_t ModelsList::findNextUnusedModelId(uint8_t moduleIdx)
|
uint8_t ModelsList::findNextUnusedModelId(uint8_t moduleIdx)
|
||||||
{
|
{
|
||||||
ModelCell* mod_cell = modelslist.getCurrentModel();
|
ModelCell * modelCell = modelslist.getCurrentModel();
|
||||||
if (!mod_cell || !mod_cell->valid_rfData) {
|
if (!modelCell || !modelCell->valid_rfData) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t type = mod_cell->moduleData[moduleIdx].type;
|
uint8_t type = modelCell->moduleData[moduleIdx].type;
|
||||||
uint8_t rfProtocol = mod_cell->moduleData[moduleIdx].rfProtocol;
|
uint8_t rfProtocol = modelCell->moduleData[moduleIdx].rfProtocol;
|
||||||
|
|
||||||
// assume 63 is the highest Model ID
|
uint8_t usedModelIds[(MAX_RXNUM + 7) / 8];
|
||||||
// and use 64 bits
|
|
||||||
uint8_t usedModelIds[8];
|
|
||||||
memset(usedModelIds, 0, sizeof(usedModelIds));
|
memset(usedModelIds, 0, sizeof(usedModelIds));
|
||||||
|
|
||||||
const std::list<ModelsCategory*>& cats = modelslist.getCategories();
|
const std::list<ModelsCategory *> & cats = modelslist.getCategories();
|
||||||
std::list<ModelsCategory*>::const_iterator cat_it = cats.begin();
|
for (auto catIt = cats.begin(); catIt != cats.end(); catIt++) {
|
||||||
for (;cat_it != cats.end(); cat_it++) {
|
for (auto it = (*catIt)->begin(); it != (*catIt)->end(); it++) {
|
||||||
for (ModelsCategory::const_iterator it = (*cat_it)->begin(); it != (*cat_it)->end(); it++) {
|
if (modelCell == *it)
|
||||||
if (mod_cell == *it)
|
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (!(*it)->valid_rfData)
|
if (!(*it)->valid_rfData)
|
||||||
@@ -536,25 +533,18 @@ uint8_t ModelsList::findNextUnusedModelId(uint8_t moduleIdx)
|
|||||||
(rfProtocol == (*it)->moduleData[moduleIdx].rfProtocol)) {
|
(rfProtocol == (*it)->moduleData[moduleIdx].rfProtocol)) {
|
||||||
|
|
||||||
uint8_t id = (*it)->modelId[moduleIdx];
|
uint8_t id = (*it)->modelId[moduleIdx];
|
||||||
|
uint8_t mask = 1 << (id & 7u);
|
||||||
uint8_t mask = 1;
|
usedModelIds[id >> 3u] |= mask;
|
||||||
for (uint8_t i = 1; i < (id & 7); i++)
|
|
||||||
mask <<= 1;
|
|
||||||
|
|
||||||
usedModelIds[id >> 3] |= mask;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t new_id = 1;
|
for (uint8_t id = 1; id <= getMaxRxNum(moduleIdx); id++) {
|
||||||
uint8_t tst_mask = 1;
|
uint8_t mask = 1u << (id & 7u);
|
||||||
for (;new_id < getMaxRxNum(moduleIdx); new_id++) {
|
if (!(usedModelIds[id >> 3u] & mask)) {
|
||||||
if (!(usedModelIds[new_id >> 3] & tst_mask)) {
|
|
||||||
// found free ID
|
// found free ID
|
||||||
return new_id;
|
return id;
|
||||||
}
|
}
|
||||||
if ((tst_mask <<= 1) == 0)
|
|
||||||
tst_mask = 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// failed finding something...
|
// failed finding something...
|
||||||
|
|||||||
Reference in New Issue
Block a user