JoystickWidget.cc 2.11 KB
Newer Older
pixhawk's avatar
pixhawk committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
#include "JoystickWidget.h"
#include "ui_JoystickWidget.h"
#include <QDebug>

JoystickWidget::JoystickWidget(JoystickInput* joystick, QWidget *parent) :
        QDialog(parent),
        m_ui(new Ui::JoystickWidget)
{
    m_ui->setupUi(this);
    this->joystick = joystick;


    connect(this->joystick, SIGNAL(joystickChanged(double,double,double,double,int,int)), this, SLOT(updateJoystick(double,double,double,double,int,int)));
    connect(this->joystick, SIGNAL(buttonPressed(int)), this, SLOT(pressKey(int)));

    // Display the widget
    this->window()->setWindowTitle(tr("Joystick Settings"));
    this->show();
}

JoystickWidget::~JoystickWidget()
{
    delete m_ui;
}

void JoystickWidget::updateJoystick(double roll, double pitch, double yaw, double thrust, int xHat, int yHat)
{
    setX(roll);
    setY(pitch);
pixhawk's avatar
pixhawk committed
30
    setZ(yaw);
pixhawk's avatar
pixhawk committed
31
    setThrottle(thrust);
pixhawk's avatar
pixhawk committed
32
    setHat(xHat, yHat);
pixhawk's avatar
pixhawk committed
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
}

void JoystickWidget::changeEvent(QEvent *e)
{
    switch (e->type()) {
    case QEvent::LanguageChange:
        m_ui->retranslateUi(this);
        break;
    default:
        break;
    }
}


void JoystickWidget::setThrottle(float thrust)
{
    m_ui->thrust->setValue(thrust*100);
}
pixhawk's avatar
pixhawk committed
51

pixhawk's avatar
pixhawk committed
52 53 54 55 56
void JoystickWidget::setX(float x)
{
    m_ui->xSlider->setValue(x*100);
    m_ui->xValue->display(x*100);
}
pixhawk's avatar
pixhawk committed
57

pixhawk's avatar
pixhawk committed
58 59 60 61 62
void JoystickWidget::setY(float y)
{
    m_ui->ySlider->setValue(y*100);
    m_ui->yValue->display(y*100);
}
pixhawk's avatar
pixhawk committed
63 64 65 66 67 68 69 70 71 72 73

void JoystickWidget::setZ(float z)
{
    m_ui->dial->setValue(z*100);
}

void JoystickWidget::setHat(float x, float y)
{
    qDebug() << __FILE__ << __LINE__ << "HAT X:" << x << "HAT Y:" << y;
}

pixhawk's avatar
pixhawk committed
74 75 76 77 78 79 80 81
void JoystickWidget::pressKey(int key)
{
    QString colorstyle;
    QColor heartbeatColor = QColor(20, 200, 20);
    colorstyle = colorstyle.sprintf("QGroupBox { border: 1px solid #EEEEEE; border-radius: 4px; padding: 0px; margin: 0px; background-color: #%02X%02X%02X;}",
                                    heartbeatColor.red(), heartbeatColor.green(), heartbeatColor.blue());
    m_ui->button0Label->setStyleSheet(colorstyle);
    m_ui->button0Label->setAutoFillBackground(true);
pixhawk's avatar
pixhawk committed
82
    qDebug() << __FILE__ << __LINE__ << "KEY" << key << " pressed on joystick";
pixhawk's avatar
pixhawk committed
83
}