OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
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. | |
7 // Using this API, apps can function as drivers for hardware devices. | |
8 namespace hid { | |
9 // HID top-level collection attributes. | |
10 // Each enumerated device interface exposes an array of these objects. | |
11 // |usagePage|: HID usage page identifier. | |
12 // |usage|: Page-defined usage identifier. | |
13 // |reportIds|: Report IDs which belong to the collection and to its children. | |
14 dictionary HidCollectionInfo { | |
15 long usagePage; | |
16 long usage; | |
17 long[] reportIds; | |
18 }; | |
19 | |
20 // Returned by <code>getDevices</code> functions to describes a connected HID | |
21 // device. Use <code>connect</code> to connect to any of the returned devices. | |
22 // |deviceId|: Device opaque ID. | |
23 // |vendorId|: Vendor ID. | |
24 // |productId|: Product ID. | |
25 // |collections|: Top-level collections from this device's report descriptor. | |
26 // |maxInputReportSize|: Top-level collection's max input report size. | |
27 // |maxOutputReportSize|: Top-level collection's max output report size. | |
28 // |maxFeatureReportSize|: Top-level collection's max feature report size. | |
29 dictionary HidDeviceInfo { | |
30 long deviceId; | |
31 long vendorId; | |
32 long productId; | |
33 HidCollectionInfo[] collections; | |
34 long maxInputReportSize; | |
35 long maxOutputReportSize; | |
36 long maxFeatureReportSize; | |
37 }; | |
38 | |
39 // Returned by <code>connect</code> to represent a communication session with | |
40 // an HID device. Must be closed with a call to <code>disconnect</code>. | |
41 dictionary HidConnectInfo { | |
42 long connectionId; | |
43 }; | |
44 | |
45 // Searching criteria to enumerate devices with. | |
46 dictionary GetDevicesOptions { | |
47 long vendorId; | |
48 long productId; | |
49 }; | |
50 | |
51 callback GetDevicesCallback = void (HidDeviceInfo[] devices); | |
52 callback ConnectCallback = void (HidConnectInfo connection); | |
53 callback DisconnectCallback = void (); | |
54 | |
55 // The callback to be invoked when a <code>receive</code> or | |
56 // <code>receiveFeatureReport</code> call is finished. | |
57 // |data|: The content of the report. | |
58 callback ReceiveCallback = void (ArrayBuffer data); | |
59 callback SendCallback = void(); | |
60 | |
61 interface Functions { | |
62 // Enumerate all the connected HID devices specified by the vendorId/ | |
63 // productId/interfaceId tuple. | |
64 // |options|: The properties to search for on target devices. | |
65 // |callback|: Invoked with the <code>HidDeviceInfo</code> array on success. | |
66 static void getDevices(GetDevicesOptions options, | |
67 GetDevicesCallback callback); | |
68 | |
69 // Open a connection to an HID device for communication. | |
70 // |deviceId|: The ID of the device to open. | |
71 // |callback|: Invoked with an <code>HidConnectInfo</code>. | |
72 static void connect(long deviceId, | |
73 ConnectCallback callback); | |
74 | |
75 // Disconnect from a device. Invoking operations on a device after calling | |
76 // this is safe but has no effect. | |
77 // |connectionId|: The connection to close. | |
78 // |callback|: The callback to invoke once the device is closed. | |
79 static void disconnect(long connectionId, | |
80 optional DisconnectCallback callback); | |
81 | |
82 // Receive an Input report from an HID device. | |
83 // | |
84 // Input reports are returned to the host through the INTERRUPT IN endpoint. | |
85 // |connectionId|: The connection from which to receive a report. | |
86 // |size|: The size of the Input report to receive. | |
87 // |callback|: The callback to invoke with received report. | |
88 static void receive(long connectionId, | |
89 long size, | |
90 ReceiveCallback callback); | |
91 | |
92 // Send an Output report to an HID device. | |
93 // <code>send</code> will send the data on the first OUT endpoint, if one | |
94 // exists. If one does not exist, the report will be sent through the | |
95 // Control endpoint. | |
96 // | |
97 // |connectionId|: The connection to which to send a report. | |
98 // |reportId|: The report ID to use, or <code>0</code> if none. | |
99 // |data|: The report data. | |
100 // |callback|: The callback to invoke once the write is finished. | |
101 static void send(long connectionId, | |
102 long reportId, | |
103 ArrayBuffer data, | |
104 SendCallback callback); | |
105 | |
106 // Receive a Feature report from the device. | |
107 // | |
108 // |connectionId|: The connection to read Input report from. | |
109 // |reportId|: The report ID, or zero if none. | |
110 // |size|: The size of the Feature report to receive. | |
111 // |callback|: The callback to invoke once the write is finished. | |
112 static void receiveFeatureReport(long connectionId, | |
113 long reportId, | |
114 long size, | |
115 ReceiveCallback callback); | |
116 | |
117 // Send a Feature report to the device. | |
118 // | |
119 // Feature reports are sent over the Control endpoint as a Set_Report | |
120 // transfer. | |
121 // |connectionId|: The connection to read Input report from. | |
122 // |reportId|: The report ID to use, or <code>0</code> if none. | |
123 // |data|: The report data. | |
124 // |callback|: The callback to invoke once the write is finished. | |
125 static void sendFeatureReport(long connectionId, | |
126 long reportId, | |
127 ArrayBuffer data, | |
128 SendCallback callback); | |
129 }; | |
130 }; | |
OLD | NEW |