Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(57)

Side by Side Diff: ui/events/ozone/evdev/gamepad_event_converter_evdev.h

Issue 2805793002: ozone: evdev: Add gamepad support (Closed)
Patch Set: Support Gamepad in Ozone. Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef UI_EVENTS_OZONE_GAMEPAD_EVENT_CONVERTER_EVDEV_H_
6 #define UI_EVENTS_OZONE_GAMEPAD_EVENT_CONVERTER_EVDEV_H_
7
8 #include <vector>
9
10 #include "base/files/file_path.h"
11 #include "base/macros.h"
12 #include "ui/events/devices/input_device.h"
13 #include "ui/events/event.h"
14 #include "ui/events/ozone/evdev/event_converter_evdev.h"
15 #include "ui/events/ozone/evdev/event_device_info.h"
16 #include "ui/events/ozone/evdev/events_ozone_evdev_export.h"
17 #include "ui/events/ozone/evdev/scoped_input_device.h"
18 #include "ui/events/ozone/gamepad/gamepad_mapping.h"
19 #include "ui/events/ozone/gamepad/webgamepad_constants.h"
20
21 struct input_event;
22
23 namespace ui {
24
25 class DeviceEventDispatcherEvdev;
26
27 class EVENTS_OZONE_EVDEV_EXPORT GamepadEventConverterEvdev
28 : public EventConverterEvdev {
29 public:
30 GamepadEventConverterEvdev(ScopedInputDevice fd,
31 base::FilePath path,
32 int id,
33 const EventDeviceInfo& info,
34 DeviceEventDispatcherEvdev* dispatcher);
35
36 ~GamepadEventConverterEvdev() override;
37
38 // EventConverterEvdev:
39 void OnFileCanReadWithoutBlocking(int fd) override;
40 bool HasGamepad() const override;
41 void OnDisabled() override;
42
43 // This function processes one input_event from evdev.
44 void ProcessEvent(const struct input_event& input);
45
46 private:
47 // This function processes EV_KEY event from gamepad device.
48 void ProcessEvdevKey(uint16_t code,
49 uint16_t value,
50 const base::TimeTicks& timestamp);
51
52 // This function processes EV_ABS event from gamepad device.
53 void ProcessEvdevAbs(uint16_t code,
54 uint16_t value,
55 const base::TimeTicks& timestamp);
56
57 // This function releases all the keys and resets all the axises.
58 void ResetGamepad();
59
60 // This function reads current gamepad status and resyncs the gamepad.
61 void ResyncGamepad();
62
63 void OnButtonChange(unsigned int code,
64 double value,
65 const base::TimeTicks& timestamp);
66 void OnAbsChange(unsigned int code,
67 double value,
68 const base::TimeTicks& timestamp);
69 void OnSync(const base::TimeTicks& timestamp);
70
71 // Sometimes, we want to drop abs values, when we do so, we no longer want to
72 // send gamepad frame event when we see next sync. This flag is set to false
73 // when each frame is sent. It is set to true when Btn or Abs event is sent.
74 bool will_send_frame_;
75
76 // Internal representation of axis information.
77
78 class Axis {
79 public:
80 Axis();
81 Axis(const input_absinfo& abs_info,
82 GamepadEventType mapped_type,
83 uint16_t mapped_code);
84
85 bool MapValue(uint16_t value, double* mapped_value);
86
87 GamepadEventType mapped_type();
88
89 uint16_t mapped_code();
90
91 private:
92 bool ValueChangeSignificantly(double new_value);
93 double last_value_;
94 double scale_;
95 double offset_;
96 double scaled_fuzz_;
97 double scaled_flat_;
98 GamepadEventType mapped_type_;
99 uint16_t mapped_code_;
100 };
101
102 Axis axes_[ABS_CNT];
103
104 // These values keeps the state of previous hat.
105 bool last_hat_left_press_;
106 bool last_hat_right_press_;
107 bool last_hat_up_press_;
108 bool last_hat_down_press_;
109
110 GamepadMapper mapper_;
111
112 // Input device file descriptor.
113 ScopedInputDevice input_device_fd_;
114
115 // Callbacks for dispatching events.
116 DeviceEventDispatcherEvdev* dispatcher_;
117
118 DISALLOW_COPY_AND_ASSIGN(GamepadEventConverterEvdev);
119 };
120
121 } // namespace ui
122
123 #endif // UI_EVENTS_OZONE_GAMEPAD_EVENT_CONVERTER_EVDEV_H_
OLDNEW
« no previous file with comments | « ui/events/ozone/evdev/event_factory_evdev.cc ('k') | ui/events/ozone/evdev/gamepad_event_converter_evdev.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698