| OLD | NEW |
| 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_standard_mappings.h" | 5 #include "content/browser/gamepad/gamepad_standard_mappings.h" |
| 6 | 6 |
| 7 #include "content/common/gamepad_hardware_buffer.h" | 7 #include "content/common/gamepad_hardware_buffer.h" |
| 8 | 8 |
| 9 namespace content { | 9 namespace content { |
| 10 | 10 |
| 11 namespace { | 11 namespace { |
| 12 | 12 |
| 13 // Maps 0..65535 to -1..1. | 13 // Maps 0..65535 to -1..1. |
| 14 float NormalizeDirectInputAxis(long value) { | 14 float NormalizeDirectInputAxis(long value) { |
| 15 return (value * 1.f / 32767.5f) - 1.f; | 15 return (value * 1.f / 32767.5f) - 1.f; |
| 16 } | 16 } |
| 17 | 17 |
| 18 float AxisNegativeAsButton(long value) { | 18 float AxisNegativeAsButton(long value) { |
| 19 return (value < 32767) ? 1.f : 0.f; | 19 return (value < 32767) ? 1.f : 0.f; |
| 20 } | 20 } |
| 21 | 21 |
| 22 float AxisPositiveAsButton(long value) { | 22 float AxisPositiveAsButton(long value) { |
| 23 return (value > 32767) ? 1.f : 0.f; | 23 return (value > 32767) ? 1.f : 0.f; |
| 24 } | 24 } |
| 25 | 25 |
| 26 void MapperDragonRiseGeneric( | 26 void MapperDragonRiseGeneric( |
| 27 const WebKit::WebGamepad& input, | 27 const blink::WebGamepad& input, |
| 28 WebKit::WebGamepad* mapped) { | 28 blink::WebGamepad* mapped) { |
| 29 *mapped = input; | 29 *mapped = input; |
| 30 mapped->buttons[0] = input.buttons[1]; | 30 mapped->buttons[0] = input.buttons[1]; |
| 31 mapped->buttons[1] = input.buttons[2]; | 31 mapped->buttons[1] = input.buttons[2]; |
| 32 mapped->buttons[2] = input.buttons[0]; | 32 mapped->buttons[2] = input.buttons[0]; |
| 33 mapped->buttons[12] = input.buttons[16]; | 33 mapped->buttons[12] = input.buttons[16]; |
| 34 mapped->buttons[13] = input.buttons[17]; | 34 mapped->buttons[13] = input.buttons[17]; |
| 35 mapped->buttons[14] = input.buttons[18]; | 35 mapped->buttons[14] = input.buttons[18]; |
| 36 mapped->buttons[15] = input.buttons[19]; | 36 mapped->buttons[15] = input.buttons[19]; |
| 37 mapped->buttonsLength = 16; | 37 mapped->buttonsLength = 16; |
| 38 mapped->axes[0] = NormalizeDirectInputAxis(input.axes[0]); | 38 mapped->axes[0] = NormalizeDirectInputAxis(input.axes[0]); |
| 39 mapped->axes[1] = NormalizeDirectInputAxis(input.axes[1]); | 39 mapped->axes[1] = NormalizeDirectInputAxis(input.axes[1]); |
| 40 mapped->axes[2] = NormalizeDirectInputAxis(input.axes[2]); | 40 mapped->axes[2] = NormalizeDirectInputAxis(input.axes[2]); |
| 41 mapped->axes[3] = NormalizeDirectInputAxis(input.axes[5]); | 41 mapped->axes[3] = NormalizeDirectInputAxis(input.axes[5]); |
| 42 mapped->axesLength = 4; | 42 mapped->axesLength = 4; |
| 43 } | 43 } |
| 44 | 44 |
| 45 void MapperLogitechDualAction( | 45 void MapperLogitechDualAction( |
| 46 const WebKit::WebGamepad& input, | 46 const blink::WebGamepad& input, |
| 47 WebKit::WebGamepad* mapped) { | 47 blink::WebGamepad* mapped) { |
| 48 *mapped = input; | 48 *mapped = input; |
| 49 mapped->buttons[0] = input.buttons[1]; | 49 mapped->buttons[0] = input.buttons[1]; |
| 50 mapped->buttons[1] = input.buttons[2]; | 50 mapped->buttons[1] = input.buttons[2]; |
| 51 mapped->buttons[2] = input.buttons[0]; | 51 mapped->buttons[2] = input.buttons[0]; |
| 52 mapped->buttons[12] = input.buttons[16]; | 52 mapped->buttons[12] = input.buttons[16]; |
| 53 mapped->buttons[13] = input.buttons[17]; | 53 mapped->buttons[13] = input.buttons[17]; |
| 54 mapped->buttons[14] = input.buttons[18]; | 54 mapped->buttons[14] = input.buttons[18]; |
| 55 mapped->buttons[15] = input.buttons[19]; | 55 mapped->buttons[15] = input.buttons[19]; |
| 56 mapped->buttonsLength = 16; | 56 mapped->buttonsLength = 16; |
| 57 mapped->axes[0] = NormalizeDirectInputAxis(input.axes[0]); | 57 mapped->axes[0] = NormalizeDirectInputAxis(input.axes[0]); |
| 58 mapped->axes[1] = NormalizeDirectInputAxis(input.axes[1]); | 58 mapped->axes[1] = NormalizeDirectInputAxis(input.axes[1]); |
| 59 mapped->axes[2] = NormalizeDirectInputAxis(input.axes[2]); | 59 mapped->axes[2] = NormalizeDirectInputAxis(input.axes[2]); |
| 60 mapped->axes[3] = NormalizeDirectInputAxis(input.axes[5]); | 60 mapped->axes[3] = NormalizeDirectInputAxis(input.axes[5]); |
| 61 mapped->axesLength = 4; | 61 mapped->axesLength = 4; |
| 62 } | 62 } |
| 63 | 63 |
| 64 void MapperLogitechPrecision( | 64 void MapperLogitechPrecision( |
| 65 const WebKit::WebGamepad& input, | 65 const blink::WebGamepad& input, |
| 66 WebKit::WebGamepad* mapped) { | 66 blink::WebGamepad* mapped) { |
| 67 *mapped = input; | 67 *mapped = input; |
| 68 mapped->buttons[0] = input.buttons[1]; | 68 mapped->buttons[0] = input.buttons[1]; |
| 69 mapped->buttons[1] = input.buttons[2]; | 69 mapped->buttons[1] = input.buttons[2]; |
| 70 mapped->buttons[2] = input.buttons[0]; | 70 mapped->buttons[2] = input.buttons[0]; |
| 71 mapped->buttons[kButtonLeftThumbstick] = 0; // Not present | 71 mapped->buttons[kButtonLeftThumbstick] = 0; // Not present |
| 72 mapped->buttons[kButtonRightThumbstick] = 0; // Not present | 72 mapped->buttons[kButtonRightThumbstick] = 0; // Not present |
| 73 mapped->buttons[12] = AxisNegativeAsButton(input.axes[1]); | 73 mapped->buttons[12] = AxisNegativeAsButton(input.axes[1]); |
| 74 mapped->buttons[13] = AxisPositiveAsButton(input.axes[1]); | 74 mapped->buttons[13] = AxisPositiveAsButton(input.axes[1]); |
| 75 mapped->buttons[14] = AxisNegativeAsButton(input.axes[0]); | 75 mapped->buttons[14] = AxisNegativeAsButton(input.axes[0]); |
| 76 mapped->buttons[15] = AxisPositiveAsButton(input.axes[0]); | 76 mapped->buttons[15] = AxisPositiveAsButton(input.axes[0]); |
| 77 mapped->buttonsLength = 16; | 77 mapped->buttonsLength = 16; |
| 78 mapped->axesLength = 0; | 78 mapped->axesLength = 0; |
| 79 } | 79 } |
| 80 | 80 |
| 81 void Mapper2Axes8Keys( | 81 void Mapper2Axes8Keys( |
| 82 const WebKit::WebGamepad& input, | 82 const blink::WebGamepad& input, |
| 83 WebKit::WebGamepad* mapped) { | 83 blink::WebGamepad* mapped) { |
| 84 *mapped = input; | 84 *mapped = input; |
| 85 mapped->buttons[kButtonLeftTrigger] = 0; // Not present | 85 mapped->buttons[kButtonLeftTrigger] = 0; // Not present |
| 86 mapped->buttons[kButtonRightTrigger] = 0; // Not present | 86 mapped->buttons[kButtonRightTrigger] = 0; // Not present |
| 87 mapped->buttons[8] = input.buttons[6]; | 87 mapped->buttons[8] = input.buttons[6]; |
| 88 mapped->buttons[9] = input.buttons[7]; | 88 mapped->buttons[9] = input.buttons[7]; |
| 89 mapped->buttons[kButtonLeftThumbstick] = 0; // Not present | 89 mapped->buttons[kButtonLeftThumbstick] = 0; // Not present |
| 90 mapped->buttons[kButtonRightThumbstick] = 0; // Not present | 90 mapped->buttons[kButtonRightThumbstick] = 0; // Not present |
| 91 mapped->buttons[12] = AxisNegativeAsButton(input.axes[1]); | 91 mapped->buttons[12] = AxisNegativeAsButton(input.axes[1]); |
| 92 mapped->buttons[13] = AxisPositiveAsButton(input.axes[1]); | 92 mapped->buttons[13] = AxisPositiveAsButton(input.axes[1]); |
| 93 mapped->buttons[14] = AxisNegativeAsButton(input.axes[0]); | 93 mapped->buttons[14] = AxisNegativeAsButton(input.axes[0]); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 115 const base::StringPiece& product_id) { | 115 const base::StringPiece& product_id) { |
| 116 for (size_t i = 0; i < arraysize(AvailableMappings); ++i) { | 116 for (size_t i = 0; i < arraysize(AvailableMappings); ++i) { |
| 117 MappingData& item = AvailableMappings[i]; | 117 MappingData& item = AvailableMappings[i]; |
| 118 if (vendor_id == item.vendor_id && product_id == item.product_id) | 118 if (vendor_id == item.vendor_id && product_id == item.product_id) |
| 119 return item.function; | 119 return item.function; |
| 120 } | 120 } |
| 121 return NULL; | 121 return NULL; |
| 122 } | 122 } |
| 123 | 123 |
| 124 } // namespace content | 124 } // namespace content |
| OLD | NEW |