add more spacing
[personal-kdebase.git] / workspace / kcontrol / hardware / joystick / joydevice.h
blob410dac40030bc68ef24abf2d09d0efb26bf60db5
1 /***************************************************************************
2 * Copyright (C) 2003 by Martin Koller *
3 * m.koller@surfeu.at *
4 * This file is part of the KDE Control Center Module for Joysticks *
5 * *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation; either version 2 of the License, or *
9 * (at your option) any later version. *
10 * *
11 * This program 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 this program; if not, write to the *
18 * Free Software Foundation, Inc., *
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
20 ***************************************************************************/
21 #ifndef _JOYDEVICE_H_
22 #define _JOYDEVICE_H_
24 #include <QString>
26 #include <sys/types.h>
28 #ifdef Q_OS_LINUX
29 #undef __STRICT_ANSI__
30 #include <linux/joystick.h>
31 #define __STRICT_ANSI__
32 #endif
34 #ifdef Q_OS_FREEBSD
35 #include <sys/joystick.h>
36 #endif
38 // helper class which holds all current values, file descriptor, etc. for
39 // one device
40 class JoyDevice
42 public:
43 enum ErrorCode
45 SUCCESS,
46 OPEN_FAILED,
47 NO_JOYSTICK,
48 WRONG_VERSION,
49 ERR_GET_VERSION,
50 ERR_GET_BUTTONS,
51 ERR_GET_AXES,
52 ERR_GET_CORR,
53 ERR_RESTORE_CORR,
54 ERR_INIT_CAL,
55 ERR_APPLY_CAL
58 enum EventType
60 BUTTON,
61 AXIS
64 // devicefile to use, e.g. "/dev/js0"
65 JoyDevice(const QString &devicefile);
66 ~JoyDevice();
68 // returns one of the error-codes from above
69 ErrorCode open();
71 // return descriptive error text for given error code
72 QString errText(ErrorCode code) const;
74 int fd() const { return joyFd; }
75 void close();
76 ErrorCode restoreCorr();
78 // return devicefilename from constructor
79 const QString &device() const { return devName; }
81 // descriptive text for this device read from the driver
82 QString text() const { return descr; }
84 int numButtons() const { return buttons; }
85 int numAxes() const { return axes; }
86 int axisMin(int axis) const;
87 int axisMax(int axis) const;
89 // read next event from device; returns true if there was an event during the short timeout
90 bool getEvent(JoyDevice::EventType &type, int &number, int &value);
92 // methods for calibration
93 ErrorCode initCalibration(); // must be called first
94 void calcPrecision();
96 void resetMinMax(int axis, int value = 0);
98 // calculate correction values
99 // min[2], center[2], max[2], index 0 == minimum, index 1 == maximum
100 void calcCorrection(int axis, int *min, int *center, int *max);
101 ErrorCode applyCalibration();
103 private:
104 QString devName; // device filename
105 QString descr; // descriptive text
106 int joyFd;
108 int buttons;
109 int axes;
110 int *amin; // axes min values
111 int *amax; // axes max values
113 struct js_corr *corr; // calibration values during the calib. steps
114 struct js_corr *origCorr; // original calibration correction values
117 #endif