Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(bw): add 'Set Screen' special function to B&W radios #5589

Merged
merged 13 commits into from
Oct 17, 2024
14 changes: 13 additions & 1 deletion companion/src/firmwares/customfunctiondata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,6 @@ bool CustomFunctionData::isFuncAvailable(const int index, const ModelData * mode
((index >= FuncRangeCheckInternalModule && index <= FuncBindExternalModule) && !fw->getCapability(DangerousFunctions)) ||
((index >= FuncAdjustGV1 && index <= FuncAdjustGVLast) && !fw->getCapability(Gvars)) ||
((index == FuncDisableTouch) && !IS_HORUS_OR_TARANIS(fw->getBoard())) ||
((index == FuncSetScreen && !Boards::getCapability(fw->getBoard(), Board::HasColorLcd))) ||
((index == FuncDisableAudioAmp && !Boards::getCapability(fw->getBoard(), Board::HasAudioMuteGPIO))) ||
((index == FuncRGBLed && !Boards::getCapability(fw->getBoard(), Board::HasLedStripGPIO))) ||
((index == FuncLCDtoVideo && !IS_FATFISH_F16(fw->getBoard()))) ||
Expand Down Expand Up @@ -424,6 +423,19 @@ AbstractStaticItemModel * CustomFunctionData::repeatLuaItemModel()
return mdl;
}

// static
AbstractStaticItemModel * CustomFunctionData::repeatSetScreenItemModel()
{
AbstractStaticItemModel * mdl = new AbstractStaticItemModel();
mdl->setName("customfunctiondata.repeatSetScreen");

mdl->appendToItemList(repeatToString(-1, false), -1);
mdl->appendToItemList(repeatToString(0, false), 0);

mdl->loadItemList();
return mdl;
}

