feat: Add 'repeat' option to 'Lua Script' special function (#3338)
* Add support for the '1x' repeat option for 'Play Script' special functions. * Add Companion and B&W radio support. * Fix B&W radio logic and layout. * Add translation hooks.
This commit is contained in:
@@ -307,7 +307,7 @@ void menuSpecialFunctions(event_t event, CustomFunctionData * functions, CustomF
|
||||
#if defined(SDCARD)
|
||||
else if (func == FUNC_PLAY_TRACK || func == FUNC_BACKGND_MUSIC || func == FUNC_PLAY_SCRIPT) {
|
||||
if (ZEXIST(cfn->play.name))
|
||||
lcdDrawSizedText(MODEL_SPECIAL_FUNC_3RD_COLUMN, y, cfn->play.name, sizeof(cfn->play.name), attr);
|
||||
lcdDrawSizedText(MODEL_SPECIAL_FUNC_3RD_COLUMN-6, y, cfn->play.name, sizeof(cfn->play.name), attr);
|
||||
else
|
||||
lcdDrawTextAtIndex(MODEL_SPECIAL_FUNC_3RD_COLUMN, y, STR_VCSWFUNC, 0, attr);
|
||||
if (active && event==EVT_KEY_BREAK(KEY_ENTER)) {
|
||||
@@ -438,16 +438,22 @@ void menuSpecialFunctions(event_t event, CustomFunctionData * functions, CustomF
|
||||
if (active) CFN_ACTIVE(cfn) = checkIncDec(event, CFN_ACTIVE(cfn), 0, 1, eeFlags);
|
||||
}
|
||||
else if (HAS_REPEAT_PARAM(func)) {
|
||||
if (CFN_PLAY_REPEAT(cfn) == 0) {
|
||||
lcdDrawChar(MODEL_SPECIAL_FUNC_4TH_COLUMN_ONOFF+3, y, '-', attr);
|
||||
}
|
||||
else if (CFN_PLAY_REPEAT(cfn) == CFN_PLAY_REPEAT_NOSTART) {
|
||||
lcdDrawText(MODEL_SPECIAL_FUNC_4TH_COLUMN_ONOFF+1, y, "!-", attr);
|
||||
if (func == FUNC_PLAY_SCRIPT) {
|
||||
lcdDrawText(MODEL_SPECIAL_FUNC_4TH_COLUMN_ONOFF-3, y, (CFN_PLAY_REPEAT(cfn) == 0) ? "On" : "1x", attr);
|
||||
if (active) CFN_PLAY_REPEAT(cfn) = checkIncDec(event, CFN_PLAY_REPEAT(cfn), 0, 1, eeFlags);
|
||||
}
|
||||
else {
|
||||
lcdDrawNumber(MODEL_SPECIAL_FUNC_4TH_COLUMN+2+FW, y, CFN_PLAY_REPEAT(cfn)*CFN_PLAY_REPEAT_MUL, RIGHT | attr);
|
||||
if (CFN_PLAY_REPEAT(cfn) == 0) {
|
||||
lcdDrawChar(MODEL_SPECIAL_FUNC_4TH_COLUMN_ONOFF+3, y, '-', attr);
|
||||
}
|
||||
else if (CFN_PLAY_REPEAT(cfn) == CFN_PLAY_REPEAT_NOSTART) {
|
||||
lcdDrawText(MODEL_SPECIAL_FUNC_4TH_COLUMN_ONOFF+1, y, "!-", attr);
|
||||
}
|
||||
else {
|
||||
lcdDrawNumber(MODEL_SPECIAL_FUNC_4TH_COLUMN+2+FW, y, CFN_PLAY_REPEAT(cfn)*CFN_PLAY_REPEAT_MUL, RIGHT | attr);
|
||||
}
|
||||
if (active) CFN_PLAY_REPEAT(cfn) = checkIncDec(event, CFN_PLAY_REPEAT(cfn)==CFN_PLAY_REPEAT_NOSTART?-1:CFN_PLAY_REPEAT(cfn), -1, 60/CFN_PLAY_REPEAT_MUL, eeFlags);
|
||||
}
|
||||
if (active) CFN_PLAY_REPEAT(cfn) = checkIncDec(event, CFN_PLAY_REPEAT(cfn)==CFN_PLAY_REPEAT_NOSTART?-1:CFN_PLAY_REPEAT(cfn), -1, 60/CFN_PLAY_REPEAT_MUL, eeFlags);
|
||||
}
|
||||
else if (attr) {
|
||||
REPEAT_LAST_CURSOR_MOVE();
|
||||
|
||||
@@ -416,18 +416,24 @@ void menuSpecialFunctions(event_t event, CustomFunctionData * functions, CustomF
|
||||
if (active) CFN_ACTIVE(cfn) = checkIncDec(event, CFN_ACTIVE(cfn), 0, 1, eeFlags);
|
||||
}
|
||||
else if (HAS_REPEAT_PARAM(func)) {
|
||||
if (CFN_PLAY_REPEAT(cfn) == 0) {
|
||||
lcdDrawText(MODEL_SPECIAL_FUNC_4TH_COLUMN+2, y, "1x", attr);
|
||||
}
|
||||
else if (CFN_PLAY_REPEAT(cfn) == CFN_PLAY_REPEAT_NOSTART) {
|
||||
lcdDrawChar(MODEL_SPECIAL_FUNC_4TH_COLUMN-1, y, '!', attr);
|
||||
lcdDrawText(MODEL_SPECIAL_FUNC_4TH_COLUMN+2, y, "1x", attr);
|
||||
if (func == FUNC_PLAY_SCRIPT) {
|
||||
lcdDrawText(MODEL_SPECIAL_FUNC_4TH_COLUMN+2, y, (CFN_PLAY_REPEAT(cfn) == 0) ? "On" : "1x", attr);
|
||||
if (active) CFN_PLAY_REPEAT(cfn) = checkIncDec(event, CFN_PLAY_REPEAT(cfn), 0, 1, eeFlags);
|
||||
}
|
||||
else {
|
||||
lcdDrawNumber(MODEL_SPECIAL_FUNC_4TH_COLUMN+2+FW, y, CFN_PLAY_REPEAT(cfn)*CFN_PLAY_REPEAT_MUL, attr|RIGHT);
|
||||
lcdDrawChar(MODEL_SPECIAL_FUNC_4TH_COLUMN+2+FW, y, 's', attr);
|
||||
if (CFN_PLAY_REPEAT(cfn) == 0) {
|
||||
lcdDrawText(MODEL_SPECIAL_FUNC_4TH_COLUMN+2, y, "1x", attr);
|
||||
}
|
||||
else if (CFN_PLAY_REPEAT(cfn) == CFN_PLAY_REPEAT_NOSTART) {
|
||||
lcdDrawChar(MODEL_SPECIAL_FUNC_4TH_COLUMN-1, y, '!', attr);
|
||||
lcdDrawText(MODEL_SPECIAL_FUNC_4TH_COLUMN+2, y, "1x", attr);
|
||||
}
|
||||
else {
|
||||
lcdDrawNumber(MODEL_SPECIAL_FUNC_4TH_COLUMN+2+FW, y, CFN_PLAY_REPEAT(cfn)*CFN_PLAY_REPEAT_MUL, attr|RIGHT);
|
||||
lcdDrawChar(MODEL_SPECIAL_FUNC_4TH_COLUMN+2+FW, y, 's', attr);
|
||||
}
|
||||
if (active) CFN_PLAY_REPEAT(cfn) = checkIncDec(event, CFN_PLAY_REPEAT(cfn)==CFN_PLAY_REPEAT_NOSTART?-1:CFN_PLAY_REPEAT(cfn), -1, 60/CFN_PLAY_REPEAT_MUL, eeFlags);
|
||||
}
|
||||
if (active) CFN_PLAY_REPEAT(cfn) = checkIncDec(event, CFN_PLAY_REPEAT(cfn)==CFN_PLAY_REPEAT_NOSTART?-1:CFN_PLAY_REPEAT(cfn), -1, 60/CFN_PLAY_REPEAT_MUL, eeFlags);
|
||||
}
|
||||
else if (attr) {
|
||||
REPEAT_LAST_CURSOR_MOVE();
|
||||
|
||||
@@ -331,20 +331,28 @@ class SpecialFunctionEditPage : public Page
|
||||
line = specialFunctionOneWindow->newLine(&grid);
|
||||
new StaticText(line, rect_t{}, STR_REPEAT,
|
||||
0, COLOR_THEME_PRIMARY1);
|
||||
auto repeat = new NumberEdit(
|
||||
line, rect_t{}, -1,
|
||||
60 / CFN_PLAY_REPEAT_MUL, GET_DEFAULT((int8_t)CFN_PLAY_REPEAT(cfn)),
|
||||
SET_DEFAULT(CFN_PLAY_REPEAT(cfn)));
|
||||
repeat->setDisplayHandler(
|
||||
[](int32_t value) {
|
||||
if (value == 0)
|
||||
return std::string("1x");
|
||||
else if (value == (int8_t)CFN_PLAY_REPEAT_NOSTART)
|
||||
return std::string("!1x");
|
||||
else {
|
||||
return formatNumberAsString(value * CFN_PLAY_REPEAT_MUL, 0, 0, nullptr, "s");
|
||||
}
|
||||
});
|
||||
if (func == FUNC_PLAY_SCRIPT) {
|
||||
auto repeat = new Choice(line, rect_t{}, 0, 1,
|
||||
GET_DEFAULT((int8_t)CFN_PLAY_REPEAT(cfn)),
|
||||
SET_DEFAULT(CFN_PLAY_REPEAT(cfn)));
|
||||
repeat->setTextHandler([](int32_t value) {
|
||||
// 0 == repeat at 50ms interval for backward compatibility
|
||||
return (value == 0) ? std::string("On") : std::string("1x");
|
||||
});
|
||||
} else {
|
||||
auto repeat = new NumberEdit(line, rect_t{}, 0, 60 / CFN_PLAY_REPEAT_MUL,
|
||||
GET_DEFAULT((int8_t)CFN_PLAY_REPEAT(cfn)),
|
||||
SET_DEFAULT(CFN_PLAY_REPEAT(cfn)));
|
||||
repeat->setDisplayHandler([](int32_t value) {
|
||||
if (value == 0)
|
||||
return std::string("1x");
|
||||
else if (value == (int8_t)CFN_PLAY_REPEAT_NOSTART)
|
||||
return std::string("!1x");
|
||||
else {
|
||||
return formatNumberAsString(value * CFN_PLAY_REPEAT_MUL, 0, 0, nullptr, "s");
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -653,11 +661,15 @@ class SpecialFunctionButton : public Button
|
||||
lv_obj_clear_state(sfEnable, LV_STATE_CHECKED);
|
||||
lv_obj_clear_flag(sfEnable, LV_OBJ_FLAG_HIDDEN);
|
||||
} else if (HAS_REPEAT_PARAM(func)) {
|
||||
sprintf(s, "(%s)",
|
||||
(CFN_PLAY_REPEAT(cfn) == 0) ? "1x" :
|
||||
(CFN_PLAY_REPEAT(cfn) == CFN_PLAY_REPEAT_NOSTART) ? "!1x" :
|
||||
formatNumberAsString(CFN_PLAY_REPEAT(cfn) * CFN_PLAY_REPEAT_MUL, 0, 0, nullptr, "s").c_str()
|
||||
);
|
||||
if (func == FUNC_PLAY_SCRIPT) {
|
||||
sprintf(s, "(%s)", (CFN_PLAY_REPEAT(cfn) == 0) ? "On" : "1x");
|
||||
} else {
|
||||
sprintf(s, "(%s)",
|
||||
(CFN_PLAY_REPEAT(cfn) == 0) ? "1x" :
|
||||
(CFN_PLAY_REPEAT(cfn) == CFN_PLAY_REPEAT_NOSTART) ? "!1x" :
|
||||
formatNumberAsString(CFN_PLAY_REPEAT(cfn) * CFN_PLAY_REPEAT_MUL, 0, 0, nullptr, "s").c_str()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
lv_label_set_text(sfRepeat, s);
|
||||
|
||||
@@ -1083,15 +1083,25 @@ static bool resumeLua(bool init, bool allowLcdUsage)
|
||||
} else
|
||||
#endif
|
||||
if (ref <= SCRIPT_GFUNC_LAST) {
|
||||
uint8_t idx;
|
||||
CustomFunctionData * fn;
|
||||
|
||||
if (ref <= SCRIPT_FUNC_LAST)
|
||||
fn = &g_model.customFn[ref - SCRIPT_FUNC_FIRST];
|
||||
else
|
||||
fn = &g_eeGeneral.customFn[ref - SCRIPT_GFUNC_FIRST];
|
||||
|
||||
if (getSwitch(fn -> swtch)) {
|
||||
CustomFunctionsContext * functionsContext;
|
||||
|
||||
if (ref <= SCRIPT_FUNC_LAST) {
|
||||
idx = ref - SCRIPT_FUNC_FIRST;
|
||||
fn = &g_model.customFn[idx];
|
||||
functionsContext = &modelFunctionsContext;
|
||||
} else {
|
||||
idx = ref - SCRIPT_GFUNC_FIRST;
|
||||
fn = &g_eeGeneral.customFn[idx];
|
||||
functionsContext = &globalFunctionsContext;
|
||||
}
|
||||
|
||||
tmr10ms_t tmr10ms = get_tmr10ms();
|
||||
|
||||
if (getSwitch(fn->swtch) && (functionsContext->lastFunctionTime[idx] == 0 || CFN_PLAY_REPEAT(fn) == 0)) {
|
||||
lua_rawgeti(lsScripts, LUA_REGISTRYINDEX, sid.run);
|
||||
functionsContext->lastFunctionTime[idx] = tmr10ms;
|
||||
}
|
||||
else {
|
||||
if (sid.background == LUA_NOREF) continue;
|
||||
|
||||
@@ -61,9 +61,9 @@
|
||||
|
||||
#define HAS_ENABLE_PARAM(func) ((func) < FUNC_FIRST_WITHOUT_ENABLE || (func == FUNC_BACKLIGHT))
|
||||
#if defined(COLORLCD)
|
||||
#define HAS_REPEAT_PARAM(func) (IS_PLAY_FUNC(func) || IS_HAPTIC_FUNC(func) || func == FUNC_SET_SCREEN)
|
||||
#define HAS_REPEAT_PARAM(func) (IS_PLAY_FUNC(func) || IS_HAPTIC_FUNC(func) || func == FUNC_PLAY_SCRIPT || func == FUNC_SET_SCREEN)
|
||||
#else
|
||||
#define HAS_REPEAT_PARAM(func) (IS_PLAY_FUNC(func) || IS_HAPTIC_FUNC(func) )
|
||||
#define HAS_REPEAT_PARAM(func) (IS_PLAY_FUNC(func) || IS_HAPTIC_FUNC(func) || func == FUNC_PLAY_SCRIPT)
|
||||
#endif
|
||||
|
||||
#define CFN_EMPTY(p) (!(p)->swtch)
|
||||
|
||||
@@ -1477,7 +1477,12 @@ static void r_customFn(void* user, uint8_t* data, uint32_t bitoffs,
|
||||
}
|
||||
}
|
||||
} else if (HAS_REPEAT_PARAM(func)) {
|
||||
if (val_len == 2
|
||||
if (func == FUNC_PLAY_SCRIPT) {
|
||||
if (val_len == 2 && val[0] == '1' && val[1] == 'x')
|
||||
CFN_PLAY_REPEAT(cfn) = 1;
|
||||
else
|
||||
CFN_PLAY_REPEAT(cfn) = 0;
|
||||
} else if (val_len == 2
|
||||
&& val[0] == '1'
|
||||
&& val[1] == 'x') {
|
||||
CFN_PLAY_REPEAT(cfn) = 0;
|
||||
@@ -1629,7 +1634,9 @@ static bool w_customFn(void* user, uint8_t* data, uint32_t bitoffs,
|
||||
// ","
|
||||
if (!wf(opaque,",",1)) return false;
|
||||
}
|
||||
if (CFN_PLAY_REPEAT(cfn) == 0) {
|
||||
if (func == FUNC_PLAY_SCRIPT) {
|
||||
if (!wf(opaque,(CFN_PLAY_REPEAT(cfn) == 0) ? "On" : "1x",2)) return false;
|
||||
} else if (CFN_PLAY_REPEAT(cfn) == 0) {
|
||||
// "1x"
|
||||
if (!wf(opaque,"1x",2)) return false;
|
||||
} else if (CFN_PLAY_REPEAT(cfn) == CFN_PLAY_REPEAT_NOSTART) {
|
||||
|
||||
Reference in New Issue
Block a user