@sdeck/elgato 0.0.0-stage → 0.5.1
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/dist/bytes.d.ts +8 -0
- package/dist/bytes.d.ts.map +1 -0
- package/dist/deck.d.ts +34 -0
- package/dist/deck.d.ts.map +1 -0
- package/dist/detect.d.ts +33 -0
- package/dist/detect.d.ts.map +1 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +675 -0
- package/dist/index.js.map +16 -0
- package/dist/legacy.d.ts +51 -0
- package/dist/legacy.d.ts.map +1 -0
- package/dist/models.d.ts +71 -0
- package/dist/models.d.ts.map +1 -0
- package/dist/protocol.d.ts +73 -0
- package/dist/protocol.d.ts.map +1 -0
- package/dist/virtual.d.ts +23 -0
- package/dist/virtual.d.ts.map +1 -0
- package/package.json +36 -4
- package/src/bytes.ts +32 -0
- package/src/deck.ts +129 -0
- package/src/detect.ts +77 -0
- package/src/index.ts +6 -0
- package/src/legacy.ts +211 -0
- package/src/models.ts +151 -0
- package/src/protocol.ts +317 -0
- package/src/virtual.ts +75 -0
- package/README.md +0 -3
package/dist/index.js
ADDED
|
@@ -0,0 +1,675 @@
|
|
|
1
|
+
// src/deck.ts
|
|
2
|
+
import { StreamDeck } from "@sdeck/core";
|
|
3
|
+
|
|
4
|
+
// src/bytes.ts
|
|
5
|
+
function assertUint(name, value, max) {
|
|
6
|
+
if (!Number.isInteger(value) || value < 0 || value > max) {
|
|
7
|
+
throw new RangeError(`${name} must be an integer between 0 and ${max}, got ${value}`);
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
function byteAt(data, offset) {
|
|
11
|
+
return data[offset] ?? 0;
|
|
12
|
+
}
|
|
13
|
+
function u16At(data, offset) {
|
|
14
|
+
return byteAt(data, offset) | byteAt(data, offset + 1) << 8;
|
|
15
|
+
}
|
|
16
|
+
function u32At(data, offset) {
|
|
17
|
+
return (u16At(data, offset) | u16At(data, offset + 2) << 16) >>> 0;
|
|
18
|
+
}
|
|
19
|
+
function i32At(data, offset) {
|
|
20
|
+
return u32At(data, offset) | 0;
|
|
21
|
+
}
|
|
22
|
+
function asciiString(data) {
|
|
23
|
+
let end = data.length;
|
|
24
|
+
const nul = data.indexOf(0);
|
|
25
|
+
if (nul !== -1)
|
|
26
|
+
end = nul;
|
|
27
|
+
let out = "";
|
|
28
|
+
for (let i = 0;i < end; i++)
|
|
29
|
+
out += String.fromCharCode(byteAt(data, i));
|
|
30
|
+
return out;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// src/protocol.ts
|
|
34
|
+
var OUTPUT_REPORT_SIZE = 1024;
|
|
35
|
+
var FEATURE_REPORT_SIZE = 32;
|
|
36
|
+
var INPUT_REPORT_ID = 1;
|
|
37
|
+
var OUTPUT_REPORT_ID = 2;
|
|
38
|
+
var SETTER_REPORT_ID = 3;
|
|
39
|
+
var GetterReportId = {
|
|
40
|
+
FirmwareLd: 4,
|
|
41
|
+
FirmwareAp2: 5,
|
|
42
|
+
SerialNumber: 6,
|
|
43
|
+
FirmwareAp1: 7,
|
|
44
|
+
UnitInformation: 8,
|
|
45
|
+
SleepDuration: 10
|
|
46
|
+
};
|
|
47
|
+
var SetterCommand = {
|
|
48
|
+
ShowLogo: 2,
|
|
49
|
+
FillLcd: 5,
|
|
50
|
+
FillKey: 6,
|
|
51
|
+
Brightness: 8,
|
|
52
|
+
SleepDuration: 13
|
|
53
|
+
};
|
|
54
|
+
var OutputCommand = {
|
|
55
|
+
ButtonImage: 7,
|
|
56
|
+
FullScreenImage: 8,
|
|
57
|
+
WindowImage: 11,
|
|
58
|
+
PartialWindowImage: 12
|
|
59
|
+
};
|
|
60
|
+
function assertRgb([r, g, b]) {
|
|
61
|
+
assertUint("red", r, 255);
|
|
62
|
+
assertUint("green", g, 255);
|
|
63
|
+
assertUint("blue", b, 255);
|
|
64
|
+
}
|
|
65
|
+
function featureReport(command, ...payload) {
|
|
66
|
+
const report = new Uint8Array(FEATURE_REPORT_SIZE);
|
|
67
|
+
report[0] = SETTER_REPORT_ID;
|
|
68
|
+
report[1] = command;
|
|
69
|
+
report.set(payload, 2);
|
|
70
|
+
return report;
|
|
71
|
+
}
|
|
72
|
+
function showLogoReport() {
|
|
73
|
+
return featureReport(SetterCommand.ShowLogo);
|
|
74
|
+
}
|
|
75
|
+
function fillLcdReport(color) {
|
|
76
|
+
assertRgb(color);
|
|
77
|
+
return featureReport(SetterCommand.FillLcd, ...color);
|
|
78
|
+
}
|
|
79
|
+
function fillKeyReport(index, color) {
|
|
80
|
+
assertUint("key index", index, 255);
|
|
81
|
+
assertRgb(color);
|
|
82
|
+
return featureReport(SetterCommand.FillKey, index, ...color);
|
|
83
|
+
}
|
|
84
|
+
function brightnessReport(percent) {
|
|
85
|
+
assertUint("brightness", percent, 100);
|
|
86
|
+
return featureReport(SetterCommand.Brightness, percent);
|
|
87
|
+
}
|
|
88
|
+
function sleepDurationReport(seconds) {
|
|
89
|
+
assertUint("sleep duration", seconds, 2147483647);
|
|
90
|
+
return featureReport(SetterCommand.SleepDuration, seconds & 255, seconds >>> 8 & 255, seconds >>> 16 & 255, seconds >>> 24 & 255);
|
|
91
|
+
}
|
|
92
|
+
function parseFirmwareVersion(report) {
|
|
93
|
+
return {
|
|
94
|
+
checksum: u32At(report, 2),
|
|
95
|
+
version: asciiString(report.subarray(6, 14))
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
function parseSerialNumber(report) {
|
|
99
|
+
const length = byteAt(report, 1);
|
|
100
|
+
return asciiString(report.subarray(2, 2 + length));
|
|
101
|
+
}
|
|
102
|
+
function parseSleepDuration(report) {
|
|
103
|
+
return i32At(report, 2);
|
|
104
|
+
}
|
|
105
|
+
function parseUnitInformation(report) {
|
|
106
|
+
if (report.length < 15) {
|
|
107
|
+
throw new RangeError(`unit information report too short: ${report.length} bytes`);
|
|
108
|
+
}
|
|
109
|
+
return {
|
|
110
|
+
keyRows: byteAt(report, 1),
|
|
111
|
+
keyColumns: byteAt(report, 2),
|
|
112
|
+
keyWidth: u16At(report, 3),
|
|
113
|
+
keyHeight: u16At(report, 5),
|
|
114
|
+
lcdWidth: u16At(report, 7),
|
|
115
|
+
lcdHeight: u16At(report, 9),
|
|
116
|
+
imageBitsPerPixel: byteAt(report, 11),
|
|
117
|
+
imageColorScheme: byteAt(report, 12),
|
|
118
|
+
galleryKeyImages: byteAt(report, 13),
|
|
119
|
+
galleryLcdImages: byteAt(report, 14),
|
|
120
|
+
demoFrames: byteAt(report, 15)
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
function chunkedImagePackets(image, headerSize, writeHeader) {
|
|
124
|
+
if (image.length === 0)
|
|
125
|
+
throw new RangeError("image data is empty");
|
|
126
|
+
const maxChunk = OUTPUT_REPORT_SIZE - headerSize;
|
|
127
|
+
const packets = [];
|
|
128
|
+
for (let offset = 0, index = 0;offset < image.length; offset += maxChunk, index++) {
|
|
129
|
+
const chunk = image.subarray(offset, offset + maxChunk);
|
|
130
|
+
const isLast = offset + maxChunk >= image.length;
|
|
131
|
+
if (index > 65535)
|
|
132
|
+
throw new RangeError("image is too large");
|
|
133
|
+
const packet = new Uint8Array(OUTPUT_REPORT_SIZE);
|
|
134
|
+
packet[0] = OUTPUT_REPORT_ID;
|
|
135
|
+
writeHeader(packet, index, chunk.length, isLast);
|
|
136
|
+
packet.set(chunk, headerSize);
|
|
137
|
+
packets.push(packet);
|
|
138
|
+
}
|
|
139
|
+
return packets;
|
|
140
|
+
}
|
|
141
|
+
function standardImagePackets(command, byte2, image) {
|
|
142
|
+
return chunkedImagePackets(image, 8, (packet, index, size, isLast) => {
|
|
143
|
+
packet[1] = command;
|
|
144
|
+
packet[2] = byte2;
|
|
145
|
+
packet[3] = isLast ? 1 : 0;
|
|
146
|
+
packet[4] = size & 255;
|
|
147
|
+
packet[5] = size >>> 8;
|
|
148
|
+
packet[6] = index & 255;
|
|
149
|
+
packet[7] = index >>> 8;
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
function buttonImagePackets(index, jpeg) {
|
|
153
|
+
assertUint("key index", index, 255);
|
|
154
|
+
return standardImagePackets(OutputCommand.ButtonImage, index, jpeg);
|
|
155
|
+
}
|
|
156
|
+
function fullScreenImagePackets(jpeg) {
|
|
157
|
+
return standardImagePackets(OutputCommand.FullScreenImage, 0, jpeg);
|
|
158
|
+
}
|
|
159
|
+
function windowImagePackets(jpeg) {
|
|
160
|
+
return standardImagePackets(OutputCommand.WindowImage, 0, jpeg);
|
|
161
|
+
}
|
|
162
|
+
function partialWindowImagePackets(region, jpeg) {
|
|
163
|
+
assertUint("x", region.x, 65535);
|
|
164
|
+
assertUint("y", region.y, 65535);
|
|
165
|
+
assertUint("width", region.width, 65535);
|
|
166
|
+
assertUint("height", region.height, 65535);
|
|
167
|
+
return chunkedImagePackets(jpeg, 16, (packet, index, size, isLast) => {
|
|
168
|
+
packet[1] = OutputCommand.PartialWindowImage;
|
|
169
|
+
packet[2] = region.x & 255;
|
|
170
|
+
packet[3] = region.x >>> 8;
|
|
171
|
+
packet[4] = region.y & 255;
|
|
172
|
+
packet[5] = region.y >>> 8;
|
|
173
|
+
packet[6] = region.width & 255;
|
|
174
|
+
packet[7] = region.width >>> 8;
|
|
175
|
+
packet[8] = region.height & 255;
|
|
176
|
+
packet[9] = region.height >>> 8;
|
|
177
|
+
packet[10] = isLast ? 1 : 0;
|
|
178
|
+
packet[11] = index & 255;
|
|
179
|
+
packet[12] = index >>> 8;
|
|
180
|
+
packet[13] = size & 255;
|
|
181
|
+
packet[14] = size >>> 8;
|
|
182
|
+
packet[15] = 0;
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
var InputCommand = { Buttons: 0, Touch: 2, Dials: 3 };
|
|
186
|
+
var Touch = { Tap: 1, Press: 2, Flick: 3 };
|
|
187
|
+
var Dials = { Pressed: 0, Turned: 1 };
|
|
188
|
+
function parseInputReport(data) {
|
|
189
|
+
if (data.length < 4 || data[0] !== INPUT_REPORT_ID)
|
|
190
|
+
return;
|
|
191
|
+
const payload = data.subarray(4, 4 + u16At(data, 2));
|
|
192
|
+
const point = (offset) => ({
|
|
193
|
+
x: u16At(data, offset),
|
|
194
|
+
y: u16At(data, offset + 2)
|
|
195
|
+
});
|
|
196
|
+
switch (data[1]) {
|
|
197
|
+
case InputCommand.Buttons:
|
|
198
|
+
return { type: "buttons", pressed: Array.from(payload, (byte) => byte === 1) };
|
|
199
|
+
case InputCommand.Dials: {
|
|
200
|
+
const dials = payload.subarray(1);
|
|
201
|
+
if (payload[0] === Dials.Pressed) {
|
|
202
|
+
return { type: "dials", pressed: Array.from(dials, (byte) => byte === 1) };
|
|
203
|
+
}
|
|
204
|
+
if (payload[0] !== Dials.Turned)
|
|
205
|
+
return;
|
|
206
|
+
return { type: "turn", ticks: Array.from(dials, (byte) => byte << 24 >> 24) };
|
|
207
|
+
}
|
|
208
|
+
case InputCommand.Touch:
|
|
209
|
+
if (data.length < 10)
|
|
210
|
+
return;
|
|
211
|
+
if (payload[0] === Touch.Tap || payload[0] === Touch.Press) {
|
|
212
|
+
return { type: "tap", at: point(6), long: payload[0] === Touch.Press };
|
|
213
|
+
}
|
|
214
|
+
if (payload[0] !== Touch.Flick || data.length < 14)
|
|
215
|
+
return;
|
|
216
|
+
return { type: "swipe", from: point(6), to: point(10) };
|
|
217
|
+
default:
|
|
218
|
+
return;
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
function inputReport(input) {
|
|
222
|
+
const u16 = (value) => [value & 255, value >> 8];
|
|
223
|
+
const at = ({ x, y }) => [...u16(x), ...u16(y)];
|
|
224
|
+
const report = (command, payload) => Uint8Array.of(INPUT_REPORT_ID, command, ...u16(payload.length), ...payload);
|
|
225
|
+
switch (input.type) {
|
|
226
|
+
case "buttons":
|
|
227
|
+
return report(InputCommand.Buttons, input.pressed.map(Number));
|
|
228
|
+
case "dials":
|
|
229
|
+
return report(InputCommand.Dials, [Dials.Pressed, ...input.pressed.map(Number)]);
|
|
230
|
+
case "turn":
|
|
231
|
+
return report(InputCommand.Dials, [Dials.Turned, ...input.ticks.map((t) => t & 255)]);
|
|
232
|
+
case "tap":
|
|
233
|
+
return report(InputCommand.Touch, [
|
|
234
|
+
input.long ? Touch.Press : Touch.Tap,
|
|
235
|
+
0,
|
|
236
|
+
...at(input.at),
|
|
237
|
+
...[0, 0, 0, 0]
|
|
238
|
+
]);
|
|
239
|
+
case "swipe":
|
|
240
|
+
return report(InputCommand.Touch, [
|
|
241
|
+
Touch.Flick,
|
|
242
|
+
0,
|
|
243
|
+
...at(input.from),
|
|
244
|
+
...at(input.to),
|
|
245
|
+
...[0, 0, 0, 0]
|
|
246
|
+
]);
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
// src/deck.ts
|
|
251
|
+
var FIRMWARE_REPORT_IDS = {
|
|
252
|
+
ld: GetterReportId.FirmwareLd,
|
|
253
|
+
ap1: GetterReportId.FirmwareAp1,
|
|
254
|
+
ap2: GetterReportId.FirmwareAp2
|
|
255
|
+
};
|
|
256
|
+
|
|
257
|
+
class ElgatoStreamDeck extends StreamDeck {
|
|
258
|
+
constructor(transport, model) {
|
|
259
|
+
super(transport, model);
|
|
260
|
+
}
|
|
261
|
+
parseInput(data) {
|
|
262
|
+
return parseInputReport(data);
|
|
263
|
+
}
|
|
264
|
+
sendKeyImage(index, jpeg) {
|
|
265
|
+
return this.#write(buttonImagePackets(index, jpeg));
|
|
266
|
+
}
|
|
267
|
+
sendScreenImage(jpeg) {
|
|
268
|
+
return this.#write(fullScreenImagePackets(jpeg));
|
|
269
|
+
}
|
|
270
|
+
sendWindowImage(jpeg) {
|
|
271
|
+
return this.#write(windowImagePackets(jpeg));
|
|
272
|
+
}
|
|
273
|
+
sendWindowRegionImage(region, jpeg) {
|
|
274
|
+
return this.#write(partialWindowImagePackets(region, jpeg));
|
|
275
|
+
}
|
|
276
|
+
sendFillKey(index, color) {
|
|
277
|
+
return this.transport.sendFeatureReport(fillKeyReport(index, color));
|
|
278
|
+
}
|
|
279
|
+
sendFillScreen(color) {
|
|
280
|
+
return this.transport.sendFeatureReport(fillLcdReport(color));
|
|
281
|
+
}
|
|
282
|
+
async onClosing() {
|
|
283
|
+
await this.transport.sendFeatureReport(showLogoReport());
|
|
284
|
+
}
|
|
285
|
+
setBrightness(percent) {
|
|
286
|
+
return this.#feature(brightnessReport(percent));
|
|
287
|
+
}
|
|
288
|
+
showLogo() {
|
|
289
|
+
return this.#feature(showLogoReport());
|
|
290
|
+
}
|
|
291
|
+
setSleepDuration(seconds) {
|
|
292
|
+
return this.#feature(sleepDurationReport(seconds));
|
|
293
|
+
}
|
|
294
|
+
async getSleepDuration() {
|
|
295
|
+
return parseSleepDuration(await this.#getFeature(GetterReportId.SleepDuration));
|
|
296
|
+
}
|
|
297
|
+
async getFirmwareVersion(kind = "ap2") {
|
|
298
|
+
return parseFirmwareVersion(await this.#getFeature(FIRMWARE_REPORT_IDS[kind]));
|
|
299
|
+
}
|
|
300
|
+
async getSerialNumber() {
|
|
301
|
+
return parseSerialNumber(await this.#getFeature(GetterReportId.SerialNumber));
|
|
302
|
+
}
|
|
303
|
+
async getUnitInformation() {
|
|
304
|
+
return parseUnitInformation(await this.#getFeature(GetterReportId.UnitInformation));
|
|
305
|
+
}
|
|
306
|
+
#feature(report) {
|
|
307
|
+
return this.enqueue(() => this.transport.sendFeatureReport(report));
|
|
308
|
+
}
|
|
309
|
+
#getFeature(reportId) {
|
|
310
|
+
return this.enqueue(() => this.transport.getFeatureReport(reportId, FEATURE_REPORT_SIZE));
|
|
311
|
+
}
|
|
312
|
+
async#write(packets) {
|
|
313
|
+
for (const packet of packets)
|
|
314
|
+
await this.transport.write(packet);
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
// src/detect.ts
|
|
318
|
+
import {
|
|
319
|
+
findDecks,
|
|
320
|
+
listDecks,
|
|
321
|
+
openDeck
|
|
322
|
+
} from "@sdeck/core";
|
|
323
|
+
|
|
324
|
+
// src/legacy.ts
|
|
325
|
+
import {
|
|
326
|
+
StreamDeck as StreamDeck2
|
|
327
|
+
} from "@sdeck/core";
|
|
328
|
+
var FEATURE_SIZE = 17;
|
|
329
|
+
var LONG_FEATURE_SIZE = 32;
|
|
330
|
+
var HEADER_SIZE = 16;
|
|
331
|
+
var BITMAP_HEADER_SIZE = 54;
|
|
332
|
+
var feature = (...bytes) => {
|
|
333
|
+
const report = new Uint8Array(FEATURE_SIZE);
|
|
334
|
+
report.set(bytes);
|
|
335
|
+
return report;
|
|
336
|
+
};
|
|
337
|
+
var legacyLogoReport = () => feature(11, 99);
|
|
338
|
+
function legacyBrightnessReport(percent) {
|
|
339
|
+
assertUint("brightness", percent, 100);
|
|
340
|
+
return feature(5, 85, 170, 209, 1, percent);
|
|
341
|
+
}
|
|
342
|
+
function legacySleepReport(seconds) {
|
|
343
|
+
assertUint("sleep duration", seconds, 2147483647);
|
|
344
|
+
const bytes = [0, 8, 16, 24].map((shift) => seconds >>> shift & 255);
|
|
345
|
+
return feature(11, 162, ...bytes);
|
|
346
|
+
}
|
|
347
|
+
function legacyKeyPackets(key, bitmap, protocol) {
|
|
348
|
+
assertUint("key index", key, 254);
|
|
349
|
+
const original = protocol === "original";
|
|
350
|
+
const size = original ? 8191 : 1024;
|
|
351
|
+
const chunk = original ? Math.ceil(bitmap.length / 2) : size - HEADER_SIZE;
|
|
352
|
+
const packets = [];
|
|
353
|
+
for (let offset = 0, page = original ? 1 : 0;offset < bitmap.length; offset += chunk, page++) {
|
|
354
|
+
const packet = new Uint8Array(size);
|
|
355
|
+
const last = offset + chunk >= bitmap.length;
|
|
356
|
+
packet.set([2, 1, page, 0, last ? 1 : 0, key + 1]);
|
|
357
|
+
packet.set(bitmap.subarray(offset, offset + chunk), HEADER_SIZE);
|
|
358
|
+
packets.push(packet);
|
|
359
|
+
}
|
|
360
|
+
return packets;
|
|
361
|
+
}
|
|
362
|
+
function keyBitmap(rgb, { width, height }, protocol) {
|
|
363
|
+
const bytes = width * height * 3;
|
|
364
|
+
const file = new Uint8Array(BITMAP_HEADER_SIZE + bytes);
|
|
365
|
+
const header = new DataView(file.buffer);
|
|
366
|
+
const perMeter = protocol === "mini" ? 2835 : 3780;
|
|
367
|
+
header.setUint16(0, 19778, true);
|
|
368
|
+
header.setUint32(2, file.length, true);
|
|
369
|
+
header.setUint32(10, BITMAP_HEADER_SIZE, true);
|
|
370
|
+
header.setUint32(14, 40, true);
|
|
371
|
+
header.setInt32(18, width, true);
|
|
372
|
+
header.setInt32(22, height, true);
|
|
373
|
+
header.setUint16(26, 1, true);
|
|
374
|
+
header.setUint16(28, 24, true);
|
|
375
|
+
header.setUint32(34, bytes, true);
|
|
376
|
+
header.setInt32(38, perMeter, true);
|
|
377
|
+
header.setInt32(42, perMeter, true);
|
|
378
|
+
for (let y = 0;y < height; y++) {
|
|
379
|
+
for (let x = 0;x < width; x++) {
|
|
380
|
+
const from = protocol === "mini" ? x * width + (width - 1 - y) : y * width + (width - 1 - x);
|
|
381
|
+
const to = BITMAP_HEADER_SIZE + (y * width + x) * 3;
|
|
382
|
+
file[to] = rgb[from * 3 + 2];
|
|
383
|
+
file[to + 1] = rgb[from * 3 + 1];
|
|
384
|
+
file[to + 2] = rgb[from * 3];
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
return file;
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
class LegacyStreamDeck extends StreamDeck2 {
|
|
391
|
+
#protocol;
|
|
392
|
+
constructor(transport, model) {
|
|
393
|
+
super(transport, model);
|
|
394
|
+
this.#protocol = model.protocol === "original" ? "original" : "mini";
|
|
395
|
+
}
|
|
396
|
+
#number(key) {
|
|
397
|
+
if (this.#protocol !== "original")
|
|
398
|
+
return key;
|
|
399
|
+
const columns = this.model.layout.keys.filter((r, _, [first]) => r.y === first?.y).length;
|
|
400
|
+
return key + columns - 1 - 2 * (key % columns);
|
|
401
|
+
}
|
|
402
|
+
parseInput(data) {
|
|
403
|
+
if (data[0] !== 1 || data.length <= this.keyCount)
|
|
404
|
+
return;
|
|
405
|
+
const pressed = this.model.layout.keys.map((_, key) => data[1 + this.#number(key)] === 1);
|
|
406
|
+
return { type: "buttons", pressed };
|
|
407
|
+
}
|
|
408
|
+
async encodeImage(rgb, size) {
|
|
409
|
+
return keyBitmap(rgb, size, this.#protocol);
|
|
410
|
+
}
|
|
411
|
+
async sendKeyImage(index, bitmap) {
|
|
412
|
+
for (const packet of legacyKeyPackets(this.#number(index), bitmap, this.#protocol)) {
|
|
413
|
+
await this.transport.write(packet);
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
sendScreenImage() {
|
|
417
|
+
return Promise.reject(new Error(`${this.model.name} takes images for its keys only`));
|
|
418
|
+
}
|
|
419
|
+
prepareFrame(screen) {
|
|
420
|
+
const keys = this.model.layout.keys.map((rect) => keyBitmap(screen.read(rect).data, rect, this.#protocol));
|
|
421
|
+
return async () => {
|
|
422
|
+
for (const [index, bitmap] of keys.entries())
|
|
423
|
+
await this.sendKeyImage(index, bitmap);
|
|
424
|
+
};
|
|
425
|
+
}
|
|
426
|
+
async sendFillScreen(color) {
|
|
427
|
+
for (let index = 0;index < this.keyCount; index++)
|
|
428
|
+
await this.sendFillKey(index, color);
|
|
429
|
+
}
|
|
430
|
+
async onClosing() {
|
|
431
|
+
await this.transport.sendFeatureReport(legacyLogoReport());
|
|
432
|
+
}
|
|
433
|
+
setBrightness(percent) {
|
|
434
|
+
return this.#feature(legacyBrightnessReport(percent));
|
|
435
|
+
}
|
|
436
|
+
showLogo() {
|
|
437
|
+
return this.#feature(legacyLogoReport());
|
|
438
|
+
}
|
|
439
|
+
async setSleepDuration(seconds) {
|
|
440
|
+
if (this.#protocol === "original")
|
|
441
|
+
return;
|
|
442
|
+
await this.#feature(legacySleepReport(seconds));
|
|
443
|
+
}
|
|
444
|
+
async getSleepDuration() {
|
|
445
|
+
return this.#protocol === "original" ? 0 : i32At(await this.#read(163), 2);
|
|
446
|
+
}
|
|
447
|
+
async getFirmwareVersion() {
|
|
448
|
+
const report = await this.#read(this.#protocol === "original" ? 4 : 161);
|
|
449
|
+
return asciiString(report.subarray(5));
|
|
450
|
+
}
|
|
451
|
+
async getSerialNumber() {
|
|
452
|
+
return asciiString((await this.#read(3)).subarray(5));
|
|
453
|
+
}
|
|
454
|
+
#feature(report) {
|
|
455
|
+
return this.enqueue(() => this.transport.sendFeatureReport(report));
|
|
456
|
+
}
|
|
457
|
+
#read(reportId) {
|
|
458
|
+
return this.enqueue(() => this.transport.getFeatureReport(reportId, LONG_FEATURE_SIZE).catch(() => this.transport.getFeatureReport(reportId, FEATURE_SIZE)));
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
// src/models.ts
|
|
463
|
+
var ELGATO_VENDOR_ID = 4057;
|
|
464
|
+
var grid = (size, x, y) => y.flatMap((top) => x.map((left) => ({ x: left, y: top, width: size, height: size })));
|
|
465
|
+
var every = (count, first, step) => Array.from({ length: count }, (_, i) => first + i * step);
|
|
466
|
+
var split = (window, count) => Array.from({ length: count }, (_, i) => {
|
|
467
|
+
const width = window.width / count;
|
|
468
|
+
return { ...window, x: window.x + i * width, width };
|
|
469
|
+
});
|
|
470
|
+
var NEO = {
|
|
471
|
+
screen: { width: 480, height: 320 },
|
|
472
|
+
keys: grid(96, every(4, 3, 126), every(2, 9, 126)),
|
|
473
|
+
sensors: [
|
|
474
|
+
{ x: 3, y: 283, width: 96, height: 16 },
|
|
475
|
+
{ x: 381, y: 283, width: 96, height: 16 }
|
|
476
|
+
],
|
|
477
|
+
window: { x: 116, y: 262, width: 248, height: 58 }
|
|
478
|
+
};
|
|
479
|
+
var CLASSIC = {
|
|
480
|
+
screen: { width: 480, height: 272 },
|
|
481
|
+
keys: grid(72, every(5, 11, 97), every(3, 5, 97)),
|
|
482
|
+
sensors: []
|
|
483
|
+
};
|
|
484
|
+
var XL = {
|
|
485
|
+
screen: { width: 1024, height: 600 },
|
|
486
|
+
keys: grid(96, [14, 142, 270, 399, 527, 655, 784, 912], every(4, 47, 135)),
|
|
487
|
+
sensors: []
|
|
488
|
+
};
|
|
489
|
+
var PLUS_WINDOW = { x: 0, y: 380, width: 800, height: 100 };
|
|
490
|
+
var PLUS = {
|
|
491
|
+
screen: { width: 800, height: 480 },
|
|
492
|
+
keys: grid(120, every(4, 13, 219), every(2, 12, 160)),
|
|
493
|
+
sensors: [],
|
|
494
|
+
window: PLUS_WINDOW,
|
|
495
|
+
dials: split(PLUS_WINDOW, 4)
|
|
496
|
+
};
|
|
497
|
+
var PLUS_XL_WINDOW = { x: 40, y: 674, width: 1200, height: 100 };
|
|
498
|
+
var PLUS_XL = {
|
|
499
|
+
screen: { width: 1280, height: 800 },
|
|
500
|
+
keys: grid(112, [11, 154, 298, 441, 585, 728, 872, 1015, 1159], [32, 176, 318, 462]),
|
|
501
|
+
sensors: [],
|
|
502
|
+
window: PLUS_XL_WINDOW,
|
|
503
|
+
dials: split(PLUS_XL_WINDOW, 6)
|
|
504
|
+
};
|
|
505
|
+
var MINI = {
|
|
506
|
+
screen: { width: 320, height: 240 },
|
|
507
|
+
keys: grid(80, [14, 122, 229], [26, 134]),
|
|
508
|
+
sensors: []
|
|
509
|
+
};
|
|
510
|
+
var DESIGN = {
|
|
511
|
+
key: { width: 96, height: 96 },
|
|
512
|
+
sensor: { width: 96, height: 16 },
|
|
513
|
+
dial: { width: 200, height: 100 },
|
|
514
|
+
window: { width: 248, height: 58 }
|
|
515
|
+
};
|
|
516
|
+
var FAMILIES = {
|
|
517
|
+
neo: { layout: NEO, rotation: 180 },
|
|
518
|
+
classic: { layout: CLASSIC, rotation: 180 },
|
|
519
|
+
scissor: { layout: CLASSIC, rotation: 180 },
|
|
520
|
+
xl: { layout: XL, rotation: 180 },
|
|
521
|
+
plus: { layout: PLUS, rotation: 0 },
|
|
522
|
+
"plus-xl": { layout: PLUS_XL, rotation: 270 },
|
|
523
|
+
mini: { layout: MINI, rotation: 270 }
|
|
524
|
+
};
|
|
525
|
+
var TABLE = {
|
|
526
|
+
neo: ["Stream Deck Neo", 154, "neo"],
|
|
527
|
+
original: ["Stream Deck (2017)", 96, "classic", "original"],
|
|
528
|
+
classic: ["Stream Deck", 109, "classic"],
|
|
529
|
+
mk2: ["Stream Deck MK.2", 128, "classic"],
|
|
530
|
+
"mk2-scissor": ["Stream Deck MK.2 Scissor Keys", 165, "scissor"],
|
|
531
|
+
"module-15": ["Stream Deck Module 15 Keys", 185, "classic"],
|
|
532
|
+
"module-15-scissor": ["Stream Deck Module 15 Scissor Keys", 228, "scissor"],
|
|
533
|
+
xl: ["Stream Deck XL", 108, "xl"],
|
|
534
|
+
"xl-2022": ["Stream Deck XL (2022)", 143, "xl"],
|
|
535
|
+
"module-32": ["Stream Deck Module 32 Keys", 186, "xl"],
|
|
536
|
+
plus: ["Stream Deck +", 132, "plus"],
|
|
537
|
+
"plus-xl": ["Stream Deck + XL", 198, "plus-xl"],
|
|
538
|
+
mini: ["Stream Deck Mini", 99, "mini", "mini"],
|
|
539
|
+
"mini-2022": ["Stream Deck Mini (2022)", 144, "mini", "mini"],
|
|
540
|
+
"mini-discord": ["Stream Deck Mini Discord Edition", 179, "mini", "mini"],
|
|
541
|
+
"module-6": ["Stream Deck Module 6 Keys", 184, "mini", "mini"]
|
|
542
|
+
};
|
|
543
|
+
var MODELS = Object.fromEntries(Object.entries(TABLE).map(([id, [name, productId, family, protocol = "general"]]) => [
|
|
544
|
+
id,
|
|
545
|
+
{
|
|
546
|
+
id,
|
|
547
|
+
name,
|
|
548
|
+
vendorId: ELGATO_VENDOR_ID,
|
|
549
|
+
productId,
|
|
550
|
+
family,
|
|
551
|
+
protocol,
|
|
552
|
+
design: DESIGN,
|
|
553
|
+
...FAMILIES[family]
|
|
554
|
+
}
|
|
555
|
+
]));
|
|
556
|
+
var layoutOf = (family) => FAMILIES[family].layout;
|
|
557
|
+
var NEO_LAYOUT = NEO;
|
|
558
|
+
|
|
559
|
+
// src/detect.ts
|
|
560
|
+
function createStreamDeck(transport, model) {
|
|
561
|
+
return model.protocol === "general" ? new ElgatoStreamDeck(transport, model) : new LegacyStreamDeck(transport, model);
|
|
562
|
+
}
|
|
563
|
+
var drivers = Object.values(MODELS).map((model) => ({
|
|
564
|
+
model,
|
|
565
|
+
create: (transport) => createStreamDeck(transport, model)
|
|
566
|
+
}));
|
|
567
|
+
var driversOf = (models) => models ? drivers.filter(({ model }) => models.includes(model.id)) : drivers;
|
|
568
|
+
var toInfo = ({ path, serialNumber, driver }) => ({
|
|
569
|
+
path,
|
|
570
|
+
serialNumber,
|
|
571
|
+
model: driver.model
|
|
572
|
+
});
|
|
573
|
+
function findStreamDecks(devices) {
|
|
574
|
+
return findDecks(devices, drivers).map(toInfo);
|
|
575
|
+
}
|
|
576
|
+
async function listStreamDecks(options = {}) {
|
|
577
|
+
return (await listDecks(drivers, options)).map(toInfo);
|
|
578
|
+
}
|
|
579
|
+
async function openStreamDeck({
|
|
580
|
+
models,
|
|
581
|
+
...options
|
|
582
|
+
} = {}) {
|
|
583
|
+
return openDeck(driversOf(models), options);
|
|
584
|
+
}
|
|
585
|
+
// src/virtual.ts
|
|
586
|
+
import {
|
|
587
|
+
createMemoryTransport,
|
|
588
|
+
inputDriver
|
|
589
|
+
} from "@sdeck/core";
|
|
590
|
+
function createVirtualStreamDeck(id = "neo", options = {}) {
|
|
591
|
+
const model = MODELS[id];
|
|
592
|
+
const serial = new TextEncoder().encode(options.serialNumber ?? "VIRTUAL");
|
|
593
|
+
const general = model.protocol === "general";
|
|
594
|
+
const transport = createMemoryTransport({
|
|
595
|
+
...options.latencyMs !== undefined && { latencyMs: options.latencyMs },
|
|
596
|
+
getFeature(reportId, length) {
|
|
597
|
+
const report = new Uint8Array(Math.max(length, FEATURE_REPORT_SIZE));
|
|
598
|
+
report[0] = reportId;
|
|
599
|
+
if (reportId === (general ? GetterReportId.SerialNumber : 3)) {
|
|
600
|
+
const at = general ? 2 : 5;
|
|
601
|
+
const bytes = serial.subarray(0, report.length - at);
|
|
602
|
+
if (general)
|
|
603
|
+
report[1] = bytes.length;
|
|
604
|
+
report.set(bytes, at);
|
|
605
|
+
}
|
|
606
|
+
return report;
|
|
607
|
+
}
|
|
608
|
+
});
|
|
609
|
+
const deck = createStreamDeck(transport, model);
|
|
610
|
+
const input = inputDriver(deck, (event) => {
|
|
611
|
+
if (general)
|
|
612
|
+
return transport.input(inputReport(event));
|
|
613
|
+
if (event.type !== "buttons")
|
|
614
|
+
return;
|
|
615
|
+
const report = new Uint8Array(65);
|
|
616
|
+
report[0] = 1;
|
|
617
|
+
event.pressed.forEach((down, key) => {
|
|
618
|
+
const number = model.protocol === "original" ? key + 4 - 2 * (key % 5) : key;
|
|
619
|
+
report[1 + number] = Number(down);
|
|
620
|
+
});
|
|
621
|
+
transport.input(report);
|
|
622
|
+
});
|
|
623
|
+
return {
|
|
624
|
+
deck,
|
|
625
|
+
transport,
|
|
626
|
+
...input,
|
|
627
|
+
tap(key) {
|
|
628
|
+
input.press(key);
|
|
629
|
+
input.release(key);
|
|
630
|
+
},
|
|
631
|
+
unplug: () => transport.fail()
|
|
632
|
+
};
|
|
633
|
+
}
|
|
634
|
+
export {
|
|
635
|
+
ELGATO_VENDOR_ID,
|
|
636
|
+
ElgatoStreamDeck,
|
|
637
|
+
FEATURE_REPORT_SIZE,
|
|
638
|
+
GetterReportId,
|
|
639
|
+
INPUT_REPORT_ID,
|
|
640
|
+
LegacyStreamDeck,
|
|
641
|
+
MODELS,
|
|
642
|
+
NEO_LAYOUT,
|
|
643
|
+
OUTPUT_REPORT_ID,
|
|
644
|
+
OUTPUT_REPORT_SIZE,
|
|
645
|
+
SETTER_REPORT_ID,
|
|
646
|
+
brightnessReport,
|
|
647
|
+
buttonImagePackets,
|
|
648
|
+
createStreamDeck,
|
|
649
|
+
createVirtualStreamDeck,
|
|
650
|
+
drivers,
|
|
651
|
+
fillKeyReport,
|
|
652
|
+
fillLcdReport,
|
|
653
|
+
findStreamDecks,
|
|
654
|
+
fullScreenImagePackets,
|
|
655
|
+
inputReport,
|
|
656
|
+
keyBitmap,
|
|
657
|
+
layoutOf,
|
|
658
|
+
legacyBrightnessReport,
|
|
659
|
+
legacyKeyPackets,
|
|
660
|
+
legacyLogoReport,
|
|
661
|
+
legacySleepReport,
|
|
662
|
+
listStreamDecks,
|
|
663
|
+
openStreamDeck,
|
|
664
|
+
parseFirmwareVersion,
|
|
665
|
+
parseInputReport,
|
|
666
|
+
parseSerialNumber,
|
|
667
|
+
parseSleepDuration,
|
|
668
|
+
parseUnitInformation,
|
|
669
|
+
partialWindowImagePackets,
|
|
670
|
+
showLogoReport,
|
|
671
|
+
sleepDurationReport,
|
|
672
|
+
windowImagePackets
|
|
673
|
+
};
|
|
674
|
+
|
|
675
|
+
//# debugId=4D6F5889A584765C64756E2164756E21
|