pingus-cvs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Pingus-CVS] r3068 - in trunk/pingus: data/controller src/input


From: grumbel at BerliOS
Subject: [Pingus-CVS] r3068 - in trunk/pingus: data/controller src/input
Date: Sun, 2 Sep 2007 21:56:03 +0200

Author: grumbel
Date: 2007-09-02 21:56:03 +0200 (Sun, 02 Sep 2007)
New Revision: 3068

Added:
   trunk/pingus/data/controller/wiimote.scm
Modified:
   trunk/pingus/src/input/core_driver.cpp
   trunk/pingus/src/input/manager.cpp
   trunk/pingus/src/input/manager.hpp
   trunk/pingus/src/input/wiimote.cpp
   trunk/pingus/src/input/wiimote.hpp
   trunk/pingus/src/input/wiimote_driver.cpp
Log:
- some improvements on the Wiimote driver

Added: trunk/pingus/data/controller/wiimote.scm
===================================================================
--- trunk/pingus/data/controller/wiimote.scm    2007-09-02 17:31:00 UTC (rev 
3067)
+++ trunk/pingus/data/controller/wiimote.scm    2007-09-02 19:56:03 UTC (rev 
3068)
@@ -0,0 +1,40 @@
+;; -*- scheme -*-
+
+(pingus-controller
+  (standard-pointer
+   (sdl:mouse-pointer)
+   (core:axis-pointer
+    (x-axis (wiimote:axis (axis "nunchuk:x")))
+    (y-axis (wiimote:axis (axis "nunchuk:y")))))
+
+ (standard-scroller
+  (core:axis-scroller
+   (x-axis (wiimote:axis (axis "nunchuk:x")))
+   (y-axis (wiimote:axis (axis "nunchuk:y")))))
+
+ (primary-button
+  (wiimote:button (button "a")))
+
+ (secondary-button
+  (wiimote:button (button "nunchuk:z")))
+
+ (pause-button
+  (wiimote:button (button "plus")))
+
+ (fast-forward-button
+  (wiimote:button (button "minus")))
+
+ (armageddon-button
+  (wiimote:button (button "home")))
+
+ (escape-button
+  (sdl:keyboard-button (key "escape")))
+
+ (action-up-button
+  (wiimote:button (button "up")))
+
+ (action-down-button
+  (wiimote:button (button "down")))
+ )
+
+;; EOF ;;

Modified: trunk/pingus/src/input/core_driver.cpp
===================================================================
--- trunk/pingus/src/input/core_driver.cpp      2007-09-02 17:31:00 UTC (rev 
3067)
+++ trunk/pingus/src/input/core_driver.cpp      2007-09-02 19:56:03 UTC (rev 
3068)
@@ -41,7 +41,7 @@
   AxisPointer(Control* parent) 
     : Pointer(parent),
       x_axis(0), y_axis(0), speed_button(0),
-      speed(200.0f)
+      speed(400.0f)
   {
   }
 

Modified: trunk/pingus/src/input/manager.cpp
===================================================================
--- trunk/pingus/src/input/manager.cpp  2007-09-02 17:31:00 UTC (rev 3067)
+++ trunk/pingus/src/input/manager.cpp  2007-09-02 19:56:03 UTC (rev 3068)
@@ -155,7 +155,9 @@
         }
     }
 
-  return controller.release();
+  Controller* ctrl = controller.release();
+  controllers.push_back(ctrl);
+  return ctrl;
 }
 
 void
@@ -164,8 +166,8 @@
   for(Drivers::iterator i = drivers.begin(); i != drivers.end(); ++i)
     (*i)->update(delta);
   
-  for(std::vector<Controller*>::iterator i = controller.begin(); 
-      i != controller.end(); ++i)
+  for(std::vector<Controller*>::iterator i = controllers.begin(); 
+      i != controllers.end(); ++i)
     (*i)->update(delta);
 }
 

