Panda3D
evdevInputDevice.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 evdevInputDevice.h
10  * @author rdb
11  * @date 2015-08-24
12  */
13 
14 #ifndef EVDEVINPUTDEVICE_H
15 #define EVDEVINPUTDEVICE_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/event# API to read
25  * data from a raw mouse or other input device. Unlike the joystick API, the
26  * evdev API supports sending force feedback (ie. rumble) events.
27  */
28 class EXPCL_PANDA_DEVICE EvdevInputDevice : public InputDevice {
29 public:
30  EvdevInputDevice(LinuxInputDeviceManager *manager, size_t index);
31  virtual ~EvdevInputDevice();
32 
33  bool reactivate_steam_controller();
34 
35 private:
36  virtual void do_set_vibration(double strong, double weak);
37  virtual void do_poll();
38 
39  bool init_device();
40  bool process_events();
41 
42 private:
43  LinuxInputDeviceManager *_manager;
44 
45  int _fd;
46  int _quirks;
47  size_t _index;
48 
49  bool _can_write;
50  int _ff_id;
51  bool _ff_playing;
52  int _ff_strong;
53  int _ff_weak;
54 
55  pvector<int> _axis_indices;
56  pvector<int> _button_indices;
57 
58  // These are used for D-pad emulation.
59  int _dpad_x_axis;
60  int _dpad_y_axis;
61  int _dpad_left_button;
62  int _dpad_up_button;
63 
64  // This is used for axis emulation.
65  int _ltrigger_axis;
66  int _ltrigger_code;
67  int _rtrigger_code;
68 
69 public:
70  static ButtonHandle map_button(int code,
71  DeviceClass device_class = DeviceClass::unknown,
72  int quirks = 0);
73 
74 public:
75  static TypeHandle get_class_type() {
76  return _type_handle;
77  }
78  static void init_type() {
79  InputDevice::init_type();
80  register_type(_type_handle, "EvdevInputDevice",
81  InputDevice::get_class_type());
82  }
83  virtual TypeHandle get_type() const {
84  return get_class_type();
85  }
86  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
87 
88 private:
89  static TypeHandle _type_handle;
90 };
91 
92 #include "evdevInputDevice.I"
93 
94 #endif // PHAVE_LINUX_INPUT_H
95 
96 #endif // EVDEVINPUTDEVICE_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
void map_button(size_t index, ButtonHandle handle)
Associates the indicated ButtonHandle with the button of the indicated index number.
Definition: inputDevice.I:189
A ButtonHandle represents a single button from any device, including keyboard buttons and mouse butto...
Definition: buttonHandle.h:26
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