feat: special function to push customisable switches (#5497)

Co-authored-by: philmoz <phil.a.mitchell@gmail.com>
Co-authored-by: elecpower <elecpower@users.noreply.github.com>
This commit is contained in:
3djc
2024-09-14 11:56:42 +10:00
committed by GitHub
co-authored by philmoz elecpower
parent 40449bf730
commit d417228677
48 changed files with 287 additions and 27 deletions
@@ -30,7 +30,10 @@
#define SD_LOGS_PERIOD_MIN 1 // 0.1s fastest period
#define SD_LOGS_PERIOD_MAX 255 // 25.5s slowest period
#define SD_LOGS_PERIOD_DEFAULT 10 // 1s default period for newly created SF
#define SD_LOGS_PERIOD_DEFAULT 10 // 1s default period for newly created SF
#define PUSH_CS_DURATION_MIN 0 // 0 no duration : as long as switch is true
#define PUSH_CS_DURATION_MAX 255 // 25.5s longest duration
void onCustomFunctionsFileSelectionMenu(const char * result)
{
@@ -269,6 +272,12 @@ void menuSpecialFunctions(event_t event, CustomFunctionData * functions, CustomF
if (active) CFN_TIMER_INDEX(cfn) = checkIncDec(event, CFN_TIMER_INDEX(cfn), 0, maxParam, eeFlags, isTimerSourceAvailable);
break;
}
#if defined(FUNCTION_SWITCHES)
else if (func == FUNC_PUSH_CUST_SWITCH) {
maxParam = NUM_FUNCTIONS_SWITCHES - 1;
drawStringWithIndex(lcdNextPos +5, y, "SW", CFN_CS_INDEX(cfn) + 1, attr);
}
#endif
else if (attr) {
repeatLastCursorMove(event);
}
@@ -381,6 +390,15 @@ void menuSpecialFunctions(event_t event, CustomFunctionData * functions, CustomF
INCDEC_ENABLE_CHECK(isSourceAvailable);
}
}
#if defined(FUNCTION_SWITCHES)
else if (func == FUNC_PUSH_CUST_SWITCH) {
val_min = PUSH_CS_DURATION_MIN;
val_max = PUSH_CS_DURATION_MAX;
lcdDrawNumber(MODEL_SPECIAL_FUNC_3RD_COLUMN, y, val_displayed, attr|PREC1|LEFT);
lcdDrawChar(lcdLastRightPos, y, 's');
}
#endif
else if (func == FUNC_LOGS) {
val_min = SD_LOGS_PERIOD_MIN;
val_max = SD_LOGS_PERIOD_MAX;
@@ -212,6 +212,12 @@ void FunctionLineButton::refresh()
strcat(s, formatNumberAsString(CFN_PARAM(cfn)).c_str());
break;
#if defined(FUNCTION_SWITCHES)
case FUNC_PUSH_CUST_SWITCH:
sprintf(s + strlen(s), "%s%d", STR_SWITCH, CFN_CS_INDEX(cfn) + 1);
break;
#endif
case FUNC_LOGS:
strcat(
s,
@@ -286,6 +292,9 @@ static const lv_coord_t row_dsc[] = {LV_GRID_CONTENT, LV_GRID_TEMPLATE_LAST};
#define SD_LOGS_PERIOD_MAX 255 // 25.5s slowest period
#define SD_LOGS_PERIOD_DEFAULT 10 // 1s default period for newly created SF
#define PUSH_CS_DURATION_MIN 0 // 0 no duration : as long as switch is true
#define PUSH_CS_DURATION_MAX 255 // 25.5s longest duration
FunctionEditPage::FunctionEditPage(uint8_t index, EdgeTxIcon icon,
const char *title, const char *prefix) :
Page(icon), index(index)
@@ -483,6 +492,25 @@ void FunctionEditPage::updateSpecialFunctionOneWindow()
addNumberEdit(line, STR_VALUE, cfn, 0, 3);
break;
#if defined(FUNCTION_SWITCHES)
case FUNC_PUSH_CUST_SWITCH: {
new StaticText(line, rect_t{}, STR_SWITCH);
auto choice = new Choice(line, rect_t{}, 0, NUM_FUNCTIONS_SWITCHES - 1, GET_SET_DEFAULT(CFN_CS_INDEX(cfn)), STR_SWITCH);
choice->setTextHandler([=](int n) {
return std::string(STR_SWITCH) + std::to_string(n + 1);
});
line = specialFunctionOneWindow->newLine(grid);
auto edit = addNumberEdit(line, STR_INTERVAL, cfn, PUSH_CS_DURATION_MIN,
PUSH_CS_DURATION_MAX);
edit->setDisplayHandler([=](int32_t value) {
return formatNumberAsString(CFN_PARAM(cfn), PREC1, 0, nullptr, "s");
});
}
break;
#endif
case FUNC_LOGS: {
if (CFN_PARAM(cfn) == 0) // use stored value if SF exists
CFN_PARAM(cfn) = SD_LOGS_PERIOD_DEFAULT; // otherwise initialize with