-
Notifications
You must be signed in to change notification settings - Fork 0
/
MainItems.ts
70 lines (59 loc) · 2.15 KB
/
MainItems.ts
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
import { CollectionType } from "./CollectionType";
import { FieldDesc } from "./FieldDesc";
import { HIDDesc } from "./HIDDesc";
import { UsagePages } from "./UsagePages";
import { ParseToHex } from "./util";
declare module "./HIDDesc" {
export interface HIDDesc<Page extends UsagePages> {
/**
A Collection item identifies a relationship between
two or more data (Input, Output, or Feature.)
*/
Collection ( collectionType: CollectionType ): HIDDesc<Page>;
/* Closes an item collection. */
EndCollection (): HIDDesc<Page>;
/**
An Input item describes information about the data provided by one or more
physical controls. An application can use this information to interpret the data
provided by the device. All data fields defined in a single item share an
identical data format
*/
Input ( desc: FieldDesc ): HIDDesc<Page>;
/**
The Output item is used to define an output data field in a report. This item is
similar to an Input item except it describes data sent to the device—for
example, LED states.
*/
Output ( desc: FieldDesc ): HIDDesc<Page>;
/**
Feature items describe device configuration information that can be sent to
the device.
*/
Feature ( desc: FieldDesc ): HIDDesc<Page>;
}
}
HIDDesc.prototype.Input = function ( desc: FieldDesc ) {
this.desc.push( ...ParseToHex( 0x80, desc ) );
return this;
}
HIDDesc.prototype.Output = function ( desc: FieldDesc ) {
this.desc.push( ...ParseToHex( 0x90, desc ) );
return this;
}
HIDDesc.prototype.Feature = function ( desc: FieldDesc ) {
this.desc.push( ...ParseToHex( 0xB0, desc ) );
return this;
}
HIDDesc.prototype.Collection = function ( collectionType: CollectionType ) {
// despite being able to define size ( 1010 00nn ),
// collectionType is always clamped between 0x00-0xff
this.desc.push( ...ParseToHex( 0xA0, collectionType ) );
return this;
}
HIDDesc.prototype.EndCollection = function () {
// this literally has no inputs, so I have no
// idea why the spec says it can be 110000nn
// like, dude. there is always going to be zero bytes of input
this.desc.push( 0xc0 );
return this;
}