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 * @since 1.10.0
30 */
31 class EXPCL_PANDA_DEVICE WinRawInputDevice final : public InputDevice {
32 public:
33 WinRawInputDevice(WinInputDeviceManager *manager, const char *path);
34 ~WinRawInputDevice();
35
36 bool on_arrival(HANDLE handle, const RID_DEVICE_INFO &info, std::string name);
37 void on_removal();
38 void on_input(PRAWINPUT input);
39 void process_report(PCHAR ptr, size_t size);
40
41 private:
42 virtual void do_poll();
43
44 private:
45 const std::string _path;
46 HANDLE _handle;
47 void *_preparsed;
48 ULONG _max_data_count;
49
50 // Indexed by report ID
51 pvector<BitArray> _report_buttons;
52
53 // Either a button index or a axis index.
54 struct Index {
55 Index() : _button(-1), _axis(-1) {}
56
57 static Index button(int index) {
58 Index idx;
59 idx._button = index;
60 return idx;
61 }
62 static Index axis(int index, bool is_signed=true) {
63 Index idx;
64 idx._axis = index;
65 idx._signed = is_signed;
66 return idx;
67 }
68
69 int _button;
70 int _axis;
71 bool _signed;
72 };
73
74 // Maps a "data index" to either button index or axis index.
75 pvector<Index> _indices;
76 int _hat_data_index;
77 int _hat_data_minimum;
78 int _hat_left_button;
79
80 WinInputDeviceManager *_manager;
81 friend class WinInputDeviceManager;
82 };
83
84 #endif // _WIN32
85
86 #endif
bitArray.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
InputDevice
This is a structure representing a single input device.
Definition: inputDevice.h:53
pvector
This is our own Panda specialization on the default STL vector.
Definition: pvector.h:42
inputDevice.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
pandabase.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.