// static
AbstractStaticItemModel * CustomFunctionData::playSoundItemModel()
{
Expand Down
1 change: 1 addition & 0 deletions companion/src/firmwares/customfunctiondata.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ class CustomFunctionData {
static QString gvarAdjustModeToString(const int value);
static AbstractStaticItemModel * repeatItemModel();
static AbstractStaticItemModel * repeatLuaItemModel();
static AbstractStaticItemModel * repeatSetScreenItemModel();
static AbstractStaticItemModel * playSoundItemModel();
static AbstractStaticItemModel * harpicItemModel();
static AbstractStaticItemModel * gvarAdjustModeItemModel();
Expand Down
25 changes: 19 additions & 6 deletions companion/src/modeledit/customfunctions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ CustomFunctionsPanel::CustomFunctionsPanel(QWidget * parent, ModelData * model,
harpicId = tabModelFactory->registerItemModel(CustomFunctionData::harpicItemModel());
repeatId = tabModelFactory->registerItemModel(CustomFunctionData::repeatItemModel());
repeatLuaId = tabModelFactory->registerItemModel(CustomFunctionData::repeatLuaItemModel());
repeatSetScreenId = tabModelFactory->registerItemModel(CustomFunctionData::repeatSetScreenItemModel());
gvarAdjustModeId = tabModelFactory->registerItemModel(CustomFunctionData::gvarAdjustModeItemModel());

tabFilterFactory = new FilteredItemModelFactory();
Expand Down Expand Up @@ -209,6 +210,8 @@ CustomFunctionsPanel::CustomFunctionsPanel(QWidget * parent, ModelData * model,
fswtchRepeat[i]->setProperty("index", i);
if (functions[i].func == FuncPlayScript || functions[i].func == FuncRGBLed)
fswtchRepeat[i]->setModel(tabModelFactory->getItemModel(repeatLuaId));
else if (functions[i].func == FuncSetScreen && !Boards::getCapability(firmware->getBoard(), Board::HasColorLcd))
fswtchRepeat[i]->setModel(tabModelFactory->getItemModel(repeatSetScreenId));
else
fswtchRepeat[i]->setModel(tabModelFactory->getItemModel(repeatId));
fswtchRepeat[i]->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Fixed);
Expand Down Expand Up @@ -550,14 +553,24 @@ void CustomFunctionsPanel::refreshCustomFunction(int i, bool modified)
widgetsMask |= CUSTOM_FUNCTION_SOURCE_PARAM;
}
else if (func == FuncSetScreen) {
if (modified)
if (modified) {
cfn.param = (uint8_t)fswtchParam[i]->value();
cfn.repeatParam = fswtchRepeat[i]->currentData().toInt();
}
fswtchParam[i]->setDecimals(0);
fswtchParam[i]->setMinimum(1);
if(model)
fswtchParam[i]->setMaximum(model->getCustomScreensCount());
else
fswtchParam[i]->setMaximum(1);
if (Boards::getCapability(firmware->getBoard(), Board::HasColorLcd)) {
fswtchParam[i]->setMinimum(1);
if(model)
fswtchParam[i]->setMaximum(model->getCustomScreensCount());
else
fswtchParam[i]->setMaximum(1);
} else {
fswtchParam[i]->setMinimum(0);
fswtchParam[i]->setMaximum(4);
widgetsMask |= CUSTOM_FUNCTION_REPEAT;
fswtchRepeat[i]->setModel(tabModelFactory->getItemModel(repeatSetScreenId));
fswtchRepeat[i]->setCurrentIndex(fswtchRepeat[i]->findData(cfn.repeatParam));
}
fswtchParam[i]->setSingleStep(1);
fswtchParam[i]->setValue(cfn.param);
widgetsMask |= CUSTOM_FUNCTION_NUMERIC_PARAM;
Expand Down
1 change: 1 addition & 0 deletions companion/src/modeledit/customfunctions.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ class CustomFunctionsPanel : public GenericPanel
int harpicId;
int repeatId;
int repeatLuaId;
int repeatSetScreenId;
int gvarAdjustModeId;

QSet<QString> tracksSet;
Expand Down
54 changes: 54 additions & 0 deletions radio/src/cfn_sort.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ Functions cfn_sorted[] = {
/* Push CS */ FUNC_PUSH_CUST_SWITCH,
#endif
/* RGB LED 灯 */ FUNC_RGB_LED,
#if !defined(COLORLCD)
/* Set Screen */ FUNC_SET_SCREEN,
#endif
/* Vario传感器 */ FUNC_VARIO,
#elif defined(TRANSLATIONS_CZ)
#if defined(COLORLCD)
Expand Down Expand Up @@ -100,6 +103,9 @@ Functions cfn_sorted[] = {
#endif
/* Reset */ FUNC_RESET,
/* RGB světlo */ FUNC_RGB_LED,
#if !defined(COLORLCD)
/* Set Screen */ FUNC_SET_SCREEN,
#endif
/* Snímek LCD */ FUNC_SCREENSHOT,
#if defined(DEBUG)
/* Test */ FUNC_TEST,
Expand Down Expand Up @@ -141,6 +147,9 @@ Functions cfn_sorted[] = {
/* RGB led */ FUNC_RGB_LED,
/* Ræs tilstand */ FUNC_RACING_MODE,
/* SD Log */ FUNC_LOGS,
#if !defined(COLORLCD)
/* Set Screen */ FUNC_SET_SCREEN,
#endif
#if defined(OLED_SCREEN)
/* Skarphed */ FUNC_BACKLIGHT,
#endif
Expand Down Expand Up @@ -194,6 +203,9 @@ Functions cfn_sorted[] = {
/* SetFailsafe */ FUNC_SET_FAILSAFE,
#if defined(COLORLCD)
/* Set Main Screen */ FUNC_SET_SCREEN,
#endif
#if !defined(COLORLCD)
/* Set Screen */ FUNC_SET_SCREEN,
#endif
/* Setze */ FUNC_SET_TIMER,
/* Spiel Töne */ FUNC_PLAY_SOUND,
Expand Down Expand Up @@ -244,6 +256,9 @@ Functions cfn_sorted[] = {
#if defined(COLORLCD)
/* Set Main Screen */ FUNC_SET_SCREEN,
#endif
#if !defined(COLORLCD)
/* Set Screen */ FUNC_SET_SCREEN,
#endif
#if defined(DEBUG)
/* Test */ FUNC_TEST,
#endif
Expand Down Expand Up @@ -288,6 +303,9 @@ Functions cfn_sorted[] = {
#if defined(COLORLCD)
/* Set Main Screen */ FUNC_SET_SCREEN,
#endif
#if !defined(COLORLCD)
/* Set Screen */ FUNC_SET_SCREEN,
#endif
#if defined(DEBUG)
/* Test */ FUNC_TEST,
#endif
Expand Down Expand Up @@ -332,6 +350,9 @@ Functions cfn_sorted[] = {
#endif
/* RGB leds */ FUNC_RGB_LED,
/* Script Lua */ FUNC_PLAY_SCRIPT,
#if !defined(COLORLCD)
/* Set Screen */ FUNC_SET_SCREEN,
#endif
#if defined(DEBUG)
/* Test */ FUNC_TEST,
#endif
Expand Down Expand Up @@ -367,6 +388,9 @@ Functions cfn_sorted[] = {
/* SD Logs */ FUNC_LOGS,
/* Set */ FUNC_SET_TIMER,
/* SetFailsafe */ FUNC_SET_FAILSAFE,
#if !defined(COLORLCD)
/* Set Screen */ FUNC_SET_SCREEN,
#endif
#if defined(DEBUG)
/* Test */ FUNC_TEST,
#endif
Expand Down Expand Up @@ -418,6 +442,9 @@ Functions cfn_sorted[] = {
/* Script Lua */ FUNC_PLAY_SCRIPT,
/* Set */ FUNC_SET_TIMER,
/* SetFailsafe */ FUNC_SET_FAILSAFE,
#if !defined(COLORLCD)
/* Set Screen */ FUNC_SET_SCREEN,
#endif
#if defined(COLORLCD)
/* Setta Schermo Princ. */ FUNC_SET_SCREEN,
#endif
Expand All @@ -444,6 +471,9 @@ Functions cfn_sorted[] = {
#endif
/* RGB LED */ FUNC_RGB_LED,
/* SDログ出力 */ FUNC_LOGS,
#if !defined(COLORLCD)
/* Set Screen */ FUNC_SET_SCREEN,
#endif
/* オーディオアンプ OFF */ FUNC_DISABLE_AUDIO_AMP,
/* サウンド再生 */ FUNC_PLAY_SOUND,
/* ダイヤル */ FUNC_VOLUME,
Expand Down Expand Up @@ -512,6 +542,9 @@ Functions cfn_sorted[] = {
#if defined(COLORLCD)
/* Set Main Screen */ FUNC_SET_SCREEN,
#endif
#if !defined(COLORLCD)
/* Set Screen */ FUNC_SET_SCREEN,
#endif
#if defined(DEBUG)
/* Test */ FUNC_TEST,
#endif
Expand Down Expand Up @@ -551,6 +584,9 @@ Functions cfn_sorted[] = {
/* RGB ledy */ FUNC_RGB_LED,
#if defined(COLORLCD)
/* Set Main Screen */ FUNC_SET_SCREEN,
#endif
#if !defined(COLORLCD)
/* Set Screen */ FUNC_SET_SCREEN,
#endif
/* SetFailsafe */ FUNC_SET_FAILSAFE,
/* SkryptyLua */ FUNC_PLAY_SCRIPT,
Expand Down Expand Up @@ -598,6 +634,9 @@ Functions cfn_sorted[] = {
/* Rep Valor */ FUNC_PLAY_VALUE,
/* Reset */ FUNC_RESET,
/* Script Lua */ FUNC_PLAY_SCRIPT,
#if !defined(COLORLCD)
/* Set Screen */ FUNC_SET_SCREEN,
#endif
/* Sobrescrv */ FUNC_OVERRIDE_CHANNEL,
#if defined(DEBUG)
/* Test */ FUNC_TEST,
Expand All @@ -621,6 +660,9 @@ Functions cfn_sorted[] = {
#endif
/* RGB подсветка */ FUNC_RGB_LED,
/* SD логи */ FUNC_LOGS,
#if !defined(COLORLCD)
/* Set Screen */ FUNC_SET_SCREEN,
#endif
/* Авар управ */ FUNC_SET_FAILSAFE,
/* Варио */ FUNC_VARIO,
/* Вибро */ FUNC_HAPTIC,
Expand Down Expand Up @@ -679,6 +721,9 @@ Functions cfn_sorted[] = {
/* Pausa Musik */ FUNC_BACKGND_MUSIC_PAUSE,
/* Range check */ FUNC_RANGECHECK,
/* RGB ledljus */ FUNC_RGB_LED,
#if !defined(COLORLCD)
/* Set Screen */ FUNC_SET_SCREEN,
#endif
/* Skärmbild */ FUNC_SCREENSHOT,
/* Spara trimmar */ FUNC_INSTANT_TRIM,
/* Spela ljud */ FUNC_PLAY_SOUND,
Expand All @@ -705,6 +750,9 @@ Functions cfn_sorted[] = {
/* Push CS */ FUNC_PUSH_CUST_SWITCH,
#endif
/* RGB led燈 */ FUNC_RGB_LED,
#if !defined(COLORLCD)
/* Set Screen */ FUNC_SET_SCREEN,
#endif
/* Vario傳感器 */ FUNC_VARIO,
#if defined(OLED_SCREEN)
/* 亮度 */ FUNC_BACKLIGHT,
Expand Down Expand Up @@ -789,6 +837,9 @@ Functions cfn_sorted[] = {
#endif
/* RGB leds */ FUNC_RGB_LED,
/* SD лог */ FUNC_LOGS,
#if !defined(COLORLCD)
/* Set Screen */ FUNC_SET_SCREEN,
#endif
#else
/* Adjust */ FUNC_ADJUST_GVAR,
/* Audio Amp Off */ FUNC_DISABLE_AUDIO_AMP,
Expand Down Expand Up @@ -828,6 +879,9 @@ Functions cfn_sorted[] = {
#if defined(COLORLCD)
/* Set Main Screen */ FUNC_SET_SCREEN,
#endif
#if !defined(COLORLCD)
/* Set Screen */ FUNC_SET_SCREEN,
#endif
#if defined(DEBUG)
/* Test */ FUNC_TEST,
#endif
Expand Down
2 changes: 1 addition & 1 deletion radio/src/dataconstants.h
Original file line number Diff line number Diff line change
Expand Up @@ -681,8 +681,8 @@ enum Functions {
FUNC_RACING_MODE,
#if defined(COLORLCD) || defined(CFN_ONLY)
FUNC_DISABLE_TOUCH,
FUNC_SET_SCREEN,
#endif
FUNC_SET_SCREEN,
FUNC_DISABLE_AUDIO_AMP,
FUNC_RGB_LED,
#if defined(VIDEO_SWITCH) || defined(CFN_ONLY)
Expand Down
2 changes: 1 addition & 1 deletion radio/src/edgetx.h
Original file line number Diff line number Diff line change
Expand Up @@ -845,7 +845,7 @@ enum TelemetryViews {
TELEMETRY_VIEW_MAX = TELEMETRY_CUSTOM_SCREEN_4
};

extern uint8_t s_frsky_view;
extern uint8_t selectedTelemView;

constexpr uint32_t EARTH_RADIUS = 6371009;

Expand Down
9 changes: 6 additions & 3 deletions radio/src/functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -428,16 +428,19 @@ void evalFunctions(CustomFunctionData * functions, CustomFunctionsContext & func
newActiveFunctions |= (1u << FUNCTION_DISABLE_AUDIO_AMP);
break;
#endif
#if defined(COLORLCD)
case FUNC_SET_SCREEN:
if (isRepeatDelayElapsed(functions, functionsContext, i)) {
TRACE("SET VIEW %d", (CFN_PARAM(cfn)));
#if defined(COLORLCD)
int8_t screenNumber = max(0, CFN_PARAM(cfn) - 1);
setRequestedMainView(screenNumber);
mainRequestFlags |= (1u << REQUEST_MAIN_VIEW);
#else
extern void showTelemScreen(uint8_t index);
showTelemScreen(CFN_PARAM(cfn));
#endif
}
break;
#endif
#if defined(VIDEO_SWITCH)
case FUNC_LCD_TO_VIDEO:
switchToVideo();
Expand Down Expand Up @@ -559,9 +562,9 @@ const char* funcGetLabel(uint8_t func)
#if defined(COLORLCD)
case FUNC_DISABLE_TOUCH:
return STR_SF_DISABLE_TOUCH;
#endif
case FUNC_SET_SCREEN:
return STR_SF_SET_SCREEN;
#endif
#if defined(AUDIO_MUTE_GPIO)
case FUNC_DISABLE_AUDIO_AMP:
return STR_SF_DISABLE_AUDIO_AMP;
Expand Down
11 changes: 10 additions & 1 deletion radio/src/gui/128x64/model_special_functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,11 @@ void menuSpecialFunctions(event_t event, CustomFunctionData * functions, CustomF
lcdDrawTextAtIndex(MODEL_SPECIAL_FUNC_3RD_COLUMN, y, STR_FUNCSOUNDS, val_displayed, attr);
}
#endif
else if (func == FUNC_SET_SCREEN) {
val_min = 0;
val_max = 4;
lcdDrawNumber(MODEL_SPECIAL_FUNC_3RD_COLUMN + 3*FW, y, val_displayed, attr|LEFT);
}
#if defined(HAPTIC)
else if (func == FUNC_HAPTIC) {
val_max = 3;
Expand Down Expand Up @@ -496,7 +501,11 @@ void menuSpecialFunctions(event_t event, CustomFunctionData * functions, CustomF
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,
(func == FUNC_SET_SCREEN ? 0 : 60/CFN_PLAY_REPEAT_MUL),
eeFlags);
}
}
else if (attr) {
Expand Down
12 changes: 6 additions & 6 deletions radio/src/gui/128x64/view_telemetry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

#define STATUS_BAR_Y (7*FH+1)

uint8_t s_frsky_view = 0;
uint8_t selectedTelemView = 0;

#define BAR_LEFT 25
#define BAR_WIDTH 100
Expand Down Expand Up @@ -163,7 +163,7 @@ bool displayCustomTelemetryScreen(uint8_t index)
{
TelemetryScreenData & screen = g_model.screens[index];

if (IS_BARS_SCREEN(s_frsky_view)) {
if (IS_BARS_SCREEN(selectedTelemView)) {
return displayGaugesTelemetryScreen(screen);
}

Expand All @@ -175,19 +175,19 @@ bool displayCustomTelemetryScreen(uint8_t index)
bool displayTelemetryScreen()
{
#if defined(LUA)
if (TELEMETRY_SCREEN_TYPE(s_frsky_view) == TELEMETRY_SCREEN_TYPE_SCRIPT) {
if (TELEMETRY_SCREEN_TYPE(selectedTelemView) == TELEMETRY_SCREEN_TYPE_SCRIPT) {
return isTelemetryScriptAvailable(); // contents will be drawn by Lua Task
}
#endif

if (TELEMETRY_SCREEN_TYPE(s_frsky_view) == TELEMETRY_SCREEN_TYPE_NONE) {
if (TELEMETRY_SCREEN_TYPE(selectedTelemView) == TELEMETRY_SCREEN_TYPE_NONE) {
return false;
}

drawTelemetryTopBar();

if (s_frsky_view < MAX_TELEMETRY_SCREENS) {
return displayCustomTelemetryScreen(s_frsky_view);
if (selectedTelemView < MAX_TELEMETRY_SCREENS) {
return displayCustomTelemetryScreen(selectedTelemView);
}

return true;
Expand Down
Loading
Loading