direcs  2012-09-30
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
joyreaderMacOS.h
Go to the documentation of this file.
1 /*************************************************************************
2  * Copyright (C) Markus Knapp *
3  * www.direcs.de *
4  * *
5  * This file is part of direcs. *
6  * *
7  * direcs is free software: you can redistribute it and/or modify it *
8  * under the terms of the GNU General Public License as published *
9  * by the Free Software Foundation, version 3 of the License. *
10  * *
11  * direcs is distributed in the hope that it will be useful, *
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14  * GNU General Public License for more details. *
15  * *
16  * You should have received a copy of the GNU General Public License *
17  * along with direcs. If not, see <http://www.gnu.org/licenses/>. *
18  * *
19  *************************************************************************/
20 
21 #ifndef MACOSXJOYSTICK_IS_INCLUDED
22 #define MACOSXJOYSTICK_IS_INCLUDED
23 /* { */
24 
25 const int JoyReaderMaxNumAxis=6;
26 const int JoyReaderMaxNumButton=32;
28 
29 #include <stdio.h>
30 #include <unistd.h>
31 #include <stdlib.h>
32 #include <ctype.h>
33 #include <sys/errno.h>
34 #include <sysexits.h>
35 #include <IOKit/hid/IOHIDLib.h>
36 #include <QDebug>
37 
38 
40 {
41 public:
42  int exist;
43  IOHIDElementRef elem;
44  int value;
45 
47 };
48 
50 {
51 public:
52  int min,max;
55 
56  JoyReaderAxis();
57  double GetCalibratedValue(void) const;
58 
59  void CaptureCenter(void);
60  void BeginCaptureMinMax(void);
61  void CaptureMinMax(void);
62  void CenterFromMinMax(void);
63 };
64 
66 {
67 public:
69 };
70 
72 {
73 public:
76  int value0Deg;
80  int GetDiscreteValue(void) const;
81 };
82 
83 class JoyReader
84 {
85 public:
86  static IOHIDManagerRef hidManager;
87  static CFMutableArrayRef devArray;
88 
89  int joyId;
90  IOHIDDeviceRef hidDev;
91  char regPath[512];
92 
96 
97  JoyReader();
98  int SetUpInterface(int joyId,IOHIDDeviceRef hidDev);
99  void Read(void);
100  void ReleaseInterface(void);
101 
102  int WriteCalibInfoFile(FILE *fp) const;
103  int ReadCalibInfoFile(FILE *fp);
104 
105 protected:
106  void AddAxis(int axisId,IOHIDElementRef elem,int min,int max,int scaledMin,int scaledMax);
107 
108 public:
109  static int SetUpJoystick(int &nJoystick,JoyReader joystick[],int maxNumJoystick);
110 };
111 
112 
113 
114 
115 int JoyReaderSetUpJoystick(int &nJoystick,JoyReader joystick[],int maxNumJoystick);
116 
117 FILE *JoyReaderOpenJoystickCalibrationFile(const char mode[]);
118 
119 int JoyReaderSaveJoystickCalibrationInfo(int nJoystick,JoyReader joystick[]);
120 int JoyReaderLoadJoystickCalibrationInfo(int nJoystick,JoyReader joystick[]);
121 
122 /* } */
123 #endif