feat: Model templates for color radios (update SD card for bundled templates) (#1569)
* Model templates - select and load after Create Model for color radios * Model templates - save model as template, only for color radios * Small fix to drawTextLines(...) to handle consecutive spaces * Change title of button for empty template folder * I found out why "no trailing slash = important" in path names! * Reworked file and path name string manipulation No longer using chdir, as Lua scripts etc. could be messing with the working dir Use buffers more and std::string less * Adjusting the size of buffers I think that I got it right now. Really hard to figure out the right size constants! Also added storageDirty(EE_MODEL) after reading the template file and renaming the model * Added storage checks * Slight simplification - all template buttons are similar * Added "Blank Model" button * Wizard Lua script If there is a Lua script with the same name as the template file in the folder, then it is run after reading the template.
This commit is contained in:
@@ -29,11 +29,12 @@
|
||||
// defined either in sdcard_raw.cpp or sdcard_yaml.cpp
|
||||
void storageCreateModelsList();
|
||||
|
||||
void getModelPath(char * path, const char * filename)
|
||||
void getModelPath(char * path, const char * filename, const char* pathName)
|
||||
{
|
||||
strcpy(path, STR_MODELS_PATH);
|
||||
path[sizeof(MODELS_PATH)-1] = '/';
|
||||
strcpy(&path[sizeof(MODELS_PATH)], filename);
|
||||
unsigned int len = strlen(pathName);
|
||||
strcpy(path, pathName);
|
||||
path[len] = '/';
|
||||
strcpy(&path[len + 1], filename);
|
||||
}
|
||||
|
||||
void storageEraseAll(bool warn)
|
||||
@@ -142,6 +143,26 @@ const char* loadModel(char* filename, bool alarms)
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
const char* loadModelTemplate(const char* fileName, const char* filePath)
|
||||
{
|
||||
preModelLoad();
|
||||
// Assuming that the template is located in current working directory
|
||||
const char* error = readModel(fileName, (uint8_t*)&g_model, sizeof(g_model), filePath);
|
||||
if (error) {
|
||||
TRACE("loadModel error=%s", error);
|
||||
// just get some clean memory state in "g_model" so the mixer can run safely
|
||||
memset(&g_model, 0, sizeof(g_model));
|
||||
applyDefaultTemplate();
|
||||
|
||||
storageCheck(true);
|
||||
postModelLoad(false);
|
||||
return error;
|
||||
}
|
||||
|
||||
postModelLoad(false);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void storageReadAll()
|
||||
{
|
||||
TRACE("storageReadAll");
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
#define _SDCARD_COMMON_H_
|
||||
|
||||
#include "ff.h"
|
||||
#include "translations.h"
|
||||
|
||||
#define DEFAULT_CATEGORY "Models"
|
||||
|
||||
@@ -54,10 +55,11 @@ const char *loadFileBin(const char *fullpath, uint8_t *data,
|
||||
struct YamlNode;
|
||||
const char* writeFileYaml(const char* path, const YamlNode* root_node, uint8_t* data);
|
||||
|
||||
void getModelPath(char * path, const char * filename);
|
||||
void getModelPath(char * path, const char * filename, const char* pathName = STR_MODELS_PATH);
|
||||
|
||||
const char * readModel(const char * filename, uint8_t * buffer, uint32_t size);
|
||||
const char * readModel(const char * filename, uint8_t * buffer, uint32_t size, const char* pathName = STR_MODELS_PATH);
|
||||
const char * loadModel(char * filename, bool alarms=true);
|
||||
const char * loadModelTemplate(const char* fileName, const char* filePath);
|
||||
const char * createModel();
|
||||
const char * writeModel();
|
||||
|
||||
|
||||
@@ -196,7 +196,7 @@ const char * writeGeneralSettings()
|
||||
}
|
||||
|
||||
|
||||
const char * readModelYaml(const char * filename, uint8_t * buffer, uint32_t size)
|
||||
const char * readModelYaml(const char * filename, uint8_t * buffer, uint32_t size, const char* pathName)
|
||||
{
|
||||
// YAML reader
|
||||
TRACE("YAML model reader");
|
||||
@@ -216,7 +216,7 @@ const char * readModelYaml(const char * filename, uint8_t * buffer, uint32_t siz
|
||||
}
|
||||
|
||||
char path[256];
|
||||
getModelPath(path, filename);
|
||||
getModelPath(path, filename, pathName);
|
||||
|
||||
YamlTreeWalker tree;
|
||||
tree.reset(data_nodes, buffer);
|
||||
@@ -247,14 +247,14 @@ const char * readModelYaml(const char * filename, uint8_t * buffer, uint32_t siz
|
||||
|
||||
static const char _wrongExtentionError[] = "wrong file extension";
|
||||
|
||||
const char* readModel(const char* filename, uint8_t* buffer, uint32_t size)
|
||||
const char* readModel(const char* filename, uint8_t* buffer, uint32_t size, const char* pathName)
|
||||
{
|
||||
const char* ext = strrchr(filename, '.');
|
||||
if (!ext || strncmp(ext, YAML_EXT, 4) != 0) {
|
||||
return _wrongExtentionError;
|
||||
}
|
||||
|
||||
return readModelYaml(filename, buffer, size);
|
||||
return readModelYaml(filename, buffer, size, pathName);
|
||||
}
|
||||
|
||||
const char * writeModelYaml(const char* filename)
|
||||
|
||||
@@ -24,5 +24,5 @@ constexpr uint8_t MODELIDX_STRLEN = sizeof(MODEL_FILENAME_PREFIX "00");
|
||||
|
||||
const char * loadRadioSettingsYaml();
|
||||
const char * writeModelYaml(const char* filename);
|
||||
const char * readModelYaml(const char * filename, uint8_t * buffer, uint32_t size);
|
||||
const char * readModelYaml(const char * filename, uint8_t * buffer, uint32_t size, const char* pathName = STR_MODELS_PATH);
|
||||
void getModelNumberStr(uint8_t idx, char* model_idx);
|
||||
|
||||
Reference in New Issue
Block a user