Skip to content

Commit 8647110

Browse files
committed
fix(cpn): topbar zone cnt and width init
1 parent b3836d5 commit 8647110

File tree

8 files changed

+89
-9
lines changed

8 files changed

+89
-9
lines changed

companion/src/firmwares/customisation_data.cpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,31 @@
2020
*/
2121

2222
#include "customisation_data.h"
23+
#include "eeprominterface.h"
24+
#include "helpers.h"
2325

2426
// cannot use QColor so use formula from libopenui_defines.h
2527
#define RADIO_RGB(r, g, b) \
2628
(uint16_t)((((r)&0xF8) << 8) + (((g)&0xFC) << 3) + (((b)&0xF8) >> 3))
2729
#define WHITE RADIO_RGB(0xFF, 0xFF, 0xFF)
2830
#define RED RADIO_RGB(229, 32, 30)
2931

32+
// based on radio/src/gui/colorlcd/libui/etx_lv_theme.h
33+
int layoutValueScaled(int value)
34+
{
35+
Firmware *firmware = getCurrentFirmware();
36+
Board::Type board = firmware->getBoard();
37+
38+
if (firmware->getCapability(IsLandscape)) {
39+
if (Boards::getCapability(board, Board::LcdWidth) == 320)
40+
return ((value * 8 + 5) / 10);
41+
else if (Boards::getCapability(board, Board::LcdWidth) == 800)
42+
return ((value * 11 + 4) / 8);
43+
}
44+
45+
return value;
46+
}
47+
3048
ZoneOptionValue::ZoneOptionValue()
3149
{
3250
clear();
@@ -262,3 +280,14 @@ void RadioLayout::init(const std::string layoutId, CustomScreens& customScreens)
262280
setZoneOptionValue(persistentData.options[j++].value, (bool)false);
263281
}
264282
}
283+
284+
// based on radio/src/gui/colorlcd/mainview/datastructs_screen.h
285+
int RadioLayout::topBarZones()
286+
{
287+
Firmware *firmware = getCurrentFirmware();
288+
Board::Type board = firmware->getBoard();
289+
const int menuHeaderButtonsLeft = layoutValueScaled(47);
290+
const int topBarZoneWidth = layoutValueScaled((firmware->getCapability(IsWideLayout) ? 74 : 70));
291+
return rangeCheck(((Boards::getCapability(board, Board::LcdWidth) - menuHeaderButtonsLeft - 1 +
292+
topBarZoneWidth / 2) / topBarZoneWidth), 0, MAX_TOPBAR_ZONES, 0);
293+
}

companion/src/firmwares/customisation_data.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,4 +191,5 @@ class RadioLayout
191191
};
192192

193193
static void init(const std::string layoutId, CustomScreens & customScreens);
194+
static int topBarZones();
194195
};

companion/src/firmwares/edgetx/yaml_modeldata.cpp

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1029,7 +1029,8 @@ Node convert<ModelData>::encode(const ModelData& rhs)
10291029
modelSettingsVersion = SemanticVersion(VERSION);
10301030

10311031
Node node;
1032-
auto board = getCurrentBoard();
1032+
auto firmware = getCurrentFirmware();
1033+
auto board = firmware->getBoard();
10331034

10341035
bool hasColorLcd = Boards::getCapability(board, Board::HasColorLcd);
10351036

@@ -1242,8 +1243,8 @@ Node convert<ModelData>::encode(const ModelData& rhs)
12421243
node["toplcdTimer"] = rhs.toplcdTimer;
12431244
}
12441245

