[email protected] | 00c0d04 | 2012-09-10 07:06:39 | [diff] [blame] | 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 |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "ppapi/shared_impl/ppb_gamepad_shared.h" |
| 6 | |
Matt Reynolds | 7550995f | 2018-05-23 03:12:55 | [diff] [blame] | 7 | #include <cstring> |
[email protected] | 00c0d04 | 2012-09-10 07:06:39 | [diff] [blame] | 8 | |
juncai | 2f298a8 | 2017-04-18 03:51:39 | [diff] [blame] | 9 | #include "device/gamepad/public/cpp/gamepads.h" |
| 10 | |
[email protected] | 00c0d04 | 2012-09-10 07:06:39 | [diff] [blame] | 11 | namespace ppapi { |
| 12 | |
juncai | 2f298a8 | 2017-04-18 03:51:39 | [diff] [blame] | 13 | void ConvertDeviceGamepadData(const device::Gamepads& device_data, |
| 14 | PP_GamepadsSampleData* output_data) { |
| 15 | output_data->length = device::Gamepads::kItemsLengthCap; |
| 16 | for (unsigned i = 0; i < device::Gamepads::kItemsLengthCap; ++i) { |
| 17 | PP_GamepadSampleData& output_pad = output_data->items[i]; |
| 18 | const device::Gamepad& device_pad = device_data.items[i]; |
| 19 | output_pad.connected = device_pad.connected ? PP_TRUE : PP_FALSE; |
| 20 | if (device_pad.connected) { |
| 21 | static_assert(sizeof(output_pad.id) == sizeof(device_pad.id), |
| 22 | "id size does not match"); |
Matt Reynolds | 7550995f | 2018-05-23 03:12:55 | [diff] [blame] | 23 | std::memcpy(output_pad.id, device_pad.id, sizeof(output_pad.id)); |
juncai | 2f298a8 | 2017-04-18 03:51:39 | [diff] [blame] | 24 | output_pad.timestamp = static_cast<double>(device_pad.timestamp); |
| 25 | output_pad.axes_length = device_pad.axes_length; |
| 26 | for (unsigned j = 0; j < device_pad.axes_length; ++j) |
| 27 | output_pad.axes[j] = static_cast<float>(device_pad.axes[j]); |
| 28 | output_pad.buttons_length = device_pad.buttons_length; |
| 29 | for (unsigned j = 0; j < device_pad.buttons_length; ++j) |
| 30 | output_pad.buttons[j] = static_cast<float>(device_pad.buttons[j].value); |
| 31 | } |
| 32 | } |
| 33 | } |
| 34 | |
[email protected] | 00c0d04 | 2012-09-10 07:06:39 | [diff] [blame] | 35 | } // namespace ppapi |