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