Panda3D
winRawInputDevice.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 winRawInputDevice.h
10  * @author rdb
11  * @date 2018-01-19
12  */
13 
14 #ifndef WINRAWINPUTDEVICE_H
15 #define WINRAWINPUTDEVICE_H
16 
17 #include "pandabase.h"
18 #include "inputDevice.h"
19 #include "bitArray.h"
20 
21 #if defined(_WIN32) && !defined(CPPPARSER)
22 
23 class WinInputDeviceManager;
24 
25 /**
26  * This implementation of InputDevice uses the Win32 raw input API and the HID
27  * parser library to support a wide range of devices.
28  */
29 class EXPCL_PANDA_DEVICE WinRawInputDevice final : public InputDevice {
30 public:
31  WinRawInputDevice(WinInputDeviceManager *manager, const char *path);
32  ~WinRawInputDevice();
33 
34  bool on_arrival(HANDLE handle, const RID_DEVICE_INFO &info, std::string name);
35  void on_removal();
36  void on_input(PRAWINPUT input);
37  void process_report(PCHAR ptr, size_t size);
38 
39 private:
40  virtual void do_poll();
41 
42 private:
43  const std::string _path;
44  HANDLE _handle;
45  void *_preparsed;
46  ULONG _max_data_count;
47 
48  // Indexed by report ID
49  pvector<BitArray> _report_buttons;
50 
51  // Either a button index or a axis index.
52  struct Index {
53  Index() : _button(-1), _axis(-1) {}
54 
55  static Index button(int index) {
56  Index idx;
57  idx._button = index;
58  return idx;
59  }
60  static Index axis(int index, bool is_signed=true) {
61  Index idx;
62  idx._axis = index;
63  idx._signed = is_signed;
64  return idx;
65  }
66 
67  int _button;
68  int _axis;
69  bool _signed;
70  };
71 
72  // Maps a "data index" to either button index or axis index.
73  pvector<Index> _indices;
74  int _hat_data_index;
75  int _hat_data_minimum;
76  int _hat_left_button;
77 
78  WinInputDeviceManager *_manager;
79  friend class WinInputDeviceManager;
80 };
81 
82 #endif // _WIN32
83 
84 #endif
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This is our own Panda specialization on the default STL vector.
Definition: pvector.h:42
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This is a structure representing a single input device.
Definition: inputDevice.h:51