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

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

Issue 2899893003: Add generic mapping for gamepad (Closed)
Patch Set: 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
1 // Copyright 2017 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ui/events/ozone/evdev/gamepad_event_converter_evdev.h" 5 #include "ui/events/ozone/evdev/gamepad_event_converter_evdev.h"
6 6
7 #include <errno.h> 7 #include <errno.h>
8 #include <linux/input.h> 8 #include <linux/input.h>
9 #include <stddef.h> 9 #include <stddef.h>
10 10
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 id, 100 id,
101 devinfo.device_type(), 101 devinfo.device_type(),
102 devinfo.name(), 102 devinfo.name(),
103 devinfo.vendor_id(), 103 devinfo.vendor_id(),
104 devinfo.product_id()), 104 devinfo.product_id()),
105 will_send_frame_(false), 105 will_send_frame_(false),
106 last_hat_left_press_(false), 106 last_hat_left_press_(false),
107 last_hat_right_press_(false), 107 last_hat_right_press_(false),
108 last_hat_up_press_(false), 108 last_hat_up_press_(false),
109 last_hat_down_press_(false), 109 last_hat_down_press_(false),
110 mapper_(GetGamepadMapper(devinfo.vendor_id(), devinfo.product_id())), 110 mapper_(GetGamepadMapper(devinfo)),
111 input_device_fd_(std::move(fd)), 111 input_device_fd_(std::move(fd)),
112 dispatcher_(dispatcher) { 112 dispatcher_(dispatcher) {
113 input_absinfo abs_info; 113 input_absinfo abs_info;
114 GamepadEventType mapped_type; 114 GamepadEventType mapped_type;
115 uint16_t mapped_code; 115 uint16_t mapped_code;
116 // In order to map gamepad, we have to save the abs_info from device_info 116 // In order to map gamepad, we have to save the abs_info from device_info
117 // and get the gamepad_mapping. 117 // and get the gamepad_mapping.
118 for (int code = 0; code < ABS_CNT; ++code) { 118 for (int code = 0; code < ABS_CNT; ++code) {
119 abs_info = devinfo.GetAbsInfoByCode(code); 119 abs_info = devinfo.GetAbsInfoByCode(code);
120 if (devinfo.HasAbsEvent(code)) { 120 if (devinfo.HasAbsEvent(code)) {
121 // If fuzz was reported as zero, it will be set to flat * 0.25f. It is 121 // If fuzz was reported as zero, it will be set to flat * 0.25f. It is
122 // the same thing done in Android InputReader.cpp. See: 122 // the same thing done in Android InputReader.cpp. See:
123 // frameworks/native/services/inputflinger/InputReader.cpp line 6988 for 123 // frameworks/native/services/inputflinger/InputReader.cpp line 6988 for
124 // more details. 124 // more details.
125 if (abs_info.fuzz == 0) { 125 if (abs_info.fuzz == 0) {
126 abs_info.fuzz = abs_info.flat * 0.25f; 126 abs_info.fuzz = abs_info.flat * 0.25f;
127 } 127 }
128 mapper_(EV_ABS, code, &mapped_type, &mapped_code); 128 (*mapper_)(EV_ABS, code, &mapped_type, &mapped_code);
129 axes_[code] = Axis(abs_info, mapped_type, mapped_code); 129 axes_[code] = Axis(abs_info, mapped_type, mapped_code);
130 } 130 }
131 } 131 }
132 } 132 }
133 133
134 GamepadEventConverterEvdev::~GamepadEventConverterEvdev() { 134 GamepadEventConverterEvdev::~GamepadEventConverterEvdev() {
135 DCHECK(!enabled_); 135 DCHECK(!enabled_);
136 delete mapper_;
136 } 137 }
137 138
138 bool GamepadEventConverterEvdev::HasGamepad() const { 139 bool GamepadEventConverterEvdev::HasGamepad() const {
139 return true; 140 return true;
140 } 141 }
141 142
142 void GamepadEventConverterEvdev::OnFileCanReadWithoutBlocking(int fd) { 143 void GamepadEventConverterEvdev::OnFileCanReadWithoutBlocking(int fd) {
143 TRACE_EVENT1("evdev", 144 TRACE_EVENT1("evdev",
144 "GamepadEventConverterEvdev::OnFileCanReadWithoutBlocking", "fd", 145 "GamepadEventConverterEvdev::OnFileCanReadWithoutBlocking", "fd",
145 fd); 146 fd);
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
183 } 184 }
184 } 185 }
185 186
186 void GamepadEventConverterEvdev::ProcessEvdevKey( 187 void GamepadEventConverterEvdev::ProcessEvdevKey(
187 uint16_t code, 188 uint16_t code,
188 uint16_t value, 189 uint16_t value,
189 const base::TimeTicks& timestamp) { 190 const base::TimeTicks& timestamp) {
190 GamepadEventType mapped_type; 191 GamepadEventType mapped_type;
191 uint16_t mapped_code; 192 uint16_t mapped_code;
192 193
193 bool found_map = mapper_(EV_KEY, code, &mapped_type, &mapped_code); 194 bool found_map = (*mapper_)(EV_KEY, code, &mapped_type, &mapped_code);
194 195
195 // If we cannot find a map for this event, it will be discarded. 196 // If we cannot find a map for this event, it will be discarded.
196 if (!found_map) { 197 if (!found_map) {
197 return; 198 return;
198 } 199 }
199 200
200 // If it's btn -> btn mapping, we can send the event and return now. 201 // If it's btn -> btn mapping, we can send the event and return now.
201 OnButtonChange(mapped_code, value, timestamp); 202 OnButtonChange(mapped_code, value, timestamp);
202 } 203 }
203 204
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
308 309
309 void GamepadEventConverterEvdev::OnSync(const base::TimeTicks& timestamp) { 310 void GamepadEventConverterEvdev::OnSync(const base::TimeTicks& timestamp) {
310 if (will_send_frame_) { 311 if (will_send_frame_) {
311 GamepadEvent event(input_device_.id, GamepadEventType::FRAME, 0, 0, 312 GamepadEvent event(input_device_.id, GamepadEventType::FRAME, 0, 0,
312 timestamp); 313 timestamp);
313 dispatcher_->DispatchGamepadEvent(event); 314 dispatcher_->DispatchGamepadEvent(event);
314 will_send_frame_ = false; 315 will_send_frame_ = false;
315 } 316 }
316 } 317 }
317 } // namespace ui 318 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698