From bf26c2912ce9533f8382e4f7d18b4ebc2dc93eff Mon Sep 17 00:00:00 2001
From: Ingo Ruhnke <grumbel@gmx.de>
Date: Fri, 19 Jun 2009 17:10:48 +0200
Subject: [PATCH] Some cleanup

---
 TODO                              |  4 ++-
 src/firestorm_dual_controller.cpp | 43 +++----------------------------
 src/firestorm_dual_controller.hpp |  2 --
 src/helper.hpp                    | 18 +++++++++++++
 4 files changed, 25 insertions(+), 42 deletions(-)

diff --git a/TODO b/TODO
index c512068..5b4271b 100644
--- a/TODO
+++ b/TODO
@@ -45,7 +45,9 @@ Stuff to do before 0.5 release:
 
 * create dummy joystick, mouse and keyboard buttons so that the
   devices always act as they should, also figure out the exakt minimum
-  requirements for each device.
+  requirements for each device (i.e. if a device is a
+  joystick/mouse/keyboard is determined if it as certain button or
+  axis).
 
 * add a way to not create a joystick/event device
 
diff --git a/src/firestorm_dual_controller.cpp b/src/firestorm_dual_controller.cpp
index f78fd4b..224772b 100644
--- a/src/firestorm_dual_controller.cpp
+++ b/src/firestorm_dual_controller.cpp
@@ -23,6 +23,7 @@
 #include <string.h>
 #include <boost/format.hpp>
 
+#include "helper.hpp"
 #include "firestorm_dual_controller.hpp"
 
 // 044f:b312
@@ -115,15 +116,6 @@ FirestormDualController::~FirestormDualController()
 
 void
 FirestormDualController::set_rumble(uint8_t left, uint8_t right)
-{
-  if (is_vsb)
-    set_rumble_vsb(left, right);
-  else
-    set_rumble_default(left, right);
-}
-
-void
-FirestormDualController::set_rumble_vsb(uint8_t left, uint8_t right)
 {
   if (left_rumble  != left ||
       right_rumble != right)
@@ -132,20 +124,10 @@ FirestormDualController::set_rumble_vsb(uint8_t left, uint8_t right)
       right_rumble = right;
 
       char cmd[] = { left, right, 0x00, 0x00 };
-      usb_control_msg(handle, 0x21, 0x09, 0x0200, 0x00, cmd, sizeof(cmd), 0);
-    }  
-}
+      if (is_vsb)
+        usb_control_msg(handle, 0x21, 0x09, 0x0200, 0x00, cmd, sizeof(cmd), 0);
+      else
 
-void
-FirestormDualController::set_rumble_default(uint8_t left, uint8_t right)
-{
-  if (left_rumble  != left ||
-      right_rumble != right)
-    {
-      left_rumble  = left;
-      right_rumble = right;
-
-      char cmd[] = { left, right, 0x00, 0x00 };
       usb_control_msg(handle, 0x21, 0x09, 0x02, 0x00, cmd, sizeof(cmd), 0);
     }
 }
@@ -156,23 +138,6 @@ FirestormDualController::set_led(uint8_t status)
   // not supported
 }
 
-// Change the sign
-inline int16_t negate_16(int16_t v)
-{
-  if (v)
-    return ~v;
-  else
-    return v;
-}
-
-inline int16_t scale_8to16(int8_t a)
-{
-  if (a > 0) 
-    return a * 32767 / 127;
-  else
-    return a * 32768 / 128;
-}
-
 bool
 FirestormDualController::read(XboxGenericMsg& msg, bool verbose, int timeout)
 {
diff --git a/src/firestorm_dual_controller.hpp b/src/firestorm_dual_controller.hpp
index e42fdf9..90b36b7 100644
--- a/src/firestorm_dual_controller.hpp
+++ b/src/firestorm_dual_controller.hpp
@@ -38,8 +38,6 @@ public:
   ~FirestormDualController();
 
   void set_rumble(uint8_t left, uint8_t right);
-  void set_rumble_default(uint8_t left, uint8_t right);
-  void set_rumble_vsb(uint8_t left, uint8_t right);
   void set_led(uint8_t status);
 
   /** @param timeout   timeout in msec, 0 means forever */
diff --git a/src/helper.hpp b/src/helper.hpp
index 5b1b5b4..cb7b213 100644
--- a/src/helper.hpp
+++ b/src/helper.hpp
@@ -62,6 +62,24 @@ T clamp (const T& low, const T& v, const T& high)
 }
 } // namespace Math
 
+
+// Change the sign
+inline int16_t negate_16(int16_t v)
+{
+  if (v)
+    return ~v;
+  else // v == 0
+    return v;
+}
+
+inline int16_t scale_8to16(int8_t a)
+{
+  if (a > 0) 
+    return a * 32767 / 127;
+  else
+    return a * 32768 / 128;
+}
+
 #endif
 
 /* EOF */