Skip to content

Commit

Permalink
Simulator re-orientate throttle from horizontal to vertical
Browse files Browse the repository at this point in the history
  • Loading branch information
elecpower committed Sep 20, 2024
1 parent e38edf3 commit 34d395d
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 23 deletions.
8 changes: 4 additions & 4 deletions companion/src/firmwares/boards.h
Original file line number Diff line number Diff line change
Expand Up @@ -162,13 +162,13 @@ namespace Board {

enum StickAxesSurface {
STICK_AXIS_SURFACE_RH = 0, // Steering
STICK_AXIS_SURFACE_LH, // Throttle
STICK_AXIS_SURFACE_LV, // Throttle
STICK_AXIS_SURFACE_COUNT
};

enum TrimAxesSurface {
TRIM_AXIS_SURFACE_RH = 0,
TRIM_AXIS_SURFACE_LH,
TRIM_AXIS_SURFACE_LH, // Throttle axis vertical but its trim horizontal in lcd
TRIM_AXIS_SURFACE_T3,
TRIM_AXIS_SURFACE_T4,
TRIM_AXIS_SURFACE_T5,
Expand All @@ -182,8 +182,8 @@ namespace Board {
{
TRIM_SW_SURFACE_RH_DEC,
TRIM_SW_SURFACE_RH_INC,
TRIM_SW_SURFACE_LH_DEC,
TRIM_SW_SURFACE_LH_INC,
TRIM_SW_SURFACE_LH_DEC, // Throttle axis vertical but its trim horizontal in lcd
TRIM_SW_SURFACE_LH_INC, // Throttle axis vertical but its trim horizontal in lcd
TRIM_SW_SURFACE_T3_DEC,
TRIM_SW_SURFACE_T3_INC,
TRIM_SW_SURFACE_T4_DEC,
Expand Down
55 changes: 36 additions & 19 deletions companion/src/simulation/widgets/virtualjoystickwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,12 @@ VirtualJoystickWidget::VirtualJoystickWidget(QWidget *parent, QChar side, bool s
hTrimWidget = createTrimWidget('H');
vTrimWidget = createTrimWidget('V');

if (isBoardSurface)
vTrimWidget->hide();
if (isBoardSurface) {
if (stickSide == 'L')
vTrimWidget->hide();
else
vTrimWidget->hide();
}

layout->addWidget(vTrimWidget, 1, colvt, 1, 1);
layout->addWidget(hTrimWidget, 2, 2, 1, 1);
Expand All @@ -114,9 +118,16 @@ VirtualJoystickWidget::VirtualJoystickWidget(QWidget *parent, QChar side, bool s
btnbox->addWidget(btnFixX = createButtonWidget(FIX_X));
btnbox->addWidget(btnHoldX = createButtonWidget(HOLD_X));
if (isBoardSurface) {
btnHoldY->hide();
btnFixY->hide();
btnFixX->hide();
if (stickSide == 'L') {
btnHoldX->hide();
btnFixY->hide();
btnFixX->hide();
}
else {
btnHoldY->hide();
btnFixY->hide();
btnFixX->hide();
}
}

layout->addLayout(btnbox, 1, colbb, 1, 1);
Expand Down Expand Up @@ -182,9 +193,9 @@ void VirtualJoystickWidget::setStickAxisValue(int index, int value)

if (isBoardSurface) {
switch (index) {
case STICK_AXIS_SURFACE_LH :
case STICK_AXIS_SURFACE_LV :
if (stickSide == 'L')
setStickX(rvalue);
setStickY(rvalue);
break;
case STICK_AXIS_SURFACE_RH :
if (stickSide == 'R')
Expand Down Expand Up @@ -322,8 +333,18 @@ void VirtualJoystickWidget::setStickColor(const QColor & color)

void VirtualJoystickWidget::loadDefaultsForMode(const unsigned mode)
{
if (isBoardSurface)
setStickConstraint(FIX_Y, true);
if (isBoardSurface) {
if (stickSide == 'L') {
setStickX(0.0);
setStickConstraint(FIX_X, true);
onNodeXChanged();
}
else {
setStickY(0.0);
setStickConstraint(FIX_Y, true);
onNodeYChanged();
}
}
else {
if (((mode & 1) && stickSide == 'L') || (!(mode & 1) && stickSide == 'R')) {
setStickConstraint(HOLD_Y, true);
Expand Down Expand Up @@ -427,22 +448,22 @@ QToolButton * VirtualJoystickWidget::createButtonWidget(int type)
switch (type) {
case HOLD_Y:
btnLabel = tr("Hld Y");
tooltip = tr("Hold Vertical stick position.");
tooltip = tr("Hold Vertical position.");
icon = Simulator::SimulatorIcon("hold_y");
break;
case FIX_Y:
btnLabel = tr("Fix Y");
tooltip = tr("Prevent Vertical movement of stick.");
tooltip = tr("Prevent Vertical movement.");
icon = Simulator::SimulatorIcon("fixed_y");
break;
case FIX_X:
btnLabel = tr("Fix X");
tooltip = tr("Prevent Horizontal movement of stick.");
tooltip = tr("Prevent Horizontal movement.");
icon = Simulator::SimulatorIcon("fixed_x");
break;
case HOLD_X:
btnLabel = tr("Hld X");
tooltip = tr("Hold Horizontal stick position.");
tooltip = tr("Hold Horizontal position.");
icon = Simulator::SimulatorIcon("hold_x");
break;
default:
Expand Down Expand Up @@ -472,11 +493,7 @@ QLayout *VirtualJoystickWidget::createNodeValueLayout(QChar type, QLabel *& valL
val->setObjectName(QString("val_%1").arg(type));
val->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
val->setAlignment(Qt::AlignCenter);
#if QT_VERSION < QT_VERSION_CHECK(5, 11, 0)
val->setMinimumWidth(val->fontMetrics().width("-100 "));
#else
val->setMinimumWidth(val->fontMetrics().horizontalAdvance("-100 "));
#endif
QVBoxLayout * layout = new QVBoxLayout();
layout->setContentsMargins(2, 2, 2, 2);
layout->setSpacing(2);
Expand All @@ -494,9 +511,9 @@ int VirtualJoystickWidget::getStickIndex(QChar type)
if (isBoardSurface) {
if (stickSide == 'L') {
if (type == 'H')
return STICK_AXIS_SURFACE_LH;
return STICK_AXIS_SURFACE_LV;
else
return STICK_AXIS_SURFACE_LH;
return STICK_AXIS_SURFACE_LV;
}
else {
if (type == 'H')
Expand Down

0 comments on commit 34d395d

Please sign in to comment.