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

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

Issue 2899893003: Add generic mapping for gamepad (Closed)
Patch Set: Add generic mapping for gamepad Created 3 years, 6 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_->Map(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(!IsEnabled()); 135 DCHECK(!IsEnabled());
136 } 136 }
137 137
138 bool GamepadEventConverterEvdev::HasGamepad() const { 138 bool GamepadEventConverterEvdev::HasGamepad() const {
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
183 } 183 }
184 } 184 }
185 185
186 void GamepadEventConverterEvdev::ProcessEvdevKey( 186 void GamepadEventConverterEvdev::ProcessEvdevKey(
187 uint16_t code, 187 uint16_t code,
188 int value, 188 int value,
189 const base::TimeTicks& timestamp) { 189 const base::TimeTicks& timestamp) {
190 GamepadEventType mapped_type; 190 GamepadEventType mapped_type;
191 uint16_t mapped_code; 191 uint16_t mapped_code;
192 192
193 bool found_map = mapper_(EV_KEY, code, &mapped_type, &mapped_code); 193 bool found_map = mapper_->Map(EV_KEY, code, &mapped_type, &mapped_code);
194 194
195 // If we cannot find a map for this event, it will be discarded. 195 // If we cannot find a map for this event, it will be discarded.
196 if (!found_map) { 196 if (!found_map) {
197 return; 197 return;
198 } 198 }
199 199
200 // If it's btn -> btn mapping, we can send the event and return now. 200 // If it's btn -> btn mapping, we can send the event and return now.
201 OnButtonChange(mapped_code, value, timestamp); 201 OnButtonChange(mapped_code, value, timestamp);
202 } 202 }
203 203
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
308 308
309 void GamepadEventConverterEvdev::OnSync(const base::TimeTicks& timestamp) { 309 void GamepadEventConverterEvdev::OnSync(const base::TimeTicks& timestamp) {
310 if (will_send_frame_) { 310 if (will_send_frame_) {
311 GamepadEvent event(input_device_.id, GamepadEventType::FRAME, 0, 0, 311 GamepadEvent event(input_device_.id, GamepadEventType::FRAME, 0, 0,
312 timestamp); 312 timestamp);
313 dispatcher_->DispatchGamepadEvent(event); 313 dispatcher_->DispatchGamepadEvent(event);
314 will_send_frame_ = false; 314 will_send_frame_ = false;
315 } 315 }
316 } 316 }
317 } // namespace ui 317 } // namespace ui
OLDNEW
« no previous file with comments | « ui/events/ozone/evdev/gamepad_event_converter_evdev.h ('k') | ui/events/ozone/gamepad/gamepad_mapping.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698