JoystickAxis.cc 2.61 KB
Newer Older
1
#include "JoystickAxis.h"
2
#include "JoystickInput.h"
3
#include "ui_JoystickAxis.h"
4
#include "UASManager.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 41 42 43 44 45 46 47 48 49 50 51 52 53
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();
    }
    this->setActiveUAS(UASManager::instance()->getActiveUAS());
}

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 58
    JoystickInput::JOYSTICK_INPUT_MAPPING mapping = (JoystickInput::JOYSTICK_INPUT_MAPPING)newMapping;
    emit mappingChanged(id, mapping);
    updateUIBasedOnUAS(UASManager::instance()->getActiveUAS(), 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::setActiveUAS(UASInterface* uas)
72 73 74 75 76
{
    updateUIBasedOnUAS(uas, (JoystickInput::JOYSTICK_INPUT_MAPPING)ui->comboBox->currentIndex());
}

void JoystickAxis::updateUIBasedOnUAS(UASInterface* uas, JoystickInput::JOYSTICK_INPUT_MAPPING axisMapping)
77
{
78 79 80
    // 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
81 82
    // This causes us to default to systems with no negative throttle.
    if (((uas && !uas->systemCanReverse()) || !uas) && axisMapping == JoystickInput::JOYSTICK_INPUT_MAPPING_THROTTLE)
83 84
    {
        ui->progressBar->setRange(0, 100);
85
        ui->rangeCheckBox->show();
86 87 88 89
    }
    else
    {
        ui->progressBar->setRange(-100, 100);
90
        ui->rangeCheckBox->hide();
91 92
    }
}