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

Side by Side Diff: device/gamepad/xbox_data_fetcher_mac.mm

Issue 2808093006: [Device Service] Move Gamepad Blink headers to be part of the Gamepad client library (Closed)
Patch Set: rebase and address comments Created 3 years, 8 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
« no previous file with comments | « device/gamepad/raw_input_data_fetcher_win.cc ('k') | device/vr/BUILD.gn » ('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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "device/gamepad/xbox_data_fetcher_mac.h" 5 #include "device/gamepad/xbox_data_fetcher_mac.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <cmath> 8 #include <cmath>
9 #include <limits> 9 #include <limits>
10 10
11 #include <CoreFoundation/CoreFoundation.h> 11 #include <CoreFoundation/CoreFoundation.h>
12 #include <IOKit/IOCFPlugIn.h> 12 #include <IOKit/IOCFPlugIn.h>
13 #include <IOKit/IOKitLib.h> 13 #include <IOKit/IOKitLib.h>
14 #include <IOKit/usb/IOUSBLib.h> 14 #include <IOKit/usb/IOUSBLib.h>
15 #include <IOKit/usb/USB.h> 15 #include <IOKit/usb/USB.h>
16 16
17 #include "base/logging.h" 17 #include "base/logging.h"
18 #include "base/mac/foundation_util.h" 18 #include "base/mac/foundation_util.h"
19 19
20 using blink::WebGamepad;
21
22 namespace device { 20 namespace device {
23 21
24 namespace { 22 namespace {
25 23
26 const int kVendorMicrosoft = 0x045e; 24 const int kVendorMicrosoft = 0x045e;
27 const int kProductXbox360Controller = 0x028e; 25 const int kProductXbox360Controller = 0x028e;
28 const int kProductXboxOneController = 0x02d1; 26 const int kProductXboxOneController = 0x02d1;
29 27
30 const int kXbox360ReadEndpoint = 1; 28 const int kXbox360ReadEndpoint = 1;
31 const int kXbox360ControlEndpoint = 2; 29 const int kXbox360ControlEndpoint = 2;
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
221 normalized_data->buttons[14] = data.sync; 219 normalized_data->buttons[14] = data.sync;
222 normalized_data->triggers[0] = NormalizeXboxOneTrigger(data.trigger_left); 220 normalized_data->triggers[0] = NormalizeXboxOneTrigger(data.trigger_left);
223 normalized_data->triggers[1] = NormalizeXboxOneTrigger(data.trigger_right); 221 normalized_data->triggers[1] = NormalizeXboxOneTrigger(data.trigger_right);
224 NormalizeAxis(data.stick_left_x, data.stick_left_y, kLeftThumbDeadzone, 222 NormalizeAxis(data.stick_left_x, data.stick_left_y, kLeftThumbDeadzone,
225 &normalized_data->axes[0], &normalized_data->axes[1]); 223 &normalized_data->axes[0], &normalized_data->axes[1]);
226 NormalizeAxis(data.stick_right_x, data.stick_right_y, kRightThumbDeadzone, 224 NormalizeAxis(data.stick_right_x, data.stick_right_y, kRightThumbDeadzone,
227 &normalized_data->axes[2], &normalized_data->axes[3]); 225 &normalized_data->axes[2], &normalized_data->axes[3]);
228 } 226 }
229 227
230 void CopyNSStringAsUTF16LittleEndian(NSString* src, 228 void CopyNSStringAsUTF16LittleEndian(NSString* src,
231 blink::WebUChar* dest, 229 UChar* dest,
232 size_t dest_len) { 230 size_t dest_len) {
233 NSData* as16 = [src dataUsingEncoding:NSUTF16LittleEndianStringEncoding]; 231 NSData* as16 = [src dataUsingEncoding:NSUTF16LittleEndianStringEncoding];
234 memset(dest, 0, dest_len); 232 memset(dest, 0, dest_len);
235 [as16 getBytes:dest length:dest_len - sizeof(blink::WebUChar)]; 233 [as16 getBytes:dest length:dest_len - sizeof(UChar)];
236 } 234 }
237 235
238 } // namespace 236 } // namespace
239 237
240 XboxController::XboxController(Delegate* delegate) 238 XboxController::XboxController(Delegate* delegate)
241 : device_(NULL), 239 : device_(NULL),
242 interface_(NULL), 240 interface_(NULL),
243 device_is_open_(false), 241 device_is_open_(false),
244 interface_is_open_(false), 242 interface_is_open_(false),
245 read_buffer_size_(0), 243 read_buffer_size_(0),
(...skipping 558 matching lines...) Expand 10 before | Expand all | Expand 10 after
804 if (controller) 802 if (controller)
805 RemoveController(controller); 803 RemoveController(controller);
806 } 804 }
807 805
808 void XboxDataFetcher::XboxControllerGotData(XboxController* controller, 806 void XboxDataFetcher::XboxControllerGotData(XboxController* controller,
809 const XboxController::Data& data) { 807 const XboxController::Data& data) {
810 PadState* state = GetPadState(controller->location_id()); 808 PadState* state = GetPadState(controller->location_id());
811 if (!state) 809 if (!state)
812 return; // No available slot for this device 810 return; // No available slot for this device
813 811
814 WebGamepad& pad = state->data; 812 Gamepad& pad = state->data;
815 813
816 for (size_t i = 0; i < 6; i++) { 814 for (size_t i = 0; i < 6; i++) {
817 pad.buttons[i].pressed = data.buttons[i]; 815 pad.buttons[i].pressed = data.buttons[i];
818 pad.buttons[i].value = data.buttons[i] ? 1.0f : 0.0f; 816 pad.buttons[i].value = data.buttons[i] ? 1.0f : 0.0f;
819 } 817 }
820 pad.buttons[6].pressed = data.triggers[0] > kDefaultButtonPressedThreshold; 818 pad.buttons[6].pressed = data.triggers[0] > kDefaultButtonPressedThreshold;
821 pad.buttons[6].value = data.triggers[0]; 819 pad.buttons[6].value = data.triggers[0];
822 pad.buttons[7].pressed = data.triggers[1] > kDefaultButtonPressedThreshold; 820 pad.buttons[7].pressed = data.triggers[1] > kDefaultButtonPressedThreshold;
823 pad.buttons[7].value = data.triggers[1]; 821 pad.buttons[7].value = data.triggers[1];
824 for (size_t i = 8; i < 17; i++) { 822 for (size_t i = 8; i < 17; i++) {
825 pad.buttons[i].pressed = data.buttons[i - 2]; 823 pad.buttons[i].pressed = data.buttons[i - 2];
826 pad.buttons[i].value = data.buttons[i - 2] ? 1.0f : 0.0f; 824 pad.buttons[i].value = data.buttons[i - 2] ? 1.0f : 0.0f;
827 } 825 }
828 for (size_t i = 0; i < arraysize(data.axes); i++) { 826 for (size_t i = 0; i < arraysize(data.axes); i++) {
829 pad.axes[i] = data.axes[i]; 827 pad.axes[i] = data.axes[i];
830 } 828 }
831 829
832 pad.timestamp = base::TimeTicks::Now().ToInternalValue(); 830 pad.timestamp = base::TimeTicks::Now().ToInternalValue();
833 } 831 }
834 832
835 void XboxDataFetcher::XboxControllerError(XboxController* controller) { 833 void XboxDataFetcher::XboxControllerError(XboxController* controller) {
836 RemoveController(controller); 834 RemoveController(controller);
837 } 835 }
838 836
839 } // namespace device 837 } // namespace device
OLDNEW
« no previous file with comments | « device/gamepad/raw_input_data_fetcher_win.cc ('k') | device/vr/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698