JoystickAxis.cc 2.74 KB
Newer Older
1
#include "JoystickAxis.h"
2
#include "JoystickInput.h"
3
#include "ui_JoystickAxis.h"
4
#include "MultiVehicleManager.h"
5 6 7 8
#include <QString>

JoystickAxis::JoystickAxis(int id, QWidget *parent) :
    QWidget(parent),
9
    id(id),
10 11 12
    ui(new Ui::JoystickAxis)
{
    ui->setupUi(this);
13
    mappingComboBoxChanged(JoystickInput::JOYSTICK_INPUT_MAPPING_NONE);
14
    ui->label->setText(QString::number(id));
15
    connect(ui->comboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(mappingComboBoxChanged(int)));
16
    connect(ui->invertedCheckBox, SIGNAL(clicked(bool)), this, SLOT(inversionCheckBoxChanged(bool)));
17
    connect(ui->rangeCheckBox, SIGNAL(clicked(bool)), this, SLOT(rangeCheckBoxChanged(bool)));
18 19 20 21 22 23 24
}

JoystickAxis::~JoystickAxis()
{
    delete ui;
}

25
void JoystickAxis::setValue(float value)
26
{
27 28 29
    ui->progressBar->setValue(100.0f * value);
}

30 31 32 33 34 35 36 37 38 39 40
void JoystickAxis::setMapping(JoystickInput::JOYSTICK_INPUT_MAPPING newMapping)
{
    ui->comboBox->setCurrentIndex(newMapping);
    if (newMapping == JoystickInput::JOYSTICK_INPUT_MAPPING_THROTTLE)
    {
        ui->rangeCheckBox->show();
    }
    else
    {
        ui->rangeCheckBox->hide();
    }
41
    this->activeVehicleChanged(MultiVehicleManager::instance()->activeVehicle());
42 43 44 45 46 47 48 49 50 51 52 53
}

void JoystickAxis::setInverted(bool newValue)
{
    ui->invertedCheckBox->setChecked(newValue);
}

void JoystickAxis::setRangeLimit(bool newValue)
{
    ui->rangeCheckBox->setChecked(newValue);
}

54 55
void JoystickAxis::mappingComboBoxChanged(int newMapping)
{
56 57
    JoystickInput::JOYSTICK_INPUT_MAPPING mapping = (JoystickInput::JOYSTICK_INPUT_MAPPING)newMapping;
    emit mappingChanged(id, mapping);
58
    updateUIBasedOnUAS(MultiVehicleManager::instance()->activeVehicle(), mapping);
59
}
60 61 62 63 64

void JoystickAxis::inversionCheckBoxChanged(bool inverted)
{
    emit inversionChanged(id, inverted);
}
65

66 67 68 69 70
void JoystickAxis::rangeCheckBoxChanged(bool limited)
{
    emit rangeChanged(id, limited);
}

71
void JoystickAxis::activeVehicleChanged(Vehicle* vehicle)
72
{
73
    updateUIBasedOnUAS(vehicle, (JoystickInput::JOYSTICK_INPUT_MAPPING)ui->comboBox->currentIndex());
74 75
}

76
void JoystickAxis::updateUIBasedOnUAS(Vehicle* vehicle, JoystickInput::JOYSTICK_INPUT_MAPPING axisMapping)
77
{
78 79 80 81 82 83
    UAS* uas = NULL;
    
    if (vehicle) {
        uas = vehicle->uas();
    }
    
84 85 86
    // Set the throttle display to only positive if:
    // * This is the throttle axis AND
    // * The current UAS can't reverse OR there is no current UAS
87 88
    // This causes us to default to systems with no negative throttle.
    if (((uas && !uas->systemCanReverse()) || !uas) && axisMapping == JoystickInput::JOYSTICK_INPUT_MAPPING_THROTTLE)
89 90
    {
        ui->progressBar->setRange(0, 100);
91
        ui->rangeCheckBox->show();
92 93 94 95
    }
    else
    {
        ui->progressBar->setRange(-100, 100);
96
        ui->rangeCheckBox->hide();
97 98
    }
}