| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 // Use the <code>chrome.hid</code> API to interact with connected HID devices. | 5 // Use the <code>chrome.hid</code> API to interact with connected HID devices. |
| 6 // This API provides access to HID operations from within the context of an app. | 6 // This API provides access to HID operations from within the context of an app. |
| 7 // Using this API, apps can function as drivers for hardware devices. | 7 // Using this API, apps can function as drivers for hardware devices. |
| 8 // |
| 9 // Errors generated by this API are reported by setting |
| 10 // $(ref:runtime.lastError) and executing the function's regular callback. The |
| 11 // callback's regular parameters will be undefined in this case. |
| 8 namespace hid { | 12 namespace hid { |
| 9 dictionary HidCollectionInfo { | 13 dictionary HidCollectionInfo { |
| 10 // HID usage page identifier. | 14 // HID usage page identifier. |
| 11 long usagePage; | 15 long usagePage; |
| 12 // Page-defined usage identifier. | 16 // Page-defined usage identifier. |
| 13 long usage; | 17 long usage; |
| 14 // Report IDs which belong to the collection and to its children. | 18 // Report IDs which belong to the collection and to its children. |
| 15 long[] reportIds; | 19 long[] reportIds; |
| 16 }; | 20 }; |
| 17 | 21 |
| 18 [noinline_doc] dictionary HidDeviceInfo { | 22 [noinline_doc] dictionary HidDeviceInfo { |
| 19 // Device opaque ID. | 23 // Opaque device ID. |
| 20 long deviceId; | 24 long deviceId; |
| 21 // Vendor ID. | 25 // Vendor ID. |
| 22 long vendorId; | 26 long vendorId; |
| 23 // Product ID. | 27 // Product ID. |
| 24 long productId; | 28 long productId; |
| 25 // Top-level collections from this device's report descriptors. | 29 // Top-level collections from this device's report descriptors. |
| 26 HidCollectionInfo[] collections; | 30 HidCollectionInfo[] collections; |
| 27 // Top-level collection's maximum input report size. | 31 // Top-level collection's maximum input report size. |
| 28 long maxInputReportSize; | 32 long maxInputReportSize; |
| 29 // Top-level collection's maximum output report size. | 33 // Top-level collection's maximum output report size. |
| 30 long maxOutputReportSize; | 34 long maxOutputReportSize; |
| 31 // Top-level collection's maximum feature report size. | 35 // Top-level collection's maximum feature report size. |
| 32 long maxFeatureReportSize; | 36 long maxFeatureReportSize; |
| 33 }; | 37 }; |
| 34 | 38 |
| 35 // Returned by <code>connect</code> to represent a communication session with | |
| 36 // an HID device. Must be closed with a call to <code>disconnect</code>. | |
| 37 dictionary HidConnectInfo { | 39 dictionary HidConnectInfo { |
| 40 // The opaque ID used to identify this connection in all other functions. |
| 38 long connectionId; | 41 long connectionId; |
| 39 }; | 42 }; |
| 40 | 43 |
| 41 [noinline_doc] dictionary DeviceFilter { | 44 [noinline_doc] dictionary DeviceFilter { |
| 42 // Device vendor ID. | 45 // Device vendor ID. |
| 43 long? vendorId; | 46 long? vendorId; |
| 44 // Device product ID, only checked only if the vendor ID matches. | 47 // Device product ID, only checked only if the vendor ID matches. |
| 45 long? productId; | 48 long? productId; |
| 46 // HID usage page identifier. | 49 // HID usage page identifier. |
| 47 long? usagePage; | 50 long? usagePage; |
| 48 // HID usage identifier, checked only if the HID usage page matches. | 51 // HID usage identifier, checked only if the HID usage page matches. |
| 49 long? usage; | 52 long? usage; |
| 50 }; | 53 }; |
| 51 | 54 |
| 52 dictionary GetDevicesOptions { | 55 dictionary GetDevicesOptions { |
| 53 [deprecated="Equivalent to setting $(ref:DeviceFilter.vendorId)."] | 56 [deprecated="Equivalent to setting $(ref:DeviceFilter.vendorId)."] |
| 54 long? vendorId; | 57 long? vendorId; |
| 55 [deprecated="Equivalent to setting $(ref:DeviceFilter.productId)."] | 58 [deprecated="Equivalent to setting $(ref:DeviceFilter.productId)."] |
| 56 long? productId; | 59 long? productId; |
| 57 // A device matching any given filter will be returned. An empty filter list | 60 // A device matching any given filter will be returned. An empty filter list |
| 58 // will return all devices the app has permission for. | 61 // will return all devices the app has permission for. |
| 59 DeviceFilter[]? filters; | 62 DeviceFilter[]? filters; |
| 60 }; | 63 }; |
| 61 | 64 |
| 62 callback GetDevicesCallback = void (HidDeviceInfo[] devices); | 65 callback GetDevicesCallback = void (HidDeviceInfo[] devices); |
| 63 callback ConnectCallback = void (HidConnectInfo connection); | 66 callback ConnectCallback = void (HidConnectInfo connection); |
| 64 callback DisconnectCallback = void (); | 67 callback DisconnectCallback = void (); |
| 65 | 68 |
| 66 // |reportId|: The ID of the report. | 69 // |reportId|: The report ID or <code>0</code> if none. |
| 67 // |data|: The content of the report. | 70 // |data|: The content of the report. |
| 68 callback ReceiveCallback = void (long reportId, ArrayBuffer data); | 71 callback ReceiveCallback = void (long reportId, ArrayBuffer data); |
| 69 | 72 |
| 70 // |data|: The content of the report. | 73 // |data|: The content of the report. |
| 71 callback ReceiveFeatureReportCallback = void (ArrayBuffer data); | 74 callback ReceiveFeatureReportCallback = void (ArrayBuffer data); |
| 72 | 75 |
| 73 callback SendCallback = void(); | 76 callback SendCallback = void(); |
| 74 | 77 |
| 75 interface Functions { | 78 interface Functions { |
| 76 // Enumerate connected HID devices. | 79 // Enumerate connected HID devices. |
| 77 // |options|: The properties to search for on target devices. | 80 // |options|: The properties to search for on target devices. |
| 78 static void getDevices(GetDevicesOptions options, | 81 static void getDevices(GetDevicesOptions options, |
| 79 GetDevicesCallback callback); | 82 GetDevicesCallback callback); |
| 80 | 83 |
| 81 // Open a connection to an HID device for communication. | 84 // Open a connection to an HID device for communication. |
| 82 // |deviceId|: The ID of the device to open. | 85 // |deviceId|: The $(ref:HidDeviceInfo.deviceId) of the device to open. |
| 83 static void connect(long deviceId, | 86 static void connect(long deviceId, |
| 84 ConnectCallback callback); | 87 ConnectCallback callback); |
| 85 | 88 |
| 86 // Disconnect from a device. Invoking operations on a device after calling | 89 // Disconnect from a device. Invoking operations on a device after calling |
| 87 // this is safe but has no effect. | 90 // this is safe but has no effect. |
| 88 // |connectionId|: The connection to close. | 91 // |connectionId|: The <code>connectionId</code> returned by $(ref:connect). |
| 89 static void disconnect(long connectionId, | 92 static void disconnect(long connectionId, |
| 90 optional DisconnectCallback callback); | 93 optional DisconnectCallback callback); |
| 91 | 94 |
| 92 // Receive an Input report from an HID device. | 95 // Receive the next input report from the device. |
| 93 // | 96 // |connectionId|: The <code>connectionId</code> returned by $(ref:connect). |
| 94 // Input reports are returned to the host through the INTERRUPT IN endpoint. | |
| 95 // |connectionId|: The connection from which to receive a report. | |
| 96 static void receive(long connectionId, | 97 static void receive(long connectionId, |
| 97 ReceiveCallback callback); | 98 ReceiveCallback callback); |
| 98 | 99 |
| 99 // Send an Output report to an HID device. | 100 // Send an output report to the device. |
| 100 // <code>send</code> will send the data on the first OUT endpoint, if one | 101 // |connectionId|: The <code>connectionId</code> returned by $(ref:connect). |
| 101 // exists. If one does not exist, the report will be sent through the | |
| 102 // Control endpoint. | |
| 103 // | |
| 104 // |connectionId|: The connection to which to send a report. | |
| 105 // |reportId|: The report ID to use, or <code>0</code> if none. | 102 // |reportId|: The report ID to use, or <code>0</code> if none. |
| 106 // |data|: The report data. | 103 // |data|: The report data. |
| 107 static void send(long connectionId, | 104 static void send(long connectionId, |
| 108 long reportId, | 105 long reportId, |
| 109 ArrayBuffer data, | 106 ArrayBuffer data, |
| 110 SendCallback callback); | 107 SendCallback callback); |
| 111 | 108 |
| 112 // Receive a Feature report from the device. | 109 // Request a feature report from the device. |
| 113 // | 110 // |connectionId|: The <code>connectionId</code> returned by $(ref:connect). |
| 114 // |connectionId|: The connection to read Input report from. | 111 // |reportId|: The report ID, or <code>0</code> if none. |
| 115 // |reportId|: The report ID, or zero if none. | |
| 116 static void receiveFeatureReport(long connectionId, | 112 static void receiveFeatureReport(long connectionId, |
| 117 long reportId, | 113 long reportId, |
| 118 ReceiveFeatureReportCallback callback); | 114 ReceiveFeatureReportCallback callback); |
| 119 | 115 |
| 120 // Send a Feature report to the device. | 116 // Send a feature report to the device. |
| 121 // | 117 // |connectionId|: The <code>connectionId</code> returned by $(ref:connect). |
| 122 // Feature reports are sent over the Control endpoint as a Set_Report | |
| 123 // transfer. | |
| 124 // |connectionId|: The connection to read Input report from. | |
| 125 // |reportId|: The report ID to use, or <code>0</code> if none. | 118 // |reportId|: The report ID to use, or <code>0</code> if none. |
| 126 // |data|: The report data. | 119 // |data|: The report data. |
| 127 static void sendFeatureReport(long connectionId, | 120 static void sendFeatureReport(long connectionId, |
| 128 long reportId, | 121 long reportId, |
| 129 ArrayBuffer data, | 122 ArrayBuffer data, |
| 130 SendCallback callback); | 123 SendCallback callback); |
| 131 }; | 124 }; |
| 132 }; | 125 }; |
| OLD | NEW |