Set current model in ModelsList while loading
This commit is contained in:
@@ -43,44 +43,6 @@ constexpr coord_t MODEL_IMAGE_WIDTH = MODEL_SELECT_CELL_WIDTH;
|
||||
constexpr coord_t MODEL_IMAGE_HEIGHT = 72;
|
||||
|
||||
|
||||
enum ModelSelectMode {
|
||||
MODE_SELECT_MODEL,
|
||||
MODE_RENAME_CATEGORY,
|
||||
MODE_MOVE_MODEL,
|
||||
};
|
||||
|
||||
enum ModelDeleteMode {
|
||||
MODE_DELETE_MODEL,
|
||||
MODE_DELETE_CATEGORY,
|
||||
};
|
||||
|
||||
uint8_t selectMode, deleteMode;
|
||||
|
||||
#if 0
|
||||
void setCurrentModel(unsigned int index)
|
||||
{
|
||||
auto it = currentCategory->begin();
|
||||
std::advance(it, index);
|
||||
currentModel = *it;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if 0
|
||||
void setCurrentCategory(unsigned int index)
|
||||
{
|
||||
currentCategoryIndex = index;
|
||||
auto it = modelslist.getCategories().begin();
|
||||
std::advance(it, index);
|
||||
currentCategory = *it;
|
||||
categoriesVerticalPosition = index;
|
||||
categoriesVerticalOffset = limit<int>(categoriesVerticalPosition-4, categoriesVerticalOffset, min<int>(categoriesVerticalPosition, max<int>(0, modelslist.getCategories().size()-5)));
|
||||
/*if (currentCategory->size() > 0)
|
||||
setCurrentModel(0);
|
||||
else
|
||||
currentModel = nullptr;*/
|
||||
}
|
||||
#endif
|
||||
|
||||
class ModelButton : public Button
|
||||
{
|
||||
public:
|
||||
|
||||
@@ -136,11 +136,9 @@ void convertBinRadioData(const char * path, int version)
|
||||
|
||||
#if defined(SDCARD_YAML) || defined(STORAGE_MODELSLIST)
|
||||
modelslist.save();
|
||||
#endif
|
||||
|
||||
// reload models list
|
||||
// trigger models list reload
|
||||
modelslist.clear();
|
||||
modelslist.load();
|
||||
#endif
|
||||
}
|
||||
|
||||
void patchFilenameToYaml(char* str)
|
||||
|
||||
@@ -355,8 +355,12 @@ bool ModelsList::loadYaml()
|
||||
// YAML reader
|
||||
TRACE("YAML modelslist reader");
|
||||
|
||||
YamlParser yp; //TODO: move to re-usable buffer
|
||||
yp.init(get_modelslist_parser_calls(), get_modelslist_iter());
|
||||
YamlParser yp;
|
||||
void* ctx = get_modelslist_iter(
|
||||
g_eeGeneral.currModelFilename,
|
||||
strnlen(g_eeGeneral.currModelFilename, LEN_MODEL_FILENAME));
|
||||
|
||||
yp.init(get_modelslist_parser_calls(), ctx);
|
||||
|
||||
UINT bytes_read=0;
|
||||
while (f_read(&file, line, sizeof(line), &bytes_read) == FR_OK) {
|
||||
|
||||
@@ -37,16 +37,21 @@ struct modelslist_iter
|
||||
};
|
||||
|
||||
ModelsList* root;
|
||||
const char* currentModel;
|
||||
unsigned currentModel_len;
|
||||
uint8_t level;
|
||||
char current_attr[16]; // set after find_node()
|
||||
};
|
||||
|
||||
static modelslist_iter __modelslist_iter_inst;
|
||||
|
||||
void* get_modelslist_iter()
|
||||
void* get_modelslist_iter(const char* currentModel, unsigned currentModel_len)
|
||||
{
|
||||
__modelslist_iter_inst.root = &modelslist;
|
||||
__modelslist_iter_inst.currentModel = currentModel;
|
||||
__modelslist_iter_inst.currentModel_len = currentModel_len;
|
||||
__modelslist_iter_inst.level = 0;
|
||||
|
||||
return &__modelslist_iter_inst;
|
||||
}
|
||||
|
||||
@@ -102,29 +107,36 @@ static bool find_node(void* ctx, char* buf, uint8_t len)
|
||||
|
||||
static void set_attr(void* ctx, char* buf, uint8_t len)
|
||||
{
|
||||
modelslist_iter* mi = (modelslist_iter*)ctx;
|
||||
list<ModelsCategory *>& cats = mi->root->getCategories();
|
||||
switch(mi->level) {
|
||||
modelslist_iter* mi = (modelslist_iter*)ctx;
|
||||
auto ml = mi->root;
|
||||
list<ModelsCategory*>& cats = ml->getCategories();
|
||||
|
||||
switch (mi->level) {
|
||||
case modelslist_iter::Model:
|
||||
if (!strcmp(mi->current_attr,"filename")) {
|
||||
if (!cats.empty()) {
|
||||
ModelCell* model = new ModelCell(buf, len);
|
||||
cats.back()->push_back(model);
|
||||
mi->root->incModelsCount();
|
||||
}
|
||||
if (!strcmp(mi->current_attr, "filename")) {
|
||||
if (!cats.empty()) {
|
||||
ModelCell* model = new ModelCell(buf, len);
|
||||
auto cat = cats.back();
|
||||
cat->push_back(model);
|
||||
ml->incModelsCount();
|
||||
|
||||
if (!strncmp(model->modelFilename, mi->currentModel,
|
||||
mi->currentModel_len)) {
|
||||
ml->setCurrentCategory(cat);
|
||||
ml->setCurrentModel(model);
|
||||
}
|
||||
}
|
||||
else if (!strcmp(mi->current_attr,"name")) {
|
||||
if (!cats.empty()) {
|
||||
ModelsCategory* cat = cats.back();
|
||||
if (!cat->empty()) {
|
||||
ModelCell* model = cat->back();
|
||||
model->setModelName(buf,len);
|
||||
}
|
||||
}
|
||||
} else if (!strcmp(mi->current_attr, "name")) {
|
||||
if (!cats.empty()) {
|
||||
auto cat = cats.back();
|
||||
if (!cat->empty()) {
|
||||
auto model = cat->back();
|
||||
model->setModelName(buf, len);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static const YamlParserCalls modelslistCalls = {
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
|
||||
struct YamlParserCalls;
|
||||
|
||||
void* get_modelslist_iter();
|
||||
void* get_modelslist_iter(const char* currentModel, unsigned currentModel_len);
|
||||
const YamlParserCalls* get_modelslist_parser_calls();
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user