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  * @since 1.10.0
28  */
29 class EXPCL_PANDA_DEVICE LinuxJoystickDevice : public InputDevice {
30 PUBLISHED:
31  LinuxJoystickDevice(LinuxInputDeviceManager *manager, size_t index);
32  virtual ~LinuxJoystickDevice();
33 
34  bool check_events() const;
35 
36 private:
37  virtual void do_poll();
38 
39  bool open_device();
40  bool process_events();
41 
42 private:
43  LinuxInputDeviceManager *_manager;
44 
45  int _fd;
46  size_t _index;
47 
48  // These are used for D-pad / hat switch emulation.
49  int _dpad_x_axis;
50  int _dpad_y_axis;
51  int _dpad_left_button;
52  int _dpad_up_button;
53 
54  // This is used for axis emulation.
55  int _ltrigger_axis;
56  int _ltrigger_button;
57  int _rtrigger_button;
58 
59 public:
60  static TypeHandle get_class_type() {
61  return _type_handle;
62  }
63  static void init_type() {
64  InputDevice::init_type();
65  register_type(_type_handle, "LinuxJoystickDevice",
66  InputDevice::get_class_type());
67  }
68 
69 private:
70  static TypeHandle _type_handle;
71 };
72 
73 #include "linuxJoystickDevice.I"
74 
75 #endif // PHAVE_LINUX_INPUT_H
76 
77 #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(),...
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:53
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:81