feat(colorlcd): Special Function to set main screen (#2160)
* Special Function to set main screen (#2135) * chore: Add new SF to LUA constants list * Companion support * Formatting * get rid of magic number * Add function to get the number of custom screens * Change screen numbering from 0-based to 1-based. * Allow SetScreen custom function for Color LCD only * add range protection * cleanup * yet, range protection once again * fix: paintSpecialFunctionLine can't alter SF param data * Fix screen initialization in companion * move screen switching to the UI * Trigger view change from guiMain() * chore: Change "SET" to "Set" for consistency * fix: Somehow missed extra comma in `TW` Co-authored-by: Peter Feerick <peter.feerick@gmail.com> Co-authored-by: elecpower <neilh713@tpg.com.au> Co-authored-by: Raphael Coeffic <raphael.coeffic@frafos.com>
This commit is contained in:
co-authored by
Peter Feerick
elecpower
Raphael Coeffic
parent
b0c1315f61
commit
4e49ac68be
@@ -123,6 +123,8 @@ QString CustomFunctionData::funcToString(const AssignFunc func, const ModelData
|
||||
return tr("Racing Mode");
|
||||
else if (func == FuncDisableTouch)
|
||||
return tr("Disable Touch");
|
||||
else if (func == FuncSetScreen)
|
||||
return tr("Set Main Screen");
|
||||
else {
|
||||
return QString(CPN_STR_UNKNOWN_ITEM);
|
||||
}
|
||||
@@ -149,6 +151,9 @@ QString CustomFunctionData::paramToString(const ModelData * model) const
|
||||
else if (func == FuncVolume || func == FuncPlayValue || func == FuncBacklight) {
|
||||
return RawSource(param).toString(model);
|
||||
}
|
||||
else if (func ==FuncSetScreen) {
|
||||
return QString("%1").arg(param);
|
||||
}
|
||||
else if (func == FuncPlayPrompt || func == FuncPlayBoth) {
|
||||
if ( getCurrentFirmware()->getCapability(VoicesAsNumbers)) {
|
||||
return QString("%1").arg(param);
|
||||
@@ -223,7 +228,8 @@ bool CustomFunctionData::isFuncAvailable(const int index)
|
||||
((index == FuncScreenshot) && !IS_HORUS_OR_TARANIS(fw->getBoard())) ||
|
||||
((index >= FuncRangeCheckInternalModule && index <= FuncBindExternalModule) && !fw->getCapability(DangerousFunctions)) ||
|
||||
((index >= FuncAdjustGV1 && index <= FuncAdjustGVLast) && !fw->getCapability(Gvars)) ||
|
||||
((index == FuncDisableTouch) && !IS_HORUS_OR_TARANIS(fw->getBoard()))
|
||||
((index == FuncDisableTouch) && !IS_HORUS_OR_TARANIS(fw->getBoard())) ||
|
||||
((index == FuncSetScreen && !Boards::getCapability(fw->getBoard(), Board::HasColorLcd)))
|
||||
);
|
||||
return !ret;
|
||||
}
|
||||
|
||||
@@ -71,6 +71,7 @@ enum AssignFunc {
|
||||
FuncBindExternalModule,
|
||||
FuncRacingMode,
|
||||
FuncDisableTouch,
|
||||
FuncSetScreen,
|
||||
FuncCount,
|
||||
FuncReserve = -1
|
||||
};
|
||||
|
||||
@@ -36,7 +36,8 @@ static bool fnHasRepeat(AssignFunc fn)
|
||||
return (fn == FuncPlayPrompt)
|
||||
|| (fn == FuncPlayValue)
|
||||
|| (fn == FuncPlayHaptic)
|
||||
|| (fn == FuncPlaySound);
|
||||
|| (fn == FuncPlaySound)
|
||||
|| (fn == FuncSetScreen);
|
||||
}
|
||||
|
||||
static const YamlLookupTable customFnLut = {
|
||||
@@ -63,6 +64,7 @@ static const YamlLookupTable customFnLut = {
|
||||
{ FuncScreenshot, "SCREENSHOT" },
|
||||
{ FuncRacingMode, "RACING_MODE" },
|
||||
{ FuncDisableTouch, "DISABLE_TOUCH" },
|
||||
{ FuncSetScreen, "SET_SCREEN"},
|
||||
};
|
||||
|
||||
static const YamlLookupTable trainerLut = {
|
||||
@@ -206,6 +208,9 @@ Node convert<CustomFunctionData>::encode(const CustomFunctionData& rhs)
|
||||
case FuncLogs:
|
||||
def += std::to_string(rhs.param);
|
||||
break;
|
||||
case FuncSetScreen:
|
||||
def += std::to_string(rhs.param);
|
||||
break;
|
||||
default:
|
||||
add_comma = false;
|
||||
break;
|
||||
@@ -349,6 +354,11 @@ bool convert<CustomFunctionData>::decode(const Node& node,
|
||||
def >> param;
|
||||
rhs.param = param;
|
||||
} break;
|
||||
case FuncSetScreen: {
|
||||
int param = 0;
|
||||
def >> param;
|
||||
rhs.param = param;
|
||||
} break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -1800,3 +1800,15 @@ AbstractStaticItemModel * ModelData::trainerModeItemModel(const GeneralSettings
|
||||
mdl->loadItemList();
|
||||
return mdl;
|
||||
}
|
||||
|
||||
int ModelData::getCustomScreensCount() const
|
||||
{
|
||||
int cnt = 0;
|
||||
|
||||
for (int i = 0; i < MAX_CUSTOM_SCREENS; i++) {
|
||||
if (customScreens.customScreenData[i].layoutId[0] != '\0')
|
||||
cnt++;
|
||||
}
|
||||
|
||||
return cnt;
|
||||
}
|
||||
|
||||
@@ -307,6 +307,7 @@ class ModelData {
|
||||
static QString funcSwitchStartToString(unsigned int value);
|
||||
static AbstractStaticItemModel * funcSwitchStartItemModel();
|
||||
|
||||
int getCustomScreensCount() const;
|
||||
|
||||
protected:
|
||||
void removeGlobalVar(int & var);
|
||||
|
||||
@@ -1513,6 +1513,7 @@ class CustomFunctionsConversionTable: public ConversionTable {
|
||||
addConversion(FuncScreenshot, val++);
|
||||
addConversion(FuncRacingMode, val++);
|
||||
addConversion(FuncDisableTouch, val++);
|
||||
addConversion(FuncSetScreen, val++);
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -1581,7 +1582,7 @@ class ArmCustomFunctionField: public TransformedField {
|
||||
|
||||
static bool hasRepeatParam(const CustomFunctionData & fn)
|
||||
{
|
||||
return (fn.func == FuncPlaySound || fn.func == FuncPlayPrompt || fn.func == FuncPlayValue || fn.func == FuncPlayHaptic);
|
||||
return (fn.func == FuncPlaySound || fn.func == FuncPlayPrompt || fn.func == FuncPlayValue || fn.func == FuncPlayHaptic || fn.func == FuncSetScreen);
|
||||
}
|
||||
|
||||
void beforeExport() override
|
||||
|
||||
@@ -428,7 +428,7 @@ void CustomFunctionsPanel::refreshCustomFunction(int i, bool modified)
|
||||
populateFuncParamCB(fswtchParamT[i], func, cfn.param);
|
||||
widgetsMask |= CUSTOM_FUNCTION_SOURCE_PARAM | CUSTOM_FUNCTION_ENABLE;
|
||||
}
|
||||
else if (func == FuncPlaySound || func == FuncPlayHaptic || func == FuncPlayValue || func == FuncPlayPrompt || func == FuncPlayBoth || func == FuncBackgroundMusic) {
|
||||
else if (func == FuncPlaySound || func == FuncPlayHaptic || func == FuncPlayValue || func == FuncPlayPrompt || func == FuncPlayBoth || func == FuncBackgroundMusic || func == FuncSetScreen) {
|
||||
if (func != FuncBackgroundMusic) {
|
||||
if (modified)
|
||||
cfn.repeatParam = fswtchRepeat[i]->currentData().toInt();
|
||||
@@ -507,6 +507,14 @@ void CustomFunctionsPanel::refreshCustomFunction(int i, bool modified)
|
||||
cfn.param = (uint8_t)fswtchParamT[i]->currentIndex();
|
||||
populateFuncParamCB(fswtchParamT[i], func, cfn.param);
|
||||
widgetsMask |= CUSTOM_FUNCTION_SOURCE_PARAM;
|
||||
} else if (func == FuncSetScreen) {
|
||||
fswtchParam[i]->setDecimals(0);
|
||||
fswtchParam[i]->setMinimum(1);
|
||||
fswtchParam[i]->setMaximum(model->getCustomScreensCount());
|
||||
fswtchParam[i]->setSingleStep(1);
|
||||
cfn.param = fswtchParam[i]->value();
|
||||
fswtchParam[i]->setValue(cfn.param);
|
||||
widgetsMask |= CUSTOM_FUNCTION_NUMERIC_PARAM;
|
||||
}
|
||||
}
|
||||
else if (func == FuncPlayScript) {
|
||||
|
||||
Reference in New Issue
Block a user