Merge pull request #1597 from opentx/projectkk2glider/lua_new_features
Projectkk2glider/lua new features
This commit is contained in:
@@ -850,6 +850,9 @@ void AudioQueue::playFile(const char *filename, uint8_t flags, uint8_t id)
|
||||
{
|
||||
#if defined(SIMU)
|
||||
printf("playFile(\"%s\", flags=%x, id=%d)\n", filename, flags, id);
|
||||
if (strlen(filename) > AUDIO_FILENAME_MAXLEN) {
|
||||
TRACE("file name too long! maximum length is %d characters", AUDIO_FILENAME_MAXLEN);
|
||||
}
|
||||
fflush(stdout);
|
||||
#else
|
||||
|
||||
|
||||
@@ -348,6 +348,8 @@ void pushPrompt(uint16_t prompt, uint8_t id=0);
|
||||
#define START_SILENCE_PERIOD()
|
||||
#endif
|
||||
|
||||
char * getAudioPath(char * path);
|
||||
|
||||
void referenceSystemAudioFiles();
|
||||
void referenceModelAudioFiles();
|
||||
|
||||
|
||||
@@ -261,6 +261,15 @@ static int luaGetValue(lua_State *L)
|
||||
static int luaPlayFile(lua_State *L)
|
||||
{
|
||||
const char * filename = luaL_checkstring(L, 1);
|
||||
if (filename[0] != '/') {
|
||||
// relative sound file path - use current languague dir for absolute path
|
||||
char file[AUDIO_FILENAME_MAXLEN+1];
|
||||
char * str = getAudioPath(file);
|
||||
strncpy(str, filename, AUDIO_FILENAME_MAXLEN - (str-file));
|
||||
file[AUDIO_FILENAME_MAXLEN] = 0;
|
||||
PLAY_FILE(file, 0, 0);
|
||||
return 0;
|
||||
}
|
||||
PLAY_FILE(filename, 0, 0);
|
||||
return 0;
|
||||
}
|
||||
@@ -274,6 +283,25 @@ static int luaPlayNumber(lua_State *L)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int luaPlayDuration(lua_State *L)
|
||||
{
|
||||
int duration = luaL_checkinteger(L, 1);
|
||||
bool playTime = (luaL_checkinteger(L, 2) != 0);
|
||||
playDuration(duration, playTime ? PLAY_TIME : 0, 0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int luaPlayTone(lua_State *L)
|
||||
{
|
||||
int frequency = luaL_checkinteger(L, 1);
|
||||
int length = luaL_checkinteger(L, 2);
|
||||
int pause = luaL_checkinteger(L, 3);
|
||||
int flags = luaL_optinteger(L, 4, 0);
|
||||
int freqIncr = luaL_optinteger(L, 5, 0);
|
||||
audioQueue.playTone(frequency, length, pause, flags, freqIncr);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int luaKillEvents(lua_State *L)
|
||||
{
|
||||
int event = luaL_checkinteger(L, 1);
|
||||
@@ -1354,6 +1382,8 @@ void luaInit()
|
||||
|
||||
lua_register(L, "playFile", luaPlayFile);
|
||||
lua_register(L, "playNumber", luaPlayNumber);
|
||||
lua_register(L, "playDuration", luaPlayDuration);
|
||||
lua_register(L, "playTone", luaPlayTone);
|
||||
lua_register(L, "popupInput", luaPopupInput);
|
||||
lua_register(L, "defaultStick", luaDefaultStick);
|
||||
lua_register(L, "defaultChannel", luaDefaultChannel);
|
||||
@@ -1406,6 +1436,8 @@ void luaInit()
|
||||
lua_registerint(L, "DOTTED", DOTTED);
|
||||
lua_registerint(L, "LCD_W", LCD_W);
|
||||
lua_registerint(L, "LCD_H", LCD_H);
|
||||
lua_registerint(L, "PLAY_NOW", PLAY_NOW);
|
||||
lua_registerint(L, "PLAY_BACKGROUND", PLAY_BACKGROUND);
|
||||
}
|
||||
|
||||
void luaFree(ScriptInternalData & sid)
|
||||
|
||||
Reference in New Issue
Block a user