-
Notifications
You must be signed in to change notification settings - Fork 0
/
GlobalItems.ts
194 lines (165 loc) · 5.57 KB
/
GlobalItems.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
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
import { HIDDesc } from "./HIDDesc";
import { Unit } from "./Units";
import { UsagePages } from "./UsagePages";
import { ParseToHex } from "./util";
declare module "./HIDDesc" {
export interface HIDDesc<Page extends UsagePages> {
/**
Unsigned integer specifying the current Usage
Page. Since a usage are 32 bit values, Usage
Page items can be used to conserve space in a
report descriptor by setting the high order 16 bits
of a subsequent usages. Any usage that follows
which is defines 16 bits or less is interpreted as a
Usage ID and concatenated with the Usage Page
to form a 32 bit Usage.
*/
UsagePage<Page extends UsagePages> ( page: Page ): HIDDesc<Page>;
/**
Extent value in logical units. This is the
minimum value that a variable or array item will
report. For example, a mouse reporting x
position values from 0 to 128 would have a
Logical Minimum of 0 and a Logical Maximum
of 128.
*/
LogicalMinimum ( min: number ): HIDDesc<Page>;
/**
Extent value in logical units. This is the
maximum value that a variable or array item will
report.
*/
LogicalMaximum ( max: number ): HIDDesc<Page>;
/**
Minimum value for the physical extent of a
variable item. This represents the Logical
Minimum with units applied to it.
*/
PhysicalMinimum ( min: number ): HIDDesc<Page>;
/**
Maximum value for the physical extent of a
variable item.
*/
PhysicalMaximum ( max: number ): HIDDesc<Page>;
/**
Value of the unit exponent in base.
*/
UnitExponent ( exp: number ): HIDDesc<Page>;
/**
Unit values.
*/
Unit ( unit: Unit ): HIDDesc<Page>;
/**
Unsigned integer specifying the size of the report
fields in bits. This allows the parser to build an
item map for the report handler to use
*/
ReportSize ( size: number ): HIDDesc<Page>;
/**
Unsigned value that specifies the Report ID. If a
Report ID tag is used anywhere in Report
descriptor, all data reports for the device are
preceded by a single byte ID field. All items
succeeding the first Report ID tag but preceding
a second Report ID tag are included in a report
prefixed by a 1-byte ID. All items succeeding the
second but preceding a third Report ID tag are
included in a second report prefixed by a second
ID, and so on.
This Report ID value indicates the prefix added
to a particular report. For example, a Report
descriptor could define a 3-byte report with a
Report ID of 01. This device would generate a
4-byte data report in which the first byte is 01.
The device may also generate other reports, each
with a unique ID. This allows the host to
distinguish different types of reports arriving
over a single interrupt in pipe. And allows the
device to distinguish different types of reports
arriving over a single interrupt out pipe. Report
ID zero is reserved and should not be used.
*/
ReportID ( id: number ): HIDDesc<Page>;
/**
Unsigned integer specifying the number of data
fields for the item; determines how many fields
are included in the report for this particular item
(and consequently how many bits are added to
the report).
*/
ReportCount ( count: number ): HIDDesc<Page>;
/**
Places a copy of the global item state table on
the stack.
*/
Push (): HIDDesc<Page>;
/**
Replaces the item state table with the top
structure from the stack.
*/
Pop (): HIDDesc<Page>;
}
}
HIDDesc.prototype.UsagePage = function <Page extends UsagePages> ( page: Page ) {
// despite being able to define size ( 0000 01nn ),
// the only usage page that isn't one byte is the
// vendor defined pages and 0xFIDO.
this.desc.push( ...ParseToHex( 0x04, page.UsagePage() ) );
return this as unknown as HIDDesc<Page>;
}
HIDDesc.prototype.ReportSize = function ( size: number ) {
this.desc.push( ...ParseToHex( 0x74, size ) );
return this;
}
HIDDesc.prototype.ReportID = function ( id: number ) {
this.desc.push( ...ParseToHex( 0x84, id ) );
return this;
}
HIDDesc.prototype.ReportCount = function ( count: number ) {
this.desc.push( ...ParseToHex( 0x94, count ) );
return this;
}
HIDDesc.prototype.LogicalMinimum = function ( min: number ) {
this.desc.push( ...ParseToHex( 0x14, min, true ) );
return this;
}
HIDDesc.prototype.LogicalMaximum = function ( max: number ) {
this.desc.push( ...ParseToHex( 0x24, max, true ) );
return this;
}
HIDDesc.prototype.PhysicalMinimum = function ( min: number ) {
this.desc.push( ...ParseToHex( 0x34, min, true ) );
return this;
}
HIDDesc.prototype.PhysicalMaximum = function ( max: number ) {
this.desc.push( ...ParseToHex( 0x44, max, true ) );
return this;
}
HIDDesc.prototype.Push = function () {
this.desc.push( 0xA4 );
return this;
}
HIDDesc.prototype.Pop = function () {
this.desc.push( 0xB4 );
return this;
}
HIDDesc.prototype.UnitExponent = function ( exp: number ) {
this.desc.push( ...ParseToHex( 0x54, exp, true ) );
return this;
}
HIDDesc.prototype.Unit = function ( unit: Unit ) {
var val: any = [], bits = 4;
val.push(
unit.System ?? 0,
unit.Length ?? 0,
unit.Mass ?? 0,
unit.Time ?? 0,
unit.Temperature ?? 0,
unit.Current ?? 0,
unit.LuminousIntensity ?? 0 );
val = parseInt( ( val.map(
( v: number ) => ( ( v < 0 ) ? v + 16 : v ).toString( 16 ) )
.join( "" ) + "0" ).split( "" ).reverse().join( "" ), 16 );
this.desc.push( ...ParseToHex( 0x64, val, true ) );
return this;
}