Modified: trunk/pingus/src/input/manager.hpp
===================================================================
--- trunk/pingus/src/input/manager.hpp  2007-09-02 17:31:00 UTC (rev 3067)
+++ trunk/pingus/src/input/manager.hpp  2007-09-02 19:56:03 UTC (rev 3068)
@@ -33,7 +33,7 @@
   typedef std::vector<Driver*> Drivers;
   Drivers drivers;
 
-  std::vector<Controller*> controller;
+  std::vector<Controller*> controllers;
   ControllerDescription desc;
 
 public:

Modified: trunk/pingus/src/input/wiimote.cpp
===================================================================
--- trunk/pingus/src/input/wiimote.cpp  2007-09-02 17:31:00 UTC (rev 3067)
+++ trunk/pingus/src/input/wiimote.cpp  2007-09-02 19:56:03 UTC (rev 3068)
@@ -33,6 +33,80 @@
 
 #ifdef HAVE_CWIID
 
+std::string
+Wiimote::id2str(int id)
+{
+  if      (id == WIIMOTE_A)     return "a";
+  else if (id == WIIMOTE_B)     return "b";
+  else if (id == WIIMOTE_LEFT)  return "left";
+  else if (id == WIIMOTE_RIGHT) return "right";
+  else if (id == WIIMOTE_UP)    return "up";
+  else if (id == WIIMOTE_DOWN)  return "down";
+  else if (id == WIIMOTE_PLUS)  return "plus";
+  else if (id == WIIMOTE_MINUS) return "minus";
+  else if (id == WIIMOTE_HOME)  return "home";
+  else if (id == WIIMOTE_1)     return "1";
+  else if (id == WIIMOTE_2)     return "2";
+
+  else if (id == NUNCHUK_C) return "nunchuk:c";
+  else if (id == NUNCHUK_Z) return "nunchuk:z";
+
+  else if (id == CLASSIC_LEFT)  return "classic:left";
+  else if (id == CLASSIC_RIGHT) return "classic:right";
+  else if (id == CLASSIC_UP)    return "classic:up";
+  else if (id == CLASSIC_DOWN)  return "classic:down";
+  else if (id == CLASSIC_PLUS)  return "classic:plus";
+  else if (id == CLASSIC_MINUS) return "classic:minus";
+  else if (id == CLASSIC_HOME)  return "classic:home";
+  else if (id == CLASSIC_A)     return "classic:a";
+  else if (id == CLASSIC_B)     return "classic:b";
+  else if (id == CLASSIC_X)     return "classic:x";
+  else if (id == CLASSIC_Y)     return "classic:y";
+  else if (id == CLASSIC_L)     return "classic:l";
+  else if (id == CLASSIC_R)     return "classic:r";
+  else if (id == CLASSIC_ZL)    return "classic:zl";
+  else if (id == CLASSIC_ZR)    return "classic:zr";
+  else 
+    return "unknown";
+}
+
+int
+Wiimote::str2id(const std::string& str)
+{
+  if      (str == "a")     return WIIMOTE_A;
+  else if (str == "b")     return WIIMOTE_B;
+  else if (str == "left")  return WIIMOTE_LEFT;
+  else if (str == "right") return WIIMOTE_RIGHT;
+  else if (str == "up")    return WIIMOTE_UP;
+  else if (str == "down")  return WIIMOTE_DOWN;
+  else if (str == "plus"  || str == "+") return WIIMOTE_PLUS;
+  else if (str == "minus" || str == "-") return WIIMOTE_MINUS;
+  else if (str == "home")  return WIIMOTE_HOME;
+  else if (str == "1")     return WIIMOTE_1;
+  else if (str == "2")     return WIIMOTE_2;
+
+  else if (str == "nunchuk:c") return NUNCHUK_C;
+  else if (str == "nunchuk:z") return NUNCHUK_Z;
+
+  else if (str == "classic:left")  return CLASSIC_LEFT;
+  else if (str == "classic:right") return CLASSIC_RIGHT;
+  else if (str == "classic:up")    return CLASSIC_UP;
+  else if (str == "classic:down")  return CLASSIC_DOWN;
+  else if (str == "classic:plus"  || str == "classic:+") return CLASSIC_PLUS;
+  else if (str == "classic:minus" || str == "classic:-") return CLASSIC_MINUS;
+  else if (str == "classic:home")  return CLASSIC_HOME;
+  else if (str == "classic:a")     return CLASSIC_A;
+  else if (str == "classic:b")     return CLASSIC_B;
+  else if (str == "classic:x")     return CLASSIC_X;
+  else if (str == "classic:y")     return CLASSIC_Y;
+  else if (str == "classic:l")     return CLASSIC_L;
+  else if (str == "classic:r")     return CLASSIC_R;
+  else if (str == "classic:zl")    return CLASSIC_ZL;
+  else if (str == "classic:zr")    return CLASSIC_ZR;
+  else 
+    return UNKNOWN;
+}
+
 void
 Wiimote::init()
 {
@@ -95,10 +169,12 @@
         std::cerr << "Unable to set message callback" << std::endl;
       }
 
