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

Side by Side Diff: content/browser/gamepad/gamepad_platform_data_fetcher_linux.cc

Issue 165983005: Updating Gamepad API to match latest spec (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed typo in GamepadProviderTest Created 6 years, 9 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 | Annotate | Revision Log
« no previous file with comments | « build/common.gypi ('k') | content/browser/gamepad/gamepad_platform_data_fetcher_mac.mm » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "content/browser/gamepad/gamepad_platform_data_fetcher_linux.h" 5 #include "content/browser/gamepad/gamepad_platform_data_fetcher_linux.h"
6 6
7 #include <fcntl.h> 7 #include <fcntl.h>
8 #include <libudev.h> 8 #include <libudev.h>
9 #include <linux/joystick.h> 9 #include <linux/joystick.h>
10 #include <string.h> 10 #include <string.h>
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 std::string id = name_string + base::StringPrintf( 184 std::string id = name_string + base::StringPrintf(
185 " (%sVendor: %s Product: %s)", 185 " (%sVendor: %s Product: %s)",
186 mapper ? "STANDARD GAMEPAD " : "", 186 mapper ? "STANDARD GAMEPAD " : "",
187 vendor_id, 187 vendor_id,
188 product_id); 188 product_id);
189 base::TruncateUTF8ToByteSize(id, WebGamepad::idLengthCap - 1, &id); 189 base::TruncateUTF8ToByteSize(id, WebGamepad::idLengthCap - 1, &id);
190 base::string16 tmp16 = base::UTF8ToUTF16(id); 190 base::string16 tmp16 = base::UTF8ToUTF16(id);
191 memset(pad.id, 0, sizeof(pad.id)); 191 memset(pad.id, 0, sizeof(pad.id));
192 tmp16.copy(pad.id, arraysize(pad.id) - 1); 192 tmp16.copy(pad.id, arraysize(pad.id) - 1);
193 193
194 if (mapper) {
195 std::string mapping = "standard";
196 base::TruncateUTF8ToByteSize(mapping, WebGamepad::mappingLengthCap - 1,
197 &mapping);
198 tmp16 = base::UTF8ToUTF16(mapping);
199 memset(pad.mapping, 0, sizeof(pad.mapping));
200 tmp16.copy(pad.mapping, arraysize(pad.mapping) - 1);
201 } else {
202 pad.mapping[0] = 0;
203 }
204
194 pad.connected = true; 205 pad.connected = true;
195 } 206 }
196 } 207 }
197 208
198 void GamepadPlatformDataFetcherLinux::EnumerateDevices() { 209 void GamepadPlatformDataFetcherLinux::EnumerateDevices() {
199 udev_enumerate* enumerate = udev_enumerate_new(udev_->udev_handle()); 210 udev_enumerate* enumerate = udev_enumerate_new(udev_->udev_handle());
200 if (!enumerate) 211 if (!enumerate)
201 return; 212 return;
202 int ret = udev_enumerate_add_match_subsystem(enumerate, kInputSubsystem); 213 int ret = udev_enumerate_add_match_subsystem(enumerate, kInputSubsystem);
203 if (ret != 0) 214 if (ret != 0)
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
239 size_t item = event.number; 250 size_t item = event.number;
240 if (event.type & JS_EVENT_AXIS) { 251 if (event.type & JS_EVENT_AXIS) {
241 if (item >= WebGamepad::axesLengthCap) 252 if (item >= WebGamepad::axesLengthCap)
242 continue; 253 continue;
243 pad.axes[item] = event.value / kMaxLinuxAxisValue; 254 pad.axes[item] = event.value / kMaxLinuxAxisValue;
244 if (item >= pad.axesLength) 255 if (item >= pad.axesLength)
245 pad.axesLength = item + 1; 256 pad.axesLength = item + 1;
246 } else if (event.type & JS_EVENT_BUTTON) { 257 } else if (event.type & JS_EVENT_BUTTON) {
247 if (item >= WebGamepad::buttonsLengthCap) 258 if (item >= WebGamepad::buttonsLengthCap)
248 continue; 259 continue;
249 pad.buttons[item] = event.value ? 1.0 : 0.0; 260 pad.buttons[item].pressed = event.value;
261 pad.buttons[item].value = event.value ? 1.0 : 0.0;
250 if (item >= pad.buttonsLength) 262 if (item >= pad.buttonsLength)
251 pad.buttonsLength = item + 1; 263 pad.buttonsLength = item + 1;
252 } 264 }
253 pad.timestamp = event.time; 265 pad.timestamp = event.time;
254 } 266 }
255 } 267 }
256 268
257 } // namespace content 269 } // namespace content
OLDNEW
« no previous file with comments | « build/common.gypi ('k') | content/browser/gamepad/gamepad_platform_data_fetcher_mac.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698