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.
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.
10 // Returned by <code>getDevices</code> functions to describes a connected HID
11 // device. Use <code>connect</code> to connect to any of the returned devices.
12 dictionary HidDeviceInfo {
18 // Returned by <code>connect</code> to represent a communication session with
19 // an HID device. Must be closed with a call to <code>disconnect</code>.
20 dictionary HidConnectInfo {
24 // Searching criteria to enumerate devices with.
25 dictionary GetDevicesOptions {
30 callback GetDevicesCallback = void (HidDeviceInfo[] devices);
31 callback ConnectCallback = void (HidConnectInfo connection);
32 callback DisconnectCallback = void ();
34 // The callback to be invoked when a <code>receive</code> or
35 // <code>receiveFeatureReport</code> call is finished.
36 // |data|: The content of the report.
37 callback ReceiveCallback = void (ArrayBuffer data);
38 callback SendCallback = void();
41 // Enumerate all the connected HID devices specified by the vendorId/
42 // productId/interfaceId tuple.
43 // |options|: The properties to search for on target devices.
44 // |callback|: Invoked with the <code>HidDeviceInfo</code> array on success.
45 static void getDevices(GetDevicesOptions options,
46 GetDevicesCallback callback);
48 // Open a connection to an HID device for communication.
49 // |deviceId|: The ID of the device to open.
50 // |callback|: Invoked with an <code>HidConnectInfo</code>.
51 static void connect(long deviceId,
52 ConnectCallback callback);
54 // Disconnect from a device. Invoking operations on a device after calling
55 // this is safe but has no effect.
56 // |connectionId|: The connection to close.
57 // |callback|: The callback to invoke once the device is closed.
58 static void disconnect(long connectionId,
59 optional DisconnectCallback callback);
61 // Receive an Input report from an HID device.
63 // Input reports are returned to the host through the INTERRUPT IN endpoint.
64 // |connectionId|: The connection from which to receive a report.
65 // |size|: The size of the Input report to receive.
66 // |callback|: The callback to invoke with received report.
67 static void receive(long connectionId,
69 ReceiveCallback callback);
71 // Send an Output report to an HID device.
72 // <code>send</code> will send the data on the first OUT endpoint, if one
73 // exists. If one does not exist, the report will be sent through the
76 // |connectionId|: The connection to which to send a report.
77 // |reportId|: The report ID to use, or <code>0</code> if none.
78 // |data|: The report data.
79 // |callback|: The callback to invoke once the write is finished.
80 static void send(long connectionId,
83 SendCallback callback);
85 // Receive a Feature report from the device.
87 // |connectionId|: The connection to read Input report from.
88 // |reportId|: The report ID, or zero if none.
89 // |size|: The size of the Feature report to receive.
90 // |callback|: The callback to invoke once the write is finished.
91 static void receiveFeatureReport(long connectionId,
94 ReceiveCallback callback);
96 // Send a Feature report to the device.
98 // Feature reports are sent over the Control endpoint as a Set_Report
100 // |connectionId|: The connection to read Input report from.
101 // |reportId|: The report ID to use, or <code>0</code> if none.
102 // |data|: The report data.
103 // |callback|: The callback to invoke once the write is finished.
104 static void sendFeatureReport(long connectionId,
107 SendCallback callback);