Now the Lua Telemetry scripts
This commit is contained in:
@@ -56,7 +56,7 @@ enum FrskyViews {
|
|||||||
FRSKY_VIEW_MAX = e_frsky_after_flight
|
FRSKY_VIEW_MAX = e_frsky_after_flight
|
||||||
};
|
};
|
||||||
|
|
||||||
static uint8_t s_frsky_view = e_frsky_custom_screen_1;
|
uint8_t s_frsky_view = e_frsky_custom_screen_1;
|
||||||
|
|
||||||
#if LCD_W >= 212
|
#if LCD_W >= 212
|
||||||
#define BAR_LEFT 26
|
#define BAR_LEFT 26
|
||||||
@@ -206,6 +206,12 @@ void menuTelemetryFrsky(uint8_t event)
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if defined(LUA)
|
||||||
|
if (isTelemetryScriptAvailable(s_frsky_view)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
lcdDrawTelemetryTopBar();
|
lcdDrawTelemetryTopBar();
|
||||||
|
|
||||||
if (s_frsky_view < MAX_FRSKY_SCREENS) {
|
if (s_frsky_view < MAX_FRSKY_SCREENS) {
|
||||||
|
|||||||
+55
-11
@@ -1169,7 +1169,7 @@ int luaLoad(const char *filename, ScriptInternalData & sid, ScriptInputsOutputs
|
|||||||
return sid.state;
|
return sid.state;
|
||||||
}
|
}
|
||||||
|
|
||||||
void luaLoadModelScript(uint8_t index)
|
void luaLoadMixScript(uint8_t index)
|
||||||
{
|
{
|
||||||
ScriptData & sd = g_model.scriptsData[index];
|
ScriptData & sd = g_model.scriptsData[index];
|
||||||
|
|
||||||
@@ -1211,13 +1211,51 @@ bool luaLoadFunctionScript(uint8_t index)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void luaLoadModelScripts()
|
void getTelemetryScriptPath(char * path, uint8_t index)
|
||||||
|
{
|
||||||
|
strcpy(path, SCRIPTS_PATH "/");
|
||||||
|
char * curs = strcat_modelname(path+sizeof(SCRIPTS_PATH), g_eeGeneral.currModel);
|
||||||
|
strcpy(curs, "/telemX.lua");
|
||||||
|
curs[6] = '0' + index;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool luaLoadTelemetryScript(uint8_t index)
|
||||||
|
{
|
||||||
|
char path[256];
|
||||||
|
getTelemetryScriptPath(path, index);
|
||||||
|
if (isFileAvailable(path)) {
|
||||||
|
if (luaScriptsCount < MAX_SCRIPTS) {
|
||||||
|
ScriptInternalData & sid = scriptInternalData[luaScriptsCount++];
|
||||||
|
memset(&sid, 0, sizeof(sid));
|
||||||
|
sid.reference = SCRIPT_TELEMETRY_FIRST+index;
|
||||||
|
sid.state = SCRIPT_NOFILE;
|
||||||
|
luaLoad(path, sid);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool isTelemetryScriptAvailable(uint8_t index)
|
||||||
|
{
|
||||||
|
for (int i=0; i<luaScriptsCount; i++) {
|
||||||
|
ScriptInternalData & sid = scriptInternalData[i];
|
||||||
|
if (sid.reference == SCRIPT_TELEMETRY_FIRST+index) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void luaLoadMixScripts()
|
||||||
{
|
{
|
||||||
luaScriptsCount = 0;
|
luaScriptsCount = 0;
|
||||||
|
|
||||||
// Load model scripts
|
// Load model scripts
|
||||||
for (int i=0; i<MAX_SCRIPTS; i++) {
|
for (int i=0; i<MAX_SCRIPTS; i++) {
|
||||||
luaLoadModelScript(i);
|
luaLoadMixScript(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load custom function scripts
|
// Load custom function scripts
|
||||||
@@ -1228,9 +1266,13 @@ void luaLoadModelScripts()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#if 0
|
// Load telemetry scripts
|
||||||
// Load telemetry screen script
|
for (int i=0; i<MAX_SCRIPTS; i++) {
|
||||||
#endif
|
if (!luaLoadTelemetryScript(i)) {
|
||||||
|
POPUP_WARNING("Too many Lua scripts!"); // TODO translation
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
char lua_warning_str[WARNING_LINE_LEN+1];
|
char lua_warning_str[WARNING_LINE_LEN+1];
|
||||||
@@ -1287,6 +1329,8 @@ void luaExec(const char *filename)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
extern uint8_t s_frsky_view;
|
||||||
|
|
||||||
void luaTask(uint8_t evt)
|
void luaTask(uint8_t evt)
|
||||||
{
|
{
|
||||||
lcd_locked = false;
|
lcd_locked = false;
|
||||||
@@ -1371,7 +1415,7 @@ void luaTask(uint8_t evt)
|
|||||||
if (luaState & LUASTATE_RELOAD_MODEL_SCRIPTS) {
|
if (luaState & LUASTATE_RELOAD_MODEL_SCRIPTS) {
|
||||||
luaState = 0;
|
luaState = 0;
|
||||||
LUA_RESET();
|
LUA_RESET();
|
||||||
luaLoadModelScripts();
|
luaLoadMixScripts();
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i=0; i<luaScriptsCount; i++) {
|
for (int i=0; i<luaScriptsCount; i++) {
|
||||||
@@ -1401,13 +1445,13 @@ void luaTask(uint8_t evt)
|
|||||||
filename = fn.play.name;
|
filename = fn.play.name;
|
||||||
lua_rawgeti(L, LUA_REGISTRYINDEX, sid.run);
|
lua_rawgeti(L, LUA_REGISTRYINDEX, sid.run);
|
||||||
}
|
}
|
||||||
#if 0
|
|
||||||
else {
|
else {
|
||||||
// SCRIPT_TELEMETRY_SCREEN
|
if (g_menuStack[0]!=menuTelemetryFrsky || sid.reference!=SCRIPT_TELEMETRY_FIRST+s_frsky_view) {
|
||||||
filename = "telem";
|
continue;
|
||||||
|
}
|
||||||
|
filename = "[telem]";
|
||||||
lua_rawgeti(L, LUA_REGISTRYINDEX, sid.run);
|
lua_rawgeti(L, LUA_REGISTRYINDEX, sid.run);
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
if (lua_pcall(L, sio ? sio->inputsCount : 0, sio ? sio->outputsCount : 0, 0) == 0) {
|
if (lua_pcall(L, sio ? sio->inputsCount : 0, sio ? sio->outputsCount : 0, 0) == 0) {
|
||||||
if (sio) {
|
if (sio) {
|
||||||
for (int j=sio->outputsCount-1; j>=0; j--) {
|
for (int j=sio->outputsCount-1; j>=0; j--) {
|
||||||
|
|||||||
+5
-3
@@ -1456,7 +1456,8 @@ enum AUDIO_SOUNDS {
|
|||||||
SCRIPT_MIX_LAST=SCRIPT_MIX_FIRST+MAX_SCRIPTS-1,
|
SCRIPT_MIX_LAST=SCRIPT_MIX_FIRST+MAX_SCRIPTS-1,
|
||||||
SCRIPT_FUNC_FIRST,
|
SCRIPT_FUNC_FIRST,
|
||||||
SCRIPT_FUNC_LAST=SCRIPT_FUNC_FIRST+MAX_SCRIPTS-1,
|
SCRIPT_FUNC_LAST=SCRIPT_FUNC_FIRST+MAX_SCRIPTS-1,
|
||||||
SCRIPT_TELEMETRY_SCREEN,
|
SCRIPT_TELEMETRY_FIRST,
|
||||||
|
SCRIPT_TELEMETRY_LAST=SCRIPT_TELEMETRY_FIRST+MAX_SCRIPTS-1,
|
||||||
};
|
};
|
||||||
struct ScriptInternalData {
|
struct ScriptInternalData {
|
||||||
uint8_t reference;
|
uint8_t reference;
|
||||||
@@ -1481,10 +1482,11 @@ enum AUDIO_SOUNDS {
|
|||||||
void luaInit();
|
void luaInit();
|
||||||
void luaTask(uint8_t evt);
|
void luaTask(uint8_t evt);
|
||||||
void luaExec(const char *filename);
|
void luaExec(const char *filename);
|
||||||
void luaLoadModelScript(uint8_t index);
|
void luaLoadMixScript(uint8_t index);
|
||||||
void luaLoadModelScripts();
|
void luaLoadMixScripts();
|
||||||
#define luaGetMemUsed(idx) scriptInternalData[idx].memory
|
#define luaGetMemUsed(idx) scriptInternalData[idx].memory
|
||||||
#define luaGetCpuUsed(idx) scriptInternalData[idx].instructions
|
#define luaGetCpuUsed(idx) scriptInternalData[idx].instructions
|
||||||
|
bool isTelemetryScriptAvailable(uint8_t index);
|
||||||
#define LUA_INIT()
|
#define LUA_INIT()
|
||||||
#define LUA_RESET() luaInit()
|
#define LUA_RESET() luaInit()
|
||||||
#define LUA_LOAD_MODEL_SCRIPTS() luaState |= LUASTATE_RELOAD_MODEL_SCRIPTS
|
#define LUA_LOAD_MODEL_SCRIPTS() luaState |= LUASTATE_RELOAD_MODEL_SCRIPTS
|
||||||
|
|||||||
Reference in New Issue
Block a user