/Users/craigcornelius/Projects/SPRING Mac Release 0.2/joystick.h

Go to the documentation of this file.
00001 // $Id: joystick.h,v 1.5 2006/05/24 16:52:41 sean Exp $
00002 // $Copyright: (c)2001 National Biocomputation Center, Stanford University $
00003 
00004 //
00005 //  joystick.h
00006 //
00007 //  Author: Chris (caschwan@hawaii.edu) - Hawaii
00008 
00009 #ifndef Joystick_Header
00010 #define Joystick_Header
00011 
00012 #ifdef _WIN32
00013 #include <winsock.h>
00014 #else
00015 #include <sys/types.h>
00016 #include <sys/socket.h>
00017 #include <netinet/in.h>
00018 #include <stdio.h>
00019 
00020 #ifndef SOCKET
00021 #define SOCKET unsigned int
00022 #endif // SOCKET
00023 
00024 #endif _WIN32
00025 
00026 #include "sensor.h"
00027 #include "socket.h"
00028 #include "timer.h"
00029 #include <iostream>      // For debugging messages
00030 
00031 
00032 class Joystick : public Sensor {
00033 
00034 public:
00035 
00036     Joystick(char* machine_name, int port_num = 9899);
00037     virtual ~Joystick();
00038 
00039     static const char* rcsid;
00040     static int debug;
00041     
00042     // the main update routine
00043     void Update();
00044 
00045         // joystick emulation mode (how the joystick buttons are mapped to position actions)
00046         enum emulation_mode {
00047                 no_emulation,                // all values are activation values
00048                 mouse_emulation,             // xyz mouse movements (primitive - first three axes used)
00049                 enhanced_3d_emulation,       // movements similar to first-person shoot but with tilting
00050                 first_person_emulation,      // movements like in a first-person shooter 
00051                 pedal_emulation,             // emulation for foot pedals (CH Products Foot Pedal)
00052                 button_pedal_emulation,      // emulation for foot pedals (XKeys 3-button Foot Pedal)
00053         };  
00054         // The joystick emulation mode (how the joystick buttons are mapped to position actions)
00055         emulation_mode joystickEmulation;
00056 
00057         // returns the joystick emulation mode
00058         emulation_mode getJoystickEmulation() { return joystickEmulation; }
00059         // sets the joystick emulation mode
00060         void setJoystickEmulation(emulation_mode emulationMode) { joystickEmulation = emulationMode; }
00061 
00062         // maximum number of joystick buttons
00063         enum { MAX_JOYSTICK_BUTTONS = 100 };
00064         // maximum number of joystick axes
00065         enum { MAX_JOYSTICK_AXES = 50 };
00066 
00067         // returns the number of joystick axes
00068         int getNumAxes() { return joydata->num_axes; }
00069         // returns the number of joystick buttons
00070         int getNumButtons() { return joydata->num_buttons; }
00071 
00072         // returns the button status of button with given obj_id: 
00073         // -index starts at 0 until (max_buttons - 1)
00074         // -button values are either 0 (not pressed) or 1 (pressed)
00075         int getButton(int index) { return joydata->buttons[index]; }
00076         // returns the axis status of axis with given obj_id:
00077         // -index starts at 0 until (max_axes - 1)
00078         // -axis values go from [-1..1] -> 0 representing the center
00079         float getAxis(int index) { return joydata->axes[index]; }
00080 
00081 private:
00082 
00083     // internal data
00084     char *buf;
00085     Socket *hsock;
00086         
00087         // last time when update done
00088         double lastUpdate;
00089         // Timer instance
00090         Timer timer;
00091 
00092         // How joystick state is internally stored
00093         struct Joydata_s {
00094                 int num_buttons;
00095                 int buttons[MAX_JOYSTICK_BUTTONS];
00096                 int num_axes;
00097                 double axes[MAX_JOYSTICK_AXES];
00098         };
00099         typedef struct Joydata_s Joydata;
00100         // The joystick used
00101         Joydata* joydata;
00102 
00103         // internal helpers
00104         void receive_info();
00105         void send_force();
00106     
00107 };
00108 
00109 #endif

Generated on Thu Aug 30 11:03:14 2007 for SPRING Mac by  doxygen 1.5.3