]> git.defcon.no Git - rctxduino/blobdiff - tools/jstt/jstt.cpp
The code is now functional for the 4 first channels, also applied some simple pulldow...
[rctxduino] / tools / jstt / jstt.cpp
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();
 }