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;
|
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
|
class ModelButton : public Button
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|||||||
@@ -136,11 +136,9 @@ void convertBinRadioData(const char * path, int version)
|
|||||||
|
|
||||||
#if defined(SDCARD_YAML) || defined(STORAGE_MODELSLIST)
|
#if defined(SDCARD_YAML) || defined(STORAGE_MODELSLIST)
|
||||||
modelslist.save();
|
modelslist.save();
|
||||||
#endif
|
// trigger models list reload
|
||||||
|
|
||||||
// reload models list
|
|
||||||
modelslist.clear();
|
modelslist.clear();
|
||||||
modelslist.load();
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void patchFilenameToYaml(char* str)
|
void patchFilenameToYaml(char* str)
|
||||||
|
|||||||
@@ -355,8 +355,12 @@ bool ModelsList::loadYaml()
|
|||||||
// YAML reader
|
// YAML reader
|
||||||
TRACE("YAML modelslist reader");
|
TRACE("YAML modelslist reader");
|
||||||
|
|
||||||
YamlParser yp; //TODO: move to re-usable buffer
|
YamlParser yp;
|
||||||
yp.init(get_modelslist_parser_calls(), get_modelslist_iter());
|
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;
|
UINT bytes_read=0;
|
||||||
while (f_read(&file, line, sizeof(line), &bytes_read) == FR_OK) {
|
while (f_read(&file, line, sizeof(line), &bytes_read) == FR_OK) {
|
||||||
|
|||||||
@@ -37,16 +37,21 @@ struct modelslist_iter
|
|||||||
};
|
};
|
||||||
|
|
||||||
ModelsList* root;
|
ModelsList* root;
|
||||||
|
const char* currentModel;
|
||||||
|
unsigned currentModel_len;
|
||||||
uint8_t level;
|
uint8_t level;
|
||||||
char current_attr[16]; // set after find_node()
|
char current_attr[16]; // set after find_node()
|
||||||
};
|
};
|
||||||
|
|
||||||
static modelslist_iter __modelslist_iter_inst;
|
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.root = &modelslist;
|
||||||
|
__modelslist_iter_inst.currentModel = currentModel;
|
||||||
|
__modelslist_iter_inst.currentModel_len = currentModel_len;
|
||||||
__modelslist_iter_inst.level = 0;
|
__modelslist_iter_inst.level = 0;
|
||||||
|
|
||||||
return &__modelslist_iter_inst;
|
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)
|
static void set_attr(void* ctx, char* buf, uint8_t len)
|
||||||
{
|
{
|
||||||
modelslist_iter* mi = (modelslist_iter*)ctx;
|
modelslist_iter* mi = (modelslist_iter*)ctx;
|
||||||
list<ModelsCategory *>& cats = mi->root->getCategories();
|
auto ml = mi->root;
|
||||||
switch(mi->level) {
|
list<ModelsCategory*>& cats = ml->getCategories();
|
||||||
|
|
||||||
|
switch (mi->level) {
|
||||||
case modelslist_iter::Model:
|
case modelslist_iter::Model:
|
||||||
if (!strcmp(mi->current_attr,"filename")) {
|
if (!strcmp(mi->current_attr, "filename")) {
|
||||||
if (!cats.empty()) {
|
if (!cats.empty()) {
|
||||||
ModelCell* model = new ModelCell(buf, len);
|
ModelCell* model = new ModelCell(buf, len);
|
||||||
cats.back()->push_back(model);
|
auto cat = cats.back();
|
||||||
mi->root->incModelsCount();
|
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")) {
|
} else if (!strcmp(mi->current_attr, "name")) {
|
||||||
if (!cats.empty()) {
|
if (!cats.empty()) {
|
||||||
ModelsCategory* cat = cats.back();
|
auto cat = cats.back();
|
||||||
if (!cat->empty()) {
|
if (!cat->empty()) {
|
||||||
ModelCell* model = cat->back();
|
auto model = cat->back();
|
||||||
model->setModelName(buf,len);
|
model->setModelName(buf, len);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
break;
|
}
|
||||||
}
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static const YamlParserCalls modelslistCalls = {
|
static const YamlParserCalls modelslistCalls = {
|
||||||
|
|||||||
@@ -24,7 +24,7 @@
|
|||||||
|
|
||||||
struct YamlParserCalls;
|
struct YamlParserCalls;
|
||||||
|
|
||||||
void* get_modelslist_iter();
|
void* get_modelslist_iter(const char* currentModel, unsigned currentModel_len);
|
||||||
const YamlParserCalls* get_modelslist_parser_calls();
|
const YamlParserCalls* get_modelslist_parser_calls();
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user