Add filename to lua model.getInfo() (#1132)
* Add filename to lua `model.getInfo()` * Make `getModelNumberStr()` globally available * Move variable extern * Move constexpr to header, remove externs * Perhaps .cpp should include its OWN header
This commit is contained in:
@@ -26,6 +26,10 @@
|
||||
#include "../timers.h"
|
||||
#include "model_init.h"
|
||||
|
||||
#if defined(SDCARD_YAML)
|
||||
#include <storage/sdcard_yaml.h>
|
||||
#endif
|
||||
|
||||
/*luadoc
|
||||
@function model.getInfo()
|
||||
|
||||
@@ -34,8 +38,9 @@ Get current Model information
|
||||
@retval table model information:
|
||||
* `name` (string) model name
|
||||
* `bitmap` (string) bitmap name (not present on X7)
|
||||
* `filename` (string) model filename
|
||||
|
||||
@status current Introduced in 2.0.6, changed in 2.2.0
|
||||
@status current Introduced in 2.0.6, changed in 2.2.0, filename added in 2.6.0
|
||||
*/
|
||||
static int luaModelGetInfo(lua_State *L)
|
||||
{
|
||||
@@ -44,6 +49,16 @@ static int luaModelGetInfo(lua_State *L)
|
||||
#if LCD_DEPTH > 1
|
||||
lua_pushtablenstring(L, "bitmap", g_model.header.bitmap);
|
||||
#endif
|
||||
|
||||
#if defined(STORAGE_MODELSLIST)
|
||||
lua_pushtablenstring(L, "filename", g_eeGeneral.currModelFilename);
|
||||
#else
|
||||
char fname[MODELIDX_STRLEN + sizeof(YAML_EXT)];
|
||||
getModelNumberStr(g_eeGeneral.currModel, fname);
|
||||
strcat(fname, YAML_EXT);
|
||||
lua_pushtablenstring(L, "filename", fname);
|
||||
#endif
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
@@ -33,6 +33,10 @@
|
||||
using namespace bin_storage_220;
|
||||
#include <storage/sdcard_common.h>
|
||||
|
||||
#if defined(SDCARD_YAML)
|
||||
#include <storage/sdcard_yaml.h>
|
||||
#endif
|
||||
|
||||
// see "yaml/yaml_datastructs.h"
|
||||
namespace yaml_conv_220 {
|
||||
const YamlNode* get_radiodata_nodes();
|
||||
@@ -138,15 +142,6 @@ const char* convertRadioData_220_to_221(const char* path)
|
||||
|
||||
#include <storage/eeprom_common.h>
|
||||
|
||||
constexpr uint8_t MODELIDX_STRLEN = sizeof(MODEL_FILENAME_PREFIX "00");
|
||||
|
||||
static void getModelNumberStr(uint8_t idx, char* model_idx)
|
||||
{
|
||||
memcpy(model_idx, MODEL_FILENAME_PREFIX, sizeof(MODEL_FILENAME_PREFIX));
|
||||
model_idx[sizeof(MODEL_FILENAME_PREFIX)-1] = '0' + idx / 10;
|
||||
model_idx[sizeof(MODEL_FILENAME_PREFIX)] = '0' + idx % 10;
|
||||
model_idx[sizeof(MODEL_FILENAME_PREFIX)+1] = '\0';
|
||||
}
|
||||
|
||||
const char* convertModelData_220_to_221(uint8_t id)
|
||||
{
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
#include "storage.h"
|
||||
#include "sdcard_common.h"
|
||||
#include "sdcard_raw.h"
|
||||
|
||||
#include "sdcard_yaml.h"
|
||||
#include "modelslist.h"
|
||||
|
||||
#include "yaml/yaml_tree_walker.h"
|
||||
@@ -264,9 +264,7 @@ const char * writeModelYaml(const char* filename)
|
||||
// EEPROM slot simulation based on file names:
|
||||
// - /MODELS/model[00-99].yml
|
||||
|
||||
constexpr uint8_t MODELIDX_STRLEN = sizeof(MODEL_FILENAME_PREFIX "00");
|
||||
|
||||
static void getModelNumberStr(uint8_t idx, char* model_idx)
|
||||
void getModelNumberStr(uint8_t idx, char* model_idx)
|
||||
{
|
||||
memcpy(model_idx, MODEL_FILENAME_PREFIX, sizeof(MODEL_FILENAME_PREFIX));
|
||||
model_idx[sizeof(MODEL_FILENAME_PREFIX)-1] = '0' + idx / 10;
|
||||
|
||||
@@ -20,7 +20,9 @@
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
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);
|
||||
void getModelNumberStr(uint8_t idx, char* model_idx);
|
||||
|
||||
Reference in New Issue
Block a user