Horus: add receiver number check (#5841)

* add receiver number check for Horus

* find the first free model ID on LONG ENTER

* use the next free model ID for new models

* improve free model ID support for std LCD as well

* fixed “duplicate model”

* fixed ModelsList::isModelIdUnique()
This commit is contained in:
Raphael Coeffic
2018-05-21 19:03:51 +02:00
committed by Bertrand Songis
parent ea898e5122
commit 7379f6064e
16 changed files with 918 additions and 325 deletions
+34 -3
View File
@@ -258,6 +258,8 @@ void menuModelSetup(event_t event)
static uint8_t selectedPxxPower = g_model.moduleData[EXTERNAL_MODULE].pxx.power; //TODO could go to the reusable struct
#endif
int8_t old_editMode = s_editMode;
#if defined(PCBTARANIS)
MENU_TAB({
HEADER_LINE_COLUMNS
@@ -1109,9 +1111,14 @@ void menuModelSetup(event_t event)
if (checkIncDec_Ret) {
modelHeaders[g_eeGeneral.currModel].modelId[moduleIdx] = g_model.header.modelId[moduleIdx];
}
}
if (editMode==0 && event==EVT_KEY_BREAK(KEY_ENTER)) {
checkModelIdUnique(g_eeGeneral.currModel, moduleIdx);
else if (event == EVT_KEY_LONG(KEY_ENTER)) {
killEvents(event);
uint8_t newVal = findNextUnusedModelId(g_eeGeneral.currModel, moduleIdx);
if (newVal != g_model.header.modelId[moduleIdx]) {
modelHeaders[g_eeGeneral.currModel].modelId[moduleIdx] = g_model.header.modelId[moduleIdx] = newVal;
storageDirty(EE_MODEL);
}
}
}
}
lcdDrawText(MODEL_SETUP_2ND_COLUMN+xOffsetBind, y, STR_MODULE_BIND, l_posHorz==1 ? attr : 0);
@@ -1507,6 +1514,30 @@ void menuModelSetup(event_t event)
lcdDrawNumber(16+4*FW, 5*FH, TELEMETRY_RSSI(), BOLD);
}
#endif
// some field just finished being edited
if (old_editMode > 0 && s_editMode == 0) {
switch(menuVerticalPosition) {
#if defined(PCBTARANIS)
case ITEM_MODEL_INTERNAL_MODULE_BIND:
if (menuHorizontalPosition == 0)
checkModelIdUnique(g_eeGeneral.currModel, INTERNAL_MODULE);
break;
#endif
#if defined(PCBSKY9X)
case ITEM_MODEL_EXTRA_MODULE_BIND:
if (menuHorizontalPosition == 0)
checkModelIdUnique(g_eeGeneral.currModel, EXTRA_MODULE);
break;
#endif
#if defined(CPUARM)
case ITEM_MODEL_EXTERNAL_MODULE_BIND:
if (menuHorizontalPosition == 0)
checkModelIdUnique(g_eeGeneral.currModel, EXTERNAL_MODULE);
break;
#endif
}
}
}
#if defined(CPUARM)
+23 -3
View File
@@ -279,6 +279,7 @@ void menuModelSetup(event_t event)
bool CURSOR_ON_CELL = (menuHorizontalPosition >= 0);
static uint8_t selectedPxxPower = g_model.moduleData[EXTERNAL_MODULE].pxx.power; //TODO could go to the reusable struct
int8_t old_editMode = s_editMode;
MENU_TAB({ 0, 0, TIMERS_ROWS, TOPLCD_ROWS 0, 1, 0, 0,
LABEL(Throttle), 0, 0, 0,
LABEL(PreflightCheck), 0, 0, SW_WARN_ITEMS(), POT_WARN_ITEMS(), NAVIGATION_LINE_BY_LINE|(NUM_STICKS+NUM_POTS+NUM_SLIDERS+NUM_ROTARY_ENCODERS-1), 0,
@@ -969,9 +970,14 @@ void menuModelSetup(event_t event)
if (checkIncDec_Ret) {
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, moduleIdx);
else if (event == EVT_KEY_LONG(KEY_ENTER)) {
killEvents(event);
uint8_t newVal = findNextUnusedModelId(g_eeGeneral.currModel, moduleIdx);
if (newVal != g_model.header.modelId[moduleIdx]) {
modelHeaders[g_eeGeneral.currModel].modelId[moduleIdx] = g_model.header.modelId[moduleIdx] = newVal;
storageDirty(EE_MODEL);
}
}
}
}
lcdDrawText(MODEL_SETUP_2ND_COLUMN+xOffsetBind, y, STR_MODULE_BIND, l_posHorz==1 ? attr : 0);
@@ -1190,6 +1196,20 @@ void menuModelSetup(event_t event)
lcdDrawNumber(16+4*FW, 5*FH, TELEMETRY_RSSI(), BOLD);
}
#endif
if (old_editMode > 0 && s_editMode == 0) {
switch(menuVerticalPosition) {
case ITEM_MODEL_INTERNAL_MODULE_BIND:
if (menuHorizontalPosition == 0)
checkModelIdUnique(g_eeGeneral.currModel, INTERNAL_MODULE);
break;
case ITEM_MODEL_EXTERNAL_MODULE_BIND:
if (menuHorizontalPosition == 0)
checkModelIdUnique(g_eeGeneral.currModel, EXTERNAL_MODULE);
break;
}
}
}
void menuModelFailsafe(event_t event)
+25 -20
View File
@@ -37,7 +37,6 @@ enum ModelDeleteMode {
};
uint8_t selectMode, deleteMode;
ModelsList modelslist;
ModelsCategory * currentCategory;
int currentCategoryIndex;
@@ -87,11 +86,12 @@ void setCurrentModel(unsigned int index)
void setCurrentCategory(unsigned int index)
{
currentCategoryIndex = index;
std::list<ModelsCategory *>::iterator it = modelslist.categories.begin();
const std::list<ModelsCategory *>& cats = modelslist.getCategories();
std::list<ModelsCategory *>::const_iterator it = cats.begin();
std::advance(it, index);
currentCategory = *it;
categoriesVerticalPosition = index;
categoriesVerticalOffset = limit<int>(categoriesVerticalPosition-4, categoriesVerticalOffset, min<int>(categoriesVerticalPosition, max<int>(0, modelslist.categories.size()-5)));
categoriesVerticalOffset = limit<int>(categoriesVerticalPosition-4, categoriesVerticalOffset, min<int>(categoriesVerticalPosition, max<int>(0, cats.size()-5)));
if (currentCategory->size() > 0)
setCurrentModel(0);
else
@@ -226,6 +226,7 @@ void onModelSelectMenu(const char * result)
storageFlushCurrentModel();
storageCheck(true);
memcpy(g_eeGeneral.currModelFilename, currentModel->modelFilename, LEN_MODEL_FILENAME);
modelslist.setCurrentModel(currentModel);
loadModel(g_eeGeneral.currModelFilename, false);
storageDirty(EE_GENERAL);
storageCheck(true);
@@ -239,9 +240,11 @@ void onModelSelectMenu(const char * result)
}
else if (result == STR_CREATE_MODEL) {
storageCheck(true);
currentModel = modelslist.currentModel = modelslist.addModel(currentCategory, createModel());
modelslist.addModel(currentCategory, createModel());
selectMode = MODE_SELECT_MODEL;
setCurrentModel(currentCategory->size() - 1);
modelslist.setCurrentModel(currentModel);
modelslist.onNewModelCreated(currentModel, &g_model);
#if defined(LUA)
chainMenu(menuModelWizard);
#endif
@@ -251,9 +254,9 @@ void onModelSelectMenu(const char * result)
memcpy(duplicatedFilename, currentModel->modelFilename, sizeof(duplicatedFilename));
if (findNextFileIndex(duplicatedFilename, LEN_MODEL_FILENAME, MODELS_PATH)) {
sdCopyFile(currentModel->modelFilename, MODELS_PATH, duplicatedFilename, MODELS_PATH);
modelslist.addModel(currentCategory, duplicatedFilename);
unsigned int index = currentCategory->size() - 1;
setCurrentModel(index);
ModelCell* dup_model = modelslist.addModel(currentCategory, duplicatedFilename);
dup_model->fetchRfData();
setCurrentModel(currentCategory->size() - 1);
}
else {
POPUP_WARNING("Invalid File");
@@ -264,7 +267,7 @@ void onModelSelectMenu(const char * result)
}
else if (result == STR_CREATE_CATEGORY) {
currentCategory = modelslist.createCategory();
setCurrentCategory(modelslist.categories.size() - 1);
setCurrentCategory(modelslist.getCategories().size() - 1);
}
else if (result == STR_RENAME_CATEGORY) {
selectMode = MODE_RENAME_CATEGORY;
@@ -291,8 +294,9 @@ void initModelsList()
categoriesVerticalOffset = 0;
bool found = false;
int index = 0;
for (std::list<ModelsCategory *>::iterator it = modelslist.categories.begin(); it != modelslist.categories.end(); ++it, ++index) {
if (*it == modelslist.currentCategory) {
const std::list<ModelsCategory *>& cats = modelslist.getCategories();
for (std::list<ModelsCategory *>::const_iterator it = cats.begin(); it != cats.end(); ++it, ++index) {
if (*it == modelslist.getCurrentCategory()) {
setCurrentCategory(index);
found = true;
break;
@@ -306,7 +310,7 @@ void initModelsList()
found = false;
index = 0;
for (ModelsCategory::iterator it = currentCategory->begin(); it != currentCategory->end(); ++it, ++index) {
if (*it == modelslist.currentModel) {
if (*it == modelslist.getCurrentModel()) {
setCurrentModel(index);
found = true;
break;
@@ -339,6 +343,7 @@ bool menuModelSelect(event_t event)
}
}
const std::list<ModelsCategory*>& cats = modelslist.getCategories();
switch(event) {
case 0:
// no need to refresh the screen
@@ -371,7 +376,7 @@ bool menuModelSelect(event_t event)
#endif
if (selectMode == MODE_SELECT_MODEL) {
if (categoriesVerticalPosition == 0)
categoriesVerticalPosition = modelslist.categories.size() - 1;
categoriesVerticalPosition = cats.size() - 1;
else
categoriesVerticalPosition -= 1;
setCurrentCategory(categoriesVerticalPosition);
@@ -394,11 +399,11 @@ bool menuModelSelect(event_t event)
#endif
if (selectMode == MODE_SELECT_MODEL) {
categoriesVerticalPosition += 1;
if (categoriesVerticalPosition >= modelslist.categories.size())
if (categoriesVerticalPosition >= cats.size())
categoriesVerticalPosition = 0;
setCurrentCategory(categoriesVerticalPosition);
}
else if (selectMode == MODE_MOVE_MODEL && categoriesVerticalPosition < modelslist.categories.size()-1) {
else if (selectMode == MODE_MOVE_MODEL && categoriesVerticalPosition < cats.size()-1) {
ModelsCategory * previous_category = currentCategory;
ModelCell * model = currentModel;
categoriesVerticalPosition += 1;
@@ -411,7 +416,7 @@ bool menuModelSelect(event_t event)
case EVT_KEY_LONG(KEY_ENTER):
if (selectMode == MODE_SELECT_MODEL) {
killEvents(event);
if (currentModel && currentModel != modelslist.currentModel) {
if (currentModel && currentModel != modelslist.getCurrentModel()) {
POPUP_MENU_ADD_ITEM(STR_SELECT_MODEL);
}
POPUP_MENU_ADD_ITEM(STR_CREATE_MODEL);
@@ -420,13 +425,13 @@ bool menuModelSelect(event_t event)
POPUP_MENU_ADD_ITEM(STR_MOVE_MODEL);
}
// POPUP_MENU_ADD_SD_ITEM(STR_BACKUP_MODEL);
if (currentModel && currentModel != modelslist.currentModel) {
if (currentModel && currentModel != modelslist.getCurrentModel()) {
POPUP_MENU_ADD_ITEM(STR_DELETE_MODEL);
}
// POPUP_MENU_ADD_ITEM(STR_RESTORE_MODEL);
POPUP_MENU_ADD_ITEM(STR_CREATE_CATEGORY);
POPUP_MENU_ADD_ITEM(STR_RENAME_CATEGORY);
if (modelslist.categories.size() > 1) {
if (cats.size() > 1) {
POPUP_MENU_ADD_ITEM(STR_DELETE_CATEGORY);
}
POPUP_MENU_START(onModelSelectMenu);
@@ -441,8 +446,8 @@ bool menuModelSelect(event_t event)
// Categories
int index = 0;
coord_t y = 97;
drawVerticalScrollbar(CATEGORIES_WIDTH-1, y-1, 5*(FH+7)-5, categoriesVerticalOffset, modelslist.categories.size(), 5);
for (std::list<ModelsCategory *>::iterator it = modelslist.categories.begin(); it != modelslist.categories.end(); ++it, ++index) {
drawVerticalScrollbar(CATEGORIES_WIDTH-1, y-1, 5*(FH+7)-5, categoriesVerticalOffset, cats.size(), 5);
for (std::list<ModelsCategory *>::const_iterator it = cats.begin(); it != cats.end(); ++it, ++index) {
if (index >= categoriesVerticalOffset && index < categoriesVerticalOffset+5) {
if (index != categoriesVerticalOffset) {
lcdDrawSolidHorizontalLine(1, y-4, CATEGORIES_WIDTH-10, LINE_COLOR);
@@ -508,7 +513,7 @@ bool menuModelSelect(event_t event)
uint32_t size = sdGetSize() / 100;
lcdDrawNumber(22, LCD_H-FH-21, size, PREC1|SMLSIZE, 0, NULL, "GB");
lcd->drawBitmap(70, LCD_H-FH-20, modelselModelQtyBitmap);
lcdDrawNumber(92, LCD_H-FH-21, modelslist.modelsCount,SMLSIZE);
lcdDrawNumber(92, LCD_H-FH-21, modelslist.getModelsCount(),SMLSIZE);
return true;
}
+60 -3
View File
@@ -19,6 +19,7 @@
*/
#include "opentx.h"
#include "storage/modelslist.h"
uint8_t g_moduleIdx;
@@ -98,6 +99,20 @@ enum MenuModelSetupItems {
#define CURRENT_MODULE_EDITED(k) (k>=ITEM_MODEL_TRAINER_LABEL ? TRAINER_MODULE : (k>=ITEM_MODEL_EXTERNAL_MODULE_LABEL ? EXTERNAL_MODULE : INTERNAL_MODULE))
void checkModelIdUnique(uint8_t moduleIdx)
{
char* warn_buf = reusableBuffer.msgbuf.msg;
// cannot rely exactly on WARNING_LINE_LEN so using WARNING_LINE_LEN-2
size_t warn_buf_len = sizeof(reusableBuffer.msgbuf.msg) - WARNING_LINE_LEN - 2;
if (!modelslist.isModelIdUnique(moduleIdx,warn_buf,warn_buf_len)) {
if (warn_buf[0] != 0) {
POPUP_WARNING(STR_MODELIDUSED);
SET_WARNING_INFO(warn_buf, sizeof(reusableBuffer.msgbuf.msg), 0);
}
}
}
void onBindMenu(const char * result)
{
uint8_t moduleIdx = (menuVerticalPosition >= ITEM_MODEL_EXTERNAL_MODULE_LABEL ? EXTERNAL_MODULE : INTERNAL_MODULE);
@@ -136,6 +151,8 @@ void onModelSetupBitmapMenu(const char * result)
// The user choosed a bmp file in the list
copySelection(g_model.header.bitmap, result, sizeof(g_model.header.bitmap));
storageDirty(EE_MODEL);
if (modelslist.getCurrentModel())
modelslist.getCurrentModel()->resetBuffer();
}
}
@@ -249,6 +266,7 @@ bool menuModelSetup(event_t event)
g_model.moduleData[INTERNAL_MODULE].pxx.external_antenna = XJT_EXTERNAL_ANTENNA;
}
int8_t old_editMode = s_editMode;
MENU(STR_MENUSETUP, MODEL_ICONS, menuTabModel, MENU_MODEL_SETUP, ITEM_MODEL_SETUP_MAX,
{ 0, 0, TIMERS_ROWS, 0, 1, 0, 0,
LABEL(Throttle), 0, 0, 0,
@@ -634,7 +652,6 @@ bool menuModelSetup(event_t event)
if (g_model.moduleData[INTERNAL_MODULE].rfProtocol == RF_PROTO_OFF)
g_model.moduleData[INTERNAL_MODULE].type = MODULE_TYPE_NONE;
}
}
break;
@@ -891,8 +908,19 @@ bool menuModelSetup(event_t event)
if (IS_MODULE_PXX(moduleIdx) || IS_MODULE_DSM2(moduleIdx) || IS_MODULE_MULTIMODULE(moduleIdx)) {
if (xOffsetBind)
lcdDrawNumber(MODEL_SETUP_2ND_COLUMN, y, g_model.header.modelId[moduleIdx], (l_posHorz==0 ? attr : 0) | LEADING0 | LEFT, 2);
if (attr && l_posHorz==0 && s_editMode>0)
CHECK_INCDEC_MODELVAR_ZERO(event, g_model.header.modelId[moduleIdx], MAX_RX_NUM(moduleIdx));
if (attr && l_posHorz==0) {
if (s_editMode>0) {
CHECK_INCDEC_MODELVAR_ZERO(event, g_model.header.modelId[moduleIdx], MAX_RX_NUM(moduleIdx));
if (event == EVT_KEY_LONG(KEY_ENTER)) {
killEvents(event);
uint8_t newVal = modelslist.findNextUnusedModelId(moduleIdx);
if (newVal != g_model.header.modelId[moduleIdx]) {
g_model.header.modelId[moduleIdx] = newVal;
storageDirty(EE_MODEL);
}
}
}
}
drawButton(MODEL_SETUP_2ND_COLUMN+xOffsetBind, y, STR_MODULE_BIND, (moduleFlag[moduleIdx] == MODULE_BIND ? BUTTON_ON : BUTTON_OFF) | (l_posHorz==1 ? attr : 0));
drawButton(MODEL_SETUP_2ND_COLUMN+MODEL_SETUP_RANGE_OFS+xOffsetBind, y, STR_MODULE_RANGE, (moduleFlag[moduleIdx] == MODULE_RANGECHECK ? BUTTON_ON : BUTTON_OFF) | (l_posHorz==2 ? attr : 0));
uint8_t newFlag = 0;
@@ -1110,6 +1138,35 @@ bool menuModelSetup(event_t event)
lcdDrawNumber(WARNING_LINE_X, WARNING_INFOLINE_Y, TELEMETRY_RSSI(), DBLSIZE|LEFT);
}
// some field just finished being edited
if (old_editMode > 0 && s_editMode == 0) {
ModelCell* mod_cell = modelslist.getCurrentModel();
if (mod_cell) {
switch(menuVerticalPosition) {
case ITEM_MODEL_NAME:
mod_cell->setModelName(g_model.header.name);
break;
case ITEM_MODEL_INTERNAL_MODULE_BIND:
if (menuHorizontalPosition != 0)
break;
case ITEM_MODEL_INTERNAL_MODULE_MODE:
mod_cell->setRfData(&g_model);
checkModelIdUnique(INTERNAL_MODULE);
break;
case ITEM_MODEL_EXTERNAL_MODULE_BIND:
if (menuHorizontalPosition != 0)
break;
case ITEM_MODEL_EXTERNAL_MODULE_MODE:
mod_cell->setRfData(&g_model);
if (g_model.moduleData[EXTERNAL_MODULE].type != MODULE_TYPE_NONE)
checkModelIdUnique(EXTERNAL_MODULE);
}
}
}
return true;
}
@@ -20,6 +20,7 @@
#include <stdio.h>
#include "opentx.h"
#include "storage/modelslist.h"
#define REFRESH_FILES() do { reusableBuffer.sdmanager.offset = 65535; currentBitmapIndex = -1; } while (0)
#define NODE_TYPE(fname) fname[SD_SCREEN_FILE_LENGTH+1]
@@ -126,6 +127,8 @@ void onSdManagerMenu(const char * result)
}
else if (result == STR_ASSIGN_BITMAP) {
memcpy(g_model.header.bitmap, line, sizeof(g_model.header.bitmap));
if(modelslist.getCurrentModel())
modelslist.getCurrentModel()->resetBuffer();
storageDirty(EE_MODEL);
}
else if (result == STR_ASSIGN_SPLASH) {