@ac-kit/format-hid 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +29 -0
- package/LICENSE +28 -0
- package/README.md +96 -2
- package/dist/descriptor/hid-field-usage.d.ts +35 -0
- package/dist/descriptor/hid-field-usage.d.ts.map +1 -0
- package/dist/descriptor/hid-field-usage.js +63 -0
- package/dist/descriptor/hid-field-usage.js.map +1 -0
- package/dist/descriptor/hid-report-descriptor.d.ts +148 -0
- package/dist/descriptor/hid-report-descriptor.d.ts.map +1 -0
- package/dist/descriptor/hid-report-descriptor.js +15 -0
- package/dist/descriptor/hid-report-descriptor.js.map +1 -0
- package/dist/descriptor/parse-hid-report-descriptor.d.ts +30 -0
- package/dist/descriptor/parse-hid-report-descriptor.d.ts.map +1 -0
- package/dist/descriptor/parse-hid-report-descriptor.js +440 -0
- package/dist/descriptor/parse-hid-report-descriptor.js.map +1 -0
- package/dist/errors.d.ts +17 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +20 -0
- package/dist/errors.js.map +1 -0
- package/dist/field/_field-value-bit-position.d.ts +7 -0
- package/dist/field/_field-value-bit-position.d.ts.map +1 -0
- package/dist/field/_field-value-bit-position.js +24 -0
- package/dist/field/_field-value-bit-position.js.map +1 -0
- package/dist/field/create-hid-report.d.ts +9 -0
- package/dist/field/create-hid-report.d.ts.map +1 -0
- package/dist/field/create-hid-report.js +14 -0
- package/dist/field/create-hid-report.js.map +1 -0
- package/dist/field/hid-field-layout.d.ts +7 -0
- package/dist/field/hid-field-layout.d.ts.map +1 -0
- package/dist/field/hid-field-layout.js +2 -0
- package/dist/field/hid-field-layout.js.map +1 -0
- package/dist/field/hid-logical-to-physical.d.ts +14 -0
- package/dist/field/hid-logical-to-physical.d.ts.map +1 -0
- package/dist/field/hid-logical-to-physical.js +27 -0
- package/dist/field/hid-logical-to-physical.js.map +1 -0
- package/dist/field/read-hid-field-value.d.ts +18 -0
- package/dist/field/read-hid-field-value.d.ts.map +1 -0
- package/dist/field/read-hid-field-value.js +35 -0
- package/dist/field/read-hid-field-value.js.map +1 -0
- package/dist/field/write-hid-field-value-in-place.d.ts +18 -0
- package/dist/field/write-hid-field-value-in-place.d.ts.map +1 -0
- package/dist/field/write-hid-field-value-in-place.js +41 -0
- package/dist/field/write-hid-field-value-in-place.js.map +1 -0
- package/dist/field/write-hid-field-value.d.ts +18 -0
- package/dist/field/write-hid-field-value.d.ts.map +1 -0
- package/dist/field/write-hid-field-value.js +41 -0
- package/dist/field/write-hid-field-value.js.map +1 -0
- package/dist/index.d.ts +18 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +18 -0
- package/dist/index.js.map +1 -0
- package/dist/item/_read-hid-item.d.ts +18 -0
- package/dist/item/_read-hid-item.d.ts.map +1 -0
- package/dist/item/_read-hid-item.js +48 -0
- package/dist/item/_read-hid-item.js.map +1 -0
- package/dist/item/decode-hid-items.d.ts +16 -0
- package/dist/item/decode-hid-items.d.ts.map +1 -0
- package/dist/item/decode-hid-items.js +24 -0
- package/dist/item/decode-hid-items.js.map +1 -0
- package/dist/item/encode-hid-items.d.ts +17 -0
- package/dist/item/encode-hid-items.d.ts.map +1 -0
- package/dist/item/encode-hid-items.js +74 -0
- package/dist/item/encode-hid-items.js.map +1 -0
- package/dist/item/hid-item-tag.d.ts +37 -0
- package/dist/item/hid-item-tag.d.ts.map +1 -0
- package/dist/item/hid-item-tag.js +40 -0
- package/dist/item/hid-item-tag.js.map +1 -0
- package/dist/item/hid-item-value.d.ts +20 -0
- package/dist/item/hid-item-value.d.ts.map +1 -0
- package/dist/item/hid-item-value.js +36 -0
- package/dist/item/hid-item-value.js.map +1 -0
- package/dist/item/hid-item.d.ts +32 -0
- package/dist/item/hid-item.d.ts.map +1 -0
- package/dist/item/hid-item.js +2 -0
- package/dist/item/hid-item.js.map +1 -0
- package/dist/unit/decode-hid-unit.d.ts +9 -0
- package/dist/unit/decode-hid-unit.d.ts.map +1 -0
- package/dist/unit/decode-hid-unit.js +26 -0
- package/dist/unit/decode-hid-unit.js.map +1 -0
- package/dist/unit/encode-hid-unit.d.ts +10 -0
- package/dist/unit/encode-hid-unit.d.ts.map +1 -0
- package/dist/unit/encode-hid-unit.js +32 -0
- package/dist/unit/encode-hid-unit.js.map +1 -0
- package/dist/unit/hid-unit.d.ts +29 -0
- package/dist/unit/hid-unit.d.ts.map +1 -0
- package/dist/unit/hid-unit.js +11 -0
- package/dist/unit/hid-unit.js.map +1 -0
- package/package.json +60 -3
|
@@ -0,0 +1,440 @@
|
|
|
1
|
+
import { ByteReader } from "@ac-kit/core";
|
|
2
|
+
import { HidDescriptorError } from "../errors.js";
|
|
3
|
+
import { readHidItem_ } from "../item/_read-hid-item.js";
|
|
4
|
+
import { HidGlobalTag, HidLocalTag, HidMainTag } from "../item/hid-item-tag.js";
|
|
5
|
+
import { hidItemSigned, hidItemUnsigned } from "../item/hid-item-value.js";
|
|
6
|
+
/**
|
|
7
|
+
* No report can exceed this many bytes: a USB control transfer's `wLength` is
|
|
8
|
+
* 16 bits (USB 2.0 §9.3.5), so GET_REPORT/SET_REPORT could not move a longer
|
|
9
|
+
* one. Also keeps `bitSize * count` exact in a double.
|
|
10
|
+
*/
|
|
11
|
+
const MAX_REPORT_BYTES_ = 0xffff;
|
|
12
|
+
const MAX_REPORT_BITS_ = MAX_REPORT_BYTES_ * 8;
|
|
13
|
+
const MAIN_DATA_KINDS_ = new Map([
|
|
14
|
+
[HidMainTag.INPUT, "input"],
|
|
15
|
+
[HidMainTag.OUTPUT, "output"],
|
|
16
|
+
[HidMainTag.FEATURE, "feature"],
|
|
17
|
+
]);
|
|
18
|
+
function createSlotBuilder_() {
|
|
19
|
+
return { slots: [], minimum: undefined, maximum: undefined };
|
|
20
|
+
}
|
|
21
|
+
function createLocalState_() {
|
|
22
|
+
return {
|
|
23
|
+
usages: createSlotBuilder_(),
|
|
24
|
+
usageRefs: [],
|
|
25
|
+
designators: createSlotBuilder_(),
|
|
26
|
+
strings: createSlotBuilder_(),
|
|
27
|
+
delimiterSet: undefined,
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
function addSlotBound_(builder, bound, value, label, offset) {
|
|
31
|
+
if (builder[bound] !== undefined) {
|
|
32
|
+
throw new HidDescriptorError(`${label} ${bound} declared twice without its pair`, offset);
|
|
33
|
+
}
|
|
34
|
+
builder[bound] = value;
|
|
35
|
+
if (builder.minimum !== undefined && builder.maximum !== undefined) {
|
|
36
|
+
builder.slots.push({
|
|
37
|
+
kind: "range",
|
|
38
|
+
minimum: builder.minimum,
|
|
39
|
+
maximum: builder.maximum,
|
|
40
|
+
});
|
|
41
|
+
builder.minimum = undefined;
|
|
42
|
+
builder.maximum = undefined;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
function resolveUsage_(ref) {
|
|
46
|
+
return ref.extended ? ref.value : ((ref.page << 16) | ref.value) >>> 0;
|
|
47
|
+
}
|
|
48
|
+
function identity_(value) {
|
|
49
|
+
return value;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Builds the final slots of one local category. A range whose bounds are
|
|
53
|
+
* reversed, or whose usages lie on two pages, has no meaning.
|
|
54
|
+
*/
|
|
55
|
+
function resolveSlots_(builder, resolve, label, offset) {
|
|
56
|
+
if (builder.minimum !== undefined || builder.maximum !== undefined) {
|
|
57
|
+
throw new HidDescriptorError(`${label} minimum without maximum, or the reverse`, offset);
|
|
58
|
+
}
|
|
59
|
+
return builder.slots.map((slot) => {
|
|
60
|
+
if (slot.kind === "single") {
|
|
61
|
+
const [first, ...rest] = slot.values.map(resolve);
|
|
62
|
+
return { kind: "single", value: first, aliases: rest };
|
|
63
|
+
}
|
|
64
|
+
const minimum = resolve(slot.minimum);
|
|
65
|
+
const maximum = resolve(slot.maximum);
|
|
66
|
+
if (minimum > maximum || minimum >>> 16 !== maximum >>> 16) {
|
|
67
|
+
throw new HidDescriptorError(`${label} range 0x${minimum.toString(16)}–0x${maximum.toString(16)} is reversed or spans two pages`, offset);
|
|
68
|
+
}
|
|
69
|
+
return { kind: "range", minimum, maximum };
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Applies the usage page in effect at the main item to the trailing usages
|
|
74
|
+
* declared before a later Usage Page item. Linux
|
|
75
|
+
* `hid_concatenate_last_usage_page()` (drivers/hid/hid-core.c): walking back
|
|
76
|
+
* from the last usage, re-page each non-extended one until meeting one already
|
|
77
|
+
* on the current page. Real descriptors place Usage Page after Usage often
|
|
78
|
+
* enough that the rule matters.
|
|
79
|
+
*/
|
|
80
|
+
function repageUsages_(refs, currentPage) {
|
|
81
|
+
for (let index = refs.length - 1; index >= 0; index--) {
|
|
82
|
+
const ref = refs[index];
|
|
83
|
+
if (ref.extended) {
|
|
84
|
+
continue;
|
|
85
|
+
}
|
|
86
|
+
if (ref.page === currentPage) {
|
|
87
|
+
break;
|
|
88
|
+
}
|
|
89
|
+
ref.page = currentPage;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* The HID 1.11 §6.2.2 item state machine. One instance per parse; holds the
|
|
94
|
+
* global table and its push stack, the local table, the open collections and
|
|
95
|
+
* the reports built so far.
|
|
96
|
+
*/
|
|
97
|
+
class DescriptorParser_ {
|
|
98
|
+
global = {
|
|
99
|
+
usagePage: 0,
|
|
100
|
+
logicalMinimum: 0,
|
|
101
|
+
logicalMaximum: { signed: 0, unsigned: 0 },
|
|
102
|
+
physicalMinimum: 0,
|
|
103
|
+
physicalMaximum: { signed: 0, unsigned: 0 },
|
|
104
|
+
unitExponent: 0,
|
|
105
|
+
unit: 0,
|
|
106
|
+
reportSize: undefined,
|
|
107
|
+
reportCount: undefined,
|
|
108
|
+
reportId: 0,
|
|
109
|
+
};
|
|
110
|
+
globalStack = [];
|
|
111
|
+
local = createLocalState_();
|
|
112
|
+
collections = [];
|
|
113
|
+
openCollections = [];
|
|
114
|
+
reports = new Map();
|
|
115
|
+
usesReportIds = false;
|
|
116
|
+
parse(bytes) {
|
|
117
|
+
const reader = new ByteReader(bytes);
|
|
118
|
+
while (!reader.atEnd) {
|
|
119
|
+
const offset = reader.position;
|
|
120
|
+
const item = readHidItem_(reader);
|
|
121
|
+
if (item.kind === "long") {
|
|
122
|
+
continue;
|
|
123
|
+
}
|
|
124
|
+
switch (item.type) {
|
|
125
|
+
case "main":
|
|
126
|
+
this.handleMain(item, offset);
|
|
127
|
+
break;
|
|
128
|
+
case "global":
|
|
129
|
+
this.handleGlobal(item, offset);
|
|
130
|
+
break;
|
|
131
|
+
case "local":
|
|
132
|
+
this.handleLocal(item, offset);
|
|
133
|
+
break;
|
|
134
|
+
case "reserved":
|
|
135
|
+
break;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
if (this.openCollections.length > 0) {
|
|
139
|
+
throw new HidDescriptorError(`${this.openCollections.length} collection(s) left open`, bytes.length);
|
|
140
|
+
}
|
|
141
|
+
return {
|
|
142
|
+
collections: this.collections,
|
|
143
|
+
reports: Array.from(this.reports.values(), (builder) => builder.report),
|
|
144
|
+
usesReportIds: this.usesReportIds,
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
handleMain(item, offset) {
|
|
148
|
+
if (this.local.delimiterSet !== undefined) {
|
|
149
|
+
throw new HidDescriptorError("Main item inside an open delimited set", offset);
|
|
150
|
+
}
|
|
151
|
+
const kind = MAIN_DATA_KINDS_.get(item.tag);
|
|
152
|
+
if (kind !== undefined) {
|
|
153
|
+
this.addField(kind, hidItemUnsigned(item), offset);
|
|
154
|
+
}
|
|
155
|
+
else if (item.tag === HidMainTag.COLLECTION) {
|
|
156
|
+
this.openCollection(hidItemUnsigned(item), offset);
|
|
157
|
+
}
|
|
158
|
+
else if (item.tag === HidMainTag.END_COLLECTION) {
|
|
159
|
+
if (this.openCollections.pop() === undefined) {
|
|
160
|
+
throw new HidDescriptorError("End Collection without an open collection", offset);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
// Reserved main tags carry nothing to apply; locals are still consumed.
|
|
164
|
+
this.local = createLocalState_();
|
|
165
|
+
}
|
|
166
|
+
resolveUsages(offset) {
|
|
167
|
+
repageUsages_(this.local.usageRefs, this.global.usagePage);
|
|
168
|
+
return resolveSlots_(this.local.usages, resolveUsage_, "Usage", offset);
|
|
169
|
+
}
|
|
170
|
+
openCollection(type, offset) {
|
|
171
|
+
const usages = this.resolveUsages(offset);
|
|
172
|
+
const first = usages[0];
|
|
173
|
+
let usage;
|
|
174
|
+
if (first !== undefined) {
|
|
175
|
+
usage = first.kind === "single" ? first.value : first.minimum;
|
|
176
|
+
}
|
|
177
|
+
this.collections.push({
|
|
178
|
+
type,
|
|
179
|
+
usage,
|
|
180
|
+
parentIndex: this.openCollections.at(-1) ?? -1,
|
|
181
|
+
});
|
|
182
|
+
this.openCollections.push(this.collections.length - 1);
|
|
183
|
+
}
|
|
184
|
+
addField(kind, flags, offset) {
|
|
185
|
+
const global = this.global;
|
|
186
|
+
const { reportSize, reportCount, reportId } = global;
|
|
187
|
+
if (reportSize === undefined || reportCount === undefined) {
|
|
188
|
+
throw new HidDescriptorError("Data item before any Report Size and Report Count", offset);
|
|
189
|
+
}
|
|
190
|
+
// Reachable through a Pop restoring a state pushed before the first Report ID.
|
|
191
|
+
if (this.usesReportIds && reportId === 0) {
|
|
192
|
+
throw new HidDescriptorError("Data item with no Report ID in a descriptor that uses them", offset);
|
|
193
|
+
}
|
|
194
|
+
if (reportSize > MAX_REPORT_BITS_ || reportCount > MAX_REPORT_BITS_) {
|
|
195
|
+
throw new HidDescriptorError(`Report Size ${reportSize} × Report Count ${reportCount} exceeds ${MAX_REPORT_BYTES_} bytes`, offset);
|
|
196
|
+
}
|
|
197
|
+
const key = `${kind}:${reportId}`;
|
|
198
|
+
let builder = this.reports.get(key);
|
|
199
|
+
if (builder === undefined) {
|
|
200
|
+
builder = {
|
|
201
|
+
report: { kind, reportId, byteLength: 0, fields: [] },
|
|
202
|
+
bitLength: reportId === 0 ? 0 : 8,
|
|
203
|
+
};
|
|
204
|
+
this.reports.set(key, builder);
|
|
205
|
+
}
|
|
206
|
+
const bitOffset = builder.bitLength;
|
|
207
|
+
builder.bitLength += reportSize * reportCount;
|
|
208
|
+
if (builder.bitLength > MAX_REPORT_BITS_) {
|
|
209
|
+
throw new HidDescriptorError(`${kind} report ${reportId} grows past ${MAX_REPORT_BYTES_} bytes`, offset);
|
|
210
|
+
}
|
|
211
|
+
builder.report.byteLength = Math.ceil(builder.bitLength / 8);
|
|
212
|
+
const logicalMaximum = global.logicalMinimum < 0
|
|
213
|
+
? global.logicalMaximum.signed
|
|
214
|
+
: global.logicalMaximum.unsigned;
|
|
215
|
+
let physicalMinimum = global.physicalMinimum;
|
|
216
|
+
let physicalMaximum = physicalMinimum < 0
|
|
217
|
+
? global.physicalMaximum.signed
|
|
218
|
+
: global.physicalMaximum.unsigned;
|
|
219
|
+
if (physicalMinimum === 0 && physicalMaximum === 0) {
|
|
220
|
+
physicalMinimum = global.logicalMinimum;
|
|
221
|
+
physicalMaximum = logicalMaximum;
|
|
222
|
+
}
|
|
223
|
+
const field = {
|
|
224
|
+
kind,
|
|
225
|
+
reportId,
|
|
226
|
+
bitOffset,
|
|
227
|
+
bitSize: reportSize,
|
|
228
|
+
count: reportCount,
|
|
229
|
+
flags: {
|
|
230
|
+
constant: (flags & 0x001) !== 0,
|
|
231
|
+
variable: (flags & 0x002) !== 0,
|
|
232
|
+
relative: (flags & 0x004) !== 0,
|
|
233
|
+
wrap: (flags & 0x008) !== 0,
|
|
234
|
+
nonLinear: (flags & 0x010) !== 0,
|
|
235
|
+
noPreferredState: (flags & 0x020) !== 0,
|
|
236
|
+
nullState: (flags & 0x040) !== 0,
|
|
237
|
+
volatile: kind !== "input" && (flags & 0x080) !== 0,
|
|
238
|
+
bufferedBytes: (flags & 0x100) !== 0,
|
|
239
|
+
},
|
|
240
|
+
logicalMinimum: global.logicalMinimum,
|
|
241
|
+
logicalMaximum,
|
|
242
|
+
physicalMinimum,
|
|
243
|
+
physicalMaximum,
|
|
244
|
+
unit: global.unit,
|
|
245
|
+
unitExponent: global.unitExponent,
|
|
246
|
+
usages: this.resolveUsages(offset),
|
|
247
|
+
designators: resolveSlots_(this.local.designators, identity_, "Designator", offset),
|
|
248
|
+
strings: resolveSlots_(this.local.strings, identity_, "String", offset),
|
|
249
|
+
collectionIndex: this.openCollections.at(-1) ?? -1,
|
|
250
|
+
};
|
|
251
|
+
builder.report.fields.push(field);
|
|
252
|
+
}
|
|
253
|
+
handleGlobal(item, offset) {
|
|
254
|
+
const global = this.global;
|
|
255
|
+
switch (item.tag) {
|
|
256
|
+
case HidGlobalTag.USAGE_PAGE: {
|
|
257
|
+
const page = hidItemUnsigned(item);
|
|
258
|
+
if (page > 0xffff) {
|
|
259
|
+
throw new HidDescriptorError(`Usage Page 0x${page.toString(16)} exceeds 16 bits`, offset);
|
|
260
|
+
}
|
|
261
|
+
global.usagePage = page;
|
|
262
|
+
break;
|
|
263
|
+
}
|
|
264
|
+
case HidGlobalTag.LOGICAL_MINIMUM:
|
|
265
|
+
global.logicalMinimum = hidItemSigned(item);
|
|
266
|
+
break;
|
|
267
|
+
case HidGlobalTag.LOGICAL_MAXIMUM:
|
|
268
|
+
global.logicalMaximum = {
|
|
269
|
+
signed: hidItemSigned(item),
|
|
270
|
+
unsigned: hidItemUnsigned(item),
|
|
271
|
+
};
|
|
272
|
+
break;
|
|
273
|
+
case HidGlobalTag.PHYSICAL_MINIMUM:
|
|
274
|
+
global.physicalMinimum = hidItemSigned(item);
|
|
275
|
+
break;
|
|
276
|
+
case HidGlobalTag.PHYSICAL_MAXIMUM:
|
|
277
|
+
global.physicalMaximum = {
|
|
278
|
+
signed: hidItemSigned(item),
|
|
279
|
+
unsigned: hidItemUnsigned(item),
|
|
280
|
+
};
|
|
281
|
+
break;
|
|
282
|
+
case HidGlobalTag.UNIT_EXPONENT: {
|
|
283
|
+
// HID 1.11 calls this a signed integer, yet descriptors in the wild write a
|
|
284
|
+
// 4-bit two's-complement nibble (0x0E for -2) in one byte; Linux reads it so too.
|
|
285
|
+
const value = hidItemUnsigned(item);
|
|
286
|
+
if (item.data.length === 1 && value <= 0xf) {
|
|
287
|
+
global.unitExponent = value >= 8 ? value - 16 : value;
|
|
288
|
+
}
|
|
289
|
+
else {
|
|
290
|
+
global.unitExponent = hidItemSigned(item);
|
|
291
|
+
}
|
|
292
|
+
break;
|
|
293
|
+
}
|
|
294
|
+
case HidGlobalTag.UNIT:
|
|
295
|
+
global.unit = hidItemUnsigned(item);
|
|
296
|
+
break;
|
|
297
|
+
case HidGlobalTag.REPORT_SIZE:
|
|
298
|
+
global.reportSize = hidItemUnsigned(item);
|
|
299
|
+
break;
|
|
300
|
+
case HidGlobalTag.REPORT_COUNT:
|
|
301
|
+
global.reportCount = hidItemUnsigned(item);
|
|
302
|
+
break;
|
|
303
|
+
case HidGlobalTag.REPORT_ID:
|
|
304
|
+
this.setReportId(hidItemUnsigned(item), offset);
|
|
305
|
+
break;
|
|
306
|
+
case HidGlobalTag.PUSH:
|
|
307
|
+
this.globalStack.push({ ...global });
|
|
308
|
+
break;
|
|
309
|
+
case HidGlobalTag.POP: {
|
|
310
|
+
const popped = this.globalStack.pop();
|
|
311
|
+
if (popped === undefined) {
|
|
312
|
+
throw new HidDescriptorError("Pop without a matching Push", offset);
|
|
313
|
+
}
|
|
314
|
+
this.global = popped;
|
|
315
|
+
break;
|
|
316
|
+
}
|
|
317
|
+
default:
|
|
318
|
+
// An unknown global could change the layout of every later field.
|
|
319
|
+
throw new HidDescriptorError(`Reserved global item tag 0x${item.tag.toString(16)}`, offset);
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
setReportId(reportId, offset) {
|
|
323
|
+
if (reportId === 0 || reportId > 0xff) {
|
|
324
|
+
throw new HidDescriptorError(`Report ID ${reportId} is not 1–255`, offset);
|
|
325
|
+
}
|
|
326
|
+
if (!this.usesReportIds && this.reports.size > 0) {
|
|
327
|
+
throw new HidDescriptorError("Report ID declared after a data item that had none", offset);
|
|
328
|
+
}
|
|
329
|
+
this.usesReportIds = true;
|
|
330
|
+
this.global.reportId = reportId;
|
|
331
|
+
}
|
|
332
|
+
handleLocal(item, offset) {
|
|
333
|
+
const local = this.local;
|
|
334
|
+
switch (item.tag) {
|
|
335
|
+
case HidLocalTag.USAGE: {
|
|
336
|
+
const ref = this.createUsageRef(item);
|
|
337
|
+
if (local.delimiterSet === undefined) {
|
|
338
|
+
local.usages.slots.push({ kind: "single", values: [ref] });
|
|
339
|
+
}
|
|
340
|
+
else {
|
|
341
|
+
local.delimiterSet.push(ref);
|
|
342
|
+
}
|
|
343
|
+
break;
|
|
344
|
+
}
|
|
345
|
+
case HidLocalTag.USAGE_MINIMUM:
|
|
346
|
+
case HidLocalTag.USAGE_MAXIMUM:
|
|
347
|
+
if (local.delimiterSet !== undefined) {
|
|
348
|
+
throw new HidDescriptorError("Usage range inside a delimited set", offset);
|
|
349
|
+
}
|
|
350
|
+
addSlotBound_(local.usages, item.tag === HidLocalTag.USAGE_MINIMUM ? "minimum" : "maximum", this.createUsageRef(item), "Usage", offset);
|
|
351
|
+
break;
|
|
352
|
+
case HidLocalTag.DESIGNATOR_INDEX:
|
|
353
|
+
local.designators.slots.push({
|
|
354
|
+
kind: "single",
|
|
355
|
+
values: [hidItemUnsigned(item)],
|
|
356
|
+
});
|
|
357
|
+
break;
|
|
358
|
+
case HidLocalTag.DESIGNATOR_MINIMUM:
|
|
359
|
+
case HidLocalTag.DESIGNATOR_MAXIMUM:
|
|
360
|
+
addSlotBound_(local.designators, item.tag === HidLocalTag.DESIGNATOR_MINIMUM ? "minimum" : "maximum", hidItemUnsigned(item), "Designator", offset);
|
|
361
|
+
break;
|
|
362
|
+
case HidLocalTag.STRING_INDEX:
|
|
363
|
+
local.strings.slots.push({
|
|
364
|
+
kind: "single",
|
|
365
|
+
values: [hidItemUnsigned(item)],
|
|
366
|
+
});
|
|
367
|
+
break;
|
|
368
|
+
case HidLocalTag.STRING_MINIMUM:
|
|
369
|
+
case HidLocalTag.STRING_MAXIMUM:
|
|
370
|
+
addSlotBound_(local.strings, item.tag === HidLocalTag.STRING_MINIMUM ? "minimum" : "maximum", hidItemUnsigned(item), "String", offset);
|
|
371
|
+
break;
|
|
372
|
+
case HidLocalTag.DELIMITER:
|
|
373
|
+
this.handleDelimiter(hidItemUnsigned(item), offset);
|
|
374
|
+
break;
|
|
375
|
+
default:
|
|
376
|
+
// A reserved local is cleared at the next main item like any other, so skipping it cannot shift the layout.
|
|
377
|
+
break;
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
createUsageRef(item) {
|
|
381
|
+
const value = hidItemUnsigned(item);
|
|
382
|
+
const ref = item.data.length === 4
|
|
383
|
+
? { value, page: value >>> 16, extended: true }
|
|
384
|
+
: { value, page: this.global.usagePage, extended: false };
|
|
385
|
+
this.local.usageRefs.push(ref);
|
|
386
|
+
return ref;
|
|
387
|
+
}
|
|
388
|
+
handleDelimiter(value, offset) {
|
|
389
|
+
const local = this.local;
|
|
390
|
+
if (value === 1) {
|
|
391
|
+
if (local.delimiterSet !== undefined) {
|
|
392
|
+
throw new HidDescriptorError("Nested delimited set", offset);
|
|
393
|
+
}
|
|
394
|
+
local.delimiterSet = [];
|
|
395
|
+
}
|
|
396
|
+
else if (value === 0) {
|
|
397
|
+
if (local.delimiterSet === undefined) {
|
|
398
|
+
throw new HidDescriptorError("Delimiter close without an open set", offset);
|
|
399
|
+
}
|
|
400
|
+
if (local.delimiterSet.length > 0) {
|
|
401
|
+
local.usages.slots.push({ kind: "single", values: local.delimiterSet });
|
|
402
|
+
}
|
|
403
|
+
local.delimiterSet = undefined;
|
|
404
|
+
}
|
|
405
|
+
else {
|
|
406
|
+
throw new HidDescriptorError(`Delimiter value ${value} is neither 1 (open) nor 0 (close)`, offset);
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
/**
|
|
411
|
+
* Reads a report descriptor into the reports a device sends and accepts, the
|
|
412
|
+
* fields that tile each one, and the collections around them — the HID 1.11
|
|
413
|
+
* §6.2.2 item state machine, with Push/Pop, delimited sets and extended
|
|
414
|
+
* usages.
|
|
415
|
+
*
|
|
416
|
+
* Use {@link decodeHidItems} instead to see or rewrite the items themselves.
|
|
417
|
+
*
|
|
418
|
+
* Follows the Linux reading wherever real devices and the letter of the spec
|
|
419
|
+
* disagree: a Logical or Physical Maximum is unsigned unless its Minimum is
|
|
420
|
+
* negative, so `0xFF` means 255; a one-byte Unit Exponent of 0–15 is a 4-bit
|
|
421
|
+
* two's-complement nibble; a Usage declared before a later Usage Page takes the
|
|
422
|
+
* page in effect at the main item. Long items, reserved main and local tags and
|
|
423
|
+
* reserved item types are skipped.
|
|
424
|
+
*
|
|
425
|
+
* Usage ranges are kept as ranges, so a field declaring `Usage Minimum (0)`,
|
|
426
|
+
* `Usage Maximum (0xFFFF)` costs one slot, not 65 536.
|
|
427
|
+
*
|
|
428
|
+
* O(n) time and memory in `bytes.length`.
|
|
429
|
+
*
|
|
430
|
+
* @throws {HidDescriptorError} When an item is truncated, a collection is left
|
|
431
|
+
* open or closed twice, `Pop` meets an empty stack, a data item has no Report
|
|
432
|
+
* Size or Report Count, a report grows past 65 535 bytes, a Report ID is 0, a
|
|
433
|
+
* data item carries no Report ID in a descriptor that declares one, a usage,
|
|
434
|
+
* designator or string range is unpaired or reversed, a delimited set is
|
|
435
|
+
* nested or unbalanced, or a reserved global tag appears.
|
|
436
|
+
*/
|
|
437
|
+
export function parseHidReportDescriptor(bytes) {
|
|
438
|
+
return new DescriptorParser_().parse(bytes);
|
|
439
|
+
}
|
|
440
|
+
//# sourceMappingURL=parse-hid-report-descriptor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parse-hid-report-descriptor.js","sourceRoot":"","sources":["../../src/descriptor/parse-hid-report-descriptor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE1C,O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AAC,YAAY,GAAG,EAAE,CAAC;QACzB,CAAC;aAAM,IAAI,KAAK,KAAK,CAAC,EAAE,CAAC;YACxB,IAAI,KAAK,CAAC,YAAY,KAAK,SAAS,EAAE,CAAC;gBACtC,MAAM,IAAI,kBAAkB,CAC3B,qCAAqC,EACrC,MAAM,CACN,CAAC;YACH,CAAC;YACD,IAAI,KAAK,CAAC,YAAY,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;gBACnC,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,EAAE,KAAK,CAAC,YAAY,EAAE,CAAC,CAAC;YACzE,CAAC;YACD,KAAK,CAAC,YAAY,GAAG,SAAS,CAAC;QAChC,CAAC;aAAM,CAAC;YACP,MAAM,IAAI,kBAAkB,CAC3B,mBAAmB,KAAK,oCAAoC,EAC5D,MAAM,CACN,CAAC;QACH,CAAC;IACF,CAAC;CACD;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,MAAM,UAAU,wBAAwB,CACvC,KAAiB;IAEjB,OAAO,IAAI,iBAAiB,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;AAC7C,CAAC"}
|
package/dist/errors.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A report descriptor is malformed: an item is truncated, or the item sequence
|
|
3
|
+
* breaks a rule of the HID 1.11 §6.2.2 state machine (an unbalanced collection,
|
|
4
|
+
* a `Pop` with nothing pushed, a data item with no Report Size, …).
|
|
5
|
+
*
|
|
6
|
+
* Thrown by {@link decodeHidItems} and {@link parseHidReportDescriptor}. An
|
|
7
|
+
* invalid argument built by the caller — an item {@link encodeHidItems} cannot
|
|
8
|
+
* spell, a value that does not fit a field — is a `RangeError` instead.
|
|
9
|
+
*/
|
|
10
|
+
export declare class HidDescriptorError extends SyntaxError {
|
|
11
|
+
/** Byte offset in the descriptor of the item the parser gave up at. */
|
|
12
|
+
readonly offset: number;
|
|
13
|
+
constructor(message: string,
|
|
14
|
+
/** Byte offset in the descriptor of the item the parser gave up at. */
|
|
15
|
+
offset: number);
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,qBAAa,kBAAmB,SAAQ,WAAW;IAGjD,uEAAuE;IACvE,QAAQ,CAAC,MAAM,EAAE,MAAM;IAHxB,YACC,OAAO,EAAE,MAAM;IACf,uEAAuE;IAC9D,MAAM,EAAE,MAAM,EAIvB;CACD"}
|
package/dist/errors.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A report descriptor is malformed: an item is truncated, or the item sequence
|
|
3
|
+
* breaks a rule of the HID 1.11 §6.2.2 state machine (an unbalanced collection,
|
|
4
|
+
* a `Pop` with nothing pushed, a data item with no Report Size, …).
|
|
5
|
+
*
|
|
6
|
+
* Thrown by {@link decodeHidItems} and {@link parseHidReportDescriptor}. An
|
|
7
|
+
* invalid argument built by the caller — an item {@link encodeHidItems} cannot
|
|
8
|
+
* spell, a value that does not fit a field — is a `RangeError` instead.
|
|
9
|
+
*/
|
|
10
|
+
export class HidDescriptorError extends SyntaxError {
|
|
11
|
+
offset;
|
|
12
|
+
constructor(message,
|
|
13
|
+
/** Byte offset in the descriptor of the item the parser gave up at. */
|
|
14
|
+
offset) {
|
|
15
|
+
super(`${message} (at byte ${offset})`);
|
|
16
|
+
this.offset = offset;
|
|
17
|
+
this.name = "HidDescriptorError";
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,MAAM,OAAO,kBAAmB,SAAQ,WAAW;IAIxC,MAAM;IAHhB,YACC,OAAe;IACf,uEAAuE;IAC9D,MAAc;QAEvB,KAAK,CAAC,GAAG,OAAO,aAAa,MAAM,GAAG,CAAC,CAAC;sBAF/B,MAAM;QAGf,IAAI,CAAC,IAAI,GAAG,oBAAoB,CAAC;IAClC,CAAC;CACD"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { HidFieldLayout } from "./hid-field-layout.js";
|
|
2
|
+
/**
|
|
3
|
+
* Validates `index` and the field's size against `report`, and returns the
|
|
4
|
+
* position of the value's first bit.
|
|
5
|
+
*/
|
|
6
|
+
export declare function fieldValueBitPosition_(report: Uint8Array, field: HidFieldLayout, index: number, caller: string): number;
|
|
7
|
+
//# sourceMappingURL=_field-value-bit-position.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_field-value-bit-position.d.ts","sourceRoot":"","sources":["../../src/field/_field-value-bit-position.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAQ5D;;;GAGG;AACH,wBAAgB,sBAAsB,CACrC,MAAM,EAAE,UAAU,EAClB,KAAK,EAAE,cAAc,EACrB,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,MAAM,GACZ,MAAM,CAmBR"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Logical Minimum/Maximum hold at most 32 bits (HID 1.11 §6.2.2.7), so a wider
|
|
3
|
+
* value has no range to be read against.
|
|
4
|
+
*/
|
|
5
|
+
const MAX_VALUE_BITS_ = 32;
|
|
6
|
+
/**
|
|
7
|
+
* Validates `index` and the field's size against `report`, and returns the
|
|
8
|
+
* position of the value's first bit.
|
|
9
|
+
*/
|
|
10
|
+
export function fieldValueBitPosition_(report, field, index, caller) {
|
|
11
|
+
const { bitSize, count } = field;
|
|
12
|
+
if (!Number.isInteger(bitSize) || bitSize < 1 || bitSize > MAX_VALUE_BITS_) {
|
|
13
|
+
throw new RangeError(`${caller}: bit size ${bitSize} is not 1–${MAX_VALUE_BITS_}`);
|
|
14
|
+
}
|
|
15
|
+
if (!Number.isInteger(index) || index < 0 || index >= count) {
|
|
16
|
+
throw new RangeError(`${caller}: index ${index} is outside 0–${count - 1}`);
|
|
17
|
+
}
|
|
18
|
+
const position = field.bitOffset + index * bitSize;
|
|
19
|
+
if (position + bitSize > report.length * 8) {
|
|
20
|
+
throw new RangeError(`${caller}: bits ${position}–${position + bitSize - 1} lie past a ${report.length}-byte report`);
|
|
21
|
+
}
|
|
22
|
+
return position;
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=_field-value-bit-position.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_field-value-bit-position.js","sourceRoot":"","sources":["../../src/field/_field-value-bit-position.ts"],"names":[],"mappings":"AAEA;;;GAGG;AACH,MAAM,eAAe,GAAG,EAAE,CAAC;AAE3B;;;GAGG;AACH,MAAM,UAAU,sBAAsB,CACrC,MAAkB,EAClB,KAAqB,EACrB,KAAa,EACb,MAAc;IAEd,MAAM,EAAE,OAAO,EAAE,KAAK,EAAE,GAAG,KAAK,CAAC;IACjC,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,OAAO,CAAC,IAAI,OAAO,GAAG,CAAC,IAAI,OAAO,GAAG,eAAe,EAAE,CAAC;QAC5E,MAAM,IAAI,UAAU,CACnB,GAAG,MAAM,cAAc,OAAO,aAAa,eAAe,EAAE,CAC5D,CAAC;IACH,CAAC;IACD,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,IAAI,KAAK,GAAG,CAAC,IAAI,KAAK,IAAI,KAAK,EAAE,CAAC;QAC7D,MAAM,IAAI,UAAU,CAAC,GAAG,MAAM,WAAW,KAAK,iBAAiB,KAAK,GAAG,CAAC,EAAE,CAAC,CAAC;IAC7E,CAAC;IAED,MAAM,QAAQ,GAAG,KAAK,CAAC,SAAS,GAAG,KAAK,GAAG,OAAO,CAAC;IACnD,IAAI,QAAQ,GAAG,OAAO,GAAG,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAC5C,MAAM,IAAI,UAAU,CACnB,GAAG,MAAM,UAAU,QAAQ,IAAI,QAAQ,GAAG,OAAO,GAAG,CAAC,eAAe,MAAM,CAAC,MAAM,cAAc,CAC/F,CAAC;IACH,CAAC;IAED,OAAO,QAAQ,CAAC;AACjB,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { HidReport } from "../descriptor/hid-report-descriptor.js";
|
|
2
|
+
/**
|
|
3
|
+
* A zeroed buffer the size of `report` as transferred, with its Report ID byte
|
|
4
|
+
* already set when it has one — ready for {@link writeHidFieldValueInPlace}.
|
|
5
|
+
*
|
|
6
|
+
* O(n) time and memory in `report.byteLength`.
|
|
7
|
+
*/
|
|
8
|
+
export declare function createHidReport(report: Pick<HidReport, "byteLength" | "reportId">): Uint8Array<ArrayBuffer>;
|
|
9
|
+
//# sourceMappingURL=create-hid-report.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-hid-report.d.ts","sourceRoot":"","sources":["../../src/field/create-hid-report.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,wCAAwC,CAAC;AAExE;;;;;GAKG;AACH,wBAAgB,eAAe,CAC9B,MAAM,EAAE,IAAI,CAAC,SAAS,EAAE,YAAY,GAAG,UAAU,CAAC,GAChD,UAAU,CAAC,WAAW,CAAC,CAOzB"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A zeroed buffer the size of `report` as transferred, with its Report ID byte
|
|
3
|
+
* already set when it has one — ready for {@link writeHidFieldValueInPlace}.
|
|
4
|
+
*
|
|
5
|
+
* O(n) time and memory in `report.byteLength`.
|
|
6
|
+
*/
|
|
7
|
+
export function createHidReport(report) {
|
|
8
|
+
const bytes = new Uint8Array(report.byteLength);
|
|
9
|
+
if (report.reportId !== 0) {
|
|
10
|
+
bytes[0] = report.reportId;
|
|
11
|
+
}
|
|
12
|
+
return bytes;
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=create-hid-report.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-hid-report.js","sourceRoot":"","sources":["../../src/field/create-hid-report.ts"],"names":[],"mappings":"AAEA;;;;;GAKG;AACH,MAAM,UAAU,eAAe,CAC9B,MAAkD;IAElD,MAAM,KAAK,GAAG,IAAI,UAAU,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;IAChD,IAAI,MAAM,CAAC,QAAQ,KAAK,CAAC,EAAE,CAAC;QAC3B,KAAK,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,QAAQ,CAAC;IAC5B,CAAC;IAED,OAAO,KAAK,CAAC;AACd,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { HidReportField } from "../descriptor/hid-report-descriptor.js";
|
|
2
|
+
/**
|
|
3
|
+
* The part of a field that locates and sizes its values, enough to read or
|
|
4
|
+
* write one.
|
|
5
|
+
*/
|
|
6
|
+
export type HidFieldLayout = Pick<HidReportField, "bitOffset" | "bitSize" | "count" | "logicalMinimum">;
|
|
7
|
+
//# sourceMappingURL=hid-field-layout.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hid-field-layout.d.ts","sourceRoot":"","sources":["../../src/field/hid-field-layout.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,wCAAwC,CAAC;AAE7E;;;GAGG;AACH,MAAM,MAAM,cAAc,GAAG,IAAI,CAChC,cAAc,EACd,WAAW,GAAG,SAAS,GAAG,OAAO,GAAG,gBAAgB,CACpD,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hid-field-layout.js","sourceRoot":"","sources":["../../src/field/hid-field-layout.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { HidReportField } from "../descriptor/hid-report-descriptor.js";
|
|
2
|
+
/**
|
|
3
|
+
* Converts a logical value to the physical quantity it measures, in the field's
|
|
4
|
+
* unit: the linear map from the logical range onto the physical range, scaled
|
|
5
|
+
* by `10 ** unitExponent` (HID 1.11 §6.2.2.7).
|
|
6
|
+
*
|
|
7
|
+
* The result is a real number; {@link decodeHidUnit} names its unit. A value
|
|
8
|
+
* outside the logical range — a null value — is extrapolated, not rejected.
|
|
9
|
+
*
|
|
10
|
+
* @returns `NaN` when the logical range is a single value, which leaves the
|
|
11
|
+
* scale undefined.
|
|
12
|
+
*/
|
|
13
|
+
export declare function hidLogicalToPhysical(field: Pick<HidReportField, "logicalMaximum" | "logicalMinimum" | "physicalMaximum" | "physicalMinimum" | "unitExponent">, value: number): number;
|
|
14
|
+
//# sourceMappingURL=hid-logical-to-physical.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hid-logical-to-physical.d.ts","sourceRoot":"","sources":["../../src/field/hid-logical-to-physical.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,wCAAwC,CAAC;AAE7E;;;;;;;;;;GAUG;AACH,wBAAgB,oBAAoB,CACnC,KAAK,EAAE,IAAI,CACV,cAAc,EACZ,gBAAgB,GAChB,gBAAgB,GAChB,iBAAiB,GACjB,iBAAiB,GACjB,cAAc,CAChB,EACD,KAAK,EAAE,MAAM,GACX,MAAM,CAkBR"}
|