+      // FIXME: Could init this depending on what events are actually bound
       if (cwiid_command(m_wiimote, CWIID_CMD_RPT_MODE, 
                         CWIID_RPT_STATUS  |
                         CWIID_RPT_NUNCHUK |
                         CWIID_RPT_ACC     |
+                        //CWIID_RPT_IR      |
                         CWIID_RPT_BTN))
         {
           std::cerr << "Wiimote: Error setting report mode" << std::endl;
@@ -301,20 +377,20 @@
   uint16_t changes = m_buttons ^ msg.buttons;
   m_buttons = msg.buttons;
  
-  CHECK_BTN(CWIID_BTN_A, 0);
-  CHECK_BTN(CWIID_BTN_B, 1);
+  CHECK_BTN(CWIID_BTN_A, WIIMOTE_A);
+  CHECK_BTN(CWIID_BTN_B, WIIMOTE_B);
 
-  CHECK_BTN(CWIID_BTN_LEFT,  2);
-  CHECK_BTN(CWIID_BTN_RIGHT, 3);
-  CHECK_BTN(CWIID_BTN_UP,    4);
-  CHECK_BTN(CWIID_BTN_DOWN,  5);
+  CHECK_BTN(CWIID_BTN_LEFT,  WIIMOTE_LEFT);
+  CHECK_BTN(CWIID_BTN_RIGHT, WIIMOTE_RIGHT);
+  CHECK_BTN(CWIID_BTN_UP,    WIIMOTE_UP);
+  CHECK_BTN(CWIID_BTN_DOWN,  WIIMOTE_DOWN);
 
-  CHECK_BTN(CWIID_BTN_PLUS,  6);
-  CHECK_BTN(CWIID_BTN_HOME,  7);
-  CHECK_BTN(CWIID_BTN_MINUS, 8);
+  CHECK_BTN(CWIID_BTN_PLUS,  WIIMOTE_PLUS);
+  CHECK_BTN(CWIID_BTN_HOME,  WIIMOTE_HOME);
+  CHECK_BTN(CWIID_BTN_MINUS, WIIMOTE_MINUS);
 
-  CHECK_BTN(CWIID_BTN_1,  9);
-  CHECK_BTN(CWIID_BTN_2, 10);
+  CHECK_BTN(CWIID_BTN_1,  WIIMOTE_1);
+  CHECK_BTN(CWIID_BTN_2,  WIIMOTE_2);
 }
 
 void