1245-
if (IS_FAMILY_HORUS_OR_T16(board)) {
1246-
for (int i=0; i<MAX_CUSTOM_SCREENS; i++) {
1246+
if (Boards::getCapability(board, Board::HasColorLcd)) {
1247+
for (int i = 0; i < MAX_CUSTOM_SCREENS; i++) {
12471248
const auto& csd = rhs.customScreens.customScreenData[i];
12481249
if (!csd.isEmpty()) {
12491250
node["screenData"][std::to_string(i)] = csd;
@@ -1254,9 +1255,11 @@ Node convert<ModelData>::encode(const ModelData& rhs)
12541255
if (topbarData && topbarData.IsMap()) {
12551256
node["topbarData"] = topbarData;
12561257
}
1257-
for (int i = 0; i < MAX_TOPBAR_ZONES; i++)
1258-
if (rhs.topbarWidgetWidth[i] > 0)
1258+
for (int i = 0; i < firmware->getCapability(TopBarZones); i++) {
1259+
if (rhs.topbarWidgetWidth[i] > 0) {
12591260
node["topbarWidgetWidth"][std::to_string(i)]["val"] = (int)rhs.topbarWidgetWidth[i];
1261+
}
1262+
}
12601263
node["view"] = rhs.view;
12611264
}
12621265

@@ -1311,7 +1314,8 @@ bool convert<ModelData>::decode(const Node& node, ModelData& rhs)
13111314
{
13121315
if (!node.IsMap()) return false;
13131316

1314-
Board::Type board = getCurrentBoard();
1317+
auto firmware = getCurrentFirmware();
1318+
auto board = firmware->getBoard();
13151319

13161320
unsigned int modelIds[CPN_MAX_MODULES];
13171321
memset(modelIds, 0, sizeof(modelIds));
@@ -1663,6 +1667,22 @@ bool convert<ModelData>::decode(const Node& node, ModelData& rhs)
16631667
YamlValidateLabelsNames(rhs, board);
16641668
rhs.sortMixes(); // critical for Companion and radio that mix lines are in sequence
16651669

1670+
// TODO move to model conversion so any changes reported
1671+
if (Boards::getCapability(board, Board::HasColorLcd)) {
1672+
// total width of topbar widgets cannot exceed firmware topbar zones
1673+
const int fwzones = firmware->getCapability(TopBarZones);
1674+
int usedzones = 0;
1675+
1676+
for (int i = 0; i < MAX_TOPBAR_ZONES; i++) {
1677+
usedzones += rhs.topbarWidgetWidth[i];
1678+
1679+
if (usedzones > fwzones) {
1680+
rhs.topbarWidgetWidth[i] = 0;
1681+
rhs.topBarData.zones[i].clear();
1682+
}
1683+
}
1684+
}
1685+
16661686
return true;
16671687
}
16681688

companion/src/firmwares/eeprominterface.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,10 @@ enum Capability {
7676
HasVarioSink,
7777
Heli,
7878
InputsLength,
79+
IsLandscape,
80+
IsNarrowLayout,
81+
IsPortrait,
82+
IsWideLayout,
7983
KeyShortcuts,
8084
LogicalSwitches,
8185
LuaInputsPerScript,

companion/src/firmwares/modeldata.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ void ModelData::clear()
312312
topBarData.clear();
313313

314314
for (int i = 0; i < MAX_TOPBAR_ZONES; i++)
315-
topbarWidgetWidth[i] = 0;
315+
topbarWidgetWidth[i] = 1;
316316

317317
view = 0;
318318
memset(&registrationId, 0, sizeof(registrationId));
@@ -414,9 +414,11 @@ void ModelData::setDefaultValues(unsigned int id, const GeneralSettings & settin
414414
clear();
415415
used = true;
416416
sprintf(name, "MODEL%02d", id + 1);
417+
417418
for (int i = 0; i < CPN_MAX_MODULES; i++) {
418419
moduleData[i].modelId = id + 1;
419420
}
421+
420422
setDefaultMixes(settings);
421423
setDefaultFunctionSwitches(Boards::getCapability(getCurrentFirmware()->getBoard(), Board::FunctionSwitches));
422424
}

companion/src/firmwares/opentx/opentxinterface.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "opentxinterface.h"
2323
#include "appdata.h"
2424
#include "constants.h"
25+
#include "customisation_data.h"
2526

2627
#include <bitset>
2728
#include <QMessageBox>
@@ -130,6 +131,16 @@ int OpenTxFirmware::getCapability(::Capability capability)
130131
return !id.contains("noheli");
131132
case InputsLength:
132133
return HAS_LARGE_LCD(board) ? 4 : 3;
134+
case IsLandscape:
135+
return Boards::getCapability(board, Board::LcdWidth) > Boards::getCapability(board, Board::LcdHeight);
136+
case IsNarrowLayout:
137+
// based on radio/src/gui/colorlcd/libui/etx_lv_theme.h
138+
return (getCapability(IsPortrait) && Boards::getCapability(board, Board::LcdWidth) == 320);
139+
case IsPortrait:
140+
return !getCapability(IsLandscape);
141+
case IsWideLayout:
142+
// based on radio/src/gui/colorlcd/libui/etx_lv_theme.h
143+
return (!getCapability(IsNarrowLayout) && Boards::getCapability(board, Board::LcdWidth) >= 800);
133144
case KeyShortcuts:
134145
return VERSION_MAJOR > 2 && Boards::getCapability(board, Board::HasColorLcd) ? MAX_KEYSHORTCUTS : 0;
135146
case LogicalSwitches:
@@ -207,7 +218,7 @@ int OpenTxFirmware::getCapability(::Capability capability)
207218
else
208219
return 3;
209220
case TopBarZones:
210-
return Boards::getCapability(board, Board::LcdWidth) > Boards::getCapability(board, Board::LcdHeight) ? 4 : 2;
221+
return Boards::getCapability(board, Board::HasColorLcd) ? RadioLayout::topBarZones() : 0;
211222
case TrainerInputs:
212223
return 16;
213224
case TrimsRange:

companion/src/helpers.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,3 +268,11 @@ class StatusDialog: public QDialog
268268
private:
269269
QLabel *msg;
270270
};
271+
272+
template <typename T>
273+
T rangeCheck(T value, T min, T max, T defaultValue) {
274+
if (value < min || value > max) {
275+
return defaultValue;
276+
}
277+
return value;
278+
}

companion/src/modeledit/colorcustomscreens.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,12 @@ UserInterfacePanel::UserInterfacePanel(QWidget * parent, ModelData & model, Gene
147147

148148
QGridLayout * tbgrid = new QGridLayout();
149149

150-
for (int i = 0; i < firmware->getCapability(TopBarZones); i++) {
150+
const int zones = firmware->getCapability(TopBarZones);
151+
int usedzones = 0;
152+
153+
for (int i = 0; i < zones; i++) {
154+
if (usedzones >= zones) break;
155+
usedzones += model.topbarWidgetWidth[i];
151156
ZonePersistentData & zpd = model.topBarData.zones[i];
152157
QPushButton * btn = new QPushButton(zpd.widgetName.c_str(), this);
153158
btn->setProperty("index", i);

0 commit comments

Comments
 (0)