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.
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.
13 dictionary HidCollectionInfo
{
14 // HID usage page identifier.
16 // Page-defined usage identifier.
18 // Report IDs which belong to the collection and to its children.
22 [noinline_doc
] dictionary HidDeviceInfo
{
29 // Top-level collections from this device's report descriptors.
30 HidCollectionInfo
[] collections
;
31 // Top-level collection's maximum input report size.
32 long maxInputReportSize
;
33 // Top-level collection's maximum output report size.
34 long maxOutputReportSize
;
35 // Top-level collection's maximum feature report size.
36 long maxFeatureReportSize
;
37 // Raw device report descriptor (not available on Windows).
38 ArrayBuffer reportDescriptor
;
41 dictionary HidConnectInfo
{
42 // The opaque ID used to identify this connection in all other functions.
46 [noinline_doc
] dictionary DeviceFilter
{
49 // Device product ID, only checked only if the vendor ID matches.
51 // HID usage page identifier.
53 // HID usage identifier, checked only if the HID usage page matches.
57 dictionary GetDevicesOptions
{
58 [deprecated
="Equivalent to setting $(ref:DeviceFilter.vendorId)."]
60 [deprecated
="Equivalent to setting $(ref:DeviceFilter.productId)."]
62 // A device matching any given filter will be returned. An empty filter list
63 // will return all devices the app has permission for.
64 DeviceFilter
[]? filters
;
67 dictionary DevicePromptOptions
{
68 // Allow the user to select multiple devices.
70 // Filter the list of devices presented to the user. If multiple filters
71 // are provided devices matching any filter will be displayed.
72 DeviceFilter
[]? filters
;
75 callback GetDevicesCallback
= void (HidDeviceInfo
[] devices
);
76 callback ConnectCallback
= void (HidConnectInfo connection
);
77 callback DisconnectCallback
= void ();
79 // |reportId|: The report ID or <code>0</code> if none.
80 // |data|: The report data, the report ID prefix (if present) is removed.
81 callback ReceiveCallback
= void (long reportId
, ArrayBuffer data
);
83 // |data|: The report data, including a report ID prefix if one is sent by the
85 callback ReceiveFeatureReportCallback
= void (ArrayBuffer data
);
87 callback SendCallback
= void();
90 // Enumerate connected HID devices.
91 // |options|: The properties to search for on target devices.
92 static
void getDevices
(GetDevicesOptions options
,
93 GetDevicesCallback
callback);
95 // Presents a device picker to the user and returns $(ref:HidDeviceInfo)
96 // objects for the devices selected.
97 // If the user cancels the picker devices will be empty. A user gesture
98 // is required for the dialog to display. Without a user gesture, the
99 // callback will run as though the user cancelled. If multiple filters are
100 // provided devices matching any filter will be displayed.
101 // |options|: Configuration of the device picker dialog box.
102 // |callback|: Invoked with a list of chosen $(ref:Device)s.
103 static
void getUserSelectedDevices
(optional DevicePromptOptions options
,
104 GetDevicesCallback
callback);
106 // Open a connection to an HID device for communication.
107 // |deviceId|: The $(ref:HidDeviceInfo.deviceId) of the device to open.
108 static
void connect
(long deviceId
,
109 ConnectCallback
callback);
111 // Disconnect from a device. Invoking operations on a device after calling
112 // this is safe but has no effect.
113 // |connectionId|: The <code>connectionId</code> returned by $(ref:connect).
114 static
void disconnect
(long connectionId
,
115 optional DisconnectCallback
callback);
117 // Receive the next input report from the device.
118 // |connectionId|: The <code>connectionId</code> returned by $(ref:connect).
119 static
void receive
(long connectionId
,
120 ReceiveCallback
callback);
122 // Send an output report to the device.
124 // <em>Note:</em> Do not include a report ID prefix in <code>data</code>.
125 // It will be added if necessary.
126 // |connectionId|: The <code>connectionId</code> returned by $(ref:connect).
127 // |reportId|: The report ID to use, or <code>0</code> if none.
128 // |data|: The report data.
129 static
void send
(long connectionId
,
132 SendCallback
callback);
134 // Request a feature report from the device.
135 // |connectionId|: The <code>connectionId</code> returned by $(ref:connect).
136 // |reportId|: The report ID, or <code>0</code> if none.
137 static
void receiveFeatureReport
(long connectionId
,
139 ReceiveFeatureReportCallback
callback);
141 // Send a feature report to the device.
143 // <em>Note:</em> Do not include a report ID prefix in <code>data</code>.
144 // It will be added if necessary.
145 // |connectionId|: The <code>connectionId</code> returned by $(ref:connect).
146 // |reportId|: The report ID to use, or <code>0</code> if none.
147 // |data|: The report data.
148 static
void sendFeatureReport
(long connectionId
,
151 SendCallback
callback);
155 // Event generated when a device is added to the system. Events are only
156 // broadcast to apps and extensions that have permission to access the
157 // device. Permission may have been granted at install time or when the user
158 // accepted an optional permission (see $(ref:permissions.request)).
159 static
void onDeviceAdded
(HidDeviceInfo device
);
161 // Event generated when a device is removed from the system. See
162 // $(ref:onDeviceAdded) for which events are delivered.
163 // |deviceId|: The <code>deviceId</code> property of the device passed to
164 // $(ref:onDeviceAdded).
165 static
void onDeviceRemoved
(long deviceId
);