@@ -331,12 +407,20 @@
 void
 Wiimote::on_ir(const cwiid_ir_mesg& msg)
 {
-  printf("IR Report: ");
+  bool is_valid = false;
   for (int i = 0; i < CWIID_IR_SRC_COUNT; ++i)
+    is_valid = is_valid || msg.src[i].valid;
+
+  if (is_valid)
     {
-      if (msg.src[i].valid) {
-        printf("(%d,%d) ", msg.src[i].pos[0], msg.src[i].pos[1]);
-      }
+      std::cout << "IR Report: ";
+      for (int i = 0; i < CWIID_IR_SRC_COUNT; ++i)
+        {
+          if (msg.src[i].valid) {
+            std::cout << "(" <<  msg.src[i].pos[0] << ", " <<  
msg.src[i].pos[1] << ") ";
+          }
+        }
+      std::cout << std::endl;
     }
 }
 
@@ -361,15 +445,15 @@
 }
 
 void
-Wiimote::on_nunchuck(const cwiid_nunchuk_mesg& msg)
+Wiimote::on_nunchuk(const cwiid_nunchuk_mesg& msg)
 {
   uint8_t changes = m_nunchuk_btns ^ msg.buttons;
   m_nunchuk_btns  = msg.buttons;
 
 #define CHECK_NCK_BTN(btn, num) if (changes & btn) add_button_event(0, num, 
m_nunchuk_btns & btn)
       
-  CHECK_NCK_BTN(CWIID_NUNCHUK_BTN_Z, 11);
-  CHECK_NCK_BTN(CWIID_NUNCHUK_BTN_C, 12);
+  CHECK_NCK_BTN(CWIID_NUNCHUK_BTN_Z, NUNCHUK_Z);
+  CHECK_NCK_BTN(CWIID_NUNCHUK_BTN_C, NUNCHUK_C);
   
   // FIXME: Read real calibration data, instead of hardcoded one
   float nunchuk_stick_x =  to_float(37, 129, 231, msg.stick[0]);
@@ -464,7 +548,7 @@
           break;
 
         case CWIID_MESG_NUNCHUK:
-          wiimote->on_nunchuck(mesg[i].nunchuk_mesg);
+          wiimote->on_nunchuk(mesg[i].nunchuk_mesg);
           break;
 
         case CWIID_MESG_CLASSIC:

Modified: trunk/pingus/src/input/wiimote.hpp
===================================================================
--- trunk/pingus/src/input/wiimote.hpp  2007-09-02 17:31:00 UTC (rev 3067)
+++ trunk/pingus/src/input/wiimote.hpp  2007-09-02 19:56:03 UTC (rev 3068)
@@ -104,6 +104,48 @@
   void add_acc_event(int device, int accelerometer, float x, float y, float z);
 
 public:
+  enum {
+    // Wiimote
+    WIIMOTE_A,
+    WIIMOTE_B,
+    WIIMOTE_LEFT,
+    WIIMOTE_RIGHT,
+    WIIMOTE_UP,
+    WIIMOTE_DOWN,
+    WIIMOTE_PLUS,
+    WIIMOTE_HOME,
+    WIIMOTE_MINUS,
+    WIIMOTE_1,
+    WIIMOTE_2,
+
+    // Nunchuk
+    NUNCHUK_C,
+    NUNCHUK_Z,
+
+    // Classic 
+    CLASSIC_LEFT,
+    CLASSIC_RIGHT,
+    CLASSIC_UP,
+    CLASSIC_DOWN,
+
+    CLASSIC_PLUS,
+    CLASSIC_HOME,
+    CLASSIC_MINUS,
+    CLASSIC_A,
+    CLASSIC_B,
+    CLASSIC_X,
+    CLASSIC_Y,
+    CLASSIC_L,
+    CLASSIC_R,
+    CLASSIC_ZL, // FIXME: This is an axis instead of a button?
+    CLASSIC_ZR,
+    
+    UNKNOWN
+  };
+
+  static std::string id2str(int id);
+  static int str2id(const std::string& str);
+
   Wiimote();
   ~Wiimote();
   
@@ -127,7 +169,7 @@
   void on_button  (const cwiid_btn_mesg& msg);
   void on_acc     (const cwiid_acc_mesg& msg);
   void on_ir      (const cwiid_ir_mesg& msg);
