Refactor code quite heavily.
[qzeecontrol] / btconnector.cpp
index 17f978f..57fafb6 100644 (file)
@@ -73,14 +73,21 @@ void BtConnector::readData(){
      * first seems to suffice.
      */
     if(data.at(0) == 5){
-        // Joystick movement
-        _x = (int)(signed char) data.at(4);
-        _y = (int)(signed char) data.at(5);
+        /*
+         * Joystick movement
+         *
+         * X-Axis: positive values -> right, negative values -> left
+         * Y-Axis: positive values -> down, negative values -> up
+         */
+
+        setX((int)(signed char) data.at(4));
+        setY((int)(signed char) data.at(5));
 
-        emit(xChanged(_x));
-        emit(yChanged(_y));
         emit(stickMoved(_x, _y));
 
+        /*
+         * Emulate a digital joystick.
+         */
         if(_up && (_y > -threshold())){
             setUp(false);
         }else if(!_up && (_y < -threshold())){
@@ -104,9 +111,10 @@ void BtConnector::readData(){
         }else if(!_right && (_x > threshold())){
             setRight(true);
         }
-    }else if(data.at(0) == 8){
-        // Button press
+    }else if(data.at(0) == 8){ 
         /*
+         * Button presses
+         *
          * A -> 0, B -> 1, C -> 2, D ->3
          * At index 3 to 6 (inclusive)
          */
@@ -129,20 +137,16 @@ void BtConnector::readData(){
                 bool val = (buttonMap & (1 << i)) > 0;
                 switch (i){
                 case 0:
-                    _a = val;
-                    emit (aChanged(val));
+                    setA(val);
                     break;
                 case 1:
-                    _b = val;
-                    emit (bChanged(val));
+                    setB(val);
                     break;
                 case 2:
-                    _c = val;
-                    emit (cChanged(val));
+                    setC(val);
                     break;
                 case 3:
-                    _d = val;
-                    emit (dChanged(val));
+                    setD(val);
                     break;
                 }
             }