Guest User

Maik Schulz

a guest
Mar 29th, 2010
251
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2.  
  3. JoystickHandler.h
  4.  
  5. Non-functional JoystickHandler.
  6. This exists to reduce the amount of #ifdefs and duplicated code.
  7.  
  8.  
  9. Oolite
  10. Copyright (C) 2004-2008 Giles C Williams and contributors
  11.  
  12. This program is free software; you can redistribute it and/or
  13. modify it under the terms of the GNU General Public License
  14. as published by the Free Software Foundation; either version 2
  15. of the License, or (at your option) any later version.
  16.  
  17. This program is distributed in the hope that it will be useful,
  18. but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  20. GNU General Public License for more details.
  21.  
  22. You should have received a copy of the GNU General Public License
  23. along with this program; if not, write to the Free Software
  24. Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
  25. MA 02110-1301, USA.
  26.  
  27.  
  28. This file may also be distributed under the MIT/X11 license:
  29.  
  30. Copyright (C) 2006 Jens Ayton, 2010 Maik Schulz
  31.  
  32. Permission is hereby granted, free of charge, to any person obtaining a copy
  33. of this software and associated documentation files (the "Software"), to deal
  34. in the Software without restriction, including without limitation the rights
  35. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  36. copies of the Software, and to permit persons to whom the Software is
  37. furnished to do so, subject to the following conditions:
  38.  
  39. The above copyright notice and this permission notice shall be included in all
  40. copies or substantial portions of the Software.
  41.  
  42. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  43. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  44. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  45. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  46. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  47. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  48. SOFTWARE.
  49.  
  50. */
  51.  
  52. #import "OOLogging.h"
  53. #import <Foundation/Foundation.h>
  54. #import <CoreFoundation/CoreFoundation.h>
  55. #import <IOKit/hid/IOHIDLib.h>
  56.  
  57. #define STICK_AXISUNASSIGNED -10.0
  58.  
  59. // Enums are used here rather than a more complex ObjC object because
  60. // these are required very frequently (once per frame) so must be light
  61. // on CPU cycles (try and avoid too many objc sendmsgs).
  62. // Controls that can be an axis
  63. enum {
  64.   AXIS_ROLL,
  65.   AXIS_PITCH,
  66.   AXIS_YAW,
  67.   AXIS_PRECISION,
  68.   AXIS_THRUST,
  69.   AXIS_VIEWX,
  70.   AXIS_VIEWY,
  71.   AXIS_end
  72. } axfn;
  73.  
  74. // Controls that can be a button
  75. enum {
  76.   BUTTON_INCTHRUST,
  77.   BUTTON_DECTHRUST,
  78.   BUTTON_SCANNERZOOM,
  79.   BUTTON_JETTISON,
  80.   BUTTON_COMPASSMODE,
  81.   BUTTON_COMMSLOG,
  82.   BUTTON_DOCKCPU,
  83.   BUTTON_DOCKCPUFAST,
  84.   BUTTON_DOCKCPUTARGET,
  85.   BUTTON_FUELINJECT,
  86.   BUTTON_HYPERSPEED,
  87.   BUTTON_HYPERDRIVE,
  88.   BUTTON_GALACTICDRIVE,
  89.   BUTTON_FIRE,
  90.   BUTTON_ARMMISSILE,
  91.   BUTTON_LAUNCHMISSILE,
  92.   BUTTON_UNARM,
  93. #if TARGET_INCOMING_MISSILES
  94.   BUTTON_TARGETINCOMINGMISSILE,
  95. #endif
  96.   BUTTON_CYCLEMISSILE,
  97.   BUTTON_ENERGYBOMB,
  98.   BUTTON_ID,
  99.   BUTTON_ECM,
  100.   BUTTON_ESCAPE,
  101.   BUTTON_CLOAK,
  102.   BUTTON_PRECISION,
  103.   BUTTON_VIEWFORWARD,
  104.   BUTTON_VIEWAFT,
  105.   BUTTON_VIEWPORT,
  106.   BUTTON_VIEWSTARBOARD,
  107.   BUTTON_end
  108. } butfn;
  109.  
  110. // Stick constants
  111. #define MAX_STICKS 4
  112. #define MAX_AXES  16
  113. #define MAX_REAL_BUTTONS  64
  114. #define MAX_HATS  0
  115. #define MAX_BUTTONS (MAX_REAL_BUTTONS + 4 * MAX_HATS)
  116. #define STICK_NOFUNCTION -1
  117. #define STICK_AXISUNASSIGNED -10.0
  118. #define STICK_PRECISIONDIV 98304 // 3 times more precise
  119. #define STICK_NORMALDIV 32768
  120. #define STICK_PRECISIONFAC (STICK_PRECISIONDIV/STICK_NORMALDIV)
  121. #define STICK_DEADZONE  0.15
  122.  
  123. // Kind of stick device (these are bits - if any more are added,
  124. // the next one is 4 and so on).
  125. #define HW_AXIS 1
  126. #define HW_BUTTON 2
  127.  
  128. // The threshold at which an axis can trigger a call back.
  129. // The max of abs(axis) is 32767.
  130. #define AXCBTHRESH 20000
  131.  
  132. // Dictionary keys - used in the defaults file
  133. #define AXIS_SETTINGS @"JoystickAxes"   // NSUserDefaults
  134. #define BUTTON_SETTINGS @"JoystickButs" // NSUserDefaults
  135. #define STICK_ISAXIS @"isAxis"          // YES=axis NO=button
  136. #define STICK_NUMBER @"stickNum"        // Stick number 0 to 4
  137. #define STICK_AXBUT  @"stickAxBt"       // Axis or button number
  138. #define STICK_FUNCTION @"stickFunc"     // Function of axis/button
  139.  
  140.  
  141. @interface JoystickHandler: NSObject
  142. {
  143.     BOOL butstate[BUTTON_end];
  144.     int numSticks;
  145.     NSPoint viewAxis;
  146.     NSPoint rollPitchAxis;
  147.     double yawAxis;
  148. }
  149.  
  150. + (id) sharedStickHandler;
  151.  
  152. - (int) getNumSticks;
  153. - (void) setNumSticks:(int)sticks;
  154. - (NSPoint) getRollPitchAxis;
  155. - (void) setRollAxis:(CGFloat)roll;
  156. - (void) setPitchAxis:(CGFloat)pitch;
  157. - (NSPoint) getViewAxis;
  158. - (void) setViewAxisX:(CGFloat)x;
  159. - (void) setViewAxisY:(CGFloat)y;
  160. - (double) getYawAxis;
  161. - (void) setYawAxis:(double)yaw;
  162. - (double) getAxisState:(int)function;
  163. - (double) getSensitivity;
  164. - (const BOOL *) getAllButtonStates;
  165. - (void) setButtonState:(BOOL)state forButton: (int)button;
  166.  
  167. @end
Advertisement
Add Comment
Please, Sign In to add comment