-  void on_nunchuck(const cwiid_nunchuk_mesg& msg);
+  void on_nunchuk(const cwiid_nunchuk_mesg& msg);
   void on_classic (const cwiid_classic_mesg& msg);
   
   void mesg(cwiid_wiimote_t*, int mesg_count, union cwiid_mesg mesg[]);

Modified: trunk/pingus/src/input/wiimote_driver.cpp
===================================================================
--- trunk/pingus/src/input/wiimote_driver.cpp   2007-09-02 17:31:00 UTC (rev 
3067)
+++ trunk/pingus/src/input/wiimote_driver.cpp   2007-09-02 19:56:03 UTC (rev 
3068)
@@ -23,6 +23,8 @@
 **  02111-1307, USA.
 */
 
+#include "debug.hpp"
+#include "globals.hpp"
 #include "string_util.hpp"
 #include "wiimote.hpp"
 #include "wiimote_driver.hpp"
@@ -52,8 +54,9 @@
       WiimoteEvent& event = *i;
       if (event.type == WiimoteEvent::WIIMOTE_BUTTON_EVENT)
         {
-          //if (event.button.down)
-          //  std::cout << event.button.button << std::endl;
+          pout(PINGUS_DEBUG_INPUT) << "WiimoteDriver: (wiimote:button (button "
+                                   << event.button.button << ")) => "
+                                   << event.button.down << std::endl;
                   
           for (std::vector<ButtonBinding>::const_iterator j = 
button_bindings.begin();
                j != button_bindings.end();
@@ -67,6 +70,11 @@
         }
       else if (event.type == WiimoteEvent::WIIMOTE_AXIS_EVENT)
         {
+          pout(PINGUS_DEBUG_INPUT) << "WiimoteDriver: (wiimote:axis (axis "
+                                   << event.axis.axis << ")) => " 
+                                   << event.axis.pos
+                                   << std::endl; // Fixme: should output string
+
           for (std::vector<AxisBinding>::const_iterator j = 
axis_bindings.begin();
                j != axis_bindings.end(); ++j)
             {
@@ -123,35 +131,9 @@
         }
       else
         {
-          button = StringUtil::to_lower(button);
-          int button_id = 0;
-          if (button == "a")
-            button_id = 0;
-          else if (button == "b")
-            button_id = 1;
-          else if (button == "dpad-left")
-            button_id = 2;
-          else if (button == "dpad-right")
-            button_id = 3;
-          else if (button == "dpad-up")
-            button_id = 4;
-          else if (button == "dpad-down")
-            button_id = 5;
-          else if (button == "+" || button == "plus")
-            button_id = 6;
-          else if (button == "home")
-            button_id = 7;
-          else if (button == "-" || button == "minus")
-            button_id = 8;
-          else if (button == "1")
-            button_id = 9;
-          else if (button == "2")
-            button_id = 10;
-          else if (button == "nunchuck:z")
-            button_id = 11;
-          else if (button == "nunchuck:c")
-            button_id = 12;
-          else
+          int button_id = Wiimote::str2id(StringUtil::to_lower(button));
+          
+          if (button_id == Wiimote::UNKNOWN)
             {
               std::cout << "Error: WiimoteDriver: unknown button: " << button 
<< std::endl;
               return 0;
@@ -186,10 +168,10 @@
         {
           axis = StringUtil::to_lower(axis);
           int axis_id = 0;
-          if (axis == "nunchuck:x")
+          if (axis == "nunchuk:x")
             axis_id = 0;
-          else if (axis == "nunchuck:y")
-            axis_id = 0;
+          else if (axis == "nunchuk:y")
+            axis_id = 1;
           else
             {
               std::cout << "WiimoteDriver: unknown axis name: " << axis << 
std::endl;





reply via email to

[Prev in Thread] Current Thread [Next in Thread]