Panda3D
linuxJoystickDevice.h
Go to the documentation of this file.
1 /**
2  * PANDA 3D SOFTWARE
3  * Copyright (c) Carnegie Mellon University. All rights reserved.
4  *
5  * All use of this software is subject to the terms of the revised BSD
6  * license. You should have received a copy of this license along
7  * with this source code in a file named "LICENSE."
8  *
9  * @file linuxJoystickDevice.h
10  * @author rdb
11  * @date 2015-08-21
12  */
13 
14 #ifndef LINUXJOYSTICKDEVICE_H
15 #define LINUXJOYSTICKDEVICE_H
16 
17 #include "inputDevice.h"
18 
19 #ifdef PHAVE_LINUX_INPUT_H
20 
21 class LinuxInputDeviceManager;
22 
23 /**
24  * This is a type of device that uses the Linux /dev/input/js# API to read
25  * data from a game controller.
26  */
27 class EXPCL_PANDA_DEVICE LinuxJoystickDevice : public InputDevice {
28 PUBLISHED:
29  LinuxJoystickDevice(LinuxInputDeviceManager *manager, size_t index);
30  virtual ~LinuxJoystickDevice();
31 
32  bool check_events() const;
33 
34 private:
35  virtual void do_poll();
36 
37  bool open_device();
38  bool process_events();
39 
40 private:
41  LinuxInputDeviceManager *_manager;
42 
43  int _fd;
44  size_t _index;
45 
46  // These are used for D-pad / hat switch emulation.
47  int _dpad_x_axis;
48  int _dpad_y_axis;
49  int _dpad_left_button;
50  int _dpad_up_button;
51 
52  // This is used for axis emulation.
53  int _ltrigger_axis;
54  int _ltrigger_button;
55  int _rtrigger_button;
56 
57 public:
58  static TypeHandle get_class_type() {
59  return _type_handle;
60  }
61  static void init_type() {
62  InputDevice::init_type();
63  register_type(_type_handle, "LinuxJoystickDevice",
64  InputDevice::get_class_type());
65  }
66 
67 private:
68  static TypeHandle _type_handle;
69 };
70 
71 #include "linuxJoystickDevice.I"
72 
73 #endif // PHAVE_LINUX_INPUT_H
74 
75 #endif // LINUXJOYSTICKDEVICE_H
void register_type(TypeHandle &type_handle, const std::string &name)
This inline function is just a convenient way to call TypeRegistry::register_type(), along with zero to four record_derivation()s.
Definition: register_type.I:22
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This is a structure representing a single input device.
Definition: inputDevice.h:51
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:81