From: Hans Åge Martinsen Date: Sat, 10 Sep 2011 13:56:38 +0000 (+0200) Subject: The code is now functional for the 4 first channels, also applied some simple pulldow... X-Git-Url: https://git.defcon.no/?p=rctxduino;a=commitdiff_plain;h=7fcb511ebdc1482a0d8a5a200e0e6a3a82c4a3d9 The code is now functional for the 4 first channels, also applied some simple pulldown menus for quit, about and help --- diff --git a/tools/jstt/jstt.cpp b/tools/jstt/jstt.cpp index 4e197db..d1bcdc8 100644 --- a/tools/jstt/jstt.cpp +++ b/tools/jstt/jstt.cpp @@ -7,17 +7,29 @@ jstt::jstt(QWidget *parent) : { ui->setupUi(this); - this->joystick = NULL; - this->init(); + joystick = NULL; + bars[0] = ui->Chan_1_bar; + bars[1] = ui->Chan_2_bar; + bars[2] = ui->Chan_3_bar; + bars[3] = ui->Chan_4_bar; + labels[0] = ui->Chan_1_val; + labels[1] = ui->Chan_2_val; + labels[2] = ui->Chan_3_val; + labels[3] = ui->Chan_4_val; + + init(); } jstt::~jstt() { - delete ui; - if( jsIsOpen() ) jsClose(); SDL_Quit(); + + delete ui; + //delete joystick; // This causes warnings that i don't understand + delete [] bars; // Will this be deleted when i delete ui? Does it matter? We're deleting the whole object anyway + delete [] labels; // Same here, will it be deleted when ui is deleted? } void jstt::init() @@ -29,6 +41,7 @@ void jstt::init() for(int i = 0; i < SDL_NumJoysticks(); i++) { jsNames.append(SDL_JoystickName(i)); } + connect(&jsPullTimer, SIGNAL(timeout()), this, SLOT(processJs())); ui->Joysticks->addItems(jsNames); @@ -42,42 +55,68 @@ void jstt::jsOpen(int js) joystick = SDL_JoystickOpen(js); if( joystick ) { - jsPullTimer.start(eventTimeout); + /* + TODO: - TODO: + numAxes = SDL_JoystickNumAxes(joystick); + numButtons = SDL_JoystickNumButtons(joystick); + numHats = SDL_JoystickNumHats(joystick); + numTrackballs = SDL_JoystickNumBalls(joystick); + JoystickTimer.start(eventTimeout); - numAxes = SDL_JoystickNumAxes(joystick); - numButtons = SDL_JoystickNumButtons(joystick); - numHats = SDL_JoystickNumHats(joystick); - numTrackballs = SDL_JoystickNumBalls(joystick); - JoystickTimer.start(eventTimeout); + When we have found out how many axes, buttons etc, we can expand the GUI further + */ - When we have found out how many axes, buttons etc, we can expand the GUI further - */ + jsPullTimer.start(eventTimeout); return; } else { + /* One should make sure the program will react on this situation instead of just returning. */ + return; } } void jstt::jsClose() { - this->jsPullTimer.stop(); + jsPullTimer.stop(); if( joystick ) SDL_JoystickClose(joystick); joystick = NULL; } void jstt::processJs() { - ui->Chan_1_bar->setValue(30); + Sint16 value; + + SDL_JoystickUpdate(); + + /* + This code needs to be fixed so that it iterates through all + axes instead of just the four i am setting up now. + */ + + for(int i = 0; i < 4; i++) { + value = SDL_JoystickGetAxis(joystick, i); + labels[i]->setNum(value); + bars[i]->setValue(percentBar(value)); + } +} + +void jstt::on_actionAbout_triggered() +{ + +} + +void jstt::on_actionHelp_triggered() +{ + } -void jstt::on_Joysticks_currentIndexChanged(int index) +void jstt::on_actionQuit_triggered() { - this->jsOpen(index); + close(); } diff --git a/tools/jstt/jstt.h b/tools/jstt/jstt.h index c2123e5..acbc312 100644 --- a/tools/jstt/jstt.h +++ b/tools/jstt/jstt.h @@ -5,8 +5,11 @@ #include #include #include +#include +#include -#define eventTimeout 1 +#define eventTimeout 100 +#define percentBar(value) (((32768 + value) * 100) / 65536) namespace Ui { class jstt; @@ -19,19 +22,25 @@ public: ~jstt(); protected: + +private: void init(); void jsOpen(int js); void jsClose(); - void processJs(); bool jsIsOpen() { return joystick != NULL; } -private: Ui::jstt *ui; SDL_Joystick *joystick; QTimer jsPullTimer; + QProgressBar *bars[4]; + QLabel *labels[4]; private slots: - void on_Joysticks_currentIndexChanged(int index); + void on_Joysticks_currentIndexChanged(int index) { jsOpen(index); } + void on_actionQuit_triggered(); + void on_actionHelp_triggered(); + void on_actionAbout_triggered(); + void processJs(); }; #endif // JSTT_H diff --git a/tools/jstt/jstt.ui b/tools/jstt/jstt.ui index b9a6a07..9abab6b 100644 --- a/tools/jstt/jstt.ui +++ b/tools/jstt/jstt.ui @@ -248,6 +248,9 @@ + + Qt::RightToLeft + TextLabel @@ -255,6 +258,9 @@ + + Qt::RightToLeft + TextLabel @@ -262,6 +268,9 @@ + + Qt::RightToLeft + TextLabel @@ -269,6 +278,9 @@ + + Qt::RightToLeft + TextLabel @@ -309,8 +321,6 @@ - verticalLayoutWidget_2 - Chan_2_val diff --git a/tools/jstt/moc_jstt.cpp b/tools/jstt/moc_jstt.cpp index eff15f4..32463ef 100644 --- a/tools/jstt/moc_jstt.cpp +++ b/tools/jstt/moc_jstt.cpp @@ -1,7 +1,7 @@ /**************************************************************************** ** Meta object code from reading C++ file 'jstt.h' ** -** Created: Sat Sep 10 02:03:53 2011 +** Created: Sat Sep 10 15:41:52 2011 ** by: The Qt Meta Object Compiler version 62 (Qt 4.6.3) ** ** WARNING! All changes made in this file will be lost! @@ -23,7 +23,7 @@ static const uint qt_meta_data_jstt[] = { 4, // revision 0, // classname 0, 0, // classinfo - 1, 14, // methods + 5, 14, // methods 0, 0, // properties 0, 0, // enums/sets 0, 0, // constructors @@ -32,12 +32,19 @@ static const uint qt_meta_data_jstt[] = { // slots: signature, parameters, type, tag, flags 12, 6, 5, 5, 0x08, + 50, 5, 5, 5, 0x08, + 76, 5, 5, 5, 0x08, + 102, 5, 5, 5, 0x08, + 129, 5, 5, 5, 0x08, 0 // eod }; static const char qt_meta_stringdata_jstt[] = { "jstt\0\0index\0on_Joysticks_currentIndexChanged(int)\0" + "on_actionQuit_triggered()\0" + "on_actionHelp_triggered()\0" + "on_actionAbout_triggered()\0processJs()\0" }; const QMetaObject jstt::staticMetaObject = { @@ -70,9 +77,13 @@ int jstt::qt_metacall(QMetaObject::Call _c, int _id, void **_a) if (_c == QMetaObject::InvokeMetaMethod) { switch (_id) { case 0: on_Joysticks_currentIndexChanged((*reinterpret_cast< int(*)>(_a[1]))); break; + case 1: on_actionQuit_triggered(); break; + case 2: on_actionHelp_triggered(); break; + case 3: on_actionAbout_triggered(); break; + case 4: processJs(); break; default: ; } - _id -= 1; + _id -= 5; } return _id; } diff --git a/tools/jstt/ui_jstt.h b/tools/jstt/ui_jstt.h index 721bc5f..6cd6340 100644 --- a/tools/jstt/ui_jstt.h +++ b/tools/jstt/ui_jstt.h @@ -1,7 +1,7 @@ /******************************************************************************** ** Form generated from reading UI file 'jstt.ui' ** -** Created: Sat Sep 10 01:13:38 2011 +** Created: Sat Sep 10 12:06:42 2011 ** by: Qt User Interface Compiler version 4.6.3 ** ** WARNING! All changes made in this file will be lost when recompiling UI file! @@ -191,21 +191,25 @@ public: Channel_values->setObjectName(QString::fromUtf8("Channel_values")); Chan_1_val = new QLabel(verticalLayoutWidget_2); Chan_1_val->setObjectName(QString::fromUtf8("Chan_1_val")); + Chan_1_val->setLayoutDirection(Qt::RightToLeft); Channel_values->addWidget(Chan_1_val); Chan_2_val = new QLabel(verticalLayoutWidget_2); Chan_2_val->setObjectName(QString::fromUtf8("Chan_2_val")); + Chan_2_val->setLayoutDirection(Qt::RightToLeft); Channel_values->addWidget(Chan_2_val); Chan_3_val = new QLabel(verticalLayoutWidget_2); Chan_3_val->setObjectName(QString::fromUtf8("Chan_3_val")); + Chan_3_val->setLayoutDirection(Qt::RightToLeft); Channel_values->addWidget(Chan_3_val); Chan_4_val = new QLabel(verticalLayoutWidget_2); Chan_4_val->setObjectName(QString::fromUtf8("Chan_4_val")); + Chan_4_val->setLayoutDirection(Qt::RightToLeft); Channel_values->addWidget(Chan_4_val); @@ -229,8 +233,6 @@ public: Std_channels->addLayout(Comboboxes); jstt->setCentralWidget(centralWidget); - verticalLayoutWidget_2->raise(); - Chan_2_val->raise(); mainToolBar = new QToolBar(jstt); mainToolBar->setObjectName(QString::fromUtf8("mainToolBar")); jstt->addToolBar(Qt::TopToolBarArea, mainToolBar);