]> git.defcon.no Git - rctxduino/commitdiff
The code is now functional for the 4 first channels, also applied some simple pulldow...
authorHans Åge Martinsen <hamartin@moshwire.com>
Sat, 10 Sep 2011 13:56:38 +0000 (15:56 +0200)
committerHans Åge Martinsen <hamartin@moshwire.com>
Sat, 10 Sep 2011 13:56:38 +0000 (15:56 +0200)
tools/jstt/jstt.cpp
tools/jstt/jstt.h
tools/jstt/jstt.ui
tools/jstt/moc_jstt.cpp
tools/jstt/ui_jstt.h

index 4e197db831608a5d9ae01e8d223a97ef23c5ab91..d1bcdc83a8d2a942bc59da2bcfb94fc6f5cf7e79 100644 (file)
@@ -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();
 }
index c2123e5a44bb26473634832f77a2f297ff06d2b0..acbc312878c1d9aeac33d3efed0a50e21bcf9bb2 100644 (file)
@@ -5,8 +5,11 @@
 #include <QStringList>
 #include <SDL/SDL.h>
 #include <QTimer>
+#include <QProgressBar>
+#include <QLabel>
 
-#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
index b9a6a0788ba568f289abc4a9a41400b52e46a091..9abab6b8dbe53637003fb6869399f0135c08c278 100644 (file)
       <layout class="QHBoxLayout" name="Channel_values">
        <item>
         <widget class="QLabel" name="Chan_1_val">
+         <property name="layoutDirection">
+          <enum>Qt::RightToLeft</enum>
+         </property>
          <property name="text">
           <string>TextLabel</string>
          </property>
        </item>
        <item>
         <widget class="QLabel" name="Chan_2_val">
+         <property name="layoutDirection">
+          <enum>Qt::RightToLeft</enum>
+         </property>
          <property name="text">
           <string>TextLabel</string>
          </property>
        </item>
        <item>
         <widget class="QLabel" name="Chan_3_val">
+         <property name="layoutDirection">
+          <enum>Qt::RightToLeft</enum>
+         </property>
          <property name="text">
           <string>TextLabel</string>
          </property>
        </item>
        <item>
         <widget class="QLabel" name="Chan_4_val">
+         <property name="layoutDirection">
+          <enum>Qt::RightToLeft</enum>
+         </property>
          <property name="text">
           <string>TextLabel</string>
          </property>
      </item>
     </layout>
    </widget>
-   <zorder>verticalLayoutWidget_2</zorder>
-   <zorder>Chan_2_val</zorder>
   </widget>
   <widget class="QToolBar" name="mainToolBar">
    <attribute name="toolBarArea">
index eff15f47622a70ce6226fa1a67eeedf714b67d28..32463ef164add8370e927fae22273fbe7740c08d 100644 (file)
@@ -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;
 }
index 721bc5fe7f143585e6a5b9f87cf21bacc1f955df..6cd6340083256d9ed804c2a4495f960501a4c52d 100644 (file)
@@ -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);