TDE base libraries and programs
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

111 lines
3.7KB

  1. /***************************************************************************
  2. * Copyright (C) 2003 by Martin Koller *
  3. * m.koller@surfeu.at *
  4. * This file is part of the Trinity 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_
  23. #include <tqstring.h>
  24. #include <sys/types.h>
  25. #undef __STRICT_ANSI__
  26. #include <linux/joystick.h>
  27. #define __STRICT_ANSI__
  28. // helper class which holds all current values, file descriptor, etc. for
  29. // one device
  30. class JoyDevice
  31. {
  32. public:
  33. enum ErrorCode
  34. {
  35. SUCCESS,
  36. OPEN_FAILED,
  37. NO_JOYSTICK,
  38. WRONG_VERSION,
  39. ERR_GET_VERSION,
  40. ERR_GET_BUTTONS,
  41. ERR_GET_AXES,
  42. ERR_GET_CORR,
  43. ERR_RESTORE_CORR,
  44. ERR_INIT_CAL,
  45. ERR_APPLY_CAL
  46. };
  47. enum EventType
  48. {
  49. BUTTON,
  50. AXIS
  51. };
  52. // devicefile to use, e.g. "/dev/js0"
  53. JoyDevice(const TQString &devicefile);
  54. ~JoyDevice();
  55. // returns one of the error-codes from above
  56. ErrorCode open();
  57. // return descriptive error text for given error code
  58. TQString errText(ErrorCode code) const;
  59. int fd() const { return joyFd; }
  60. void close();
  61. ErrorCode restoreCorr();
  62. // return devicefilename from constructor
  63. const TQString &device() const { return devName; }
  64. // descriptive text for this device read from the driver
  65. TQString text() const { return descr; }
  66. int numButtons() const { return buttons; }
  67. int numAxes() const { return axes; }
  68. int axisMin(int axis) const;
  69. int axisMax(int axis) const;
  70. // read next event from device; returns true if there was an event during the short timeout
  71. bool getEvent(JoyDevice::EventType &type, int &number, int &value);
  72. // methods for calibration
  73. ErrorCode initCalibration(); // must be called first
  74. void calcPrecision();
  75. void resetMinMax(int axis, int value = 0);
  76. // calculate correction values
  77. // min[2], center[2], max[2], index 0 == minimum, index 1 == maximum
  78. void calcCorrection(int axis, int *min, int *center, int *max);
  79. ErrorCode applyCalibration();
  80. private:
  81. TQString devName; // device filename
  82. TQString descr; // descriptive text
  83. int joyFd;
  84. int buttons;
  85. int axes;
  86. int *amin; // axes min values
  87. int *amax; // axes max values
  88. struct js_corr *corr; // calibration values during the calib. steps
  89. struct js_corr *origCorr; // original calibration correction values
  90. };
  91. #endif